LuaFunctions.cpp 435 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 561 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. if(spawn->GetSpawnGroupID() == new_group_id) {
  685. lua_interface->SetBooleanValue(state, false);
  686. return 1;
  687. }
  688. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  689. lua_interface->SetBooleanValue(state, true);
  690. return 1;
  691. }
  692. lua_interface->SetBooleanValue(state, false);
  693. return 1;
  694. }
  695. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  696. Spawn* spawn = lua_interface->GetSpawn(state);
  697. lua_interface->ResetFunctionStack(state);
  698. if (spawn) {
  699. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  700. return 1;
  701. }
  702. return 0;
  703. }
  704. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  705. Spawn* spawn = lua_interface->GetSpawn(state);
  706. lua_interface->ResetFunctionStack(state);
  707. if (spawn) {
  708. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  709. return 1;
  710. }
  711. return 0;
  712. }
  713. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  714. Player* player = (Player*)lua_interface->GetSpawn(state);
  715. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  716. lua_interface->ResetFunctionStack(state);
  717. if (player && player->IsPlayer() && faction_id > 0) {
  718. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  719. return 1;
  720. }
  721. return 0;
  722. }
  723. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  724. if (!lua_interface)
  725. return 0;
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. int32 value = lua_interface->GetInt32Value(state, 2);
  728. lua_interface->ResetFunctionStack(state);
  729. if (spawn) {
  730. spawn->SetFactionID(value);
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  735. Spawn* spawn = lua_interface->GetSpawn(state);
  736. lua_interface->ResetFunctionStack(state);
  737. if (spawn) {
  738. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  739. return 1;
  740. }
  741. return 0;
  742. }
  743. int EQ2Emu_lua_GetGender(lua_State* state) {
  744. Spawn* spawn = lua_interface->GetSpawn(state);
  745. lua_interface->ResetFunctionStack(state);
  746. if (spawn) {
  747. lua_interface->SetInt32Value(state, spawn->GetGender());
  748. return 1;
  749. }
  750. return 0;
  751. }
  752. int EQ2Emu_lua_GetTarget(lua_State* state) {
  753. Spawn* spawn = lua_interface->GetSpawn(state);
  754. lua_interface->ResetFunctionStack(state);
  755. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  756. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  757. return 1;
  758. }
  759. return 0;
  760. }
  761. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  762. if (!lua_interface)
  763. return 0;
  764. Spawn* spawn = lua_interface->GetSpawn(state);
  765. string mp3_string = lua_interface->GetStringValue(state, 2);
  766. int32 key1 = lua_interface->GetInt32Value(state, 3);
  767. int32 key2 = lua_interface->GetInt32Value(state, 4);
  768. Spawn* player = lua_interface->GetSpawn(state, 5);
  769. lua_interface->ResetFunctionStack(state);
  770. if (spawn && mp3_string.length() > 0) {
  771. Client* client = 0;
  772. if (player && player->IsPlayer())
  773. client = ((Player*)player)->GetClient();
  774. if (client) {
  775. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  776. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  777. }
  778. else
  779. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  780. }
  781. return 0;
  782. }
  783. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  784. if (!lua_interface)
  785. return 0;
  786. Spawn* spawn = lua_interface->GetSpawn(state);
  787. lua_interface->ResetFunctionStack(state);
  788. if (spawn) {
  789. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  790. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  791. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  792. return 3;
  793. }
  794. return 0;
  795. }
  796. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. lua_interface->ResetFunctionStack(state);
  803. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  804. return 1;
  805. }
  806. lua_interface->ResetFunctionStack(state);
  807. return 0;
  808. }
  809. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. Spawn* spawn = lua_interface->GetSpawn(state);
  813. if (spawn && spawn->IsEntity()) {
  814. int32 item_id = lua_interface->GetInt32Value(state, 2);
  815. int16 charges = lua_interface->GetInt16Value(state, 3);
  816. if (charges == 0)
  817. charges = 1;
  818. ((Entity*)spawn)->AddLootItem(item_id, charges);
  819. }
  820. lua_interface->ResetFunctionStack(state);
  821. return 0;
  822. }
  823. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  824. if (!lua_interface)
  825. return 0;
  826. Spawn* spawn = lua_interface->GetSpawn(state);
  827. if (spawn && spawn->IsEntity()) {
  828. int32 item_id = lua_interface->GetInt32Value(state, 2);
  829. Item* item = spawn->LootItem(item_id);
  830. lua_interface->SetLuaUserDataStale(item);
  831. safe_delete(item);
  832. }
  833. lua_interface->ResetFunctionStack(state);
  834. return 0;
  835. }
  836. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  837. if (!lua_interface)
  838. return 0;
  839. Spawn* spawn = lua_interface->GetSpawn(state);
  840. if (spawn) {
  841. int32 val = lua_interface->GetInt32Value(state, 2);
  842. spawn->AddLootCoins(val);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. if (entity && player && player->IsPlayer()) {
  853. int32 coins = lua_interface->GetInt32Value(state, 3);
  854. vector<Item*>* items = 0;
  855. int i = 0;
  856. int32 item_id = 0;
  857. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  858. if (items == 0)
  859. items = new vector<Item*>;
  860. if (master_item_list.GetItem(item_id))
  861. items->push_back(master_item_list.GetItem(item_id));
  862. i++;
  863. }
  864. Client* client = 0;
  865. client = ((Player*)player)->GetClient();
  866. if (client)
  867. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  868. if(coins > 0)
  869. entity->AddLootCoins(coins);
  870. safe_delete(items);
  871. }
  872. lua_interface->ResetFunctionStack(state);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  876. if (!lua_interface)
  877. return 0;
  878. Spawn* entity = lua_interface->GetSpawn(state);
  879. Spawn* player = lua_interface->GetSpawn(state, 2);
  880. int32 item_id = lua_interface->GetInt32Value(state, 3);
  881. lua_interface->ResetFunctionStack(state);
  882. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  883. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  884. return 1;
  885. }
  886. return 0;
  887. }
  888. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  889. if (!lua_interface)
  890. return 0;
  891. Spawn* entity = lua_interface->GetSpawn(state);
  892. Spawn* player = lua_interface->GetSpawn(state, 2);
  893. lua_interface->ResetFunctionStack(state);
  894. if (entity && player && player->IsPlayer()) {
  895. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  896. return 1;
  897. }
  898. return 0;
  899. }
  900. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  901. if (!lua_interface)
  902. return 0;
  903. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  904. lua_interface->SetLuaUserDataStale(conversation);
  905. safe_delete(conversation);
  906. lua_interface->ResetFunctionStack(state);
  907. conversation = new vector<ConversationOption>();
  908. lua_interface->SetConversationValue(state, conversation);
  909. return 1;
  910. }
  911. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  915. if (conversation) {
  916. ConversationOption conv_option;
  917. conv_option.option = lua_interface->GetStringValue(state, 2);
  918. conv_option.function = lua_interface->GetStringValue(state, 3);
  919. if (conv_option.option.length() > 0)
  920. conversation->push_back(conv_option);
  921. }
  922. lua_interface->ResetFunctionStack(state);
  923. return 0;
  924. }
  925. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  926. if (!lua_interface)
  927. return 0;
  928. Spawn* npc = lua_interface->GetSpawn(state);
  929. Spawn* player = lua_interface->GetSpawn(state, 2);
  930. lua_interface->ResetFunctionStack(state);
  931. if (npc && player && player->IsPlayer() && player->GetZone()) {
  932. Client* client = ((Player*)player)->GetClient();
  933. if (client) {
  934. int32 conversation_id = client->GetConversationID(npc, 0);
  935. client->CloseDialog(conversation_id);
  936. }
  937. }
  938. return 0;
  939. }
  940. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  941. if (!lua_interface)
  942. return 0;
  943. Item* item = lua_interface->GetItem(state);
  944. Spawn* player = lua_interface->GetSpawn(state, 2);
  945. lua_interface->ResetFunctionStack(state);
  946. if (item && player && player->IsPlayer() && player->GetZone()) {
  947. Client* client = ((Player*)player)->GetClient();
  948. if (client) {
  949. int32 conversation_id = client->GetConversationID(0, item);
  950. client->CloseDialog(conversation_id);
  951. }
  952. }
  953. return 0;
  954. }
  955. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  956. if (!lua_interface)
  957. return 0;
  958. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  959. Spawn* spawn = 0;
  960. Item* item = 0;
  961. int8 type = lua_interface->GetInt8Value(state, 2);
  962. if (type == 1 || type == 3)
  963. spawn = lua_interface->GetSpawn(state, 3);
  964. else if (type == 2 || type == 4)
  965. item = lua_interface->GetItem(state, 3);
  966. Spawn* player = lua_interface->GetSpawn(state, 4);
  967. string text = lua_interface->GetStringValue(state, 5);
  968. string mp3 = lua_interface->GetStringValue(state, 6);
  969. int32 key1 = lua_interface->GetInt32Value(state, 7);
  970. int32 key2 = lua_interface->GetInt32Value(state, 8);
  971. int8 language = lua_interface->GetInt8Value(state, 9);
  972. int numargs = lua_interface->GetNumberOfArgs(state);
  973. int8 can_close = 1;
  974. if(numargs > 9)
  975. can_close = lua_interface->GetInt32Value(state, 10);
  976. lua_interface->ResetFunctionStack(state);
  977. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  978. Client* client = ((Player*)player)->GetClient();
  979. if (client) {
  980. if (spawn) {
  981. // Need to do this so the function works the same as it did before
  982. if (type == 1)
  983. type++;
  984. if (mp3.length() > 0)
  985. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  986. else
  987. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  988. }
  989. else {
  990. if (mp3.length() > 0)
  991. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  992. else
  993. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  994. }
  995. }
  996. }
  997. lua_interface->SetLuaUserDataStale(conversation);
  998. safe_delete(conversation);
  999. return 0;
  1000. }
  1001. int EQ2Emu_lua_StartConversation(lua_State* state) {
  1002. if (!lua_interface)
  1003. return 0;
  1004. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1005. Spawn* source = lua_interface->GetSpawn(state, 2);
  1006. Spawn* player = lua_interface->GetSpawn(state, 3);
  1007. string text = lua_interface->GetStringValue(state, 4);
  1008. string mp3 = lua_interface->GetStringValue(state, 5);
  1009. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1010. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1011. int8 language = lua_interface->GetInt32Value(state, 8);
  1012. int numargs = lua_interface->GetNumberOfArgs(state);
  1013. int8 can_close = 1;
  1014. if(numargs > 8)
  1015. can_close = lua_interface->GetInt32Value(state, 9);
  1016. lua_interface->ResetFunctionStack(state);
  1017. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1018. Client* client = ((Player*)player)->GetClient();
  1019. if (mp3.length() > 0)
  1020. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1021. else
  1022. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1023. lua_interface->SetLuaUserDataStale(conversation);
  1024. safe_delete(conversation);
  1025. }
  1026. else
  1027. 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.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1028. return 0;
  1029. }
  1030. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1031. if (!lua_interface)
  1032. return 0;
  1033. Spawn* spawn = lua_interface->GetSpawn(state);
  1034. float distance = lua_interface->GetFloatValue(state, 2);
  1035. string in_range_function = lua_interface->GetStringValue(state, 3);
  1036. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1037. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1038. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1039. return 0;
  1040. }
  1041. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1042. ZoneServer* zone = lua_interface->GetZone(state);
  1043. float x = lua_interface->GetFloatValue(state, 2);
  1044. float y = lua_interface->GetFloatValue(state, 3);
  1045. float z = lua_interface->GetFloatValue(state, 4);
  1046. float max_variation = lua_interface->GetFloatValue(state, 5);
  1047. string in_range_function = lua_interface->GetStringValue(state, 6);
  1048. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1049. lua_interface->ResetFunctionStack(state);
  1050. if (zone && in_range_function.length() > 0)
  1051. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1052. return 0;
  1053. }
  1054. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1055. if (!lua_interface)
  1056. return 0;
  1057. Spawn* spawn = lua_interface->GetSpawn(state);
  1058. if (spawn && spawn->IsEntity()) {
  1059. int32 val = lua_interface->GetInt32Value(state, 2);
  1060. ((Entity*)spawn)->SetLootCoins(val);
  1061. }
  1062. lua_interface->ResetFunctionStack(state);
  1063. return 0;
  1064. }
  1065. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1066. if (!lua_interface)
  1067. return 0;
  1068. Spawn* spawn = lua_interface->GetSpawn(state);
  1069. lua_interface->ResetFunctionStack(state);
  1070. if (spawn && spawn->IsEntity()) {
  1071. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1072. return 1;
  1073. }
  1074. return 0;
  1075. }
  1076. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1077. if (!lua_interface)
  1078. return 0;
  1079. Spawn* spawn = lua_interface->GetSpawn(state);
  1080. float x = lua_interface->GetFloatValue(state, 2);
  1081. float y = lua_interface->GetFloatValue(state, 3);
  1082. float z = lua_interface->GetFloatValue(state, 4);
  1083. float speed = lua_interface->GetFloatValue(state, 5);
  1084. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1085. string function = lua_interface->GetStringValue(state, 7);
  1086. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1087. float heading = lua_interface->GetFloatValue(state, 8);
  1088. if (spawn) {
  1089. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1090. spawn->GetZone()->AddMovementNPC(spawn);
  1091. }
  1092. lua_interface->ResetFunctionStack(state);
  1093. return 0;
  1094. }
  1095. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1096. if (!lua_interface)
  1097. return 0;
  1098. Spawn* spawn = lua_interface->GetSpawn(state);
  1099. lua_interface->ResetFunctionStack(state);
  1100. if (spawn) {
  1101. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1102. return 1;
  1103. }
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* spawn = lua_interface->GetSpawn(state);
  1110. lua_interface->ResetFunctionStack(state);
  1111. if (spawn && spawn->IsPlayer()) {
  1112. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1113. return 1;
  1114. }
  1115. lua_interface->SetInt32Value(state, 0);
  1116. return 1;
  1117. }
  1118. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. Spawn* target = lua_interface->GetSpawn(state, 2);
  1123. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1124. bool reset_action_state = true;
  1125. if(num_args > 2)
  1126. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1127. if (spawn && target) {
  1128. if (spawn->IsEntity())
  1129. // ((Entity*)spawn)->FaceTarget(target);
  1130. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1131. }
  1132. lua_interface->ResetFunctionStack(state);
  1133. return 0;
  1134. }
  1135. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1136. if (!lua_interface)
  1137. return 0;
  1138. Spawn* spawn = lua_interface->GetSpawn(state);
  1139. float x = lua_interface->GetFloatValue(state, 2);
  1140. float y = lua_interface->GetFloatValue(state, 3);
  1141. float z = lua_interface->GetFloatValue(state, 4);
  1142. float speed = lua_interface->GetFloatValue(state, 5);
  1143. string lua_function = lua_interface->GetStringValue(state, 6);
  1144. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1145. if (spawn) {
  1146. if (speed == 0)
  1147. speed = spawn->GetSpeed();
  1148. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1149. }
  1150. lua_interface->ResetFunctionStack(state);
  1151. return 0;
  1152. }
  1153. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1154. if (!lua_interface)
  1155. return 0;
  1156. Spawn* spawn = lua_interface->GetSpawn(state);
  1157. lua_interface->ResetFunctionStack(state);
  1158. if (spawn) {
  1159. spawn->ClearRunningLocations();
  1160. }
  1161. return 0;
  1162. }
  1163. int EQ2Emu_lua_Say(lua_State* state) {
  1164. if (!lua_interface)
  1165. return 0;
  1166. Spawn* spawn = lua_interface->GetSpawn(state);
  1167. string message = lua_interface->GetStringValue(state, 2);
  1168. Spawn* player = lua_interface->GetSpawn(state, 3);
  1169. float dist = lua_interface->GetFloatValue(state, 4);
  1170. int32 language = lua_interface->GetInt32Value(state, 5);
  1171. if (spawn && message.length() > 0) {
  1172. Client* client = 0;
  1173. if (player && player->IsPlayer())
  1174. client = ((Player*)player)->GetClient();
  1175. if (client)
  1176. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1177. else
  1178. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1179. }
  1180. lua_interface->ResetFunctionStack(state);
  1181. return 0;
  1182. }
  1183. int EQ2Emu_lua_Shout(lua_State* state) {
  1184. if (!lua_interface)
  1185. return 0;
  1186. Spawn* spawn = lua_interface->GetSpawn(state);
  1187. string message = lua_interface->GetStringValue(state, 2);
  1188. Spawn* player = lua_interface->GetSpawn(state, 3);
  1189. float dist = lua_interface->GetFloatValue(state, 4);
  1190. int32 language = lua_interface->GetInt32Value(state, 5);
  1191. if (spawn && message.length() > 0) {
  1192. Client* client = 0;
  1193. if (player && player->IsPlayer())
  1194. client = ((Player*)player)->GetClient();
  1195. if (client)
  1196. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1197. else
  1198. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1199. }
  1200. lua_interface->ResetFunctionStack(state);
  1201. return 0;
  1202. }
  1203. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1204. if (!lua_interface)
  1205. return 0;
  1206. Spawn* spawn = lua_interface->GetSpawn(state);
  1207. string message = lua_interface->GetStringValue(state, 2);
  1208. Spawn* player = lua_interface->GetSpawn(state, 3);
  1209. float dist = lua_interface->GetFloatValue(state, 4);
  1210. int32 language = lua_interface->GetInt32Value(state, 5);
  1211. if (spawn && message.length() > 0) {
  1212. Client* client = 0;
  1213. if (player && player->IsPlayer())
  1214. client = ((Player*)player)->GetClient();
  1215. if (client)
  1216. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1217. else
  1218. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1219. }
  1220. lua_interface->ResetFunctionStack(state);
  1221. return 0;
  1222. }
  1223. int EQ2Emu_lua_Emote(lua_State* state) {
  1224. if (!lua_interface)
  1225. return 0;
  1226. Spawn* spawn = lua_interface->GetSpawn(state);
  1227. string message = lua_interface->GetStringValue(state, 2);
  1228. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1229. Spawn* player = lua_interface->GetSpawn(state, 4);
  1230. char* to = 0;
  1231. if (spawn2)
  1232. to = spawn2->GetName();
  1233. if (spawn && message.length() > 0) {
  1234. Client* client = 0;
  1235. if (player && player->IsPlayer())
  1236. client = ((Player*)player)->GetClient();
  1237. if (client)
  1238. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1239. else
  1240. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1241. }
  1242. lua_interface->ResetFunctionStack(state);
  1243. return 0;
  1244. }
  1245. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1246. if (!lua_interface)
  1247. return 0;
  1248. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1249. if(!luaspell || luaspell->resisted) {
  1250. lua_interface->ResetFunctionStack(state);
  1251. return 0;
  1252. }
  1253. Spawn* caster = luaspell->caster;
  1254. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1255. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1256. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1257. Spawn* target = lua_interface->GetSpawn(state, 4);
  1258. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1259. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1260. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1261. lua_interface->ResetFunctionStack(state);
  1262. boost::to_lower(heal_type);
  1263. if (caster && caster->IsEntity()) {
  1264. bool success = false;
  1265. luaspell->resisted = false;
  1266. if (target) {
  1267. float distance = caster->GetDistance(target, true);
  1268. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1269. success = true;
  1270. }
  1271. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1272. Spawn* target = 0;
  1273. ZoneServer* zone = luaspell->caster->GetZone();
  1274. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1275. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1276. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1277. float distance = caster->GetDistance(target, true);
  1278. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1279. }
  1280. }
  1281. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1282. success = true;
  1283. }
  1284. if (success) {
  1285. if (caster->GetZone())
  1286. caster->GetZone()->TriggerCharSheetTimer();
  1287. }
  1288. }
  1289. return 0;
  1290. }
  1291. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1292. if (!lua_interface)
  1293. return 0;
  1294. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1295. if(!luaspell || luaspell->resisted) {
  1296. lua_interface->ResetFunctionStack(state);
  1297. return 0;
  1298. }
  1299. Spawn* caster = luaspell->caster;
  1300. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1301. float percentage = lua_interface->GetFloatValue(state, 2);
  1302. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1303. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1304. Spawn* target = lua_interface->GetSpawn(state, 5);
  1305. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1306. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1307. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1308. lua_interface->ResetFunctionStack(state);
  1309. boost::to_lower(heal_type);
  1310. int32 min_heal = 0, max_heal = 0;
  1311. if (caster && caster->IsEntity() && target) {
  1312. if(percentage <= 0.0f)
  1313. {
  1314. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1315. return 0;
  1316. }
  1317. if(heal_type == "power")
  1318. {
  1319. if(current_value)
  1320. {
  1321. if(caster_value)
  1322. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1323. else
  1324. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1325. }
  1326. else
  1327. {
  1328. if(caster_value)
  1329. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1330. else
  1331. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1332. }
  1333. }
  1334. else
  1335. {
  1336. if(current_value)
  1337. {
  1338. if(caster_value)
  1339. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1340. else
  1341. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1342. }
  1343. else
  1344. {
  1345. if(caster_value)
  1346. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1347. else
  1348. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1349. }
  1350. }
  1351. bool success = false;
  1352. luaspell->resisted = false;
  1353. if (target) {
  1354. float distance = caster->GetDistance(target, true);
  1355. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1356. success = true;
  1357. }
  1358. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1359. Spawn* target = 0;
  1360. ZoneServer* zone = luaspell->caster->GetZone();
  1361. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1362. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1363. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1364. float distance = caster->GetDistance(target, true);
  1365. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1366. }
  1367. }
  1368. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1369. success = true;
  1370. }
  1371. if (success) {
  1372. if (caster->GetZone())
  1373. caster->GetZone()->TriggerCharSheetTimer();
  1374. }
  1375. }
  1376. return 0;
  1377. }
  1378. int EQ2Emu_lua_AddItem(lua_State* state) {
  1379. if (!lua_interface)
  1380. return 0;
  1381. Spawn* spawn = lua_interface->GetSpawn(state);
  1382. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1383. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1384. lua_interface->ResetFunctionStack(state);
  1385. // default of 1 quantity to add
  1386. if (quantity == 0)
  1387. quantity = 1;
  1388. if (spawn && spawn->IsPlayer()) {
  1389. Client* client = ((Player*)spawn)->GetClient();
  1390. if (client && item_id > 0) {
  1391. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1392. return 1;
  1393. }
  1394. }
  1395. lua_interface->SetBooleanValue(state, false);
  1396. return 1;
  1397. }
  1398. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1399. if (!lua_interface)
  1400. return 0;
  1401. Spawn* spawn = lua_interface->GetSpawn(state);
  1402. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1403. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1404. string location = lua_interface->GetStringValue(state, 4);
  1405. int16 item_count = lua_interface->GetInt16Value(state,5);
  1406. //devn00b: if we dont have a count, assume 1 item.
  1407. if(!item_count) {
  1408. item_count = 1;
  1409. }
  1410. lua_interface->ResetFunctionStack(state);
  1411. if (spawn && spawn->IsPlayer()) {
  1412. Client* client = ((Player*)spawn)->GetClient();
  1413. if (client && item_id > 0) {
  1414. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1415. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1416. else
  1417. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1418. if (send_messages) {
  1419. Item* item = master_item_list.GetItem(item_id);
  1420. if (item) {
  1421. if(item_count > 1) {
  1422. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1423. string popup_text1 = "You receive "+ item_count;
  1424. string popup_text2 = " " + item->name;
  1425. string popup_text = popup_text1 + popup_text2;
  1426. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1427. // return 1;
  1428. } else {
  1429. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1430. string popup_text = "You receive " + item->name;
  1431. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1432. }
  1433. }
  1434. }
  1435. return 1;
  1436. }
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1442. Spawn* spawn = lua_interface->GetSpawn(state);
  1443. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1444. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1445. lua_interface->ResetFunctionStack(state);
  1446. // default of 1 to remove
  1447. if (quantity == 0)
  1448. quantity = 1;
  1449. Client* client;
  1450. Item* item;
  1451. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1452. if ((client = ((Player*)spawn)->GetClient())) {
  1453. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1454. if (client->RemoveItem(item, quantity)) {
  1455. lua_interface->SetBooleanValue(state, true);
  1456. return 1;
  1457. }
  1458. }
  1459. }
  1460. }
  1461. lua_interface->SetBooleanValue(state, false);
  1462. return 1;
  1463. }
  1464. int EQ2Emu_lua_HasItem(lua_State* state) {
  1465. Spawn* player = lua_interface->GetSpawn(state);
  1466. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1467. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1468. lua_interface->ResetFunctionStack(state);
  1469. if (player && player->IsPlayer()) {
  1470. bool hasItem = false;
  1471. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1472. if (!hasItem)
  1473. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1474. lua_interface->SetBooleanValue(state, hasItem);
  1475. return 1;
  1476. }
  1477. lua_interface->SetBooleanValue(state, false);
  1478. return 1;
  1479. }
  1480. int EQ2Emu_lua_Spawn(lua_State* state) {
  1481. if (!lua_interface)
  1482. return 0;
  1483. ZoneServer* zone = lua_interface->GetZone(state);
  1484. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1485. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1486. float x = lua_interface->GetFloatValue(state, 4);
  1487. float y = lua_interface->GetFloatValue(state, 5);
  1488. float z = lua_interface->GetFloatValue(state, 6);
  1489. float heading = lua_interface->GetFloatValue(state, 7);
  1490. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1491. Spawn* spawn = zone->GetSpawn(spawn_id);
  1492. if (!spawn)
  1493. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1494. else {
  1495. spawn->SetX(x);
  1496. spawn->SetZ(z);
  1497. spawn->SetY(y,true,true);
  1498. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1499. spawn->SetHeading(heading);
  1500. if (restricted_npc)
  1501. spawn->AddAllowAccessSpawn(spawn);
  1502. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1503. bool scriptActive = false;
  1504. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1505. scriptActive = true;
  1506. spawn->SetSpawnScript(string(spawn_script));
  1507. }
  1508. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1509. zone->AddSpawn(spawn);
  1510. if (scriptActive) {
  1511. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1512. }
  1513. lua_interface->ResetFunctionStack(state);
  1514. lua_interface->SetSpawnValue(state, spawn);
  1515. return 1;
  1516. }
  1517. }
  1518. else {
  1519. string output = "Invalid paramaters to LUA Spawn command: \n";
  1520. if (!zone)
  1521. output = output.append("\t").append("Missing zone reference. \n");
  1522. if (spawn_id == 0)
  1523. output = output.append("\t").append("Missing spawn_id.");
  1524. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1525. }
  1526. lua_interface->ResetFunctionStack(state);
  1527. return 0;
  1528. }
  1529. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1530. if (!lua_interface)
  1531. return 0;
  1532. ZoneServer* zone = lua_interface->GetZone(state);
  1533. lua_interface->ResetFunctionStack(state);
  1534. if (zone) {
  1535. lua_interface->SetStringValue(state, zone->GetZoneName());
  1536. return 1;
  1537. }
  1538. return 0;
  1539. }
  1540. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1541. if (!lua_interface)
  1542. return 0;
  1543. ZoneServer* zone = lua_interface->GetZone(state);
  1544. lua_interface->ResetFunctionStack(state);
  1545. if (zone) {
  1546. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. int EQ2Emu_lua_GetZone(lua_State* state) {
  1552. if (!lua_interface)
  1553. return 0;
  1554. int32 zone_id = lua_interface->GetInt32Value(state);
  1555. ZoneServer* zone = 0;
  1556. if (zone_id > 0)
  1557. zone = zone_list.Get(zone_id, true, false, false);
  1558. else {
  1559. string zone_name = lua_interface->GetStringValue(state);
  1560. if (zone_name.length() > 0) {
  1561. zone = zone_list.Get(zone_name.c_str(), true, false, false);
  1562. }
  1563. else {
  1564. Spawn* spawn = lua_interface->GetSpawn(state);
  1565. if (spawn)
  1566. zone = spawn->GetZone();
  1567. }
  1568. }
  1569. lua_interface->ResetFunctionStack(state);
  1570. if (zone) {
  1571. lua_interface->SetZoneValue(state, zone);
  1572. return 1;
  1573. }
  1574. return 0;
  1575. }
  1576. int EQ2Emu_lua_AddHate(lua_State* state) {
  1577. Spawn* entity = lua_interface->GetSpawn(state);
  1578. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1579. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1580. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1581. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1582. if(luaspell && luaspell->resisted) {
  1583. lua_interface->ResetFunctionStack(state);
  1584. return 0;
  1585. }
  1586. if (entity && entity->IsEntity() && amount != 0) {
  1587. if (luaspell && luaspell->caster) {
  1588. ZoneServer* zone = luaspell->caster->GetZone();
  1589. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1590. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1591. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1592. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1593. entity->CheckEncounterState((Entity*)spawn);
  1594. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1595. if (send_packet)
  1596. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1597. }
  1598. }
  1599. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1600. }
  1601. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1602. entity->CheckEncounterState((Entity*)npc);
  1603. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1604. }
  1605. }
  1606. lua_interface->ResetFunctionStack(state);
  1607. return 0;
  1608. }
  1609. int EQ2Emu_lua_Zone(lua_State* state) {
  1610. if (!lua_interface)
  1611. return 0;
  1612. ZoneServer* zone = lua_interface->GetZone(state);
  1613. Spawn* player = lua_interface->GetSpawn(state, 2);
  1614. Client* client = 0;
  1615. if (player && player->IsPlayer())
  1616. client = ((Player*)player)->GetClient();
  1617. float x = lua_interface->GetFloatValue(state, 3);
  1618. float y = lua_interface->GetFloatValue(state, 4);
  1619. float z = lua_interface->GetFloatValue(state, 5);
  1620. float heading = lua_interface->GetFloatValue(state, 6);
  1621. if (zone && client) {
  1622. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1623. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1624. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1625. {
  1626. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1627. return 0;
  1628. }
  1629. if (x != 0 || y != 0 || z != 0) {
  1630. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1631. player->SetX(x);
  1632. player->SetY(y);
  1633. player->SetZ(z);
  1634. player->SetHeading(heading);
  1635. client->Zone(zone->GetZoneName(), false);
  1636. }
  1637. else
  1638. client->Zone(zone->GetZoneName());
  1639. }
  1640. else
  1641. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1642. lua_interface->ResetFunctionStack(state);
  1643. return 0;
  1644. }
  1645. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1646. if (!lua_interface)
  1647. return 0;
  1648. Spawn* spawn = lua_interface->GetSpawn(state);
  1649. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1650. if (spawn && spawn2)
  1651. spawn->AddAllowAccessSpawn(spawn2);
  1652. lua_interface->ResetFunctionStack(state);
  1653. return 0;
  1654. }
  1655. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1656. if (!lua_interface)
  1657. return 0;
  1658. Spawn* target = lua_interface->GetSpawn(state);
  1659. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1660. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1661. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1662. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (!target) {
  1665. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1666. return 0;
  1667. }
  1668. if (!target->IsEntity()) {
  1669. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1670. return 0;
  1671. }
  1672. if (spell_id <= 0) {
  1673. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1674. return 0;
  1675. }
  1676. if (caster && !caster->IsEntity()) {
  1677. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1678. return 0;
  1679. }
  1680. if (spell_tier == 0)
  1681. spell_tier = 1;
  1682. if (!caster)
  1683. caster = target;
  1684. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1685. return 0;
  1686. }
  1687. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1688. if (!lua_interface)
  1689. return 0;
  1690. Spawn* target = lua_interface->GetSpawn(state);
  1691. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1692. if(!luaspell || luaspell->resisted) {
  1693. lua_interface->ResetFunctionStack(state);
  1694. lua_interface->SetBooleanValue(state, false);
  1695. return 1;
  1696. }
  1697. Spawn* caster = luaspell->caster;
  1698. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1699. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1700. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1701. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1702. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1703. //lua_interface->ResetFunctionStack(state);
  1704. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1705. vector<int16> faction_req;
  1706. vector<int16> race_req;
  1707. int32 class_req = 0;
  1708. int32 i = 0;
  1709. int8 f = 0;
  1710. int8 r = 0;
  1711. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1712. if (class_id < 100) {
  1713. class_req += pow(2.0, double(class_id - 1));
  1714. }
  1715. else if (class_id > 100 && class_id < 1000) {
  1716. race_req.push_back(class_id);
  1717. r++;
  1718. }
  1719. else {
  1720. faction_req.push_back(class_id);
  1721. f++;
  1722. }
  1723. i++;
  1724. }
  1725. lua_interface->ResetFunctionStack(state);
  1726. if (caster && caster->IsEntity()) {
  1727. bool race_match = false;
  1728. bool success = false;
  1729. luaspell->resisted = false;
  1730. if (luaspell->targets.size() > 0) {
  1731. ZoneServer* zone = luaspell->caster->GetZone();
  1732. Spawn* target = 0;
  1733. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1734. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1735. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1736. if (race_req.size() > 0) {
  1737. for (int8 i = 0; i < race_req.size(); i++) {
  1738. if(race_req[i] == target->GetRace() ||
  1739. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1740. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1741. race_match = true;
  1742. }
  1743. }
  1744. }
  1745. else
  1746. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1747. if (race_match == true) {
  1748. float distance = caster->GetDistance(target, true);
  1749. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1750. }
  1751. }
  1752. }
  1753. success = true;
  1754. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1755. }
  1756. else if (target) {
  1757. //check class and race/faction here
  1758. if (race_req.size() > 0) {
  1759. for (int8 i = 0; i < race_req.size(); i++) {
  1760. if(race_req[i] == target->GetRace() ||
  1761. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1762. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1763. race_match = true;
  1764. }
  1765. }
  1766. }
  1767. else
  1768. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1769. if (race_match == true) {
  1770. float distance = caster->GetDistance(target, true);
  1771. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1772. success = true;
  1773. }
  1774. }
  1775. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1776. if (success) {
  1777. Spell* spell = luaspell->spell;
  1778. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1779. ((Player*)caster)->InCombat(true);
  1780. if (caster->GetZone())
  1781. caster->GetZone()->TriggerCharSheetTimer();
  1782. }
  1783. }
  1784. }
  1785. else {
  1786. lua_interface->SetBooleanValue(state, false);
  1787. }
  1788. return 1;
  1789. }
  1790. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1791. if (!lua_interface)
  1792. return 0;
  1793. Spawn* target = lua_interface->GetSpawn(state);
  1794. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1795. if(!luaspell || luaspell->resisted) {
  1796. lua_interface->ResetFunctionStack(state);
  1797. lua_interface->SetBooleanValue(state, false);
  1798. return 1;
  1799. }
  1800. Spawn* caster = luaspell->caster;
  1801. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1802. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1803. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1804. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1805. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1806. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1807. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1808. //lua_interface->ResetFunctionStack(state);
  1809. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1810. vector<int16> faction_req;
  1811. vector<int16> race_req;
  1812. int32 class_req = 0;
  1813. int32 i = 0;
  1814. int8 f = 0;
  1815. int8 r = 0;
  1816. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1817. if (class_id < 100) {
  1818. class_req += pow(2.0, double(class_id - 1));
  1819. }
  1820. else if (class_id > 100 && class_id < 1000) {
  1821. race_req.push_back(class_id);
  1822. r++;
  1823. }
  1824. else {
  1825. faction_req.push_back(class_id);
  1826. f++;
  1827. }
  1828. i++;
  1829. }
  1830. lua_interface->ResetFunctionStack(state);
  1831. if (caster && caster->IsEntity()) {
  1832. bool race_match = false;
  1833. bool success = false;
  1834. luaspell->resisted = false;
  1835. if (luaspell->targets.size() > 0) {
  1836. ZoneServer* zone = luaspell->caster->GetZone();
  1837. Spawn* target = 0;
  1838. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1839. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1840. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1841. if (race_req.size() > 0) {
  1842. for (int8 i = 0; i < race_req.size(); i++) {
  1843. if(race_req[i] == target->GetRace() ||
  1844. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1845. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1846. race_match = true;
  1847. }
  1848. }
  1849. }
  1850. else
  1851. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1852. if (race_match == true) {
  1853. float distance = caster->GetDistance(target, true);
  1854. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1855. }
  1856. }
  1857. }
  1858. success = true;
  1859. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1860. }
  1861. else if (target) {
  1862. //check class and race/faction here
  1863. if (race_req.size() > 0) {
  1864. for (int8 i = 0; i < race_req.size(); i++) {
  1865. if(race_req[i] == target->GetRace() ||
  1866. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1867. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1868. race_match = true;
  1869. }
  1870. }
  1871. }
  1872. else
  1873. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1874. if (race_match == true) {
  1875. float distance = caster->GetDistance(target, true);
  1876. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1877. success = true;
  1878. }
  1879. }
  1880. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1881. if (success) {
  1882. Spell* spell = luaspell->spell;
  1883. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1884. ((Player*)caster)->InCombat(true);
  1885. if (caster->GetZone())
  1886. caster->GetZone()->TriggerCharSheetTimer();
  1887. }
  1888. }
  1889. }
  1890. else {
  1891. lua_interface->SetBooleanValue(state, false);
  1892. }
  1893. return 1;
  1894. }
  1895. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1896. if (!lua_interface)
  1897. return 0;
  1898. Spawn* spawn = lua_interface->GetSpawn(state);
  1899. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1900. lua_interface->ResetFunctionStack(state);
  1901. if (spawn && value != 0) {
  1902. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1903. spawn->SetPower(spawn->GetTotalPower());
  1904. else
  1905. spawn->SetPower(spawn->GetPower() + value);
  1906. }
  1907. return 0;
  1908. }
  1909. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1910. if (!lua_interface)
  1911. return 0;
  1912. Spawn* spawn = lua_interface->GetSpawn(state);
  1913. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1914. lua_interface->ResetFunctionStack(state);
  1915. if (spawn && value != 0) {
  1916. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1917. spawn->SetHP(spawn->GetTotalHP());
  1918. else
  1919. spawn->SetHP(spawn->GetHP() + value);
  1920. }
  1921. return 0;
  1922. }
  1923. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1924. if (!lua_interface)
  1925. return 0;
  1926. Spawn* spawn = lua_interface->GetSpawn(state);
  1927. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1928. lua_interface->ResetFunctionStack(state);
  1929. if (spawn && value != 0) {
  1930. spawn->SetTotalPower(value);
  1931. spawn->SetTotalPowerBaseInstance(value);
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1936. if (!lua_interface)
  1937. return 0;
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1940. lua_interface->ResetFunctionStack(state);
  1941. if (spawn && value != 0) {
  1942. spawn->SetTotalHP(value);
  1943. spawn->SetTotalHPBaseInstance(value);
  1944. }
  1945. return 0;
  1946. }
  1947. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1948. if (!lua_interface)
  1949. return 0;
  1950. Spawn* spawn = lua_interface->GetSpawn(state);
  1951. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1952. lua_interface->ResetFunctionStack(state);
  1953. if (spawn) {
  1954. spawn->SetHP(value);
  1955. if (value > spawn->GetTotalHPBase())
  1956. spawn->SetTotalHP(value);
  1957. }
  1958. return 0;
  1959. }
  1960. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1961. if (!lua_interface)
  1962. return 0;
  1963. Spawn* spawn = lua_interface->GetSpawn(state);
  1964. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1965. float value = lua_interface->GetFloatValue(state, 2);
  1966. lua_interface->ResetFunctionStack(state);
  1967. if (spawn && spawn->IsEntity() && value > 0)
  1968. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1969. if (spawn && spawn->IsPlayer())
  1970. ((Player*)spawn)->SetCharSheetChanged(true);
  1971. return 0;
  1972. }
  1973. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1974. if (!lua_interface)
  1975. return 0;
  1976. Spawn* spawn = lua_interface->GetSpawn(state);
  1977. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1978. lua_interface->ResetFunctionStack(state);
  1979. if (spawn && spawn->IsEntity() && value > 0)
  1980. ((Entity*)spawn)->SetTotalHPBase(value);
  1981. return 0;
  1982. }
  1983. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1984. if (!lua_interface)
  1985. return 0;
  1986. Spawn* spawn = lua_interface->GetSpawn(state);
  1987. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1988. lua_interface->ResetFunctionStack(state);
  1989. if (spawn && value > 0) {
  1990. spawn->SetPower(value);
  1991. if (value > spawn->GetTotalPowerBase())
  1992. spawn->SetTotalPower(value);
  1993. }
  1994. return 0;
  1995. }
  1996. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1997. if (!lua_interface)
  1998. return 0;
  1999. Spawn* spawn = lua_interface->GetSpawn(state);
  2000. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2001. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2002. lua_interface->ResetFunctionStack(state);
  2003. if (spawn && spawn->IsEntity() && value > 0)
  2004. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2005. return 0;
  2006. }
  2007. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2008. if (!lua_interface)
  2009. return 0;
  2010. Spawn* spawn = lua_interface->GetSpawn(state);
  2011. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2012. lua_interface->ResetFunctionStack(state);
  2013. if (spawn && spawn->IsEntity() && value > 0)
  2014. ((Entity*)spawn)->SetTotalPowerBase(value);
  2015. return 0;
  2016. }
  2017. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2018. if (!lua_interface)
  2019. return 0;
  2020. Spawn* spawn = lua_interface->GetSpawn(state);
  2021. float x = lua_interface->GetFloatValue(state, 2);
  2022. float y = lua_interface->GetFloatValue(state, 3);
  2023. float z = lua_interface->GetFloatValue(state, 4);
  2024. float heading = lua_interface->GetFloatValue(state, 5);
  2025. lua_interface->ResetFunctionStack(state);
  2026. if (spawn) {
  2027. spawn->SetX(x);
  2028. spawn->SetY(y);
  2029. spawn->SetZ(z);
  2030. if (heading != 0)
  2031. spawn->SetHeading(heading);
  2032. spawn->SetSpawnOrigX(spawn->GetX());
  2033. spawn->SetSpawnOrigY(spawn->GetY());
  2034. spawn->SetSpawnOrigZ(spawn->GetZ());
  2035. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2036. if (spawn->IsPlayer()) {
  2037. Client* client = ((Player*)spawn)->GetClient();
  2038. if (client) {
  2039. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2040. client->QueuePacket(packet);
  2041. }
  2042. }
  2043. }
  2044. return 0;
  2045. }
  2046. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2047. if (!lua_interface)
  2048. return 0;
  2049. Spawn* spawn = lua_interface->GetSpawn(state);
  2050. float value = lua_interface->GetFloatValue(state, 2);
  2051. lua_interface->ResetFunctionStack(state);
  2052. if (spawn) {
  2053. spawn->SetHeading(value);
  2054. if (spawn->IsPlayer()) {
  2055. Client* client = ((Player*)spawn)->GetClient();
  2056. if (client) {
  2057. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2058. client->QueuePacket(packet);
  2059. }
  2060. }
  2061. }
  2062. return 0;
  2063. }
  2064. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2065. if (!lua_interface)
  2066. return 0;
  2067. Spawn* spawn = lua_interface->GetSpawn(state);
  2068. int16 value = lua_interface->GetInt16Value(state, 2);
  2069. lua_interface->ResetFunctionStack(state);
  2070. if (spawn)
  2071. spawn->SetModelType(value);
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. int8 value = lua_interface->GetInt8Value(state, 2);
  2079. lua_interface->ResetFunctionStack(state);
  2080. if (spawn) {
  2081. if (spawn->IsPlayer())
  2082. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2083. else
  2084. spawn->SetAdventureClass(value);
  2085. }
  2086. return 0;
  2087. }
  2088. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2089. if (!lua_interface)
  2090. return 0;
  2091. Spawn* spawn = lua_interface->GetSpawn(state);
  2092. int8 value = lua_interface->GetInt8Value(state, 2);
  2093. lua_interface->ResetFunctionStack(state);
  2094. if (spawn) {
  2095. spawn->SetTradeskillClass(value);
  2096. if (spawn->IsEntity()) {
  2097. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2098. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2099. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2100. }
  2101. if (spawn->IsPlayer())
  2102. ((Player*)spawn)->SetCharSheetChanged(true);
  2103. }
  2104. return 0;
  2105. }
  2106. int EQ2Emu_lua_SetMount(lua_State* state) {
  2107. if (!lua_interface)
  2108. return 0;
  2109. Spawn* spawn = lua_interface->GetSpawn(state);
  2110. int16 value = lua_interface->GetInt16Value(state, 2);
  2111. if (spawn && spawn->IsEntity()) {
  2112. ((Entity*)spawn)->SetMount(value);
  2113. EQ2_Color color;
  2114. color.red = 255;
  2115. color.green = 255;
  2116. color.blue = 255;
  2117. ((Entity*)spawn)->SetMountColor(&color);
  2118. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2119. }
  2120. return 0;
  2121. }
  2122. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2123. if (!lua_interface)
  2124. return 0;
  2125. Spawn* spawn = lua_interface->GetSpawn(state);
  2126. EQ2_Color mount_color;
  2127. EQ2_Color saddle_color;
  2128. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2129. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2130. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2131. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2132. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2133. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2134. if (spawn && spawn->IsEntity()) {
  2135. ((Entity*)spawn)->SetMountColor(&mount_color);
  2136. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2137. }
  2138. return 0;
  2139. }
  2140. int EQ2Emu_lua_GetMount(lua_State* state) {
  2141. if (!lua_interface)
  2142. return 0;
  2143. Spawn* spawn = lua_interface->GetSpawn(state);
  2144. if (spawn && spawn->IsEntity()) {
  2145. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2146. return 1;
  2147. }
  2148. return 0;
  2149. }
  2150. int EQ2Emu_lua_GetRace(lua_State* state) {
  2151. if (!lua_interface)
  2152. return 0;
  2153. Spawn* spawn = lua_interface->GetSpawn(state);
  2154. if (spawn)
  2155. {
  2156. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2157. lua_interface->SetInt32Value(state, spawn->GetRace());
  2158. return 1;
  2159. }
  2160. return 0;
  2161. }
  2162. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2163. if (!lua_interface)
  2164. return 0;
  2165. Spawn* spawn = lua_interface->GetSpawn(state);
  2166. if (spawn) {
  2167. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2168. return 1;
  2169. }
  2170. return 0;
  2171. }
  2172. int EQ2Emu_lua_GetClass(lua_State* state) {
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. if (spawn) {
  2175. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2176. return 1;
  2177. }
  2178. return 0;
  2179. }
  2180. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2181. Spawn* spawn = lua_interface->GetSpawn(state);
  2182. if (spawn) {
  2183. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2184. return 1;
  2185. }
  2186. return 0;
  2187. }
  2188. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2189. if (!lua_interface)
  2190. return 0;
  2191. Spawn* spawn = lua_interface->GetSpawn(state);
  2192. float value = lua_interface->GetFloatValue(state, 2);
  2193. lua_interface->ResetFunctionStack(state);
  2194. if (spawn) {
  2195. spawn->SetSpeed(value);
  2196. if(spawn->IsEntity())
  2197. ((Entity*)spawn)->SetSpeed(value);
  2198. if (spawn->IsPlayer()) {
  2199. Client* client = ((Player*)spawn)->GetClient();
  2200. if (client) {
  2201. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2202. if (packet) {
  2203. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2204. packet->setDataByName("speed", value);
  2205. packet->setDataByName("size", 0.51);
  2206. EQ2Packet* app = packet->serialize();
  2207. client->QueuePacket(app);
  2208. safe_delete(packet);
  2209. }
  2210. }
  2211. }
  2212. }
  2213. return 0;
  2214. }
  2215. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2216. if (!lua_interface)
  2217. return 0;
  2218. Spawn* spawn = lua_interface->GetSpawn(state);
  2219. const int16 type = lua_interface->GetInt16Value(state, 2);
  2220. const float value = lua_interface->GetFloatValue(state, 3);
  2221. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2222. if(!luaspell || luaspell->resisted) {
  2223. lua_interface->ResetFunctionStack(state);
  2224. return 0;
  2225. }
  2226. int64 class_req = 0;
  2227. int32 class_id = 0;
  2228. vector<int16> faction_req;
  2229. vector<int16> race_req;
  2230. int32 i = 0;
  2231. int8 f = 0;
  2232. int8 r = 0;
  2233. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2234. if (class_id < 100) {
  2235. class_req += pow(2.0, double(class_id - 1));
  2236. }
  2237. else if (class_id > 100 && class_id < 1000) {
  2238. race_req.push_back(class_id);
  2239. r++;
  2240. }
  2241. else {
  2242. faction_req.push_back(class_id);
  2243. f++;
  2244. }
  2245. i++;
  2246. }
  2247. if (value != 0 && type >= 0) {
  2248. if (luaspell && luaspell->spell && luaspell->caster) {
  2249. ZoneServer* zone = luaspell->caster->GetZone();
  2250. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2251. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2252. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2253. if (target) {
  2254. if (target->IsPlayer()) {
  2255. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2256. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2257. if (((Player*)target)->GetGroupMemberInfo())
  2258. ((Player*)target)->UpdateGroupMemberInfo();
  2259. ((Player*)target)->SetCharSheetChanged(true);
  2260. }
  2261. else if (target->IsNPC())
  2262. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2263. else
  2264. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2265. }
  2266. }
  2267. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2268. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2269. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2270. }
  2271. else if (spawn && spawn->IsEntity()) {
  2272. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2273. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2274. if (spawn->IsPlayer())
  2275. ((Player*)spawn)->SetCharSheetChanged(true);
  2276. }
  2277. else
  2278. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2279. }
  2280. else
  2281. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2282. return 0;
  2283. }
  2284. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2285. if (!lua_interface)
  2286. return 0;
  2287. Spawn* spawn = lua_interface->GetSpawn(state);
  2288. int16 type = lua_interface->GetInt16Value(state, 2);
  2289. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2291. if (!spawn) {
  2292. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2293. return 0;
  2294. }
  2295. if (!spawn->IsEntity()) {
  2296. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2297. return 0;
  2298. }
  2299. if (value == 0) {
  2300. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2301. return 0;
  2302. }
  2303. if (!luaspell || !luaspell->spell) {
  2304. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2305. return 0;
  2306. }
  2307. if(luaspell->resisted) {
  2308. lua_interface->ResetFunctionStack(state);
  2309. return 0;
  2310. }
  2311. int32 class_req = 0;
  2312. vector<int16> faction_req;
  2313. vector<int16> race_req;
  2314. int32 class_id = 0;
  2315. int32 i = 0;
  2316. int8 f = 0;
  2317. int8 r = 0;
  2318. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2319. if (class_id < 100) {
  2320. class_req += pow(2.0, double(class_id - 1));
  2321. }
  2322. else if (class_id > 100 && class_id < 1000) {
  2323. race_req.push_back(class_id);
  2324. r++;
  2325. }
  2326. else {
  2327. faction_req.push_back(class_id);
  2328. f++;
  2329. }
  2330. i++;
  2331. }
  2332. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2333. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2334. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2335. if (spawn->IsPlayer())
  2336. ((Player*)spawn)->SetCharSheetChanged(true);
  2337. return 0;
  2338. }
  2339. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2340. if (!lua_interface)
  2341. return 0;
  2342. Spawn* spawn = lua_interface->GetSpawn(state);
  2343. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2344. if (!spawn) {
  2345. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2346. return 0;
  2347. }
  2348. if (!spawn->IsEntity()) {
  2349. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2350. return 0;
  2351. }
  2352. if (!luaspell || !luaspell->spell) {
  2353. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2354. return 0;
  2355. }
  2356. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2357. if (spawn->IsPlayer())
  2358. ((Player*)spawn)->SetCharSheetChanged(true);
  2359. return 0;
  2360. }
  2361. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2362. if (!lua_interface)
  2363. return 0;
  2364. Spawn* spawn = lua_interface->GetSpawn(state);
  2365. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2366. if (luaspell && luaspell->spell) {
  2367. ZoneServer* zone = nullptr;
  2368. if (luaspell->caster != nullptr)
  2369. zone = luaspell->caster->GetZone();
  2370. if(!zone && spawn) {
  2371. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2372. }
  2373. Spawn* target = 0;
  2374. if(zone) {
  2375. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2376. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2377. target = zone->GetSpawnByID(luaspell->targets[i]);
  2378. if (target && target->IsEntity()) {
  2379. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2380. if (target->IsPlayer())
  2381. ((Player*)target)->SetCharSheetChanged(true);
  2382. }
  2383. }
  2384. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2385. }
  2386. else {
  2387. LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
  2388. }
  2389. }
  2390. else if (spawn && spawn->IsEntity()) {
  2391. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2392. if (spawn->IsPlayer())
  2393. ((Player*)spawn)->SetCharSheetChanged(true);
  2394. }
  2395. return 0;
  2396. }
  2397. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2398. if (!lua_interface)
  2399. return 0;
  2400. Spawn* spawn = lua_interface->GetSpawn(state);
  2401. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2402. float value = lua_interface->GetFloatValue(state, 3);
  2403. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2404. if (value != 0) {
  2405. int32 spell_id = 0;
  2406. if (luaspell && luaspell->spell && luaspell->caster) {
  2407. if(luaspell->resisted) {
  2408. lua_interface->ResetFunctionStack(state);
  2409. return 0;
  2410. }
  2411. spell_id = luaspell->spell->GetSpellID();
  2412. ZoneServer* zone = luaspell->caster->GetZone();
  2413. Spawn* target = 0;
  2414. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2415. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2416. target = zone->GetSpawnByID(luaspell->targets[i]);
  2417. if (target && target->Alive()) {
  2418. if (target->IsPlayer()) {
  2419. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2420. Client* client = ((Player*)target)->GetClient();
  2421. if (client) {
  2422. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2423. if (packet)
  2424. client->QueuePacket(packet);
  2425. }
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2428. }
  2429. else if (target->IsNPC()) {
  2430. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2431. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2432. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2433. }
  2434. else
  2435. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2436. }
  2437. }
  2438. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2439. }
  2440. else if (spawn) {
  2441. if (spawn->IsPlayer()) {
  2442. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2443. Client* client = ((Player*)spawn)->GetClient();
  2444. if (client) {
  2445. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2446. if (packet)
  2447. client->QueuePacket(packet);
  2448. }
  2449. }
  2450. else if (spawn->IsNPC())
  2451. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2452. else
  2453. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2454. }
  2455. }
  2456. else
  2457. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2458. return 0;
  2459. }
  2460. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2461. if (!lua_interface)
  2462. return 0;
  2463. Spawn* spawn = lua_interface->GetSpawn(state);
  2464. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2465. if (spawn && spawn->IsPlayer()) {
  2466. int32 spell_id = 0;
  2467. if (luaspell && luaspell->spell && luaspell->caster) {
  2468. if(luaspell->resisted) {
  2469. lua_interface->ResetFunctionStack(state);
  2470. return 0;
  2471. }
  2472. spell_id = luaspell->spell->GetSpellID();
  2473. ZoneServer* zone = luaspell->caster->GetZone();
  2474. Spawn* target = 0;
  2475. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2476. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2477. target = zone->GetSpawnByID(luaspell->targets[i]);
  2478. if (target) {
  2479. if (target->IsPlayer()) {
  2480. ((Player*)target)->RemoveSkillBonus(spell_id);
  2481. Client* client = ((Player*)target)->GetClient();
  2482. if (client) {
  2483. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2484. if (packet)
  2485. client->QueuePacket(packet);
  2486. }
  2487. }
  2488. else if (target->IsNPC())
  2489. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2490. else
  2491. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2492. }
  2493. }
  2494. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2495. }
  2496. else if (spawn) {
  2497. if (spawn->IsPlayer()) {
  2498. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2499. Client* client = ((Player*)spawn)->GetClient();
  2500. if (client) {
  2501. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2502. if (packet)
  2503. client->QueuePacket(packet);
  2504. }
  2505. }
  2506. else if (spawn->IsNPC())
  2507. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2508. else
  2509. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2510. }
  2511. }
  2512. return 0;
  2513. }
  2514. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2515. if (!lua_interface)
  2516. return 0;
  2517. Spawn* spawn = lua_interface->GetSpawn(state);
  2518. int8 type = lua_interface->GetInt32Value(state, 2);
  2519. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2520. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2521. if(luaspell && luaspell->resisted) {
  2522. lua_interface->ResetFunctionStack(state);
  2523. return 0;
  2524. }
  2525. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2526. ZoneServer* zone = luaspell->caster->GetZone();
  2527. Spawn* target = 0;
  2528. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2529. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2530. target = zone->GetSpawnByID(luaspell->targets[i]);
  2531. if (target && target->IsEntity()) {
  2532. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2533. ((Entity*)target)->AddMezSpell(luaspell);
  2534. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2535. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2536. if (target->IsNPC())
  2537. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2538. }
  2539. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2540. ((Entity*)target)->AddStifleSpell(luaspell);
  2541. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2542. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2543. if (target->IsNPC())
  2544. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2545. }
  2546. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2547. ((Entity*)target)->AddDazeSpell(luaspell);
  2548. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2549. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2550. if (target->IsNPC())
  2551. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2552. }
  2553. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2554. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2555. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2556. ((Entity*)target)->AddStunSpell(luaspell);
  2557. if (target->IsNPC())
  2558. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2559. }
  2560. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2561. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2562. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2563. ((Entity*)target)->AddRootSpell(luaspell);
  2564. if (target->IsNPC())
  2565. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2566. }
  2567. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2568. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2569. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2570. ((Entity*)target)->AddFearSpell(luaspell);
  2571. if (target->IsNPC())
  2572. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2573. }
  2574. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2575. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2576. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2577. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2578. }
  2579. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2580. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2581. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2582. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2583. }
  2584. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2585. ((Entity*)target)->AddSnareSpell(luaspell);
  2586. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2587. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2588. if (target->IsNPC())
  2589. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2590. }
  2591. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2592. ((Entity*)target)->AddFlightSpell(luaspell);
  2593. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2594. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2595. }
  2596. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2597. ((Entity*)target)->AddGlideSpell(luaspell);
  2598. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2599. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2600. }
  2601. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2602. ((Entity*)target)->AddSafefallSpell(luaspell);
  2603. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2604. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2605. }
  2606. else
  2607. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2608. }
  2609. else
  2610. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2611. }
  2612. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2613. }
  2614. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2615. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2616. ((Entity*)spawn)->AddMezSpell(luaspell);
  2617. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2618. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2619. }
  2620. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2621. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2622. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2623. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2624. }
  2625. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2626. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2627. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2628. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2629. }
  2630. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2631. ((Entity*)spawn)->AddStunSpell(luaspell);
  2632. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2633. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2634. }
  2635. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2636. ((Entity*)spawn)->AddRootSpell(luaspell);
  2637. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2638. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2639. }
  2640. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2641. ((Entity*)spawn)->AddFearSpell(luaspell);
  2642. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2643. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2644. }
  2645. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2646. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2647. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2648. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2649. }
  2650. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2651. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2652. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2653. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2654. }
  2655. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2656. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2657. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2658. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2659. }
  2660. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2661. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2662. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2663. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2664. }
  2665. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2666. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2667. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2668. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2669. }
  2670. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2671. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2672. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2673. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2674. }
  2675. else
  2676. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2677. }
  2678. else
  2679. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2680. return 0;
  2681. }
  2682. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2683. if (!lua_interface)
  2684. return 0;
  2685. Spawn* spawn = lua_interface->GetSpawn(state);
  2686. int8 type = lua_interface->GetInt8Value(state, 2);
  2687. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2689. if (spawn && spawn->IsEntity()) {
  2690. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2691. ZoneServer* zone = luaspell->caster->GetZone();
  2692. Spawn* target = 0;
  2693. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2694. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2695. target = zone->GetSpawnByID(luaspell->targets[i]);
  2696. if (target) {
  2697. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2698. ((Entity*)target)->RemoveMezSpell(luaspell);
  2699. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2700. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2701. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2702. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2703. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2704. ((Entity*)target)->RemoveStunSpell(luaspell);
  2705. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2706. ((Entity*)target)->RemoveRootSpell(luaspell);
  2707. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2708. ((Entity*)target)->RemoveFearSpell(luaspell);
  2709. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2710. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2711. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2712. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2713. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2714. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2715. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2716. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2717. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2718. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2719. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2720. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2721. else
  2722. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2723. }
  2724. }
  2725. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2726. }
  2727. else if (only_remove_spawn) {
  2728. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2729. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2730. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2731. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2732. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2733. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2734. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2735. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2736. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2737. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2738. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2739. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2740. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2741. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2742. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2743. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2744. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2745. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2746. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2747. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2748. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2749. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2750. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2751. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2752. else
  2753. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2754. }
  2755. }
  2756. return 0;
  2757. }
  2758. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2759. if (!lua_interface)
  2760. return 0;
  2761. Spawn* spawn = lua_interface->GetSpawn(state);
  2762. int8 type = lua_interface->GetInt8Value(state, 2);
  2763. bool hasEffect = false;
  2764. if (!spawn)
  2765. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2766. else if (!spawn->IsEntity())
  2767. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2768. else if (type < CONTROL_MAX_EFFECTS)
  2769. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2770. else
  2771. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2772. lua_interface->SetBooleanValue(state, hasEffect);
  2773. return 1;
  2774. }
  2775. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. float distance = 0.0f;
  2780. if (!spawn)
  2781. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2782. else if (!spawn->IsNPC())
  2783. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2784. else
  2785. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2786. lua_interface->SetFloatValue(state, distance);
  2787. return 1;
  2788. }
  2789. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2790. if (!lua_interface)
  2791. return 0;
  2792. Spawn* spawn = lua_interface->GetSpawn(state);
  2793. float distance = 0.0f;
  2794. if (!spawn)
  2795. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2796. else if (!spawn->IsNPC())
  2797. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2798. else
  2799. distance = ((NPC*)spawn)->GetAggroRadius();
  2800. lua_interface->SetFloatValue(state, distance);
  2801. return 1;
  2802. }
  2803. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2804. if (!lua_interface)
  2805. return 0;
  2806. Spawn* spawn = lua_interface->GetSpawn(state);
  2807. float distance = lua_interface->GetFloatValue(state, 2);
  2808. bool override = lua_interface->GetBooleanValue(state, 3);
  2809. bool result = false;
  2810. lua_interface->ResetFunctionStack(state);
  2811. if (!spawn)
  2812. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2813. else if (!spawn->IsNPC())
  2814. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2815. else
  2816. {
  2817. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2818. result = true;
  2819. }
  2820. lua_interface->SetBooleanValue(state, result);
  2821. return 1;
  2822. }
  2823. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2824. if (!lua_interface)
  2825. return 0;
  2826. Spawn* spawn = lua_interface->GetSpawn(state);
  2827. int16 value = lua_interface->GetInt16Value(state, 2);
  2828. if (spawn && spawn->IsEntity()) {
  2829. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2830. if (spawn->IsPlayer())
  2831. ((Player*)spawn)->SetCharSheetChanged(true);
  2832. }
  2833. return 0;
  2834. }
  2835. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2836. if (!lua_interface)
  2837. return 0;
  2838. Spawn* spawn = lua_interface->GetSpawn(state);
  2839. int16 value = lua_interface->GetInt16Value(state, 2);
  2840. if (spawn && spawn->IsEntity()) {
  2841. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2842. if (spawn->IsPlayer())
  2843. ((Player*)spawn)->SetCharSheetChanged(true);
  2844. }
  2845. return 0;
  2846. }
  2847. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2848. if (!lua_interface)
  2849. return 0;
  2850. Spawn* spawn = lua_interface->GetSpawn(state);
  2851. int16 value = lua_interface->GetInt16Value(state, 2);
  2852. if (spawn && spawn->IsEntity()) {
  2853. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2854. if (spawn->IsPlayer())
  2855. ((Player*)spawn)->SetCharSheetChanged(true);
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. int16 value = lua_interface->GetInt16Value(state, 2);
  2864. if (spawn && spawn->IsEntity()) {
  2865. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2866. if (spawn->IsPlayer())
  2867. ((Player*)spawn)->SetCharSheetChanged(true);
  2868. }
  2869. return 0;
  2870. }
  2871. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2872. if (!lua_interface)
  2873. return 0;
  2874. Spawn* spawn = lua_interface->GetSpawn(state);
  2875. int16 value = lua_interface->GetInt16Value(state, 2);
  2876. if (spawn && spawn->IsEntity()) {
  2877. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2878. if (spawn->IsPlayer())
  2879. ((Player*)spawn)->SetCharSheetChanged(true);
  2880. }
  2881. return 0;
  2882. }
  2883. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2884. if (!lua_interface)
  2885. return 0;
  2886. Spawn* spawn = lua_interface->GetSpawn(state);
  2887. int8 value = lua_interface->GetInt8Value(state, 2);
  2888. if (spawn && spawn->IsEntity()) {
  2889. ((Entity*)spawn)->SetDeity(value);
  2890. if (spawn->IsPlayer())
  2891. ((Player*)spawn)->SetCharSheetChanged(true);
  2892. }
  2893. lua_interface->ResetFunctionStack(state);
  2894. return 0;
  2895. }
  2896. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2897. if (!lua_interface)
  2898. return 0;
  2899. Spawn* spawn = lua_interface->GetSpawn(state);
  2900. if (spawn && spawn->IsEntity()) {
  2901. int8 deity = ((Entity*)spawn)->GetDeity();
  2902. lua_interface->SetInt32Value(state, deity);
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_SetInt(lua_State* state) {
  2908. if (!lua_interface)
  2909. return 0;
  2910. Spawn* spawn = lua_interface->GetSpawn(state);
  2911. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2912. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2913. if (spawn && spawn->IsEntity()) {
  2914. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2915. if (spawn->IsPlayer())
  2916. ((Player*)spawn)->SetCharSheetChanged(true);
  2917. }
  2918. return 0;
  2919. }
  2920. int EQ2Emu_lua_SetWis(lua_State* state) {
  2921. if (!lua_interface)
  2922. return 0;
  2923. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2924. Spawn* spawn = lua_interface->GetSpawn(state);
  2925. float value = lua_interface->GetFloatValue(state, 2);
  2926. if (spawn && spawn->IsEntity()) {
  2927. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2928. if (spawn->IsPlayer())
  2929. ((Player*)spawn)->SetCharSheetChanged(true);
  2930. }
  2931. return 0;
  2932. }
  2933. int EQ2Emu_lua_SetSta(lua_State* state) {
  2934. if (!lua_interface)
  2935. return 0;
  2936. Spawn* spawn = lua_interface->GetSpawn(state);
  2937. float value = lua_interface->GetFloatValue(state, 2);
  2938. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2939. if (spawn && spawn->IsEntity()) {
  2940. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2941. if (spawn->IsPlayer())
  2942. ((Player*)spawn)->SetCharSheetChanged(true);
  2943. }
  2944. return 0;
  2945. }
  2946. int EQ2Emu_lua_SetStr(lua_State* state) {
  2947. if (!lua_interface)
  2948. return 0;
  2949. Spawn* spawn = lua_interface->GetSpawn(state);
  2950. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2951. float value = lua_interface->GetFloatValue(state, 2);
  2952. if (spawn && spawn->IsEntity()) {
  2953. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2954. if (spawn->IsPlayer())
  2955. ((Player*)spawn)->SetCharSheetChanged(true);
  2956. }
  2957. return 0;
  2958. }
  2959. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2960. if (!lua_interface)
  2961. return 0;
  2962. Spawn* spawn = lua_interface->GetSpawn(state);
  2963. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2964. float value = lua_interface->GetFloatValue(state, 2);
  2965. if (spawn && spawn->IsEntity()) {
  2966. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2967. if (spawn->IsPlayer())
  2968. ((Player*)spawn)->SetCharSheetChanged(true);
  2969. }
  2970. return 0;
  2971. }
  2972. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2973. if (!lua_interface)
  2974. return 0;
  2975. Spawn* spawn = lua_interface->GetSpawn(state);
  2976. if (spawn) {
  2977. lua_interface->SetInt32Value(state, spawn->GetHP());
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* spawn = lua_interface->GetSpawn(state);
  2986. if (spawn) {
  2987. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2988. return 1;
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2993. if (!lua_interface)
  2994. return 0;
  2995. Spawn* spawn = lua_interface->GetSpawn(state);
  2996. if (spawn) {
  2997. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2998. return 1;
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_GetName(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Spawn* spawn = lua_interface->GetSpawn(state);
  3006. if (spawn) {
  3007. lua_interface->SetStringValue(state, spawn->GetName());
  3008. return 1;
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3013. Spawn* spawn = lua_interface->GetSpawn(state);
  3014. if (spawn) {
  3015. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3016. return 1;
  3017. }
  3018. return 0;
  3019. }
  3020. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3021. Spawn* spawn = lua_interface->GetSpawn(state);
  3022. if (spawn) {
  3023. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3024. return 1;
  3025. }
  3026. return 0;
  3027. }
  3028. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3029. if (!lua_interface)
  3030. return 0;
  3031. Spawn* spawn = lua_interface->GetSpawn(state);
  3032. if (spawn) {
  3033. lua_interface->SetInt32Value(state, spawn->GetPower());
  3034. return 1;
  3035. }
  3036. return 0;
  3037. }
  3038. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3039. if (!lua_interface)
  3040. return 0;
  3041. Spawn* spawn = lua_interface->GetSpawn(state);
  3042. if (spawn) {
  3043. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3044. return 1;
  3045. }
  3046. return 0;
  3047. }
  3048. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3049. if (!lua_interface)
  3050. return 0;
  3051. Spawn* spawn = lua_interface->GetSpawn(state);
  3052. if (spawn) {
  3053. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3054. return 1;
  3055. }
  3056. return 0;
  3057. }
  3058. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3059. if (!lua_interface)
  3060. return 0;
  3061. Spawn* spawn = lua_interface->GetSpawn(state);
  3062. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3063. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3064. if (spawn && spawn2) {
  3065. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3066. lua_interface->SetFloatValue(state, distance);
  3067. return 1;
  3068. }
  3069. return 0;
  3070. }
  3071. int EQ2Emu_lua_GetX(lua_State* state) {
  3072. if (!lua_interface)
  3073. return 0;
  3074. Spawn* spawn = lua_interface->GetSpawn(state);
  3075. if (spawn) {
  3076. lua_interface->SetFloatValue(state, spawn->GetX());
  3077. return 1;
  3078. }
  3079. return 0;
  3080. }
  3081. int EQ2Emu_lua_GetY(lua_State* state) {
  3082. if (!lua_interface)
  3083. return 0;
  3084. Spawn* spawn = lua_interface->GetSpawn(state);
  3085. if (spawn) {
  3086. lua_interface->SetFloatValue(state, spawn->GetY());
  3087. return 1;
  3088. }
  3089. return 0;
  3090. }
  3091. int EQ2Emu_lua_GetZ(lua_State* state) {
  3092. if (!lua_interface)
  3093. return 0;
  3094. Spawn* spawn = lua_interface->GetSpawn(state);
  3095. if (spawn) {
  3096. lua_interface->SetFloatValue(state, spawn->GetZ());
  3097. return 1;
  3098. }
  3099. return 0;
  3100. }
  3101. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3102. if (!lua_interface)
  3103. return 0;
  3104. Spawn* spawn = lua_interface->GetSpawn(state);
  3105. if (spawn) {
  3106. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3107. return 1;
  3108. }
  3109. return 0;
  3110. }
  3111. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3112. if (!lua_interface)
  3113. return 0;
  3114. Spawn* spawn = lua_interface->GetSpawn(state);
  3115. if (spawn) {
  3116. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3117. return 1;
  3118. }
  3119. return 0;
  3120. }
  3121. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3122. if (!lua_interface)
  3123. return 0;
  3124. Spawn* spawn = lua_interface->GetSpawn(state);
  3125. if (spawn) {
  3126. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3127. return 1;
  3128. }
  3129. return 0;
  3130. }
  3131. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3132. if (!lua_interface)
  3133. return 0;
  3134. Spawn* spawn = lua_interface->GetSpawn(state);
  3135. if (spawn && spawn->IsEntity()) {
  3136. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3137. return 1;
  3138. }
  3139. return 0;
  3140. }
  3141. int EQ2Emu_lua_GetInt(lua_State* state) {
  3142. if (!lua_interface)
  3143. return 0;
  3144. Spawn* spawn = lua_interface->GetSpawn(state);
  3145. if (spawn && spawn->IsEntity()) {
  3146. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3147. return 1;
  3148. }
  3149. return 0;
  3150. }
  3151. int EQ2Emu_lua_GetWis(lua_State* state) {
  3152. if (!lua_interface)
  3153. return 0;
  3154. Spawn* spawn = lua_interface->GetSpawn(state);
  3155. if (spawn && spawn->IsEntity()) {
  3156. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3157. return 1;
  3158. }
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_GetSta(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Spawn* spawn = lua_interface->GetSpawn(state);
  3165. if (spawn && spawn->IsEntity()) {
  3166. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3167. return 1;
  3168. }
  3169. return 0;
  3170. }
  3171. int EQ2Emu_lua_GetStr(lua_State* state) {
  3172. if (!lua_interface)
  3173. return 0;
  3174. Spawn* spawn = lua_interface->GetSpawn(state);
  3175. if (spawn && spawn->IsEntity()) {
  3176. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Spawn* spawn = lua_interface->GetSpawn(state);
  3185. if (spawn && spawn->IsEntity()) {
  3186. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3187. return 1;
  3188. }
  3189. return 0;
  3190. }
  3191. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3192. if (!lua_interface)
  3193. return 0;
  3194. Spawn* spawn = lua_interface->GetSpawn(state);
  3195. if (spawn && spawn->IsEntity()) {
  3196. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3197. return 1;
  3198. }
  3199. return 0;
  3200. }
  3201. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3202. if (!lua_interface)
  3203. return 0;
  3204. Spawn* spawn = lua_interface->GetSpawn(state);
  3205. if (spawn && spawn->IsEntity()) {
  3206. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3207. return 1;
  3208. }
  3209. return 0;
  3210. }
  3211. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3212. if (!lua_interface)
  3213. return 0;
  3214. Spawn* spawn = lua_interface->GetSpawn(state);
  3215. if (spawn && spawn->IsEntity()) {
  3216. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3217. return 1;
  3218. }
  3219. return 0;
  3220. }
  3221. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3222. if (!lua_interface)
  3223. return 0;
  3224. Spawn* spawn = lua_interface->GetSpawn(state);
  3225. if (spawn && spawn->IsEntity()) {
  3226. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3227. return 1;
  3228. }
  3229. return 0;
  3230. }
  3231. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3232. if (!lua_interface)
  3233. return 0;
  3234. Spawn* spawn = lua_interface->GetSpawn(state);
  3235. if (spawn && spawn->IsEntity()) {
  3236. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3237. return 1;
  3238. }
  3239. return 0;
  3240. }
  3241. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3242. if (!lua_interface)
  3243. return 0;
  3244. Spawn* player = lua_interface->GetSpawn(state);
  3245. if (!player || !player->IsPlayer()) {
  3246. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3247. return 0;
  3248. }
  3249. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3250. if (quest_id <= 0) {
  3251. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3252. return 0;
  3253. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3254. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3255. return 0;
  3256. }
  3257. int32 step = lua_interface->GetInt32Value(state, 3);
  3258. if (step > 0) {
  3259. Client* client = ((Player*)player)->GetClient();
  3260. if (client)
  3261. client->AddPendingQuestUpdate(quest_id, step);
  3262. } else {
  3263. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3264. }
  3265. return 0;
  3266. }
  3267. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3268. Spawn* player = lua_interface->GetSpawn(state);
  3269. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3270. int32 step = lua_interface->GetInt32Value(state, 3);
  3271. int32 progress = lua_interface->GetInt32Value(state, 4);
  3272. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3273. Client* client = ((Player*)player)->GetClient();
  3274. if (client)
  3275. client->AddPendingQuestUpdate(quest_id, step, progress);
  3276. }
  3277. return 0;
  3278. }
  3279. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3280. if (!lua_interface)
  3281. return 0;
  3282. Spawn* player = lua_interface->GetSpawn(state);
  3283. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3284. if (player && player->IsPlayer() && quest_id > 0) {
  3285. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3286. return 1;
  3287. }
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Spawn* player = lua_interface->GetSpawn(state);
  3294. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3295. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3296. if (player && player->IsPlayer() && quest_id > 0) {
  3297. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3298. return 1;
  3299. }
  3300. return 0;
  3301. }
  3302. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3303. if (!lua_interface)
  3304. return 0;
  3305. Spawn* player = lua_interface->GetSpawn(state);
  3306. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3307. if (player && player->IsPlayer() && quest_id > 0) {
  3308. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3309. return 1;
  3310. }
  3311. return 0;
  3312. }
  3313. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3314. if (!lua_interface)
  3315. return 0;
  3316. Quest* quest = lua_interface->GetQuest(state);
  3317. string name = lua_interface->GetStringValue(state, 2);
  3318. string type = lua_interface->GetStringValue(state, 3);
  3319. string zone = lua_interface->GetStringValue(state, 4);
  3320. int16 level = lua_interface->GetInt16Value(state, 5);
  3321. string description = lua_interface->GetStringValue(state, 6);
  3322. bool load = true;
  3323. if (!quest) {
  3324. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3325. load = false;
  3326. }
  3327. if (load && name.length() == 0) {
  3328. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3329. load = false;
  3330. }
  3331. if (load && type.length() == 0) {
  3332. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3333. load = false;
  3334. }
  3335. if (load && zone.length() == 0) {
  3336. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3337. load = false;
  3338. }
  3339. if (load && description.length() == 0) {
  3340. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3341. load = false;
  3342. }
  3343. if (load && level == 0) {
  3344. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3345. load = false;
  3346. }
  3347. if (load)
  3348. quest->RegisterQuest(name, type, zone, level, description);
  3349. return 0;
  3350. }
  3351. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3352. if (!lua_interface)
  3353. return 0;
  3354. Quest* quest = lua_interface->GetQuest(state);
  3355. if (quest) {
  3356. int8 level = lua_interface->GetInt16Value(state, 2);
  3357. quest->SetPrereqLevel(level);
  3358. }
  3359. return 0;
  3360. }
  3361. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3362. if (!lua_interface)
  3363. return 0;
  3364. Quest* quest = lua_interface->GetQuest(state);
  3365. if (quest) {
  3366. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3367. quest->AddPrereqQuest(quest_id);
  3368. }
  3369. return 0;
  3370. }
  3371. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3372. if (!lua_interface)
  3373. return 0;
  3374. Quest* quest = lua_interface->GetQuest(state);
  3375. if (quest) {
  3376. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3377. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3378. if (quantity == 0)
  3379. quantity = 1;
  3380. Item* master_item = master_item_list.GetItem(item_id);
  3381. if (master_item) {
  3382. Item* item = new Item(master_item);
  3383. item->details.count = quantity;
  3384. quest->AddPrereqItem(item);
  3385. }
  3386. }
  3387. return 0;
  3388. }
  3389. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3390. if (!lua_interface)
  3391. return 0;
  3392. Spawn* player = lua_interface->GetSpawn(state);
  3393. if(!player || !player->IsPlayer()) {
  3394. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3395. return 0;
  3396. }
  3397. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3398. if (quest_id > 0) {
  3399. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
  3400. return 1;
  3401. } else {
  3402. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3403. }
  3404. return 0;
  3405. }
  3406. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3407. if (!lua_interface)
  3408. return 0;
  3409. Quest* quest = lua_interface->GetQuest(state);
  3410. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3411. lua_interface->ResetFunctionStack(state);
  3412. if (quest && spawn_id > 0)
  3413. quest->SetQuestReturnNPC(spawn_id);
  3414. return 0;
  3415. }
  3416. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3417. if (!lua_interface)
  3418. return 0;
  3419. Spawn* spawn = lua_interface->GetSpawn(state);
  3420. int32 time = lua_interface->GetInt32Value(state, 2);
  3421. string function = lua_interface->GetStringValue(state, 3);
  3422. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3423. Spawn* player = lua_interface->GetSpawn(state, 5);
  3424. lua_interface->ResetFunctionStack(state);
  3425. if (!spawn) {
  3426. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3427. return 0;
  3428. }
  3429. if (time <= 0) {
  3430. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3431. return 0;
  3432. }
  3433. if (function.length() == 0) {
  3434. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3435. return 0;
  3436. }
  3437. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3438. if ( time < 10)
  3439. time = 10;
  3440. timer->timer = Timer::GetCurrentTime2() + time;
  3441. timer->function = function;
  3442. timer->spawn = spawn->GetID();
  3443. timer->player = player ? player->GetID() : 0;
  3444. if (max_count == 0)
  3445. max_count = 1;
  3446. timer->max_count = max_count;
  3447. timer->current_count = 0;
  3448. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3449. return 0;
  3450. }
  3451. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3452. if (!lua_interface)
  3453. return 0;
  3454. Spawn* spawn = lua_interface->GetSpawn(state);
  3455. string function = lua_interface->GetStringValue(state, 2);
  3456. lua_interface->ResetFunctionStack(state);
  3457. if (!spawn) {
  3458. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3459. return 0;
  3460. }
  3461. if(!spawn->GetZone()) {
  3462. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3463. return 0;
  3464. }
  3465. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3466. return 0;
  3467. }
  3468. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3469. if (!lua_interface)
  3470. return 0;
  3471. Spawn* player = lua_interface->GetSpawn(state);
  3472. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3473. lua_interface->ResetFunctionStack(state);
  3474. if (player && player->IsPlayer() && quest_id > 0) {
  3475. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3476. return 1;
  3477. }
  3478. return 0;
  3479. }
  3480. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3481. if (!lua_interface)
  3482. return 0;
  3483. Spawn* player = lua_interface->GetSpawn(state);
  3484. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3485. lua_interface->ResetFunctionStack(state);
  3486. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3487. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3488. if (quest)
  3489. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3490. return 1;
  3491. }
  3492. return 0;
  3493. }
  3494. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3495. if (!lua_interface)
  3496. return 0;
  3497. Spawn* player = lua_interface->GetSpawn(state);
  3498. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3499. lua_interface->ResetFunctionStack(state);
  3500. if (player && player->IsPlayer() && quest_id > 0) {
  3501. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3502. return 1;
  3503. }
  3504. return 0;
  3505. }
  3506. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3507. if (!lua_interface)
  3508. return 0;
  3509. Spawn* npc = lua_interface->GetSpawn(state);
  3510. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3511. lua_interface->ResetFunctionStack(state);
  3512. if (npc && !npc->IsPlayer() && quest_id > 0)
  3513. npc->AddProvidedQuest(quest_id);
  3514. return 0;
  3515. }
  3516. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Spawn* npc = lua_interface->GetSpawn(state);
  3520. Spawn* player = lua_interface->GetSpawn(state, 2);
  3521. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3522. bool forced = lua_interface->GetBooleanValue(state, 4);
  3523. lua_interface->ResetFunctionStack(state);
  3524. /* NPC is allowed to be null */
  3525. if (player && player->IsPlayer() && quest_id > 0) {
  3526. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3527. if (master_quest) {
  3528. Client* client = ((Player*)player)->GetClient();
  3529. if (!client) {
  3530. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3531. }
  3532. Quest* quest = new Quest(master_quest);
  3533. if (!quest) {
  3534. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3535. }
  3536. if (client && quest) {
  3537. if (npc)
  3538. quest->SetQuestGiver(npc->GetDatabaseID());
  3539. else
  3540. quest->SetQuestGiver(0);
  3541. client->AddPendingQuest(quest, forced);
  3542. }
  3543. }
  3544. else {
  3545. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3546. }
  3547. }
  3548. else {
  3549. lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
  3550. }
  3551. return 0;
  3552. }
  3553. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3554. if (!lua_interface)
  3555. return 0;
  3556. Quest* quest = lua_interface->GetQuest(state);
  3557. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3558. lua_interface->ResetFunctionStack(state);
  3559. if (quest) {
  3560. quest->AddPrereqClass(class_id);
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3565. if (!lua_interface)
  3566. return 0;
  3567. Quest* quest = lua_interface->GetQuest(state);
  3568. int8 race = lua_interface->GetInt8Value(state, 2);
  3569. lua_interface->ResetFunctionStack(state);
  3570. if (quest) {
  3571. quest->AddPrereqRace(race);
  3572. }
  3573. return 0;
  3574. }
  3575. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3576. if (!lua_interface)
  3577. return 0;
  3578. Quest* quest = lua_interface->GetQuest(state);
  3579. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3580. lua_interface->ResetFunctionStack(state);
  3581. if (quest) {
  3582. quest->AddPrereqModelType(model_type);
  3583. }
  3584. return 0;
  3585. }
  3586. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3587. if (!lua_interface)
  3588. return 0;
  3589. Quest* quest = lua_interface->GetQuest(state);
  3590. int8 level = lua_interface->GetInt8Value(state, 2);
  3591. lua_interface->ResetFunctionStack(state);
  3592. if (!quest) {
  3593. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3594. return 0;
  3595. }
  3596. quest->SetPrereqTSLevel(level);
  3597. return 0;
  3598. }
  3599. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3600. if (!lua_interface)
  3601. return 0;
  3602. Quest* quest = lua_interface->GetQuest(state);
  3603. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3604. lua_interface->ResetFunctionStack(state);
  3605. if (!quest) {
  3606. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3607. return 0;
  3608. }
  3609. quest->AddPrereqTradeskillClass(class_id);
  3610. return 0;
  3611. }
  3612. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3613. if (!lua_interface)
  3614. return 0;
  3615. Quest* quest = lua_interface->GetQuest(state);
  3616. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3617. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3618. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3619. lua_interface->ResetFunctionStack(state);
  3620. if (quest) {
  3621. quest->AddPrereqFaction(faction_id, min, max);
  3622. }
  3623. return 0;
  3624. }
  3625. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3626. if (!lua_interface)
  3627. return 0;
  3628. Quest* quest = lua_interface->GetQuest(state);
  3629. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3630. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3631. lua_interface->ResetFunctionStack(state);
  3632. if (quest) {
  3633. if (quantity == 0)
  3634. quantity = 1;
  3635. Item* master_item = master_item_list.GetItem(item_id);
  3636. if (master_item) {
  3637. Item* item = new Item(master_item);
  3638. item->details.count = quantity;
  3639. quest->AddSelectableRewardItem(item);
  3640. }
  3641. }
  3642. return 0;
  3643. }
  3644. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3645. if (!lua_interface)
  3646. return 0;
  3647. Quest* quest = lua_interface->GetQuest(state);
  3648. if (quest) {
  3649. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3650. vector<Item*>* items = quest->GetRewardItems();
  3651. if (items) {
  3652. vector<Item*>::iterator itr;
  3653. for (itr = items->begin(); itr != items->end(); itr++) {
  3654. if (*itr && (*itr)->details.item_id == item_id) {
  3655. lua_interface->SetBooleanValue(state, true);
  3656. return 1;
  3657. }
  3658. }
  3659. }
  3660. }
  3661. lua_interface->SetBooleanValue(state, false);
  3662. return 1;
  3663. }
  3664. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3665. if (!lua_interface)
  3666. return 0;
  3667. Quest* quest = lua_interface->GetQuest(state);
  3668. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3669. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3670. lua_interface->ResetFunctionStack(state);
  3671. if (quest) {
  3672. if (quantity == 0)
  3673. quantity = 1;
  3674. Item* master_item = master_item_list.GetItem(item_id);
  3675. if (master_item) {
  3676. Item* item = new Item(master_item);
  3677. item->details.count = quantity;
  3678. quest->AddRewardItem(item);
  3679. }
  3680. }
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 copper = lua_interface->GetInt32Value(state, 2);
  3688. int32 silver = lua_interface->GetInt32Value(state, 3);
  3689. int32 gold = lua_interface->GetInt32Value(state, 4);
  3690. int32 plat = lua_interface->GetInt32Value(state, 5);
  3691. lua_interface->ResetFunctionStack(state);
  3692. if (quest) {
  3693. quest->AddRewardCoins(copper, silver, gold, plat);
  3694. }
  3695. return 0;
  3696. }
  3697. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3698. if (!lua_interface)
  3699. return 0;
  3700. Quest* quest = lua_interface->GetQuest(state);
  3701. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3702. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3703. lua_interface->ResetFunctionStack(state);
  3704. if (quest && faction_id > 0 && amount != 0)
  3705. quest->AddRewardFaction(faction_id, amount);
  3706. return 0;
  3707. }
  3708. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3709. if (!lua_interface)
  3710. return 0;
  3711. Quest* quest = lua_interface->GetQuest(state);
  3712. int32 status = lua_interface->GetInt32Value(state, 2);
  3713. lua_interface->ResetFunctionStack(state);
  3714. if (quest) {
  3715. quest->SetRewardStatus(status);
  3716. }
  3717. return 0;
  3718. }
  3719. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3720. if (!lua_interface)
  3721. return 0;
  3722. Quest* quest = lua_interface->GetQuest(state);
  3723. int32 status = lua_interface->GetInt32Value(state, 2);
  3724. lua_interface->ResetFunctionStack(state);
  3725. if (quest) {
  3726. quest->SetStatusTmpReward(status);
  3727. }
  3728. return 0;
  3729. }
  3730. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3731. if (!lua_interface)
  3732. return 0;
  3733. Quest* quest = lua_interface->GetQuest(state);
  3734. int64 coins = lua_interface->GetInt64Value(state, 2);
  3735. lua_interface->ResetFunctionStack(state);
  3736. if (quest) {
  3737. quest->SetCoinTmpReward(coins);
  3738. }
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3742. if (!lua_interface)
  3743. return 0;
  3744. Quest* quest = lua_interface->GetQuest(state);
  3745. string comment = lua_interface->GetStringValue(state, 2);
  3746. lua_interface->ResetFunctionStack(state);
  3747. if (quest) {
  3748. quest->SetRewardComment(comment);
  3749. }
  3750. return 0;
  3751. }
  3752. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3753. if (!lua_interface)
  3754. return 0;
  3755. Quest* quest = lua_interface->GetQuest(state);
  3756. int32 exp = lua_interface->GetInt32Value(state, 2);
  3757. lua_interface->ResetFunctionStack(state);
  3758. if (quest) {
  3759. quest->SetRewardXP(exp);
  3760. }
  3761. return 0;
  3762. }
  3763. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3764. Quest* quest = lua_interface->GetQuest(state);
  3765. int32 step = lua_interface->GetInt32Value(state, 2);
  3766. string description = lua_interface->GetStringValue(state, 3);
  3767. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3768. float percentage = lua_interface->GetFloatValue(state, 5);
  3769. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3770. int16 icon = lua_interface->GetInt16Value(state, 7);
  3771. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3772. if (quest) {
  3773. const char* taskgroup = 0;
  3774. if (str_taskgroup.length() > 0)
  3775. taskgroup = str_taskgroup.c_str();
  3776. int32 id = 0;
  3777. vector<int32>* ids = 0;
  3778. int i = 0;
  3779. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3780. if (ids == 0)
  3781. ids = new vector<int32>;
  3782. ids->push_back(id);
  3783. i++;
  3784. }
  3785. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3786. if (quest_step && icon && quantity > 0)
  3787. quest_step->SetIcon(icon);
  3788. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3789. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3790. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3791. }
  3792. }
  3793. lua_interface->ResetFunctionStack(state);
  3794. return 0;
  3795. }
  3796. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3797. {
  3798. if (!lua_interface)
  3799. return 0;
  3800. Quest* quest = lua_interface->GetQuest(state);
  3801. int32 step = lua_interface->GetInt32Value(state, 2);
  3802. string description = lua_interface->GetStringValue(state, 3);
  3803. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3804. float percentage = lua_interface->GetFloatValue(state, 5);
  3805. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3806. int16 icon = lua_interface->GetInt16Value(state, 7);
  3807. if (quest) {
  3808. const char* taskgroup = 0;
  3809. if (str_taskgroup.length() > 0)
  3810. taskgroup = str_taskgroup.c_str();
  3811. int32 id = 0;
  3812. vector<int32>* ids = 0;
  3813. int i = 0;
  3814. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3815. if (ids == 0)
  3816. ids = new vector<int32>;
  3817. ids->push_back(id);
  3818. i++;
  3819. }
  3820. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3821. if (quest_step && icon > 0 && quantity > 0)
  3822. quest_step->SetIcon(icon);
  3823. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3824. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3825. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3826. }
  3827. safe_delete(ids);
  3828. }
  3829. lua_interface->ResetFunctionStack(state);
  3830. return 0;
  3831. }
  3832. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3833. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3834. }
  3835. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3836. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3837. }
  3838. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3839. if (!lua_interface)
  3840. return 0;
  3841. Quest* quest = lua_interface->GetQuest(state);
  3842. int32 step = lua_interface->GetInt32Value(state, 2);
  3843. string description = lua_interface->GetStringValue(state, 3);
  3844. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3845. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3846. int16 icon = lua_interface->GetInt16Value(state, 6);
  3847. if (quest) {
  3848. const char* taskgroup = 0;
  3849. if (str_taskgroup.length() > 0)
  3850. taskgroup = str_taskgroup.c_str();
  3851. int32 npc_id = 0;
  3852. vector<int32>* ids = 0;
  3853. int i = 0;
  3854. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3855. if (ids == 0)
  3856. ids = new vector<int32>;
  3857. ids->push_back(npc_id);
  3858. i++;
  3859. }
  3860. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3861. if (quest_step && icon > 0)
  3862. quest_step->SetIcon(icon);
  3863. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3864. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3865. if(client)
  3866. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3867. }
  3868. safe_delete(ids);
  3869. }
  3870. lua_interface->ResetFunctionStack(state);
  3871. return 0;
  3872. }
  3873. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3874. if (!lua_interface)
  3875. return 0;
  3876. Quest* quest = lua_interface->GetQuest(state);
  3877. int32 step = lua_interface->GetInt32Value(state, 2);
  3878. string description = lua_interface->GetStringValue(state, 3);
  3879. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3880. float percentage = lua_interface->GetFloatValue(state, 5);
  3881. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3882. int16 icon = lua_interface->GetInt16Value(state, 7);
  3883. if (quest) {
  3884. const char* taskgroup = 0;
  3885. if (str_taskgroup.length() > 0)
  3886. taskgroup = str_taskgroup.c_str();
  3887. int32 item_id = 0;
  3888. vector<int32>* ids = 0;
  3889. int i = 0;
  3890. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3891. if (ids == 0)
  3892. ids = new vector<int32>;
  3893. ids->push_back(item_id);
  3894. i++;
  3895. }
  3896. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3897. if (quest_step && icon > 0 && quantity > 0)
  3898. quest_step->SetIcon(icon);
  3899. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3900. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3901. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3902. }
  3903. safe_delete(ids);
  3904. }
  3905. lua_interface->ResetFunctionStack(state);
  3906. return 0;
  3907. }
  3908. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3909. if (!lua_interface)
  3910. return 0;
  3911. Quest* quest = lua_interface->GetQuest(state);
  3912. int32 step = lua_interface->GetInt32Value(state, 2);
  3913. string description = lua_interface->GetStringValue(state, 3);
  3914. float max_variation = lua_interface->GetFloatValue(state, 4);
  3915. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3916. int16 icon = lua_interface->GetInt16Value(state, 6);
  3917. if (quest) {
  3918. const char* taskgroup = 0;
  3919. if (str_taskgroup.length() > 0)
  3920. taskgroup = str_taskgroup.c_str();
  3921. vector<Location>* locations = 0;
  3922. int8 i = 7;
  3923. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3924. while (true) {
  3925. Location loc;
  3926. loc.x = lua_interface->GetFloatValue(state, i);
  3927. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3928. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3929. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3930. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3931. break;
  3932. if (locations == 0)
  3933. locations = new vector<Location>;
  3934. locations->push_back(loc);
  3935. i += 4;
  3936. }
  3937. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3938. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3939. if (quest_step && icon > 0)
  3940. quest_step->SetIcon(icon);
  3941. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3942. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3943. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3944. }
  3945. }
  3946. lua_interface->ResetFunctionStack(state);
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3950. if (!lua_interface)
  3951. return 0;
  3952. Quest* quest = lua_interface->GetQuest(state);
  3953. int32 step = lua_interface->GetInt32Value(state, 2);
  3954. string description = lua_interface->GetStringValue(state, 3);
  3955. float max_variation = lua_interface->GetFloatValue(state, 4);
  3956. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3957. int16 icon = lua_interface->GetInt16Value(state, 6);
  3958. if (quest) {
  3959. const char* taskgroup = 0;
  3960. if (str_taskgroup.length() > 0)
  3961. taskgroup = str_taskgroup.c_str();
  3962. vector<Location>* locations = 0;
  3963. int8 i = 7;
  3964. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3965. while (true) {
  3966. Location loc;
  3967. loc.x = lua_interface->GetFloatValue(state, i);
  3968. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3969. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3970. loc.zone_id = 0;
  3971. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3972. break;
  3973. if (locations == 0)
  3974. locations = new vector<Location>;
  3975. locations->push_back(loc);
  3976. i += 3;
  3977. }
  3978. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3979. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3980. if (quest_step && icon > 0)
  3981. quest_step->SetIcon(icon);
  3982. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3983. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3984. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3985. }
  3986. }
  3987. lua_interface->ResetFunctionStack(state);
  3988. return 0;
  3989. }
  3990. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3991. if (!lua_interface)
  3992. return 0;
  3993. Quest* quest = lua_interface->GetQuest(state);
  3994. int32 step = lua_interface->GetInt32Value(state, 2);
  3995. string description = lua_interface->GetStringValue(state, 3);
  3996. float max_variation = lua_interface->GetFloatValue(state, 4);
  3997. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3998. int16 icon = lua_interface->GetInt16Value(state, 6);
  3999. if (quest) {
  4000. const char* taskgroup = 0;
  4001. if (str_taskgroup.length() > 0)
  4002. taskgroup = str_taskgroup.c_str();
  4003. vector<Location>* locations = 0;
  4004. int i = 7;
  4005. while (true) {
  4006. Location loc;
  4007. loc.x = lua_interface->GetFloatValue(state, i);
  4008. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4009. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4010. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4011. break;
  4012. if (locations == 0)
  4013. locations = new vector<Location>;
  4014. locations->push_back(loc);
  4015. i += 3;
  4016. }
  4017. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4018. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4019. if (quest_step && icon > 0)
  4020. quest_step->SetIcon(icon);
  4021. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4022. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4023. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4024. }
  4025. }
  4026. lua_interface->ResetFunctionStack(state);
  4027. return 0;
  4028. }
  4029. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4030. Quest* quest = lua_interface->GetQuest(state);
  4031. int32 step = lua_interface->GetInt32Value(state, 2);
  4032. string description = lua_interface->GetStringValue(state, 3);
  4033. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4034. float percentage = lua_interface->GetFloatValue(state, 5);
  4035. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4036. int16 icon = lua_interface->GetInt16Value(state, 7);
  4037. if (quest) {
  4038. const char* taskgroup = 0;
  4039. if (str_taskgroup.length() > 0)
  4040. taskgroup = str_taskgroup.c_str();
  4041. int32 spell_id = 0;
  4042. vector<int32>* ids = 0;
  4043. int i = 0;
  4044. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4045. if (ids == 0)
  4046. ids = new vector<int32>;
  4047. ids->push_back(spell_id);
  4048. i++;
  4049. }
  4050. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4051. if (quest_step && icon > 0 && quantity > 0)
  4052. quest_step->SetIcon(icon);
  4053. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4054. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4055. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4056. }
  4057. safe_delete(ids);
  4058. }
  4059. lua_interface->ResetFunctionStack(state);
  4060. return 0;
  4061. }
  4062. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4063. if (!lua_interface)
  4064. return 0;
  4065. Quest* quest = lua_interface->GetQuest(state);
  4066. int32 step = lua_interface->GetInt32Value(state, 2);
  4067. string description = lua_interface->GetStringValue(state, 3);
  4068. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4069. float percentage = lua_interface->GetFloatValue(state, 5);
  4070. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4071. int16 icon = lua_interface->GetInt16Value(state, 7);
  4072. if (quest) {
  4073. const char* taskgroup = 0;
  4074. if (str_taskgroup.length() > 0)
  4075. taskgroup = str_taskgroup.c_str();
  4076. int32 item_id = 0;
  4077. vector<int32>* ids = 0;
  4078. int i = 0;
  4079. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4080. if (ids == 0)
  4081. ids = new vector<int32>;
  4082. ids->push_back(item_id);
  4083. i++;
  4084. }
  4085. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4086. if (quest_step && icon > 0 && quantity > 0)
  4087. quest_step->SetIcon(icon);
  4088. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4089. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4090. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4091. }
  4092. safe_delete(ids);
  4093. }
  4094. lua_interface->ResetFunctionStack(state);
  4095. return 0;
  4096. }
  4097. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4098. if (!lua_interface)
  4099. return 0;
  4100. Quest* quest = lua_interface->GetQuest(state);
  4101. int32 step = lua_interface->GetInt32Value(state, 2);
  4102. string description = lua_interface->GetStringValue(state, 3);
  4103. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4104. float percentage = lua_interface->GetFloatValue(state, 5);
  4105. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4106. int16 icon = lua_interface->GetInt16Value(state, 7);
  4107. if (quest) {
  4108. const char* taskgroup = 0;
  4109. if (str_taskgroup.length() > 0)
  4110. taskgroup = str_taskgroup.c_str();
  4111. int32 item_id = 0;
  4112. vector<int32>* ids = 0;
  4113. int i = 0;
  4114. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4115. if (ids == 0)
  4116. ids = new vector<int32>;
  4117. ids->push_back(item_id);
  4118. i++;
  4119. }
  4120. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4121. if (quest_step && icon > 0 && quantity > 0)
  4122. quest_step->SetIcon(icon);
  4123. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4124. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4125. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4126. }
  4127. safe_delete(ids);
  4128. }
  4129. lua_interface->ResetFunctionStack(state);
  4130. return 0;
  4131. }
  4132. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4133. if (!lua_interface)
  4134. return 0;
  4135. Quest* quest = lua_interface->GetQuest(state);
  4136. string action = lua_interface->GetStringValue(state, 2);
  4137. lua_interface->ResetFunctionStack(state);
  4138. if (quest) {
  4139. if (action.length() > 0)
  4140. quest->SetCompleteAction(action);
  4141. }
  4142. return 0;
  4143. }
  4144. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4145. if (!lua_interface)
  4146. return 0;
  4147. Quest* quest = lua_interface->GetQuest(state);
  4148. int32 step = lua_interface->GetInt32Value(state, 2);
  4149. string action = lua_interface->GetStringValue(state, 3);
  4150. lua_interface->ResetFunctionStack(state);
  4151. if (quest) {
  4152. if (step > 0 && action.length() > 0)
  4153. quest->AddCompleteAction(step, action);
  4154. }
  4155. return 0;
  4156. }
  4157. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4158. if (!lua_interface)
  4159. return 0;
  4160. Quest* quest = lua_interface->GetQuest(state);
  4161. int32 step = lua_interface->GetInt32Value(state, 2);
  4162. string action = lua_interface->GetStringValue(state, 3);
  4163. lua_interface->ResetFunctionStack(state);
  4164. if (quest) {
  4165. if (step > 0 && action.length() > 0)
  4166. quest->AddProgressAction(step, action);
  4167. }
  4168. return 0;
  4169. }
  4170. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4171. if (!lua_interface)
  4172. return 0;
  4173. Quest* quest = lua_interface->GetQuest(state);
  4174. string description = lua_interface->GetStringValue(state, 2);
  4175. lua_interface->ResetFunctionStack(state);
  4176. if (quest && description.length() > 0)
  4177. quest->SetDescription(description);
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4181. if (!lua_interface)
  4182. return 0;
  4183. Quest* quest = lua_interface->GetQuest(state);
  4184. string description = lua_interface->GetStringValue(state, 2);
  4185. lua_interface->ResetFunctionStack(state);
  4186. if (quest && description.length() > 0)
  4187. quest->SetCompletedDescription(description);
  4188. return 0;
  4189. }
  4190. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4191. if (!lua_interface)
  4192. return 0;
  4193. Quest* quest = lua_interface->GetQuest(state);
  4194. int32 step = lua_interface->GetInt32Value(state, 2);
  4195. string description = lua_interface->GetStringValue(state, 3);
  4196. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4197. lua_interface->ResetFunctionStack(state);
  4198. if (quest && step > 0 && description.length() > 0) {
  4199. quest->SetTaskGroupDescription(step, description, display_bullets);
  4200. }
  4201. return 0;
  4202. }
  4203. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4204. if (!lua_interface)
  4205. return 0;
  4206. Quest* quest = lua_interface->GetQuest(state);
  4207. int32 step = lua_interface->GetInt32Value(state, 2);
  4208. string description = lua_interface->GetStringValue(state, 3);
  4209. lua_interface->ResetFunctionStack(state);
  4210. if (quest && step > 0 && description.length() > 0) {
  4211. quest->SetStepDescription(step, description);
  4212. }
  4213. return 0;
  4214. }
  4215. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4216. Quest* quest = lua_interface->GetQuest(state);
  4217. string zone = lua_interface->GetStringValue(state, 2);
  4218. lua_interface->ResetFunctionStack(state);
  4219. if (quest && zone.length() > 0)
  4220. quest->SetZone(zone);
  4221. return 0;
  4222. }
  4223. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4224. if (!lua_interface)
  4225. return 0;
  4226. Quest* quest = lua_interface->GetQuest(state);
  4227. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4228. lua_interface->ResetFunctionStack(state);
  4229. if (quest && spawn) {
  4230. if (spawn->IsPlayer()) {
  4231. Client* client = ((Player*)spawn)->GetClient();
  4232. if (client) {
  4233. client->AddPendingQuestReward(quest);
  4234. }
  4235. }
  4236. }
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_Harvest(lua_State* state) {
  4240. if (!lua_interface)
  4241. return 0;
  4242. Spawn* player = lua_interface->GetSpawn(state);
  4243. Spawn* node = lua_interface->GetSpawn(state, 2);
  4244. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4245. Client* client = ((Player*)player)->GetClient();
  4246. if (client) {
  4247. ((GroundSpawn*)node)->ProcessHarvest(client);
  4248. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4249. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4250. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4251. }
  4252. }
  4253. }
  4254. else if (player && player->IsPlayer()) {
  4255. Client* client = ((Player*)player)->GetClient();
  4256. if (client)
  4257. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4258. }
  4259. lua_interface->ResetFunctionStack(state);
  4260. return 0;
  4261. }
  4262. int EQ2Emu_lua_Bind(lua_State* state) {
  4263. if (!lua_interface)
  4264. return 0;
  4265. Spawn* spawn = lua_interface->GetSpawn(state);
  4266. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4267. float x = lua_interface->GetFloatValue(state, 3);
  4268. float y = lua_interface->GetFloatValue(state, 4);
  4269. float z = lua_interface->GetFloatValue(state, 5);
  4270. float h = lua_interface->GetFloatValue(state, 6);
  4271. lua_interface->ResetFunctionStack(state);
  4272. if (!spawn) {
  4273. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4274. return 0;
  4275. }
  4276. if (!spawn->IsPlayer()) {
  4277. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4278. return 0;
  4279. }
  4280. if (zone_id == 0) {
  4281. Client* client = ((Player*)spawn)->GetClient();
  4282. if (!client) {
  4283. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4284. return 0;
  4285. }
  4286. if (!client->Bind())
  4287. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4288. }
  4289. else {
  4290. Player* player = (Player*)spawn;
  4291. player->GetPlayerInfo()->SetBindZone(zone_id);
  4292. player->GetPlayerInfo()->SetBindX(x);
  4293. player->GetPlayerInfo()->SetBindY(y);
  4294. player->GetPlayerInfo()->SetBindZ(z);
  4295. player->GetPlayerInfo()->SetBindHeading(h);
  4296. }
  4297. return 0;
  4298. }
  4299. int EQ2Emu_lua_Gate(lua_State* state) {
  4300. if (!lua_interface)
  4301. return 0;
  4302. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4303. Spawn* spawn = lua_interface->GetSpawn(state);
  4304. lua_interface->ResetFunctionStack(state);
  4305. if (spawn) {
  4306. if (spawn->IsPlayer()) {
  4307. Client* client = ((Player*)spawn)->GetClient();
  4308. if (client) {
  4309. if (!client->Gate((spell != nullptr) ? true : false))
  4310. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4311. }
  4312. }
  4313. }
  4314. return 0;
  4315. }
  4316. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4317. if (!lua_interface)
  4318. return 0;
  4319. bool ret = false;
  4320. Spawn* spawn = lua_interface->GetSpawn(state);
  4321. lua_interface->ResetFunctionStack(state);
  4322. if (spawn) {
  4323. if (spawn->IsPlayer()) {
  4324. Client* client = ((Player*)spawn)->GetClient();
  4325. if (client)
  4326. ret = client->BindAllowed();
  4327. }
  4328. }
  4329. lua_interface->SetBooleanValue(state, ret);
  4330. return 1;
  4331. }
  4332. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4333. if (!lua_interface)
  4334. return 0;
  4335. bool ret = false;
  4336. Spawn* spawn = lua_interface->GetSpawn(state);
  4337. lua_interface->ResetFunctionStack(state);
  4338. if (spawn) {
  4339. if (spawn->IsPlayer()) {
  4340. Client* client = ((Player*)spawn)->GetClient();
  4341. ZoneServer* zone = lua_interface->GetZone(state);
  4342. if (client && zone){
  4343. ret = zone->GetCanGate();
  4344. }
  4345. }
  4346. }
  4347. lua_interface->SetBooleanValue(state, ret);
  4348. return 1;
  4349. }
  4350. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4351. Spawn* spawn = lua_interface->GetSpawn(state);
  4352. lua_interface->ResetFunctionStack(state);
  4353. if (spawn) {
  4354. lua_interface->SetBooleanValue(state, spawn->Alive());
  4355. return 1;
  4356. }
  4357. return 0;
  4358. }
  4359. int EQ2Emu_lua_IsSpawnGroupAlive(lua_State* state) {
  4360. ZoneServer* zone = lua_interface->GetZone(state);
  4361. int32 group_id = lua_interface->GetInt32Value(state, 2);
  4362. lua_interface->ResetFunctionStack(state);
  4363. if (zone) {
  4364. lua_interface->SetBooleanValue(state, zone->IsSpawnGroupAlive(group_id));
  4365. return 1;
  4366. }
  4367. return 0;
  4368. }
  4369. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4370. if (!lua_interface)
  4371. return 0;
  4372. Spawn* spawn = lua_interface->GetSpawn(state);
  4373. lua_interface->ResetFunctionStack(state);
  4374. if (spawn && spawn->IsEntity()) {
  4375. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4376. return 1;
  4377. }
  4378. return 0;
  4379. }
  4380. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4381. Spawn* spawn = lua_interface->GetSpawn(state);
  4382. string message = lua_interface->GetStringValue(state, 2);
  4383. string color_str = lua_interface->GetStringValue(state, 3);
  4384. lua_interface->ResetFunctionStack(state);
  4385. int8 color = CHANNEL_NARRATIVE;
  4386. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4387. Client* client = ((Player*)spawn)->GetClient();
  4388. if (client) {
  4389. if (color_str.length() > 0) {
  4390. // leave for backwards compat, but all future should just use the number
  4391. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4392. color = CHANNEL_COLOR_RED;
  4393. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4394. color = CHANNEL_COLOR_YELLOW;
  4395. else
  4396. {
  4397. // use a number to specify the channel as per Commands/Commands.h defines
  4398. color = (int8)atoul(color_str.c_str());
  4399. }
  4400. }
  4401. client->SimpleMessage(color, message.c_str());
  4402. }
  4403. }
  4404. return 0;
  4405. }
  4406. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4407. Spawn* spawn = lua_interface->GetSpawn(state);
  4408. string message = lua_interface->GetStringValue(state, 2);
  4409. int8 red = lua_interface->GetInt8Value(state, 3);
  4410. int8 green = lua_interface->GetInt8Value(state, 4);
  4411. int8 blue = lua_interface->GetInt8Value(state, 5);
  4412. lua_interface->ResetFunctionStack(state);
  4413. if (!spawn) {
  4414. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4415. return 0;
  4416. }
  4417. if (!spawn->IsPlayer()) {
  4418. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4419. return 0;
  4420. }
  4421. int32 words = ::CountWordsInString(message.c_str());
  4422. if (words < 5)
  4423. words = 5;
  4424. Client* client = ((Player*)spawn)->GetClient();
  4425. if (client)
  4426. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4427. return 0;
  4428. }
  4429. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4430. Spawn* spawn = lua_interface->GetSpawn(state);
  4431. int8 param = lua_interface->GetInt8Value(state, 2);
  4432. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4433. int8 value = lua_interface->GetInt8Value(state, 4);
  4434. lua_interface->ResetFunctionStack(state);
  4435. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4436. Client* client = ((Player*)spawn)->GetClient();
  4437. if (client) {
  4438. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4439. switch (param) {
  4440. case 1: {
  4441. packet->setDataByName("parameter1", param_value);
  4442. break;
  4443. }
  4444. case 2: {
  4445. packet->setDataByName("parameter2", param_value);
  4446. break;
  4447. }
  4448. case 3: {
  4449. packet->setDataByName("parameter3", param_value);
  4450. break;
  4451. }
  4452. case 4: {
  4453. packet->setDataByName("parameter4", param_value);
  4454. break;
  4455. }
  4456. case 5: {
  4457. packet->setDataByName("parameter5", param_value);
  4458. break;
  4459. }
  4460. }
  4461. packet->setDataByName("value", value);
  4462. client->QueuePacket(packet->serialize());
  4463. safe_delete(packet);
  4464. }
  4465. }
  4466. return 0;
  4467. }
  4468. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4469. Spawn* spawn = lua_interface->GetSpawn(state);
  4470. lua_interface->ResetFunctionStack(state);
  4471. if (spawn && spawn->IsPlayer()) {
  4472. if (((Player*)spawn)->GetIsTracking())
  4473. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4474. else
  4475. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4476. }
  4477. return 0;
  4478. }
  4479. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4480. Spawn* player = lua_interface->GetSpawn(state);
  4481. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4482. string name = lua_interface->GetStringValue(state, 3);
  4483. float distance = lua_interface->GetFloatValue(state, 4);
  4484. string command = lua_interface->GetStringValue(state, 5);
  4485. string error_text = lua_interface->GetStringValue(state, 6);
  4486. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4487. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4488. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4489. lua_interface->ResetFunctionStack(state);
  4490. if (spawn) {
  4491. if (distance == 0)
  4492. distance = 10.0f;
  4493. if (command.length() == 0)
  4494. command = name;
  4495. if (command.length() < 1 && name.length() < 1)
  4496. {
  4497. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4498. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4499. spawn->RemovePrimaryCommands();
  4500. }
  4501. else
  4502. {
  4503. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4504. }
  4505. }
  4506. return 0;
  4507. }
  4508. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4509. if (!lua_interface)
  4510. return 0;
  4511. Spawn* player = lua_interface->GetSpawn(state);
  4512. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4513. int16 tier = lua_interface->GetInt16Value(state, 3);
  4514. lua_interface->ResetFunctionStack(state);
  4515. if (player && player->IsPlayer()) {
  4516. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4517. return 1;
  4518. }
  4519. return 0;
  4520. }
  4521. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4522. if (!lua_interface)
  4523. return 0;
  4524. Spawn* player = lua_interface->GetSpawn(state);
  4525. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4526. int16 tier = lua_interface->GetInt16Value(state, 3);
  4527. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4528. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4529. bool add_to_hotbar = true;
  4530. if (num_args > 4) {
  4531. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4532. }
  4533. lua_interface->ResetFunctionStack(state);
  4534. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4535. if (player && spell && player->IsPlayer()) {
  4536. Client* client = player->GetClient();
  4537. if (client) {
  4538. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4539. {
  4540. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4541. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4542. client->GetPlayer()->UnlockSpell(spell);
  4543. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4544. }
  4545. else
  4546. {
  4547. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4548. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4549. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4550. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4551. client->GetPlayer()->UnlockSpell(spell);
  4552. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4553. }
  4554. //if (client ) {
  4555. // ((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);
  4556. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4557. if (outapp)
  4558. client->QueuePacket(outapp);
  4559. }
  4560. }
  4561. return 0;
  4562. }
  4563. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4564. if (!lua_interface)
  4565. return 0;
  4566. Spawn* player = lua_interface->GetSpawn(state);
  4567. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4568. lua_interface->ResetFunctionStack(state);
  4569. if (player && player->IsPlayer()) {
  4570. Client* client = player->GetClient();
  4571. if (client) {
  4572. ((Player*)player)->DeleteSpellBook(type_selection);
  4573. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4574. if (outapp)
  4575. client->QueuePacket(outapp);
  4576. }
  4577. }
  4578. return 0;
  4579. }
  4580. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4581. if (!lua_interface)
  4582. return 0;
  4583. Spawn* player = lua_interface->GetSpawn(state);
  4584. lua_interface->ResetFunctionStack(state);
  4585. if (player && player->IsPlayer()) {
  4586. Client* client = player->GetClient();
  4587. if (client) {
  4588. client->SendNewAdventureSpells();
  4589. }
  4590. }
  4591. return 0;
  4592. }
  4593. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. Spawn* player = lua_interface->GetSpawn(state);
  4597. lua_interface->ResetFunctionStack(state);
  4598. if (player && player->IsPlayer()) {
  4599. Client* client = player->GetClient();
  4600. if (client) {
  4601. client->SendNewTradeskillSpells();
  4602. }
  4603. }
  4604. return 0;
  4605. }
  4606. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4607. if (!lua_interface)
  4608. return 0;
  4609. Spawn* player = lua_interface->GetSpawn(state);
  4610. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4611. lua_interface->ResetFunctionStack(state);
  4612. if (player && player->IsPlayer()) {
  4613. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4614. Client* client = player->GetClient();
  4615. if (sbe && client) {
  4616. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4617. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4618. if (outapp)
  4619. client->QueuePacket(outapp);
  4620. }
  4621. }
  4622. return 0;
  4623. }
  4624. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4625. if (!lua_interface)
  4626. return 0;
  4627. Spawn* player = lua_interface->GetSpawn(state);
  4628. lua_interface->ResetFunctionStack(state);
  4629. if (player && player->IsPlayer()) {
  4630. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4631. return 1;
  4632. }
  4633. return 0;
  4634. }
  4635. int EQ2Emu_lua_Attack(lua_State* state) {
  4636. if (lua_interface) {
  4637. Spawn* npc = lua_interface->GetSpawn(state);
  4638. Spawn* player = lua_interface->GetSpawn(state, 2);
  4639. lua_interface->ResetFunctionStack(state);
  4640. if (npc && player && npc->IsNPC() && player->IsEntity())
  4641. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4642. }
  4643. return 0;
  4644. }
  4645. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4646. if (lua_interface) {
  4647. Spawn* target = lua_interface->GetSpawn(state);
  4648. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4649. lua_interface->ResetFunctionStack(state);
  4650. if (target && target->GetZone())
  4651. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4652. }
  4653. return 0;
  4654. }
  4655. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4656. Spawn* player;
  4657. if (lua_interface) {
  4658. player = lua_interface->GetSpawn(state);
  4659. lua_interface->ResetFunctionStack(state);
  4660. if (player && player->IsPlayer()) {
  4661. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4662. return 1;
  4663. }
  4664. }
  4665. return 0;
  4666. }
  4667. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4668. Spawn* player;
  4669. Client* client;
  4670. if (lua_interface) {
  4671. player = lua_interface->GetSpawn(state);
  4672. lua_interface->ResetFunctionStack(state);
  4673. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4674. if ((client = ((Player*)player)->GetClient()))
  4675. client->HandInCollections();
  4676. }
  4677. return 0;
  4678. }
  4679. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4680. Spawn* widget;
  4681. if (lua_interface) {
  4682. widget = lua_interface->GetSpawn(state);
  4683. lua_interface->ResetFunctionStack(state);
  4684. if (widget && widget->IsWidget())
  4685. ((Widget*)widget)->HandleUse(nullptr, "");
  4686. }
  4687. return 0;
  4688. }
  4689. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4690. Spawn* spawn = 0;
  4691. int32 primary_list = 0;
  4692. int32 secondary_list = 0;
  4693. if (lua_interface) {
  4694. spawn = lua_interface->GetSpawn(state);
  4695. primary_list = lua_interface->GetInt32Value(state, 2);
  4696. secondary_list = lua_interface->GetInt32Value(state, 3);
  4697. lua_interface->ResetFunctionStack(state);
  4698. if (!spawn->IsNPC()) {
  4699. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4700. return 0;
  4701. }
  4702. NPC* npc = (NPC*)spawn;
  4703. npc->SetPrimarySpellList(primary_list);
  4704. npc->SetSecondarySpellList(secondary_list);
  4705. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4706. }
  4707. return 0;
  4708. }
  4709. int EQ2Emu_lua_GetPet(lua_State* state) {
  4710. if (!lua_interface)
  4711. return 0;
  4712. Spawn* spawn = lua_interface->GetSpawn(state);
  4713. lua_interface->ResetFunctionStack(state);
  4714. if (spawn) {
  4715. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4716. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4717. return 1;
  4718. }
  4719. }
  4720. return 0;
  4721. }
  4722. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4723. if (!lua_interface)
  4724. return 0;
  4725. Spawn* spawn = lua_interface->GetSpawn(state);
  4726. lua_interface->ResetFunctionStack(state);
  4727. if (spawn) {
  4728. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4730. return 1;
  4731. }
  4732. }
  4733. return 0;
  4734. }
  4735. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4736. if (!lua_interface)
  4737. return 0;
  4738. Spawn* spawn = lua_interface->GetSpawn(state);
  4739. lua_interface->ResetFunctionStack(state);
  4740. if (spawn) {
  4741. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4742. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4743. return 1;
  4744. }
  4745. }
  4746. return 0;
  4747. }
  4748. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4749. if (!lua_interface)
  4750. return 0;
  4751. Spawn* spawn = lua_interface->GetSpawn(state);
  4752. lua_interface->ResetFunctionStack(state);
  4753. if (spawn) {
  4754. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4755. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4756. return 1;
  4757. }
  4758. }
  4759. return 0;
  4760. }
  4761. int EQ2Emu_lua_Charm(lua_State* state) {
  4762. if (!lua_interface)
  4763. return 0;
  4764. Spawn* owner = lua_interface->GetSpawn(state);
  4765. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4766. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4767. lua_interface->ResetFunctionStack(state);
  4768. if (!luaspell) {
  4769. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4770. return 0;
  4771. }
  4772. if(luaspell->resisted) {
  4773. return 0;
  4774. }
  4775. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4776. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4777. pet->SetPet(true);
  4778. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4779. ((NPC*)pet)->SetOwner((Entity*)owner);
  4780. // If owner is player and player does not have a summoned pet set the players charsheet
  4781. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4782. Player* player = (Player*)owner;
  4783. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4784. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4785. player->GetInfoStruct()->set_pet_movement(2);
  4786. player->GetInfoStruct()->set_pet_behavior(3);
  4787. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4788. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4789. // Make sure the values get sent to the client
  4790. player->SetCharSheetChanged(true);
  4791. }
  4792. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4793. pet->SetSpawnScript("");
  4794. // Set faction to the same as the owner
  4795. pet->SetFactionID(owner->GetFactionID());
  4796. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4797. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4798. // Clear hate list
  4799. ((NPC*)pet)->Brain()->ClearHate();
  4800. // Set the brain to a pet brain
  4801. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4802. }
  4803. return 0;
  4804. }
  4805. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4806. if (!lua_interface)
  4807. return 0;
  4808. Spawn* spawn = lua_interface->GetSpawn(state);
  4809. lua_interface->ResetFunctionStack(state);
  4810. if (!spawn) {
  4811. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4812. return 0;
  4813. }
  4814. vector<Spawn*> groupMembers;
  4815. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4816. groupMembers = *spawn->GetSpawnGroup();
  4817. }
  4818. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4819. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4820. deque<GroupMemberInfo*>::iterator itr;
  4821. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4822. if (group)
  4823. {
  4824. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4825. deque<GroupMemberInfo*>* members = group->GetMembers();
  4826. GroupMemberInfo* info = 0;
  4827. for (itr = members->begin(); itr != members->end(); itr++) {
  4828. info = *itr;
  4829. if (info->client)
  4830. groupMembers.push_back(info->client->GetPlayer());
  4831. }
  4832. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4833. }
  4834. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4835. }
  4836. else
  4837. return 0;
  4838. lua_createtable(state, groupMembers.size(), 0);
  4839. int newTable = lua_gettop(state);
  4840. for (int32 i = 0; i < groupMembers.size(); i++) {
  4841. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4842. lua_rawseti(state, newTable, i + 1);
  4843. }
  4844. return 1;
  4845. }
  4846. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4847. if (!lua_interface)
  4848. return 0;
  4849. lua_interface->ResetFunctionStack(state);
  4850. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4851. lua_interface->SetOptionWindowValue(state, option_window);
  4852. return 1;
  4853. }
  4854. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4855. if (!lua_interface)
  4856. return 0;
  4857. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4858. if (option_window) {
  4859. OptionWindowOption option_window_option;
  4860. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4861. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4862. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4863. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4864. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4865. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4866. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4867. option_window->push_back(option_window_option);
  4868. }
  4869. lua_interface->ResetFunctionStack(state);
  4870. return 0;
  4871. }
  4872. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4873. if (!lua_interface)
  4874. return 0;
  4875. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4876. Spawn* player = lua_interface->GetSpawn(state, 2);
  4877. string window_title = lua_interface->GetStringValue(state, 3);
  4878. string cancel_command = lua_interface->GetStringValue(state, 4);
  4879. lua_interface->ResetFunctionStack(state);
  4880. if (!player->IsPlayer()) {
  4881. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4882. return 0;
  4883. }
  4884. Client* client = ((Player*)player)->GetClient();
  4885. if (option_window && window_title.length() > 0 && client) {
  4886. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4887. if (!packet)
  4888. return 0;
  4889. packet->setDataByName("title_text", window_title.c_str());
  4890. if (cancel_command.length() > 0)
  4891. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4892. packet->setArrayLengthByName("num_selections", option_window->size());
  4893. vector<OptionWindowOption>::iterator itr;
  4894. int8 i = 0;
  4895. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4896. OptionWindowOption opt = *itr;
  4897. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4898. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4899. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4900. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4901. if (opt.optionCommand.length() > 0)
  4902. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4903. if (opt.optionConfirmTitle.length() > 0)
  4904. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4905. i++;
  4906. }
  4907. client->QueuePacket(packet->serialize());
  4908. lua_interface->SetLuaUserDataStale(option_window);
  4909. safe_delete(option_window);
  4910. safe_delete(packet);
  4911. }
  4912. return 0;
  4913. }
  4914. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4915. if (!lua_interface)
  4916. return 0;
  4917. Spawn* spawn = lua_interface->GetSpawn(state);
  4918. lua_interface->ResetFunctionStack(state);
  4919. if (spawn) {
  4920. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4921. return 1;
  4922. }
  4923. else
  4924. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4925. return 0;
  4926. }
  4927. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4928. if (!lua_interface)
  4929. return 0;
  4930. Spawn* spawn = lua_interface->GetSpawn(state);
  4931. lua_interface->ResetFunctionStack(state);
  4932. if (spawn) {
  4933. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4934. return 1;
  4935. }
  4936. else
  4937. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4938. return 0;
  4939. }
  4940. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4941. if (!lua_interface)
  4942. return 0;
  4943. Spawn* spawn = lua_interface->GetSpawn(state);
  4944. lua_interface->ResetFunctionStack(state);
  4945. if (spawn) {
  4946. int8 class_id = spawn->GetTradeskillClass();
  4947. // Need to add 42 for the offset in the array
  4948. class_id += 44;
  4949. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4950. return 1;
  4951. }
  4952. else
  4953. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4954. return 0;
  4955. }
  4956. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4957. if (!lua_interface)
  4958. return 0;
  4959. Spawn* spawn = lua_interface->GetSpawn(state);
  4960. int16 level = lua_interface->GetInt8Value(state, 2);
  4961. lua_interface->ResetFunctionStack(state);
  4962. if (spawn) {
  4963. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4964. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4965. else
  4966. spawn->SetTSLevel(level);
  4967. }
  4968. else
  4969. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4970. return 0;
  4971. }
  4972. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4973. if (!lua_interface)
  4974. return 0;
  4975. Spawn* spawn = lua_interface->GetSpawn(state);
  4976. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4977. lua_interface->ResetFunctionStack(state);
  4978. if (spawn) {
  4979. spawn->SetAttackable(attackable);
  4980. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4981. }
  4982. return 0;
  4983. }
  4984. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4985. // Check to see if we have a valid lua_interface
  4986. if (!lua_interface)
  4987. return 0;
  4988. // Get the spawn that is getting the pet
  4989. Spawn* spawn = lua_interface->GetSpawn(state);
  4990. // Get the DB ID of the pet
  4991. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4992. // The max level the pet can gain
  4993. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4994. // Get the spell that this command was called from
  4995. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4996. lua_interface->ResetFunctionStack(state);
  4997. // Check to make sure the spawn pointer is valid
  4998. if (!spawn) {
  4999. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5000. return 0;
  5001. }
  5002. // Check to make sure the spawn is an entity
  5003. if (!spawn->IsEntity()) {
  5004. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5005. return 0;
  5006. }
  5007. // Check to make sure the spawn doesn't already have a pet of this type
  5008. if (((Entity*)spawn)->GetPet()) {
  5009. if (spawn->IsPlayer()) {
  5010. Client* client = ((Player*)spawn)->GetClient();
  5011. if (client)
  5012. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5013. }
  5014. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5015. return 0;
  5016. }
  5017. // Check to see if the DB ID for the pet is set
  5018. if (pet_id == 0) {
  5019. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5020. return 0;
  5021. }
  5022. // Check to see if the pointer to the spell is valid
  5023. if (!luaspell) {
  5024. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5025. return 0;
  5026. }
  5027. if(luaspell->resisted) {
  5028. return 0;
  5029. }
  5030. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5031. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5032. if (!pet) {
  5033. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5034. return 0;
  5035. }
  5036. // Check to make sure the pet is an npc
  5037. if (!pet->IsNPC()) {
  5038. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5039. return 0;
  5040. }
  5041. // Spawn the pet at the same location as the owner
  5042. pet->SetX(spawn->GetX());
  5043. pet->SetY(spawn->GetY());
  5044. pet->SetZ(spawn->GetZ());
  5045. pet->SetLocation(spawn->GetLocation());
  5046. pet->SetHeading(spawn->GetHeading());
  5047. std::string petName = std::string("");
  5048. if(spawn->IsEntity()) {
  5049. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5050. }
  5051. if(petName.size() < 1) {
  5052. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5053. petName = spawn->GetZone()->pet_names.at(rand_index);
  5054. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5055. }
  5056. // If player set various values for the char sheet (pet window)
  5057. if (spawn->IsPlayer()) {
  5058. Player* player = (Player*)spawn;
  5059. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5060. player->GetInfoStruct()->set_pet_name(petName);
  5061. player->GetInfoStruct()->set_pet_movement(2);
  5062. player->GetInfoStruct()->set_pet_behavior(3);
  5063. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5064. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5065. // Make sure the values get sent to the client
  5066. player->SetCharSheetChanged(true);
  5067. }
  5068. // Set the pets name
  5069. pet->SetName(petName.c_str());
  5070. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5071. if (max_level > 0)
  5072. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5073. else
  5074. pet->SetLevel(spawn->GetLevel());
  5075. // Set the max level this pet can reach
  5076. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5077. ((NPC*)pet)->UpdateWeapons();
  5078. // Set the faction of the pet to the same faction as the owner
  5079. pet->SetFactionID(spawn->GetFactionID());
  5080. // Set the spawn as a pet
  5081. pet->SetPet(true);
  5082. // Give a pointer of the owner to the pet
  5083. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5084. // Give a pointer of the pet to the owner
  5085. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5086. // Set the pet type
  5087. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5088. // Set the spell id used to create this pet
  5089. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5090. // Set the spell tier used to create this pet
  5091. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5092. // Set the pets spawn type to 6
  5093. pet->SetSpawnType(6);
  5094. // Set the pets brain
  5095. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5096. // Check to see if the pet has a subtitle
  5097. if (strlen(pet->GetSubTitle()) > 0) {
  5098. // Add the players name to the front of the sub title
  5099. string pet_subtitle;
  5100. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5101. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5102. // Set the pets subtitle to the new one
  5103. pet->SetSubTitle(pet_subtitle.c_str());
  5104. }
  5105. // Add the "Pet Options" entity command to the pet
  5106. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5107. const char* spawn_script = world.GetSpawnScript(pet_id);
  5108. bool runScript = false;
  5109. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5110. runScript = true;
  5111. pet->SetSpawnScript(string(spawn_script));
  5112. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5113. }
  5114. spawn->GetZone()->AddSpawn(pet);
  5115. if(runScript){
  5116. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5117. }
  5118. // Set the pet as the return value for this function
  5119. lua_interface->SetSpawnValue(state, pet);
  5120. return 1;
  5121. }
  5122. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5123. if (!lua_interface)
  5124. return 0;
  5125. Spawn* spawn = lua_interface->GetSpawn(state);
  5126. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5127. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5128. lua_interface->ResetFunctionStack(state);
  5129. if (!spawn) {
  5130. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5131. return 0;
  5132. }
  5133. if (!spawn->IsEntity()) {
  5134. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5135. return 0;
  5136. }
  5137. if (((Entity*)spawn)->GetDeityPet()) {
  5138. if (spawn->IsPlayer()) {
  5139. Client* client = ((Player*)spawn)->GetClient();
  5140. if (client)
  5141. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5142. }
  5143. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5144. return 0;
  5145. }
  5146. if (pet_id == 0) {
  5147. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5148. return 0;
  5149. }
  5150. if (!luaspell) {
  5151. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5152. return 0;
  5153. }
  5154. if(luaspell->resisted) {
  5155. return 0;
  5156. }
  5157. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5158. if (!pet) {
  5159. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5160. return 0;
  5161. }
  5162. if (!pet->IsNPC()) {
  5163. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5164. return 0;
  5165. }
  5166. pet->SetX(spawn->GetX());
  5167. pet->SetY(spawn->GetY());
  5168. pet->SetZ(spawn->GetZ());
  5169. pet->SetLocation(spawn->GetLocation());
  5170. pet->SetHeading(spawn->GetHeading());
  5171. spawn->GetZone()->AddSpawn(pet);
  5172. string random_pet_name;
  5173. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5174. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5175. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5176. pet->SetName(random_pet_name.c_str());
  5177. pet->SetLevel(spawn->GetLevel());
  5178. pet->SetFactionID(spawn->GetFactionID());
  5179. pet->SetPet(true);
  5180. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5181. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5182. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5183. pet->SetSpawnType(6);
  5184. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5185. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5186. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5187. if (strlen(pet->GetSubTitle()) > 0) {
  5188. string pet_subtitle;
  5189. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5190. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5191. pet->SetSubTitle(pet_subtitle.c_str());
  5192. }
  5193. // deity and cosmetic pets are not attackable
  5194. pet->SetAttackable(false);
  5195. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5196. lua_interface->SetSpawnValue(state, pet);
  5197. return 1;
  5198. }
  5199. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5200. if (!lua_interface)
  5201. return 0;
  5202. Spawn* spawn = lua_interface->GetSpawn(state);
  5203. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5204. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5205. lua_interface->ResetFunctionStack(state);
  5206. if (!spawn) {
  5207. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5208. return 0;
  5209. }
  5210. if (!spawn->IsEntity()) {
  5211. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5212. return 0;
  5213. }
  5214. if (((Entity*)spawn)->GetCosmeticPet()) {
  5215. if (spawn->IsPlayer()) {
  5216. Client* client = ((Player*)spawn)->GetClient();
  5217. if (client)
  5218. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5219. }
  5220. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5221. return 0;
  5222. }
  5223. if (pet_id == 0) {
  5224. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5225. return 0;
  5226. }
  5227. if (!luaspell) {
  5228. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5229. return 0;
  5230. }
  5231. if(luaspell->resisted) {
  5232. return 0;
  5233. }
  5234. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5235. if (!pet) {
  5236. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5237. return 0;
  5238. }
  5239. if (!pet->IsNPC()) {
  5240. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5241. return 0;
  5242. }
  5243. pet->SetX(spawn->GetX());
  5244. pet->SetY(spawn->GetY());
  5245. pet->SetZ(spawn->GetZ());
  5246. pet->SetLocation(spawn->GetLocation());
  5247. pet->SetHeading(spawn->GetHeading());
  5248. spawn->GetZone()->AddSpawn(pet);
  5249. string random_pet_name;
  5250. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5251. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5252. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5253. pet->SetName(random_pet_name.c_str());
  5254. pet->SetLevel(spawn->GetLevel());
  5255. pet->SetFactionID(spawn->GetFactionID());
  5256. pet->SetPet(true);
  5257. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5258. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5259. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5260. pet->SetSpawnType(6);
  5261. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5262. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5263. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5264. if (strlen(pet->GetSubTitle()) > 0) {
  5265. string pet_subtitle;
  5266. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5267. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5268. pet->SetSubTitle(pet_subtitle.c_str());
  5269. }
  5270. pet->SetAttackable(false);
  5271. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5272. lua_interface->SetSpawnValue(state, pet);
  5273. return 1;
  5274. }
  5275. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5276. if (!lua_interface)
  5277. return 0;
  5278. Spawn* spawn = lua_interface->GetSpawn(state);
  5279. lua_interface->ResetFunctionStack(state);
  5280. if (!spawn) {
  5281. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5282. return 0;
  5283. }
  5284. if (!spawn->IsPet()) {
  5285. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5286. return 0;
  5287. }
  5288. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5289. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5290. return 0;
  5291. }
  5292. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5293. if (!lua_interface)
  5294. return 0;
  5295. Quest* quest = lua_interface->GetQuest(state);
  5296. if (!quest) {
  5297. 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));
  5298. lua_interface->ResetFunctionStack(state);
  5299. return 0;
  5300. }
  5301. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5302. lua_interface->ResetFunctionStack(state);
  5303. if (feather_color > 0)
  5304. quest->SetFeatherColor(feather_color);
  5305. return 0;
  5306. }
  5307. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5308. if (!lua_interface)
  5309. return 0;
  5310. Spawn* spawn = lua_interface->GetSpawn(state);
  5311. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5312. lua_interface->ResetFunctionStack(state);
  5313. if (!spawn) {
  5314. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5315. return 0;
  5316. }
  5317. if (!spawn2) {
  5318. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. spawn->RemoveSpawnAccess(spawn2);
  5322. return 0;
  5323. }
  5324. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5325. if (!lua_interface)
  5326. return 0;
  5327. ZoneServer* zone = lua_interface->GetZone(state);
  5328. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5329. lua_interface->ResetFunctionStack(state);
  5330. if (!zone) {
  5331. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5332. return 0;
  5333. }
  5334. if (location_id == 0) {
  5335. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5336. return 0;
  5337. }
  5338. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5339. if (!location) {
  5340. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5341. return 0;
  5342. }
  5343. Spawn* spawn = 0;
  5344. if (location->entities[0]) {
  5345. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5346. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5347. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5348. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5349. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5350. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5351. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5352. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5353. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5354. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5355. if(spawn && spawn->IsOmittedByDBFlag())
  5356. {
  5357. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5358. safe_delete(spawn);
  5359. spawn = 0;
  5360. return 0;
  5361. }
  5362. if (spawn) {
  5363. const char* script = 0;
  5364. for (int x = 0; x < 3; x++) {
  5365. switch (x) {
  5366. case 0:
  5367. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5368. break;
  5369. case 1:
  5370. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5371. break;
  5372. case 2:
  5373. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5374. break;
  5375. }
  5376. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5377. spawn->SetSpawnScript(string(script));
  5378. break;
  5379. }
  5380. }
  5381. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5382. lua_interface->SetSpawnValue(state, spawn);
  5383. return 1;
  5384. }
  5385. else {
  5386. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5387. safe_delete(spawn);
  5388. }
  5389. }
  5390. return 0;
  5391. }
  5392. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5393. if (!lua_interface)
  5394. return 0;
  5395. Spawn* caster = lua_interface->GetSpawn(state);
  5396. Spawn* target = lua_interface->GetSpawn(state, 2);
  5397. int32 id = lua_interface->GetInt32Value(state, 3);
  5398. string command = lua_interface->GetStringValue(state, 4);
  5399. lua_interface->ResetFunctionStack(state);
  5400. if (!caster) {
  5401. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5402. return 0;
  5403. }
  5404. if (!target) {
  5405. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5406. return 0;
  5407. }
  5408. if (!caster->IsPlayer()) {
  5409. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5410. return 0;
  5411. }
  5412. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5413. if (!entity_command) {
  5414. 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());
  5415. return 0;
  5416. }
  5417. Client* client = ((Player*)caster)->GetClient();
  5418. if (!client) {
  5419. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5420. return 0;
  5421. }
  5422. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5423. return 0;
  5424. }
  5425. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5426. if (!lua_interface)
  5427. return 0;
  5428. Spawn* spawn = lua_interface->GetSpawn(state);
  5429. lua_interface->ResetFunctionStack(state);
  5430. if (!spawn) {
  5431. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5432. return 0;
  5433. }
  5434. if (!spawn->IsNPC()) {
  5435. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5436. return 0;
  5437. }
  5438. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5439. return 0;
  5440. }
  5441. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5442. if (!lua_interface)
  5443. return 0;
  5444. Spawn* spawn = lua_interface->GetSpawn(state);
  5445. int16 tick = lua_interface->GetInt16Value(state, 2);
  5446. lua_interface->ResetFunctionStack(state);
  5447. if (!spawn) {
  5448. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5449. return 0;
  5450. }
  5451. if (!spawn->IsNPC()) {
  5452. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5453. return 0;
  5454. }
  5455. if (tick < 20) {
  5456. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5457. return 0;
  5458. }
  5459. ((NPC*)spawn)->Brain()->SetTick(tick);
  5460. return 0;
  5461. }
  5462. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5463. if (!lua_interface)
  5464. return 0;
  5465. Spawn* spawn = lua_interface->GetSpawn(state);
  5466. Spawn* target = lua_interface->GetSpawn(state, 2);
  5467. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5468. lua_interface->ResetFunctionStack(state);
  5469. if (!spawn) {
  5470. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5471. return 0;
  5472. }
  5473. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5474. spawn->SetFollowTarget(target, follow_distance);
  5475. return 0;
  5476. }
  5477. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5478. if (!lua_interface)
  5479. return 0;
  5480. Spawn* spawn = lua_interface->GetSpawn(state);
  5481. lua_interface->ResetFunctionStack(state);
  5482. if (!spawn) {
  5483. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5484. return 0;
  5485. }
  5486. Spawn* target = spawn->GetFollowTarget();
  5487. if (target) {
  5488. lua_interface->SetSpawnValue(state, target);
  5489. return 1;
  5490. }
  5491. return 0;
  5492. }
  5493. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5494. if (!lua_interface)
  5495. return 0;
  5496. Spawn* spawn = lua_interface->GetSpawn(state);
  5497. lua_interface->ResetFunctionStack(state);
  5498. if (!spawn) {
  5499. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5500. return 0;
  5501. }
  5502. if (spawn->following)
  5503. spawn->following = false;
  5504. else
  5505. spawn->following = true;
  5506. return 0;
  5507. }
  5508. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5509. if (!lua_interface)
  5510. return 0;
  5511. Spawn* spawn = lua_interface->GetSpawn(state);
  5512. lua_interface->ResetFunctionStack(state);
  5513. if (!spawn) {
  5514. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5515. return 0;
  5516. }
  5517. lua_interface->SetBooleanValue(state, spawn->following);
  5518. return 1;
  5519. }
  5520. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5521. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5522. // I will attempt to explain how this function works for future refrence
  5523. // Fist lets make sure lua_interface is valid, if not return out
  5524. if (!lua_interface)
  5525. return 0;
  5526. // Next we grab the first 2 params same as we usually would
  5527. Spawn* spawn = lua_interface->GetSpawn(state);
  5528. string var = lua_interface->GetStringValue(state, 2);
  5529. // 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
  5530. // 1 = Spawn
  5531. // 2 = Zone
  5532. // 3 = Item
  5533. // 4 = Quest
  5534. // 5 = String
  5535. // 6 = nil (null)
  5536. int8 dataType = 0;
  5537. // Define pointers for each potential type
  5538. Spawn* spawnVal = 0;
  5539. ZoneServer* zone = 0;
  5540. Item* item = 0;
  5541. Quest* quest = 0;
  5542. string val;
  5543. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5544. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5545. // options window are also light user data be we do not handle those.
  5546. // We check with lua_islightuserdata(lua_State*, index)
  5547. if (lua_islightuserdata(state, 3)) {
  5548. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5549. // and convert it to LUAUserData*
  5550. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5551. // Check to make sure the data we got is valid, if not give an error
  5552. if (!data || !data->IsCorrectlyInitialized()) {
  5553. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5554. }
  5555. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5556. else if (data->IsSpawn()) {
  5557. spawnVal = data->spawn;
  5558. dataType = 1;
  5559. }
  5560. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5561. else if (data->IsZone()) {
  5562. zone = data->zone;
  5563. dataType = 2;
  5564. }
  5565. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5566. else if (data->IsItem()) {
  5567. item = data->item;
  5568. dataType = 3;
  5569. }
  5570. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5571. else if (data->IsQuest()) {
  5572. quest = data->quest;
  5573. dataType = 4;
  5574. }
  5575. }
  5576. // Wasn't light user data, check if it is nil(null)
  5577. else if (lua_isnil(state, 3)) {
  5578. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5579. dataType = 6;
  5580. }
  5581. // Wasn't light user data or nil (null), must be a string
  5582. else {
  5583. // Set the string and dataType variable
  5584. val = lua_interface->GetStringValue(state, 3);
  5585. dataType = 5;
  5586. }
  5587. lua_interface->ResetFunctionStack(state);
  5588. // We now have all the params, lets check to make sure they are valid
  5589. if (!spawn) {
  5590. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5591. return 0;
  5592. }
  5593. if (var.length() == 0) {
  5594. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5595. return 0;
  5596. }
  5597. if (dataType == 0) {
  5598. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5599. return 0;
  5600. }
  5601. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5602. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5603. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5604. switch (dataType) {
  5605. case 1:
  5606. // 1 = Spawn
  5607. spawn->AddTempVariable(var, spawnVal);
  5608. break;
  5609. case 2:
  5610. // 2 = Zone
  5611. spawn->AddTempVariable(var, zone);
  5612. break;
  5613. case 3:
  5614. // 3 = Item
  5615. spawn->AddTempVariable(var, item);
  5616. break;
  5617. case 4:
  5618. // 4 = Quest
  5619. spawn->AddTempVariable(var, quest);
  5620. break;
  5621. case 5:
  5622. // 5 = String
  5623. spawn->AddTempVariable(var, val);
  5624. break;
  5625. case 6:
  5626. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5627. spawn->DeleteTempVariable(var);
  5628. break;
  5629. }
  5630. // And we are done so return out
  5631. return 0;
  5632. }
  5633. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5634. if (!lua_interface)
  5635. return 0;
  5636. Spawn* spawn = lua_interface->GetSpawn(state);
  5637. string var = lua_interface->GetStringValue(state, 2);
  5638. lua_interface->ResetFunctionStack(state);
  5639. if (!spawn) {
  5640. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5641. return 0;
  5642. }
  5643. if (var.length() == 0) {
  5644. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5645. return 0;
  5646. }
  5647. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5648. int8 type = spawn->GetTempVariableType(var);
  5649. Spawn* spawn2 = 0;
  5650. ZoneServer* zone = 0;
  5651. Item* item = 0;
  5652. Quest* quest = 0;
  5653. // Set the lua function return value based on the type of data the variable contains
  5654. switch (type) {
  5655. case 1:
  5656. spawn2 = spawn->GetTempVariableSpawn(var);
  5657. if (!spawn2)
  5658. return 0;
  5659. lua_interface->SetSpawnValue(state, spawn2);
  5660. break;
  5661. case 2:
  5662. zone = spawn->GetTempVariableZone(var);
  5663. if (!zone)
  5664. return 0;
  5665. lua_interface->SetZoneValue(state, zone);
  5666. break;
  5667. case 3:
  5668. item = spawn->GetTempVariableItem(var);
  5669. if (!item)
  5670. return 0;
  5671. lua_interface->SetItemValue(state, item);
  5672. break;
  5673. case 4:
  5674. quest = spawn->GetTempVariableQuest(var);
  5675. if (!quest)
  5676. return 0;
  5677. lua_interface->SetQuestValue(state, quest);
  5678. break;
  5679. case 5:
  5680. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5681. break;
  5682. default:
  5683. // Not a valid type then the variable was not set so return out
  5684. return 0;
  5685. }
  5686. // Return value was set so return out
  5687. return 1;
  5688. }
  5689. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5690. {
  5691. if (!lua_interface)
  5692. return 0;
  5693. Quest* quest = lua_interface->GetQuest(state);
  5694. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5695. string description = lua_interface->GetStringValue(state, 3);
  5696. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5697. if (!quest) {
  5698. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5699. lua_interface->ResetFunctionStack(state);
  5700. lua_interface->SetBooleanValue(state, false);
  5701. return 1;
  5702. }
  5703. if (!spawn) {
  5704. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5705. lua_interface->ResetFunctionStack(state);
  5706. lua_interface->SetBooleanValue(state, false);
  5707. return 1;
  5708. }
  5709. if (!spawn->IsPlayer()) {
  5710. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5711. lua_interface->ResetFunctionStack(state);
  5712. lua_interface->SetBooleanValue(state, false);
  5713. return 1;
  5714. }
  5715. if (item_id == 0) {
  5716. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5717. lua_interface->ResetFunctionStack(state);
  5718. lua_interface->SetBooleanValue(state, false);
  5719. return 1;
  5720. }
  5721. Client* client = ((Player*)spawn)->GetClient();
  5722. if (!client) {
  5723. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5724. lua_interface->ResetFunctionStack(state);
  5725. lua_interface->SetBooleanValue(state, false);
  5726. return 1;
  5727. }
  5728. Item* item = master_item_list.GetItem(item_id);
  5729. if (!item) {
  5730. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5731. lua_interface->ResetFunctionStack(state);
  5732. lua_interface->SetBooleanValue(state, false);
  5733. return 1;
  5734. }
  5735. Item* firstItem = new Item(item);
  5736. quest->AddTmpRewardItem(firstItem);
  5737. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5738. bool itemsAddedSuccessfully = true;
  5739. if(num_args > 4)
  5740. {
  5741. for(int8 n=5;n<num_args+1;n++)
  5742. {
  5743. int32 new_item = lua_interface->GetInt32Value(state, n);
  5744. Item* tmpItem = master_item_list.GetItem(new_item);
  5745. if(tmpItem)
  5746. {
  5747. Item* newTmpItem = new Item(tmpItem);
  5748. quest->AddTmpRewardItem(newTmpItem);
  5749. }
  5750. else
  5751. itemsAddedSuccessfully = false;
  5752. }
  5753. }
  5754. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5755. lua_interface->ResetFunctionStack(state);
  5756. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5757. return 1;
  5758. }
  5759. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5760. if (!lua_interface)
  5761. return 0;
  5762. Quest* quest = lua_interface->GetQuest(state);
  5763. lua_interface->ResetFunctionStack(state);
  5764. if (!quest) {
  5765. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5766. return 0;
  5767. }
  5768. quest->SetRepeatable(true);
  5769. return 0;
  5770. }
  5771. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5772. if (!lua_interface)
  5773. return 0;
  5774. Spawn* spawn = lua_interface->GetSpawn(state);
  5775. lua_interface->ResetFunctionStack(state);
  5776. if (!spawn) {
  5777. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5781. string ret = classes.GetClassNameCase(base_class);
  5782. if (ret.length() > 0) {
  5783. lua_interface->SetStringValue(state, ret.c_str());
  5784. return 1;
  5785. }
  5786. return 0;
  5787. }
  5788. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5789. if (!lua_interface)
  5790. return 0;
  5791. Spawn* player = lua_interface->GetSpawn(state);
  5792. lua_interface->ResetFunctionStack(state);
  5793. if (player && player->IsPlayer()) {
  5794. Client* client = player->GetClient();
  5795. if (client)
  5796. client->SendWaypoints();
  5797. }
  5798. return 0;
  5799. }
  5800. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5801. if (!lua_interface)
  5802. return 0;
  5803. Spawn* player = lua_interface->GetSpawn(state);
  5804. string name = lua_interface->GetStringValue(state, 2);
  5805. int32 type = lua_interface->GetInt32Value(state, 3);
  5806. lua_interface->ResetFunctionStack(state);
  5807. if (type == 0)
  5808. type = 2;
  5809. if (name.length() > 0) {
  5810. if (player && player->IsPlayer()) {
  5811. Client* client = player->GetClient();
  5812. if (client)
  5813. client->AddWaypoint(name, type);
  5814. }
  5815. }
  5816. return 0;
  5817. }
  5818. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5819. if (!lua_interface)
  5820. return 0;
  5821. Spawn* player = lua_interface->GetSpawn(state);
  5822. string name = lua_interface->GetStringValue(state, 2);
  5823. lua_interface->ResetFunctionStack(state);
  5824. if (name.length() > 0) {
  5825. if (player && player->IsPlayer()) {
  5826. Client* client = player->GetClient();
  5827. if (client)
  5828. client->RemoveWaypoint(name);
  5829. }
  5830. }
  5831. return 0;
  5832. }
  5833. int EQ2Emu_lua_AddWard(lua_State* state) {
  5834. if (!lua_interface)
  5835. return 0;
  5836. int32 damage = lua_interface->GetInt32Value(state);
  5837. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5838. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5839. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5840. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5841. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5842. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5843. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5844. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5845. lua_interface->ResetFunctionStack(state);
  5846. if(!spell || spell->resisted) {
  5847. return 0;
  5848. }
  5849. bool ward_was_added = false;
  5850. ZoneServer* zone = spell->caster->GetZone();
  5851. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5852. for (int32 i = 0; i < spell->targets.size(); i++) {
  5853. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5854. if (!target)
  5855. continue;
  5856. if (target->IsEntity()) {
  5857. // If the ward is already active remove it
  5858. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5859. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5860. // Create new ward info
  5861. WardInfo* ward = new WardInfo;
  5862. ward->Spell = spell;
  5863. ward->BaseDamage = damage;
  5864. ward->DamageLeft = damage;
  5865. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5866. ward->keepWard = keepWard;
  5867. ward->WardType = wardType;
  5868. if (damageAbsorptionPercent > 100)
  5869. damageAbsorptionPercent = 100;
  5870. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5871. if (damageAbsorptionMaxHealthPercent > 100)
  5872. damageAbsorptionMaxHealthPercent = 100;
  5873. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5874. ward->RedirectDamagePercent = redirectDamagePercent;
  5875. ward->LastRedirectDamage = 0;
  5876. ward->LastAbsorbedDamage = 0;
  5877. ward->HitCount = 0;
  5878. spell->num_triggers = maxHitCount;
  5879. spell->had_triggers = true;
  5880. spell->cancel_after_all_triggers = false;
  5881. ward->MaxHitCount = maxHitCount;
  5882. ward->RoundTriggered = false;
  5883. if (wardType == WARD_TYPE_MAGICAL)
  5884. ward->DamageType = damageTypes;
  5885. // Add the ward to the entity
  5886. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5887. ward_was_added = true;
  5888. }
  5889. }
  5890. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5891. if (ward_was_added && spell->caster->IsPlayer()) {
  5892. spell->had_dmg_remaining = true;
  5893. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5894. }
  5895. return 0;
  5896. }
  5897. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5898. if (!lua_interface)
  5899. return 0;
  5900. int32 amount = lua_interface->GetInt32Value(state);
  5901. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5902. lua_interface->ResetFunctionStack(state);
  5903. WardInfo* ward = 0;
  5904. if(!spell || spell->resisted) {
  5905. return 0;
  5906. }
  5907. ZoneServer* zone = spell->caster->GetZone();
  5908. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5909. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5910. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5911. ward = target->GetWard(spell->spell->GetSpellID());
  5912. if (target && ward) {
  5913. ward->DamageLeft += amount;
  5914. if (ward->DamageLeft > ward->BaseDamage)
  5915. ward->DamageLeft = ward->BaseDamage;
  5916. for (int32 i = 0; i < spell->targets.size(); i++) {
  5917. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5918. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5919. }
  5920. }
  5921. }
  5922. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5923. if (ward && spell->caster->IsPlayer())
  5924. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5925. return 0;
  5926. }
  5927. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5928. if (!lua_interface)
  5929. return 0;
  5930. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5931. lua_interface->ResetFunctionStack(state);
  5932. if (!spell) {
  5933. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5934. return 0;
  5935. }
  5936. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5937. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5938. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5939. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5940. if (ward) {
  5941. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5942. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5943. return 1;
  5944. }
  5945. }
  5946. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5947. return 0;
  5948. }
  5949. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5950. if (!lua_interface)
  5951. return 0;
  5952. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5953. if (!spell) {
  5954. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5955. lua_interface->ResetFunctionStack(state);
  5956. return 0;
  5957. }
  5958. string type = lua_interface->GetStringValue(state, 2);
  5959. lua_interface->ResetFunctionStack(state);
  5960. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5961. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5962. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5963. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5964. if (ward) {
  5965. if (boost::iequals(type, "damageleft"))
  5966. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5967. else if (boost::iequals(type, "basedamage"))
  5968. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5969. else if (boost::iequals(type, "keepward"))
  5970. lua_interface->SetBooleanValue(state, ward->keepWard);
  5971. else if (boost::iequals(type, "wardtype"))
  5972. lua_interface->SetInt32Value(state, ward->WardType);
  5973. else if (boost::iequals(type, "dmgabsorptionpct"))
  5974. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5975. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5976. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5977. else if (boost::iequals(type, "redirectdamagepercent"))
  5978. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5979. else if (boost::iequals(type, "lastredirectdamage"))
  5980. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5981. else if (boost::iequals(type, "lastabsorbeddamage"))
  5982. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5983. else if (boost::iequals(type, "hitcount"))
  5984. lua_interface->SetInt32Value(state, ward->HitCount);
  5985. else if (boost::iequals(type, "maxhitcount"))
  5986. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5987. else
  5988. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5989. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5990. return 1;
  5991. }
  5992. }
  5993. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5994. return 0;
  5995. }
  5996. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5997. if (!lua_interface)
  5998. return 0;
  5999. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6000. lua_interface->ResetFunctionStack(state);
  6001. if(!spell) {
  6002. return 0;
  6003. }
  6004. ZoneServer* zone = spell->caster->GetZone();
  6005. Spawn* target = 0;
  6006. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6007. for (int32 i = 0; i < spell->targets.size(); i++) {
  6008. target = zone->GetSpawnByID(spell->targets.at(i));
  6009. if (target && target->IsEntity()) {
  6010. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  6011. }
  6012. }
  6013. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6014. return 0;
  6015. }
  6016. int EQ2Emu_lua_Interrupt(lua_State* state)
  6017. {
  6018. if (!lua_interface)
  6019. return 0;
  6020. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6021. Spawn* target = lua_interface->GetSpawn(state, 2);
  6022. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6023. lua_interface->ResetFunctionStack(state);
  6024. if (!caster)
  6025. {
  6026. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6027. return 0;
  6028. }
  6029. if (!target)
  6030. {
  6031. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6032. return 0;
  6033. }
  6034. if (!spell) {
  6035. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6036. return 0;
  6037. }
  6038. if (!target->IsEntity() && !spell)
  6039. {
  6040. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6041. return 0;
  6042. }
  6043. if (!target && spell) {
  6044. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6045. for (int8 i = 0; i < spell->targets.size(); i++) {
  6046. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6047. if (!target || !target->IsEntity())
  6048. continue;
  6049. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6050. }
  6051. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6052. }
  6053. else
  6054. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6055. return 0;
  6056. }
  6057. int EQ2Emu_lua_Stealth(lua_State* state) {
  6058. if (!lua_interface)
  6059. return 0;
  6060. int8 type = lua_interface->GetInt8Value(state);
  6061. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6062. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6063. lua_interface->ResetFunctionStack(state);
  6064. if (!spell) {
  6065. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6066. return 0;
  6067. }
  6068. ZoneServer* zone = spell->caster->GetZone();
  6069. if (spawn) {
  6070. if (spawn->IsEntity()) {
  6071. if (type == 1) {
  6072. ((Entity*)spawn)->AddStealthSpell(spell);
  6073. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6074. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6075. }
  6076. else if (type == 2) {
  6077. ((Entity*)spawn)->AddInvisSpell(spell);
  6078. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6079. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6080. }
  6081. return 0;
  6082. }
  6083. else {
  6084. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6085. return 0;
  6086. }
  6087. }
  6088. else {
  6089. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6090. for (int32 i = 0; i < spell->targets.size(); i++) {
  6091. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6092. if (!spawn || !spawn->IsEntity())
  6093. continue;
  6094. if (type == 1) {
  6095. ((Entity*)spawn)->AddStealthSpell(spell);
  6096. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6097. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6098. }
  6099. else if (type == 2) {
  6100. ((Entity*)spawn)->AddInvisSpell(spell);
  6101. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6102. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6103. }
  6104. else {
  6105. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6106. break;
  6107. }
  6108. }
  6109. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6110. }
  6111. return 0;
  6112. }
  6113. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6114. if (!lua_interface)
  6115. return 0;
  6116. Spawn* spawn = lua_interface->GetSpawn(state);
  6117. lua_interface->ResetFunctionStack(state);
  6118. if (!spawn) {
  6119. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6120. return 0;
  6121. }
  6122. if (spawn->IsEntity()) {
  6123. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6124. return 1;
  6125. }
  6126. else
  6127. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6128. return 0;
  6129. }
  6130. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6131. if (!lua_interface)
  6132. return 0;
  6133. Spawn* spawn = lua_interface->GetSpawn(state);
  6134. lua_interface->ResetFunctionStack(state);
  6135. if (!spawn) {
  6136. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6137. return 0;
  6138. }
  6139. if (spawn->IsEntity()) {
  6140. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6141. return 1;
  6142. }
  6143. else
  6144. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6145. return 0;
  6146. }
  6147. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6148. if (!lua_interface)
  6149. return 0;
  6150. Spawn* player = lua_interface->GetSpawn(state);
  6151. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6152. lua_interface->ResetFunctionStack(state);
  6153. if (!player->IsPlayer()) {
  6154. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6155. return 0;
  6156. }
  6157. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6158. return 1;
  6159. }
  6160. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6161. if (!lua_interface)
  6162. return 0;
  6163. Spawn* spawn = lua_interface->GetSpawn(state);
  6164. int8 slot = lua_interface->GetInt8Value(state, 2);
  6165. lua_interface->ResetFunctionStack(state);
  6166. if (!spawn) {
  6167. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6168. return 0;
  6169. }
  6170. if (!spawn->IsEntity()) {
  6171. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6172. return 0;
  6173. }
  6174. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6175. if (!item) {
  6176. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6177. return 0;
  6178. }
  6179. lua_interface->SetItemValue(state, item);
  6180. return 1;
  6181. }
  6182. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6183. if (!lua_interface)
  6184. return 0;
  6185. Spawn* player = lua_interface->GetSpawn(state);
  6186. int32 id = lua_interface->GetInt32Value(state, 2);
  6187. lua_interface->ResetFunctionStack(state);
  6188. if (!player) {
  6189. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6190. return 0;
  6191. }
  6192. if (!player->IsPlayer()) {
  6193. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6194. return 0;
  6195. }
  6196. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6197. if (!item) {
  6198. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6199. return 0;
  6200. }
  6201. lua_interface->SetItemValue(state, item);
  6202. return 1;
  6203. }
  6204. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6205. if (!lua_interface)
  6206. return 0;
  6207. Spawn* spawn = lua_interface->GetSpawn(state);
  6208. int8 slot = lua_interface->GetInt8Value(state, 2);
  6209. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6210. lua_interface->ResetFunctionStack(state);
  6211. if (!spawn) {
  6212. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6213. return 0;
  6214. }
  6215. if (!spawn->IsEntity()) {
  6216. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6217. return 0;
  6218. }
  6219. Item* item = master_item_list.GetItem(item_id);
  6220. if (!item) {
  6221. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6222. return 0;
  6223. }
  6224. Item* copy = new Item(item);
  6225. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6226. if(result)
  6227. {
  6228. ((Entity*)spawn)->SetEquipment(copy, slot);
  6229. spawn->vis_changed = true;
  6230. if(spawn->IsPlayer())
  6231. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6232. }
  6233. else
  6234. {
  6235. safe_delete(copy);
  6236. }
  6237. lua_interface->SetBooleanValue(state, result);
  6238. return 1;
  6239. }
  6240. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6241. if (!lua_interface)
  6242. return 0;
  6243. Spawn* spawn = lua_interface->GetSpawn(state);
  6244. int8 slot = lua_interface->GetInt8Value(state, 2);
  6245. Item* item = lua_interface->GetItem(state, 3);
  6246. lua_interface->ResetFunctionStack(state);
  6247. if (!spawn) {
  6248. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6249. return 0;
  6250. }
  6251. if (!spawn->IsEntity()) {
  6252. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6253. return 0;
  6254. }
  6255. if (!item) {
  6256. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6257. return 0;
  6258. }
  6259. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6260. if(result)
  6261. {
  6262. ((Entity*)spawn)->SetEquipment(item, slot);
  6263. spawn->vis_changed = true;
  6264. if(spawn->IsPlayer())
  6265. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6266. }
  6267. lua_interface->SetBooleanValue(state, result);
  6268. return 1;
  6269. }
  6270. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6271. if (!lua_interface)
  6272. return 0;
  6273. Spawn* spawn = lua_interface->GetSpawn(state);
  6274. int8 slot = lua_interface->GetInt8Value(state, 2);
  6275. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6276. lua_interface->ResetFunctionStack(state);
  6277. if (!spawn) {
  6278. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6279. return 0;
  6280. }
  6281. if (!spawn->IsEntity()) {
  6282. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6283. return 0;
  6284. }
  6285. if(slot >= NUM_SLOTS) {
  6286. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6287. return 0;
  6288. }
  6289. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6290. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6291. if(item) {
  6292. item->save_needed = true;
  6293. if(no_delete_item) {
  6294. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6295. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6296. }
  6297. else{
  6298. Client* client = ((Player*)spawn)->GetClient();
  6299. client->UnequipItem(item->details.index);
  6300. }
  6301. }
  6302. }
  6303. else
  6304. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6305. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6306. spawn->vis_changed = true;
  6307. if(spawn->IsPlayer())
  6308. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6309. lua_interface->SetBooleanValue(state, true);
  6310. return 1;
  6311. }
  6312. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6313. if (!lua_interface)
  6314. return 0;
  6315. Spawn* spawn = lua_interface->GetSpawn(state);
  6316. int8 slot = lua_interface->GetInt8Value(state, 2);
  6317. int16 type = lua_interface->GetInt16Value(state, 3);
  6318. int8 r = lua_interface->GetInt8Value(state, 4);
  6319. int8 g = lua_interface->GetInt8Value(state, 5);
  6320. int8 b = lua_interface->GetInt8Value(state, 6);
  6321. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6322. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6323. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6324. lua_interface->ResetFunctionStack(state);
  6325. if (!spawn) {
  6326. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6327. return 0;
  6328. }
  6329. if (!spawn->IsEntity()) {
  6330. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6331. return 0;
  6332. }
  6333. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6334. spawn->vis_changed = true;
  6335. lua_interface->SetBooleanValue(state, true);
  6336. return 1;
  6337. }
  6338. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6339. if (!lua_interface)
  6340. return 0;
  6341. Spawn* player = lua_interface->GetSpawn(state);
  6342. int32 id = lua_interface->GetInt32Value(state, 2);
  6343. int8 count = lua_interface->GetInt8Value(state, 3);
  6344. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6345. lua_interface->ResetFunctionStack(state);
  6346. if (!player) {
  6347. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6348. return 0;
  6349. }
  6350. if (!player->IsPlayer()) {
  6351. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6352. return 0;
  6353. }
  6354. if (!count)
  6355. count = 1;
  6356. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6357. if (!item) {
  6358. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6359. return 0;
  6360. }
  6361. lua_interface->SetItemValue(state, item);
  6362. return 1;
  6363. }
  6364. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6365. if (!lua_interface)
  6366. return 0;
  6367. Spawn* spawn = lua_interface->GetSpawn(state);
  6368. int32 anim = lua_interface->GetInt32Value(state, 2);
  6369. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6370. int8 type = lua_interface->GetInt8Value(state, 4);
  6371. lua_interface->ResetFunctionStack(state);
  6372. if (!spawn) {
  6373. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6374. return 0;
  6375. }
  6376. if (spawn2) {
  6377. if (spawn2->IsPlayer()) {
  6378. if (type != 1 && type != 2)
  6379. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6380. else
  6381. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6382. return 0;
  6383. }
  6384. else {
  6385. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6386. return 0;
  6387. }
  6388. }
  6389. else
  6390. spawn->GetZone()->PlayAnimation(spawn, anim);
  6391. return 0;
  6392. }
  6393. int EQ2Emu_lua_IsPet(lua_State* state) {
  6394. if (!lua_interface)
  6395. return 0;
  6396. Spawn* spawn = lua_interface->GetSpawn(state);
  6397. lua_interface->ResetFunctionStack(state);
  6398. if (!spawn) {
  6399. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6400. return 0;
  6401. }
  6402. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6403. return 1;
  6404. }
  6405. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6406. if (!lua_interface)
  6407. return 0;
  6408. Spawn* spawn = lua_interface->GetSpawn(state);
  6409. lua_interface->ResetFunctionStack(state);
  6410. if (!spawn) {
  6411. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6412. return 0;
  6413. }
  6414. if (!spawn->IsNPC()) {
  6415. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6416. return 0;
  6417. }
  6418. if (((NPC*)spawn)->GetOwner()) {
  6419. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6420. return 1;
  6421. }
  6422. return 0;
  6423. }
  6424. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6425. if (!lua_interface)
  6426. return 0;
  6427. Spawn* spawn = lua_interface->GetSpawn(state);
  6428. Spawn* target = lua_interface->GetSpawn(state, 2);
  6429. lua_interface->ResetFunctionStack(state);
  6430. if (!spawn) {
  6431. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6432. return 0;
  6433. }
  6434. if (!spawn) {
  6435. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6436. return 0;
  6437. }
  6438. spawn->SetTarget(target);
  6439. return 0;
  6440. }
  6441. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6442. if (!lua_interface)
  6443. return 0;
  6444. Spawn* spawn = lua_interface->GetSpawn(state);
  6445. bool val = lua_interface->GetBooleanValue(state, 2);
  6446. lua_interface->ResetFunctionStack(state);
  6447. if (!spawn) {
  6448. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6449. return 0;
  6450. }
  6451. if (!spawn->IsEntity()) {
  6452. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6453. return 0;
  6454. }
  6455. ((Entity*)spawn)->InCombat(val);
  6456. if (val) {
  6457. spawn->ClearRunningLocations();
  6458. spawn->CalculateRunningLocation(true);
  6459. }
  6460. return 0;
  6461. }
  6462. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6463. if (!lua_interface)
  6464. return 0;
  6465. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6466. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6467. lua_interface->ResetFunctionStack(state);
  6468. if (!spawn1) {
  6469. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6470. return 0;
  6471. }
  6472. if (!spawn2) {
  6473. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6474. return 0;
  6475. }
  6476. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6477. return 1;
  6478. }
  6479. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6480. if (!lua_interface)
  6481. return 0;
  6482. Spawn* spawn = lua_interface->GetSpawn(state);
  6483. lua_interface->ResetFunctionStack(state);
  6484. if (!spawn) {
  6485. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6486. return 0;
  6487. }
  6488. if (!spawn->IsNPC()) {
  6489. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6490. return 0;
  6491. }
  6492. ((NPC*)spawn)->ClearRunback();
  6493. return 0;
  6494. }
  6495. int EQ2Emu_lua_Runback(lua_State* state) {
  6496. if (!lua_interface)
  6497. return 0;
  6498. Spawn* spawn = lua_interface->GetSpawn(state);
  6499. lua_interface->ResetFunctionStack(state);
  6500. if (!spawn) {
  6501. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6502. return 0;
  6503. }
  6504. if (!spawn->IsNPC()) {
  6505. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6506. return 0;
  6507. }
  6508. ((NPC*)spawn)->Runback();
  6509. return 0;
  6510. }
  6511. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6512. if (!lua_interface)
  6513. return 0;
  6514. Spawn* spawn = lua_interface->GetSpawn(state);
  6515. lua_interface->ResetFunctionStack(state);
  6516. if (!spawn) {
  6517. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6518. return 0;
  6519. }
  6520. if (!spawn->IsNPC()) {
  6521. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6522. return 0;
  6523. }
  6524. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6525. return 1;
  6526. }
  6527. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6528. if (!lua_interface)
  6529. return 0;
  6530. Spawn* spawn = lua_interface->GetSpawn(state);
  6531. lua_interface->ResetFunctionStack(state);
  6532. if (!spawn) {
  6533. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6534. return 0;
  6535. }
  6536. if (!spawn->IsEntity()) {
  6537. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6538. return 0;
  6539. }
  6540. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6541. return 1;
  6542. }
  6543. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6544. if (!lua_interface)
  6545. return 0;
  6546. Spawn* spawn = lua_interface->GetSpawn(state);
  6547. lua_interface->ResetFunctionStack(state);
  6548. if (!spawn) {
  6549. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6550. return 0;
  6551. }
  6552. if (!spawn->IsEntity()) {
  6553. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6557. return 1;
  6558. }
  6559. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6560. if (!lua_interface)
  6561. return 0;
  6562. Spawn* spawn = lua_interface->GetSpawn(state);
  6563. lua_interface->ResetFunctionStack(state);
  6564. if (!spawn) {
  6565. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6566. return 0;
  6567. }
  6568. if (!spawn->IsEntity()) {
  6569. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6570. return 0;
  6571. }
  6572. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6573. return 1;
  6574. }
  6575. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6576. if (!lua_interface)
  6577. return 0;
  6578. Spawn* spawn = lua_interface->GetSpawn(state);
  6579. lua_interface->ResetFunctionStack(state);
  6580. if (!spawn) {
  6581. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6582. return 0;
  6583. }
  6584. if (!spawn->IsEntity()) {
  6585. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6586. return 0;
  6587. }
  6588. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6589. return 1;
  6590. }
  6591. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6592. if (!lua_interface)
  6593. return 0;
  6594. Spawn* spawn = lua_interface->GetSpawn(state);
  6595. Spawn* target = lua_interface->GetSpawn(state, 2);
  6596. float distance = lua_interface->GetFloatValue(state, 3);
  6597. lua_interface->ResetFunctionStack(state);
  6598. if (!spawn) {
  6599. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6600. return 0;
  6601. }
  6602. if (!target) {
  6603. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6604. return 0;
  6605. }
  6606. if (!spawn->IsNPC()) {
  6607. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6608. return 0;
  6609. }
  6610. if (!target->IsEntity()) {
  6611. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6612. return 0;
  6613. }
  6614. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6615. return 1;
  6616. }
  6617. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6618. if (!lua_interface)
  6619. return 0;
  6620. Spawn* spawn = lua_interface->GetSpawn(state);
  6621. Spawn* target = lua_interface->GetSpawn(state, 2);
  6622. float distance = lua_interface->GetFloatValue(state, 3);
  6623. lua_interface->ResetFunctionStack(state);
  6624. if (!spawn) {
  6625. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6626. return 0;
  6627. }
  6628. if (!target) {
  6629. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6630. return 0;
  6631. }
  6632. if (!spawn->IsNPC()) {
  6633. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6634. return 0;
  6635. }
  6636. if (!target->IsEntity()) {
  6637. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6641. return 0;
  6642. }
  6643. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6644. if (!lua_interface)
  6645. return 0;
  6646. Spawn* spawn = lua_interface->GetSpawn(state);
  6647. lua_interface->ResetFunctionStack(state);
  6648. if (!spawn) {
  6649. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6650. return 0;
  6651. }
  6652. if (!spawn->IsNPC()) {
  6653. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6654. return 0;
  6655. }
  6656. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6657. return 1;
  6658. }
  6659. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6660. if (!lua_interface)
  6661. return 0;
  6662. Spawn* spawn = lua_interface->GetSpawn(state);
  6663. lua_interface->ResetFunctionStack(state);
  6664. if (!spawn) {
  6665. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6666. return 0;
  6667. }
  6668. if (!spawn->IsNPC()) {
  6669. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6670. return 0;
  6671. }
  6672. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6673. return 1;
  6674. }
  6675. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6676. if (!lua_interface)
  6677. return 0;
  6678. Spawn* spawn = lua_interface->GetSpawn(state);
  6679. lua_interface->ResetFunctionStack(state);
  6680. if (!spawn) {
  6681. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6682. return 0;
  6683. }
  6684. if (!spawn->IsNPC()) {
  6685. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6686. return 0;
  6687. }
  6688. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6689. if (hated) {
  6690. lua_interface->SetSpawnValue(state, hated);
  6691. return 1;
  6692. }
  6693. return 0;
  6694. }
  6695. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6696. if (!lua_interface)
  6697. return 0;
  6698. Spawn* spawn = lua_interface->GetSpawn(state);
  6699. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6700. lua_interface->ResetFunctionStack(state);
  6701. if (!spawn) {
  6702. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6703. return 0;
  6704. }
  6705. if (!spawn->IsNPC()) {
  6706. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6707. return 0;
  6708. }
  6709. if (!hated) {
  6710. ((NPC*)spawn)->Brain()->ClearHate();
  6711. return 0;
  6712. }
  6713. else
  6714. {
  6715. if (!hated->IsEntity()) {
  6716. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6717. return 0;
  6718. }
  6719. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6720. return 0;
  6721. }
  6722. return 0;
  6723. }
  6724. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6725. if (!lua_interface)
  6726. return 0;
  6727. Spawn* spawn = lua_interface->GetSpawn(state);
  6728. lua_interface->ResetFunctionStack(state);
  6729. if (!spawn) {
  6730. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6731. return 0;
  6732. }
  6733. if (!spawn->IsNPC()) {
  6734. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6735. return 0;
  6736. }
  6737. ((NPC*)spawn)->Brain()->ClearEncounter();
  6738. return 0;
  6739. }
  6740. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6741. if (!lua_interface)
  6742. return 0;
  6743. Spawn* spawn = lua_interface->GetSpawn(state);
  6744. lua_interface->ResetFunctionStack(state);
  6745. if (!spawn) {
  6746. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6747. return 0;
  6748. }
  6749. if (!spawn->IsNPC()) {
  6750. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6751. return 0;
  6752. }
  6753. // Temp list to store hate list
  6754. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6755. if (encounterList->size() == 0) {
  6756. safe_delete(encounterList);
  6757. return 0;
  6758. }
  6759. lua_createtable(state, encounterList->size(), 0);
  6760. int newTable = lua_gettop(state);
  6761. for (int32 i = 0; i < encounterList->size(); i++) {
  6762. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6763. if (temp)
  6764. lua_interface->SetSpawnValue(state, temp);
  6765. lua_rawseti(state, newTable, i + 1);
  6766. }
  6767. safe_delete(encounterList);
  6768. return 1;
  6769. }
  6770. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6771. if (!lua_interface)
  6772. return 0;
  6773. Spawn* spawn = lua_interface->GetSpawn(state);
  6774. lua_interface->ResetFunctionStack(state);
  6775. if (!spawn) {
  6776. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6777. return 0;
  6778. }
  6779. if (!spawn->IsNPC()) {
  6780. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6781. return 0;
  6782. }
  6783. // Temp list to store hate list
  6784. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6785. if (hateList->size() == 0) {
  6786. safe_delete(hateList);
  6787. return 0;
  6788. }
  6789. lua_createtable(state, hateList->size(), 0);
  6790. int newTable = lua_gettop(state);
  6791. for (int32 i = 0; i < hateList->size(); i++) {
  6792. lua_interface->SetSpawnValue(state, hateList->at(i));
  6793. lua_rawseti(state, newTable, i + 1);
  6794. }
  6795. safe_delete(hateList);
  6796. return 1;
  6797. }
  6798. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6799. if (!lua_interface)
  6800. return 0;
  6801. Spawn* spawn = lua_interface->GetSpawn(state);
  6802. lua_interface->ResetFunctionStack(state);
  6803. if (!spawn) {
  6804. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6805. return 0;
  6806. }
  6807. if (spawn->IsPlayer()) {
  6808. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6809. lua_interface->SetBooleanValue(state, true);
  6810. else
  6811. lua_interface->SetBooleanValue(state, false);
  6812. return 1;
  6813. }
  6814. else {
  6815. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6816. return 1;
  6817. }
  6818. }
  6819. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6820. if (!lua_interface)
  6821. return 0;
  6822. Quest* quest = lua_interface->GetQuest(state);
  6823. lua_interface->ResetFunctionStack(state);
  6824. if (!quest) {
  6825. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6826. return 0;
  6827. }
  6828. quest->SetCompletedFlag(true);
  6829. return 0;
  6830. }
  6831. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6832. if (!lua_interface)
  6833. return 0;
  6834. Spawn* spawn = lua_interface->GetSpawn(state);
  6835. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6836. int8 tier = lua_interface->GetInt8Value(state, 3);
  6837. lua_interface->ResetFunctionStack(state);
  6838. if (!spawn) {
  6839. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6840. return 0;
  6841. }
  6842. if (!spawn->IsEntity()) {
  6843. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6844. return 0;
  6845. }
  6846. if (spellID == 0) {
  6847. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6848. return 0;
  6849. }
  6850. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6851. if (effect) {
  6852. if (tier > 0) {
  6853. // If a tier was passed chec to see if it is the same as the effect
  6854. if (tier == effect->tier)
  6855. lua_interface->SetBooleanValue(state, true);
  6856. else
  6857. lua_interface->SetBooleanValue(state, false);
  6858. return 1;
  6859. }
  6860. else {
  6861. // Have an effect but no tier was passed so return true
  6862. lua_interface->SetBooleanValue(state, true);
  6863. }
  6864. return 1;
  6865. }
  6866. // no effect so return false
  6867. lua_interface->SetBooleanValue(state, false);
  6868. return 1;
  6869. }
  6870. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6871. if (!lua_interface)
  6872. return 0;
  6873. Spawn* spawn = lua_interface->GetSpawn(state);
  6874. int32 id = lua_interface->GetInt32Value(state, 2);
  6875. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6876. lua_interface->ResetFunctionStack(state);
  6877. Spawn* spawn2 = 0;
  6878. vector<Spawn*> list;
  6879. if (!spawn) {
  6880. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6881. return 0;
  6882. }
  6883. //If zone not provided, use spawn's zone
  6884. if (!zone)
  6885. zone = spawn->GetZone();
  6886. list = zone->GetSpawnsByID(id);
  6887. if (list.size() == 0) {
  6888. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6889. return 0;
  6890. }
  6891. vector<Spawn*>::iterator itr = list.begin();
  6892. for (int8 i = 0; i < list.size(); i++) {
  6893. spawn2 = itr[i];
  6894. if (spawn2)
  6895. spawn2->AddAllowAccessSpawn(spawn);
  6896. }
  6897. return 0;
  6898. }
  6899. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6900. if (!lua_interface)
  6901. return 0;
  6902. Spawn* spawn = lua_interface->GetSpawn(state);
  6903. int32 id = lua_interface->GetInt32Value(state, 2);
  6904. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6905. lua_interface->ResetFunctionStack(state);
  6906. Spawn* spawn2 = 0;
  6907. if (!spawn) {
  6908. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6909. return 0;
  6910. }
  6911. //If zone not provided, use spawn's zone
  6912. if (!zone)
  6913. zone = spawn->GetZone();
  6914. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6915. vector<Spawn*>::iterator itr = list.begin();
  6916. if (list.size() == 0) {
  6917. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6918. return 0;
  6919. }
  6920. for (int8 i = 0; i < list.size(); i++) {
  6921. spawn2 = itr[i];
  6922. if (spawn2)
  6923. spawn2->RemoveSpawnAccess(spawn);
  6924. }
  6925. return 0;
  6926. }
  6927. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6928. if (!lua_interface)
  6929. return 0;
  6930. Quest* quest = lua_interface->GetQuest(state);
  6931. lua_interface->ResetFunctionStack(state);
  6932. if (!quest) {
  6933. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6934. return 0;
  6935. }
  6936. quest->SetYellowName(true);
  6937. return 0;
  6938. }
  6939. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6940. if (!lua_interface)
  6941. return 0;
  6942. Spawn* spawn = lua_interface->GetSpawn(state);
  6943. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6944. lua_interface->ResetFunctionStack(state);
  6945. if (!spawn) {
  6946. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6947. return 0;
  6948. }
  6949. if (!spawn->IsPlayer()) {
  6950. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6951. return 0;
  6952. }
  6953. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6954. return 1;
  6955. }
  6956. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6957. if (!lua_interface)
  6958. return 0;
  6959. Spawn* spawn = lua_interface->GetSpawn(state);
  6960. lua_interface->ResetFunctionStack(state);
  6961. if (!spawn) {
  6962. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6963. return 0;
  6964. }
  6965. if (!spawn->IsPlayer()) {
  6966. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6967. return 0;
  6968. }
  6969. ZoneServer* zone = spawn->GetZone();
  6970. if (!zone) {
  6971. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6972. return 0;
  6973. }
  6974. Instance_Type iType = zone->GetInstanceType();
  6975. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6976. iType == GROUP_LOCKOUT_INSTANCE ||
  6977. iType == RAID_LOCKOUT_INSTANCE ||
  6978. iType == SOLO_PERSIST_INSTANCE ||
  6979. iType == GROUP_PERSIST_INSTANCE ||
  6980. iType == RAID_PERSIST_INSTANCE) {
  6981. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6982. if (data) {
  6983. // Check to see if the timer has already been set, if it has return out.
  6984. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6985. return 0;
  6986. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6987. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6988. if(spawn->IsPlayer()) {
  6989. Client* client = ((Player*)spawn)->GetClient();
  6990. if (client) {
  6991. string time_msg = "";
  6992. int32 time = data->success_lockout_time;
  6993. int16 hour;
  6994. int8 min;
  6995. int8 sec;
  6996. hour = time / 3600;
  6997. time = time % 3600;
  6998. min = time / 60;
  6999. time = time % 60;
  7000. sec = time;
  7001. if (hour > 0) {
  7002. char temp[10];
  7003. sprintf(temp, " %i", hour);
  7004. time_msg.append(temp);
  7005. time_msg.append(" hour");
  7006. time_msg.append((hour > 1) ? "s" : "");
  7007. }
  7008. if (min > 0) {
  7009. char temp[5];
  7010. sprintf(temp, " %i", min);
  7011. time_msg.append(temp);
  7012. time_msg.append(" minute");
  7013. time_msg.append((min > 1) ? "s" : "");
  7014. }
  7015. // Only add seconds if minutes and hours are 0
  7016. if (hour == 0 && min == 0 && sec > 0) {
  7017. char temp[5];
  7018. sprintf(temp, " %i", sec);
  7019. time_msg.append(temp);
  7020. time_msg.append(" second");
  7021. time_msg.append((sec > 1) ? "s" : "");
  7022. }
  7023. 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());
  7024. }
  7025. else {
  7026. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7027. }
  7028. }
  7029. }
  7030. else
  7031. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7032. }
  7033. else
  7034. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7035. return 0;
  7036. }
  7037. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7038. if (!lua_interface)
  7039. return 0;
  7040. Spawn* spawn = lua_interface->GetSpawn(state);
  7041. lua_interface->ResetFunctionStack(state);
  7042. if (!spawn) {
  7043. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7044. return 0;
  7045. }
  7046. if (!spawn->IsPlayer()) {
  7047. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7048. return 0;
  7049. }
  7050. ZoneServer* zone = spawn->GetZone();
  7051. if (!zone) {
  7052. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7053. return 0;
  7054. }
  7055. Instance_Type iType = zone->GetInstanceType();
  7056. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7057. iType == GROUP_LOCKOUT_INSTANCE ||
  7058. iType == RAID_LOCKOUT_INSTANCE ||
  7059. iType == SOLO_PERSIST_INSTANCE ||
  7060. iType == GROUP_PERSIST_INSTANCE ||
  7061. iType == RAID_PERSIST_INSTANCE) {
  7062. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7063. if (data) {
  7064. // Check to see if the timer has already been set, if it has return out.
  7065. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7066. return 0;
  7067. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7068. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7069. if(spawn->IsPlayer()) {
  7070. Client* client = ((Player*)spawn)->GetClient();
  7071. if (client) {
  7072. string time_msg = "";
  7073. int32 time = data->failure_lockout_time;
  7074. int16 hour;
  7075. int8 min;
  7076. int8 sec;
  7077. hour = time / 3600;
  7078. time = time % 3600;
  7079. min = time / 60;
  7080. time = time % 60;
  7081. sec = time;
  7082. if (hour > 0) {
  7083. char temp[10];
  7084. sprintf(temp, " %i", hour);
  7085. time_msg.append(temp);
  7086. time_msg.append(" hour");
  7087. time_msg.append((hour > 1) ? "s" : "");
  7088. }
  7089. if (min > 0) {
  7090. char temp[5];
  7091. sprintf(temp, " %i", min);
  7092. time_msg.append(temp);
  7093. time_msg.append(" minute");
  7094. time_msg.append((min > 1) ? "s" : "");
  7095. }
  7096. // Only add seconds if minutes and hours are 0
  7097. if (hour == 0 && min == 0 && sec > 0) {
  7098. char temp[5];
  7099. sprintf(temp, " %i", sec);
  7100. time_msg.append(temp);
  7101. time_msg.append(" second");
  7102. time_msg.append((sec > 1) ? "s" : "");
  7103. }
  7104. 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());
  7105. }
  7106. }
  7107. else {
  7108. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7109. }
  7110. }
  7111. else
  7112. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7113. }
  7114. else
  7115. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7116. return 0;
  7117. }
  7118. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7119. if (!lua_interface)
  7120. return 0;
  7121. Spawn* spawn = lua_interface->GetSpawn(state);
  7122. lua_interface->ResetFunctionStack(state);
  7123. if (!spawn) {
  7124. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7125. return 0;
  7126. }
  7127. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7128. return 1;
  7129. }
  7130. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7131. if (!lua_interface)
  7132. return 0;
  7133. Spawn* player = lua_interface->GetSpawn(state);
  7134. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7135. if (!player) {
  7136. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7137. lua_interface->ResetFunctionStack(state);
  7138. return 0;
  7139. }
  7140. if (!player->IsPlayer()) {
  7141. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7142. lua_interface->ResetFunctionStack(state);
  7143. return 0;
  7144. }
  7145. if (!ground) {
  7146. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7147. lua_interface->ResetFunctionStack(state);
  7148. return 0;
  7149. }
  7150. if (!ground->IsGroundSpawn()) {
  7151. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7152. lua_interface->ResetFunctionStack(state);
  7153. return 0;
  7154. }
  7155. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7156. if (!groundspawn_entries) {
  7157. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7158. lua_interface->ResetFunctionStack(state);
  7159. return 0;
  7160. }
  7161. Skill* skill = 0;
  7162. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7163. if (collection_skill == "Collecting")
  7164. skill = ((Player*)player)->GetSkillByName("Gathering");
  7165. else
  7166. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7167. if (!skill) {
  7168. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7169. lua_interface->ResetFunctionStack(state);
  7170. return 0;
  7171. }
  7172. vector<GroundSpawnEntry*>::iterator itr;
  7173. GroundSpawnEntry* entry = 0;
  7174. bool can_harvest = false;
  7175. sint32 min_skill = -1;
  7176. int16 totalSkill = skill->current_val;
  7177. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7178. if(skillID != 0xFFFFFFFF)
  7179. {
  7180. ((Entity*)player)->MStats.lock();
  7181. totalSkill += ((Entity*)player)->stats[skillID];
  7182. ((Entity*)player)->MStats.unlock();
  7183. }
  7184. // first, iterate through groundspawn_entries, discard tables player cannot use
  7185. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7186. {
  7187. entry = *itr;
  7188. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7189. min_skill = entry->min_skill_level;
  7190. // if player lacks skill, skip table
  7191. if (entry->min_skill_level > totalSkill)
  7192. continue;
  7193. // if bonus, but player lacks level, skip table
  7194. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7195. continue;
  7196. can_harvest = true;
  7197. break;
  7198. }
  7199. lua_interface->SetBooleanValue(state, can_harvest);
  7200. // If false, send the message to the client
  7201. if (!can_harvest) {
  7202. Client* client = ((Player*)player)->GetClient();
  7203. if (client) {
  7204. string msg = "You do not have enough skill to ";
  7205. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7206. msg.append("gather");
  7207. else if (collection_skill == "Mining")
  7208. msg.append("mine");
  7209. else if (collection_skill == "Trapping")
  7210. msg.append("trap");
  7211. else if (collection_skill == "Foresting")
  7212. msg.append("forest");
  7213. else if (collection_skill == "Fishing")
  7214. msg.append("catch");
  7215. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7216. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7217. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7218. }
  7219. }
  7220. lua_interface->ResetFunctionStack(state);
  7221. return 1;
  7222. }
  7223. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7224. if (!lua_interface)
  7225. return 0;
  7226. Spawn* player = lua_interface->GetSpawn(state);
  7227. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7228. lua_interface->ResetFunctionStack(state);
  7229. if (!player) {
  7230. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7231. return 0;
  7232. }
  7233. if (!player->IsPlayer()) {
  7234. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7235. return 0;
  7236. }
  7237. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7238. lua_interface->SetBooleanValue(state, ret);
  7239. return 1;
  7240. }
  7241. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7242. // Check to see if we have a valid lua_interface
  7243. if (!lua_interface)
  7244. return 0;
  7245. // Get the spawn that is getting the pet
  7246. Spawn* spawn = lua_interface->GetSpawn(state);
  7247. Spawn* target = lua_interface->GetSpawn(state, 2);
  7248. // Get the DB ID of the pet
  7249. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7250. float x = lua_interface->GetFloatValue(state, 4);
  7251. float y = lua_interface->GetFloatValue(state, 5);
  7252. float z = lua_interface->GetFloatValue(state, 6);
  7253. // Get the spell that this command was called from
  7254. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7255. lua_interface->ResetFunctionStack(state);
  7256. // Check to make sure the spawn pointer is valid
  7257. if (!spawn) {
  7258. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7259. return 0;
  7260. }
  7261. // Check to make sure the spawn is an entity
  7262. if (!spawn->IsEntity()) {
  7263. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7264. return 0;
  7265. }
  7266. if (!target) {
  7267. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7268. return 0;
  7269. }
  7270. if (!target->IsEntity()) {
  7271. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7272. return 0;
  7273. }
  7274. // Check to see if the DB ID for the pet is set
  7275. if (pet_id == 0) {
  7276. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7277. return 0;
  7278. }
  7279. // Check to see if the pointer to the spell is valid
  7280. if (!luaspell) {
  7281. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7282. return 0;
  7283. }
  7284. if(luaspell->resisted) {
  7285. return 0;
  7286. }
  7287. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7288. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7289. if (!pet) {
  7290. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7291. return 0;
  7292. }
  7293. // Check to make sure the pet is an npc
  7294. if (!pet->IsNPC()) {
  7295. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7296. return 0;
  7297. }
  7298. if (x == 0)
  7299. x = spawn->GetX();
  7300. if (y == 0)
  7301. y = spawn->GetY();
  7302. if (z == 0)
  7303. z = spawn->GetZ();
  7304. // Spawn the pet at the same location as the owner
  7305. pet->SetX(x);
  7306. pet->SetY(y);
  7307. pet->SetZ(z);
  7308. pet->SetLocation(spawn->GetLocation());
  7309. pet->SetHeading(spawn->GetHeading());
  7310. spawn->GetZone()->AddSpawn(pet);
  7311. const char* spawn_script = world.GetSpawnScript(pet_id);
  7312. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7313. spawn->SetSpawnScript(string(spawn_script));
  7314. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7315. }
  7316. std::string petName = std::string("");
  7317. if(spawn->IsEntity()) {
  7318. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7319. }
  7320. if(petName.size() < 1) {
  7321. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7322. petName = spawn->GetZone()->pet_names.at(rand_index);
  7323. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7324. }
  7325. // Set the pets name
  7326. pet->SetName(petName.c_str());
  7327. // Set the level of the pet to the owners level
  7328. pet->SetLevel(spawn->GetLevel());
  7329. // Set the faction of the pet to the same faction as the owner
  7330. pet->SetFactionID(spawn->GetFactionID());
  7331. // Set the spawn as a pet
  7332. pet->SetPet(true);
  7333. // Give a pointer of the owner to the pet
  7334. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7335. // Set the pet type
  7336. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7337. // Set the spell id used to create this pet
  7338. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7339. // Set the spell tier used to create this pet
  7340. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7341. // Set the pets spawn type to 6
  7342. pet->SetSpawnType(6);
  7343. // Set the pets brain
  7344. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7345. // Check to see if the pet has a subtitle
  7346. if (strlen(pet->GetSubTitle()) > 0) {
  7347. // Add the players name to the front of the sub title
  7348. string pet_subtitle;
  7349. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7350. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7351. // Set the pets subtitle to the new one
  7352. pet->SetSubTitle(pet_subtitle.c_str());
  7353. }
  7354. // Set the pet as the return value for this function
  7355. lua_interface->SetSpawnValue(state, pet);
  7356. return 1;
  7357. }
  7358. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7359. if (!lua_interface)
  7360. return 0;
  7361. Spawn* spawn = lua_interface->GetSpawn(state);
  7362. Spawn* player = lua_interface->GetSpawn(state, 2);
  7363. float max_distance = lua_interface->GetFloatValue(state, 3);
  7364. string type = lua_interface->GetStringValue(state, 4);
  7365. lua_interface->ResetFunctionStack(state);
  7366. if (!spawn || (spawn && spawn->IsPlayer())) {
  7367. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7368. return 0;
  7369. }
  7370. if (!player || !player->IsPlayer()) {
  7371. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7372. return 0;
  7373. }
  7374. Client* client = ((Player*)player)->GetClient();
  7375. if (!client) {
  7376. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7377. return 0;
  7378. }
  7379. //Set max_distance to default if not set or not proper value
  7380. if (max_distance <= 0)
  7381. max_distance = 500;
  7382. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7383. if (packet) {
  7384. float unknown2_3 = 0;
  7385. int8 placement_mode = 0;
  7386. if (type == "wall") {
  7387. placement_mode = 2;
  7388. unknown2_3 = 150;
  7389. }
  7390. else if (type == "ceiling")
  7391. placement_mode = 1;
  7392. packet->setDataByName("placement_mode", placement_mode);
  7393. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7394. packet->setDataByName("model_type", spawn->GetModelType());
  7395. packet->setDataByName("unknown", 1); //size
  7396. packet->setDataByName("unknown2", 1); //size 2
  7397. packet->setDataByName("unknown2", .5, 1); //size 3
  7398. packet->setDataByName("unknown2", 3, 2);
  7399. packet->setDataByName("unknown2", unknown2_3, 3);
  7400. packet->setDataByName("max_distance", max_distance);
  7401. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7402. client->QueuePacket(packet->serialize());
  7403. safe_delete(packet);
  7404. }
  7405. return 0;
  7406. }
  7407. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7408. if (!lua_interface)
  7409. return 0;
  7410. Item* item = lua_interface->GetItem(state);
  7411. lua_interface->ResetFunctionStack(state);
  7412. if (!item) {
  7413. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7414. return 0;
  7415. }
  7416. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7417. return 1;
  7418. }
  7419. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7420. if (!lua_interface)
  7421. return 0;
  7422. Item* item = lua_interface->GetItem(state);
  7423. lua_interface->ResetFunctionStack(state);
  7424. if (!item) {
  7425. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7426. return 0;
  7427. }
  7428. lua_interface->SetInt32Value(state, item->effect_type);
  7429. return 1;
  7430. }
  7431. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7432. if (!lua_interface)
  7433. return 0;
  7434. Spawn* spawn = lua_interface->GetSpawn(state);
  7435. lua_interface->ResetFunctionStack(state);
  7436. if (!spawn) {
  7437. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7438. return 0;
  7439. }
  7440. if (spawn->GetZone())
  7441. spawn->GetZone()->AddTransportSpawn(spawn);
  7442. return 0;
  7443. }
  7444. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7445. if (!lua_interface)
  7446. return 0;
  7447. Spawn* spawn = lua_interface->GetSpawn(state);
  7448. lua_interface->ResetFunctionStack(state);
  7449. if (!spawn) {
  7450. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7451. return 0;
  7452. }
  7453. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7454. return 1;
  7455. }
  7456. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7457. if (!lua_interface)
  7458. return 0;
  7459. Skill* skill = lua_interface->GetSkill(state);
  7460. lua_interface->ResetFunctionStack(state);
  7461. if (!skill) {
  7462. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7463. return 0;
  7464. }
  7465. lua_interface->SetInt32Value(state, skill->current_val);
  7466. return 1;
  7467. }
  7468. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7469. if (!lua_interface)
  7470. return 0;
  7471. Skill* skill = lua_interface->GetSkill(state);
  7472. lua_interface->ResetFunctionStack(state);
  7473. if (!skill) {
  7474. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7475. return 0;
  7476. }
  7477. lua_interface->SetInt32Value(state, skill->max_val);
  7478. return 1;
  7479. }
  7480. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7481. if (!lua_interface)
  7482. return 0;
  7483. Skill* skill = lua_interface->GetSkill(state);
  7484. lua_interface->ResetFunctionStack(state);
  7485. if (!skill) {
  7486. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7490. return 1;
  7491. }
  7492. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7493. if (!lua_interface)
  7494. return 0;
  7495. Skill* skill = lua_interface->GetSkill(state);
  7496. int16 value = lua_interface->GetInt16Value(state, 2);
  7497. lua_interface->ResetFunctionStack(state);
  7498. if (!skill) {
  7499. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7500. return 0;
  7501. }
  7502. skill->max_val = value;
  7503. if (skill->max_val < skill->current_val)
  7504. skill->current_val = skill->max_val;
  7505. return 0;
  7506. }
  7507. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7508. if (!lua_interface)
  7509. return 0;
  7510. Skill* skill = lua_interface->GetSkill(state);
  7511. int16 value = lua_interface->GetInt16Value(state, 2);
  7512. lua_interface->ResetFunctionStack(state);
  7513. if (!skill) {
  7514. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7515. return 0;
  7516. }
  7517. if (value > skill->max_val)
  7518. skill->current_val = skill->max_val;
  7519. else
  7520. skill->current_val = value;
  7521. return 0;
  7522. }
  7523. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7524. if (!lua_interface)
  7525. return 0;
  7526. Spawn* player = lua_interface->GetSpawn(state);
  7527. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7528. lua_interface->ResetFunctionStack(state);
  7529. if (skill_id > 0 && player && player->IsPlayer()) {
  7530. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7531. return 1;
  7532. }
  7533. return 0;
  7534. }
  7535. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7536. if (!lua_interface)
  7537. return 0;
  7538. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7539. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7540. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7541. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7542. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7543. lua_interface->ResetFunctionStack(state);
  7544. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7545. if (player_spawn && player_spawn->IsPlayer()) {
  7546. Player* player = (Player*)player_spawn;
  7547. bool added = false;
  7548. if (!player->skill_list.HasSkill(skill_id)) {
  7549. player->AddSkill(skill_id, current_val, max_val, true);
  7550. added = true;
  7551. }
  7552. if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
  7553. Client* client = player->GetClient();
  7554. if (client) {
  7555. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7556. if (packet)
  7557. client->QueuePacket(packet);
  7558. }
  7559. }
  7560. if (added) {
  7561. lua_interface->SetBooleanValue(state, true);
  7562. return 1;
  7563. }
  7564. }
  7565. else {
  7566. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7567. }
  7568. }
  7569. else {
  7570. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7571. }
  7572. lua_interface->SetBooleanValue(state, false);
  7573. return 1;
  7574. }
  7575. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7576. if (!lua_interface)
  7577. return 0;
  7578. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7579. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7580. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7581. lua_interface->ResetFunctionStack(state);
  7582. if (skill_id > 0) {
  7583. if (player_spawn && player_spawn->IsPlayer()) {
  7584. Player* player = (Player*)player_spawn;
  7585. if (player->skill_list.HasSkill(skill_id)) {
  7586. player->RemovePlayerSkill(skill_id, true);
  7587. if (!more_to_remove) {
  7588. Client* client = player->GetClient();
  7589. if (client) {
  7590. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7591. if (packet)
  7592. client->QueuePacket(packet);
  7593. }
  7594. }
  7595. }
  7596. }
  7597. else {
  7598. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7599. }
  7600. }
  7601. else {
  7602. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7603. }
  7604. return 0;
  7605. }
  7606. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7607. if (!lua_interface)
  7608. return 0;
  7609. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7610. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7611. int16 amount = lua_interface->GetInt8Value(state, 3);
  7612. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7613. lua_interface->ResetFunctionStack(state);
  7614. if (amount > 0 && skill_type < 100) {
  7615. if (player_spawn && player_spawn->IsPlayer()) {
  7616. Player* player = (Player*)player_spawn;
  7617. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7618. if (!more_to_increase) {
  7619. Client* client = player->GetClient();
  7620. if (client) {
  7621. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7622. if (packet)
  7623. client->QueuePacket(packet);
  7624. }
  7625. }
  7626. }
  7627. else {
  7628. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7629. }
  7630. }
  7631. else {
  7632. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7633. }
  7634. return 0;
  7635. }
  7636. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7637. if (!lua_interface)
  7638. return 0;
  7639. Spawn* spawn = lua_interface->GetSpawn(state);
  7640. string name = lua_interface->GetStringValue(state, 2);
  7641. lua_interface->ResetFunctionStack(state);
  7642. if (!spawn) {
  7643. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7644. return 0;
  7645. }
  7646. if (!spawn->IsEntity()) {
  7647. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7648. return 0;
  7649. }
  7650. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7651. if (skill) {
  7652. lua_interface->SetSkillValue(state, skill);
  7653. return 1;
  7654. }
  7655. return 0;
  7656. }
  7657. int EQ2Emu_lua_AddProc(lua_State* state) {
  7658. if (!lua_interface)
  7659. return 0;
  7660. Spawn* spawn = lua_interface->GetSpawn(state);
  7661. int8 type = lua_interface->GetInt8Value(state, 2);
  7662. float chance = lua_interface->GetFloatValue(state, 3);
  7663. Item* item = lua_interface->GetItem(state, 4);
  7664. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7665. LuaSpell* spell = 0;
  7666. if (!item)
  7667. spell = lua_interface->GetCurrentSpell(state);
  7668. if (!spawn && (!spell || !use_all_spelltargets)) {
  7669. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7670. return 0;
  7671. }
  7672. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7673. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7674. return 0;
  7675. }
  7676. if (!item && !spell) {
  7677. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7678. return 0;
  7679. }
  7680. if(spell && spell->resisted) {
  7681. return 0;
  7682. }
  7683. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7684. Spawn* target;
  7685. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7686. for (int8 i = 0; i < spell->targets.size(); i++) {
  7687. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7688. if (!target || !target->IsEntity())
  7689. continue;
  7690. ((Entity*)target)->AddProc(type, chance, item, spell);
  7691. }
  7692. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7693. }
  7694. else
  7695. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7696. return 0;
  7697. }
  7698. int EQ2Emu_lua_AddProcExt(lua_State* state) {
  7699. if (!lua_interface)
  7700. return 0;
  7701. Spawn* spawn = lua_interface->GetSpawn(state);
  7702. int8 type = lua_interface->GetInt8Value(state, 2);
  7703. int8 damage_type = lua_interface->GetInt8Value(state, 3);
  7704. float chance = lua_interface->GetFloatValue(state, 4);
  7705. int8 hp_ratio = lua_interface->GetInt8Value(state, 5);
  7706. bool below_health = lua_interface->GetBooleanValue(state, 6);
  7707. bool target_health = lua_interface->GetBooleanValue(state, 7);
  7708. Item* item = lua_interface->GetItem(state, 8);
  7709. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 9) == 1);
  7710. bool extended_version = true;
  7711. LuaSpell* spell = 0;
  7712. if (!item)
  7713. spell = lua_interface->GetCurrentSpell(state);
  7714. if (!spawn && (!spell || !use_all_spelltargets)) {
  7715. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7716. return 0;
  7717. }
  7718. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7719. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7720. return 0;
  7721. }
  7722. if (!item && !spell) {
  7723. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7724. return 0;
  7725. }
  7726. if(spell && spell->resisted) {
  7727. return 0;
  7728. }
  7729. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7730. Spawn* target;
  7731. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7732. for (int8 i = 0; i < spell->targets.size(); i++) {
  7733. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7734. if (!target || !target->IsEntity())
  7735. continue;
  7736. ((Entity*)target)->AddProc(type, chance, item, spell, damage_type, hp_ratio, below_health, target_health, extended_version);
  7737. }
  7738. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7739. }
  7740. else
  7741. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7742. return 0;
  7743. }
  7744. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7745. if (!lua_interface)
  7746. return 0;
  7747. Spawn* spawn = lua_interface->GetSpawn(state);
  7748. Item* item = lua_interface->GetItem(state, 2);
  7749. LuaSpell* spell = 0;
  7750. if (!spawn) {
  7751. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7752. lua_interface->ResetFunctionStack(state);
  7753. return 0;
  7754. }
  7755. if (!spawn->IsEntity()) {
  7756. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7757. lua_interface->ResetFunctionStack(state);
  7758. return 0;
  7759. }
  7760. if (!item)
  7761. spell = lua_interface->GetCurrentSpell(state);
  7762. lua_interface->ResetFunctionStack(state);
  7763. if (!item && !spell) {
  7764. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7765. return 0;
  7766. }
  7767. if (spell && spell->caster && spell->caster->GetZone()) {
  7768. Spawn* target;
  7769. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7770. for (int8 i = 0; i < spell->targets.size(); i++) {
  7771. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7772. if (!target || !target->IsEntity())
  7773. continue;
  7774. ((Entity*)target)->RemoveProc(item, spell);
  7775. }
  7776. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7777. spell->caster->RemoveProc(item, spell);
  7778. }
  7779. else
  7780. ((Entity*)spawn)->RemoveProc(item, spell);
  7781. return 0;
  7782. }
  7783. int EQ2Emu_lua_Knockback(lua_State* state) {
  7784. if (!lua_interface)
  7785. return 0;
  7786. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7787. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7788. int32 duration = lua_interface->GetInt32Value(state, 3);
  7789. float vertical = lua_interface->GetFloatValue(state, 4);
  7790. float horizontal = lua_interface->GetFloatValue(state, 5);
  7791. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7792. lua_interface->ResetFunctionStack(state);
  7793. if (!target_spawn) {
  7794. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7795. return 0;
  7796. }
  7797. if (!spawn) {
  7798. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7799. return 0;
  7800. }
  7801. if ((vertical != 0 || horizontal != 0)) {
  7802. if(spawn->IsPlayer()) {
  7803. Client* client = ((Player*)spawn)->GetClient();
  7804. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7805. if (packet) {
  7806. packet->setDataByName("target_x", target_spawn->GetX());
  7807. packet->setDataByName("target_y", target_spawn->GetY());
  7808. packet->setDataByName("target_z", target_spawn->GetZ());
  7809. packet->setDataByName("vertical_movement", vertical);
  7810. packet->setDataByName("horizontal_movement", horizontal);
  7811. if (use_heading)
  7812. packet->setDataByName("use_player_heading", 1);
  7813. client->QueuePacket(packet->serialize());
  7814. }
  7815. safe_delete(packet);
  7816. }
  7817. else {
  7818. spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
  7819. }
  7820. }
  7821. return 0;
  7822. }
  7823. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7824. if (!lua_interface)
  7825. return 0;
  7826. Spawn* spawn = lua_interface->GetSpawn(state);
  7827. lua_interface->ResetFunctionStack(state);
  7828. if (!spawn) {
  7829. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7830. return 0;
  7831. }
  7832. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7833. return 1;
  7834. }
  7835. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7836. if (!lua_interface)
  7837. return 0;
  7838. Spawn* caster = lua_interface->GetSpawn(state);
  7839. Spawn* target = lua_interface->GetSpawn(state, 2);
  7840. string name = lua_interface->GetStringValue(state, 3);
  7841. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7842. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7843. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7844. string success_msg = lua_interface->GetStringValue(state, 7);
  7845. string effect_msg = lua_interface->GetStringValue(state, 8);
  7846. lua_interface->ResetFunctionStack(state);
  7847. if (!caster) {
  7848. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7849. return 0;
  7850. }
  7851. if (!caster->IsEntity()) {
  7852. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7853. return 0;
  7854. }
  7855. if (!target) {
  7856. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7857. return 0;
  7858. }
  7859. if (!target->IsEntity()) {
  7860. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7861. return 0;
  7862. }
  7863. if (name.length() == 0) {
  7864. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7865. return 0;
  7866. }
  7867. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7868. return 0;
  7869. }
  7870. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7871. if (!lua_interface)
  7872. return 0;
  7873. string name = lua_interface->GetStringValue(state);
  7874. lua_interface->ResetFunctionStack(state);
  7875. if (name.length() == 0) {
  7876. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7877. return 0;
  7878. }
  7879. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7880. if (!skill) {
  7881. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7882. return 0;
  7883. }
  7884. lua_interface->SetInt32Value(state, skill->skill_id);
  7885. return 1;
  7886. }
  7887. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7888. if (!lua_interface)
  7889. return 0;
  7890. Spawn* spawn = lua_interface->GetSpawn(state);
  7891. lua_interface->ResetFunctionStack(state);
  7892. if (!spawn) {
  7893. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7894. return 0;
  7895. }
  7896. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7897. return 1;
  7898. }
  7899. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7900. if (!lua_interface)
  7901. return 0;
  7902. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7903. lua_interface->ResetFunctionStack(state);
  7904. if (!luaspell) {
  7905. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7906. return 0;
  7907. }
  7908. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7909. return 1;
  7910. }
  7911. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7912. if (!lua_interface)
  7913. return 0;
  7914. Spawn* spawn = lua_interface->GetSpawn(state);
  7915. Spawn* target = lua_interface->GetSpawn(state, 2);
  7916. lua_interface->ResetFunctionStack(state);
  7917. if (!spawn) {
  7918. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7919. return 0;
  7920. }
  7921. if (!spawn->IsEntity()) {
  7922. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7923. return 0;
  7924. }
  7925. if (!target) {
  7926. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7927. return 0;
  7928. }
  7929. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7930. return 1;
  7931. }
  7932. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7933. if (!lua_interface)
  7934. return 0;
  7935. Spawn* spawn = lua_interface->GetSpawn(state);
  7936. Spawn* target = lua_interface->GetSpawn(state, 2);
  7937. lua_interface->ResetFunctionStack(state);
  7938. if (!spawn) {
  7939. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7940. return 0;
  7941. }
  7942. if (!spawn->IsEntity()) {
  7943. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7944. return 0;
  7945. }
  7946. if (!target) {
  7947. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7948. return 0;
  7949. }
  7950. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7951. return 1;
  7952. }
  7953. int EQ2Emu_lua_InFront(lua_State* state) {
  7954. if (!lua_interface)
  7955. return 0;
  7956. Spawn* spawn = lua_interface->GetSpawn(state);
  7957. Spawn* target = lua_interface->GetSpawn(state, 2);
  7958. lua_interface->ResetFunctionStack(state);
  7959. if (!spawn) {
  7960. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7961. return 0;
  7962. }
  7963. if (!spawn->IsEntity()) {
  7964. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7965. return 0;
  7966. }
  7967. if (!target) {
  7968. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  7969. return 0;
  7970. }
  7971. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  7972. return 1;
  7973. }
  7974. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7975. if (!lua_interface)
  7976. return 0;
  7977. Item* item = lua_interface->GetItem(state);
  7978. lua_interface->ResetFunctionStack(state);
  7979. if (!item) {
  7980. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7981. return 0;
  7982. }
  7983. lua_interface->SetInt32Value(state, item->details.count);
  7984. return 1;
  7985. }
  7986. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7987. if (!lua_interface)
  7988. return 0;
  7989. Item* item = lua_interface->GetItem(state);
  7990. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7991. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7992. lua_interface->ResetFunctionStack(state);
  7993. if (!item) {
  7994. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7995. return 0;
  7996. }
  7997. if (!owner) {
  7998. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7999. return 0;
  8000. }
  8001. if (!owner->IsPlayer()) {
  8002. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8003. return 0;
  8004. }
  8005. if (item->stack_count < new_count) {
  8006. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  8007. return 0;
  8008. }
  8009. if (new_count > 0) {
  8010. item->details.count = new_count;
  8011. item->save_needed = true;
  8012. }
  8013. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  8014. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  8015. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  8016. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  8017. else
  8018. {
  8019. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  8020. return 0;
  8021. }
  8022. Client* client = ((Player*)owner)->GetClient();
  8023. if (!client)
  8024. return 0;
  8025. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  8026. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  8027. if (app)
  8028. client->QueuePacket(app);
  8029. return 0;
  8030. }
  8031. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  8032. if (!lua_interface)
  8033. return 0;
  8034. int32 time = lua_interface->GetInt32Value(state);
  8035. string function = lua_interface->GetStringValue(state, 2);
  8036. Spawn* caster = lua_interface->GetSpawn(state, 3);
  8037. Spawn* target = lua_interface->GetSpawn(state, 4);
  8038. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8039. lua_interface->ResetFunctionStack(state);
  8040. if (time == 0) {
  8041. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  8042. return 0;
  8043. }
  8044. if (function.length() == 0) {
  8045. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  8046. return 0;
  8047. }
  8048. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  8049. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  8050. return 0;
  8051. }
  8052. SpellScriptTimer* timer = new SpellScriptTimer;
  8053. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  8054. #ifdef WIN32
  8055. ZeroMemory(timer, sizeof(SpellScriptTimer));
  8056. #else
  8057. bzero(timer, sizeof(SpellScriptTimer));
  8058. #endif*/
  8059. timer->caster = 0;
  8060. timer->deleteWhenDone = false;
  8061. timer->target = 0;
  8062. timer->time = Timer::GetCurrentTime2() + time;
  8063. timer->customFunction = function;
  8064. timer->spell = spell;
  8065. if (caster)
  8066. timer->caster = caster->GetID();
  8067. if (target)
  8068. timer->target = target->GetID();
  8069. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8070. return 0;
  8071. }
  8072. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8073. if (!lua_interface)
  8074. return 0;
  8075. float hp_perc = lua_interface->GetFloatValue(state);
  8076. float power_perc = lua_interface->GetFloatValue(state, 2);
  8077. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8078. Spawn* target = lua_interface->GetSpawn(state, 4);
  8079. string heal_name = lua_interface->GetStringValue(state, 5);
  8080. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8081. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8082. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8083. lua_interface->ResetFunctionStack(state);
  8084. if (!spell) {
  8085. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8086. return 0;
  8087. }
  8088. Entity* caster = spell->caster;
  8089. if (!caster) {
  8090. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8091. return 0;
  8092. }
  8093. Client* client = 0;
  8094. PendingResurrection* rez = 0;
  8095. ZoneServer* zone = spell->caster->GetZone();
  8096. if (!target) {
  8097. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8098. if (spell->targets.size() > 0) {
  8099. vector<int32> spell_targets = spell->targets;
  8100. for (int8 i = 0; i < spell_targets.size(); i++) {
  8101. target = zone->GetSpawnByID(spell_targets.at(i));
  8102. if (!target)
  8103. continue;
  8104. if (!target->IsPlayer())
  8105. continue;
  8106. client = ((Player*)target)->GetClient();
  8107. if (!client)
  8108. continue;
  8109. rez = client->GetCurrentRez();
  8110. if (rez->active)
  8111. continue;
  8112. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8113. rez->active = true;
  8114. rez->caster = caster;
  8115. rez->expire_timer = new Timer;
  8116. int32 duration = spell->spell->GetSpellDuration();
  8117. rez->expire_timer->Start(duration * 100);
  8118. rez->hp_perc = hp_perc;
  8119. rez->mp_perc = power_perc;
  8120. rez->range = spell->spell->GetSpellData()->range;
  8121. rez->spell_name = spell->spell->GetName();
  8122. if (heal_name.length() > 0)
  8123. rez->heal_name = heal_name;
  8124. else
  8125. rez->heal_name = rez->spell_name;
  8126. rez->no_calcs = no_calcs;
  8127. rez->crit_mod = crit_mod;
  8128. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8129. if (send_window)
  8130. client->SendResurrectionWindow();
  8131. else {
  8132. target->GetZone()->ResurrectSpawn(target, client);
  8133. rez->should_delete = true;
  8134. }
  8135. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8136. }
  8137. }
  8138. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8139. }
  8140. else {
  8141. if(!target->IsPlayer())
  8142. return 0;
  8143. client = ((Player*)target)->GetClient();
  8144. if (!client)
  8145. return 0;
  8146. rez = client->GetCurrentRez();
  8147. if (rez->active)
  8148. return 0;
  8149. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8150. rez->active = true;
  8151. rez->caster = caster;
  8152. rez->expire_timer = new Timer;
  8153. int32 duration = spell->spell->GetSpellDuration();
  8154. rez->expire_timer->Start(duration * 100);
  8155. rez->hp_perc = hp_perc;
  8156. rez->mp_perc = power_perc;
  8157. rez->range = spell->spell->GetSpellData()->range;
  8158. rez->spell_name = spell->spell->GetName();
  8159. if (heal_name.length() > 0)
  8160. rez->heal_name = heal_name;
  8161. else
  8162. rez->heal_name = rez->spell_name;
  8163. rez->no_calcs = no_calcs;
  8164. rez->crit_mod = crit_mod;
  8165. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8166. if (send_window)
  8167. client->SendResurrectionWindow();
  8168. else {
  8169. target->GetZone()->ResurrectSpawn(target, client);
  8170. rez->should_delete = true;
  8171. }
  8172. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8173. }
  8174. return 0;
  8175. }
  8176. int EQ2Emu_lua_SetVision(lua_State* state) {
  8177. if (!lua_interface)
  8178. return 0;
  8179. Spawn* spawn = lua_interface->GetSpawn(state);
  8180. int32 vision = lua_interface->GetInt32Value(state, 2);
  8181. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8182. lua_interface->ResetFunctionStack(state);
  8183. if (!spawn) {
  8184. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8185. return 0;
  8186. }
  8187. if (!spawn->IsEntity()) {
  8188. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8189. return 0;
  8190. }
  8191. if (spell && spell->targets.size() > 0) {
  8192. ZoneServer* zone = spell->caster->GetZone();
  8193. for (int8 i = 0; i < spell->targets.size(); i++) {
  8194. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8195. if (target && target->IsEntity()) {
  8196. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8197. if (target->IsPlayer())
  8198. ((Player*)target)->SetCharSheetChanged(true);
  8199. }
  8200. }
  8201. }
  8202. else {
  8203. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8204. if (spawn->IsPlayer())
  8205. ((Player*)spawn)->SetCharSheetChanged(true);
  8206. }
  8207. return 0;
  8208. }
  8209. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8210. if (!lua_interface)
  8211. return 0;
  8212. Spawn* spawn = lua_interface->GetSpawn(state);
  8213. float intensity = lua_interface->GetFloatValue(state, 2);
  8214. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8215. lua_interface->ResetFunctionStack(state);
  8216. if (!spawn) {
  8217. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8218. return 0;
  8219. }
  8220. if (!spawn->IsEntity()) {
  8221. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8222. return 0;
  8223. }
  8224. if (spell && spell->targets.size() > 0) {
  8225. ZoneServer* zone = spell->caster->GetZone();
  8226. for (int8 i = 0; i < spell->targets.size(); i++) {
  8227. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8228. if (target && target->IsEntity()) {
  8229. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8230. if (target->IsPlayer())
  8231. ((Player*)target)->SetCharSheetChanged(true);
  8232. }
  8233. }
  8234. }
  8235. else {
  8236. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8237. if (spawn->IsPlayer())
  8238. ((Player*)spawn)->SetCharSheetChanged(true);
  8239. }
  8240. return 0;
  8241. }
  8242. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8243. if (!lua_interface)
  8244. return 0;
  8245. Spawn* spawn = lua_interface->GetSpawn(state);
  8246. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8247. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8248. lua_interface->ResetFunctionStack(state);
  8249. if (!spawn) {
  8250. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8251. return 0;
  8252. }
  8253. if (!spawn->IsEntity()) {
  8254. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8255. return 0;
  8256. }
  8257. if (spell && spell->targets.size() > 0) {
  8258. ZoneServer* zone = spell->caster->GetZone();
  8259. for (int8 i = 0; i < spell->targets.size(); i++) {
  8260. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8261. if (target && target->IsEntity()) {
  8262. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8263. if (target->IsPlayer())
  8264. ((Player*)target)->SetCharSheetChanged(true);
  8265. }
  8266. }
  8267. }
  8268. else {
  8269. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8270. if (spawn->IsPlayer())
  8271. ((Player*)spawn)->SetCharSheetChanged(true);
  8272. }
  8273. return 0;
  8274. }
  8275. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8276. if (!lua_interface)
  8277. return 0;
  8278. Item* item = lua_interface->GetItem(state);
  8279. int8 type = lua_interface->GetInt32Value(state, 2);
  8280. lua_interface->ResetFunctionStack(state);
  8281. if (!item) {
  8282. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8283. return 0;
  8284. }
  8285. if (type == 1)
  8286. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8287. else if (type == 2)
  8288. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8289. return 1;
  8290. }
  8291. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8292. if (!lua_interface)
  8293. return 0;
  8294. Spawn* target = lua_interface->GetSpawn(state);
  8295. float val = lua_interface->GetFloatValue(state, 2);
  8296. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8297. lua_interface->ResetFunctionStack(state);
  8298. // Added from Gangrenous post
  8299. if (spell && spell->resisted)
  8300. return 0;
  8301. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8302. if (val > 1.0f)
  8303. val = 1.0f - (val / 100.0f);
  8304. if (spell && spell->spell && spell->targets.size() > 0) {
  8305. ZoneServer* zone = spell->caster->GetZone();
  8306. for (int32 i = 0; i != spell->targets.size(); i++) {
  8307. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8308. if (spawn && spawn->IsEntity()) {
  8309. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8310. if (spawn->IsPlayer())
  8311. ((Player*)spawn)->SetCharSheetChanged(true);
  8312. }
  8313. }
  8314. }
  8315. else {
  8316. if (target && target->IsEntity()) {
  8317. ((Entity*)target)->SetSpeedMultiplier(val);
  8318. if (target->IsPlayer())
  8319. ((Player*)target)->SetCharSheetChanged(true);
  8320. }
  8321. }
  8322. return 0;
  8323. }
  8324. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8325. if (!lua_interface)
  8326. return 0;
  8327. Spawn* spawn = lua_interface->GetSpawn(state);
  8328. int16 model = lua_interface->GetInt16Value(state, 2);
  8329. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8330. lua_interface->ResetFunctionStack(state);
  8331. if (spell && spell->spell && spell->targets.size() > 0) {
  8332. ZoneServer* zone = spell->caster->GetZone();
  8333. for (int32 i = 0; i < spell->targets.size(); i++) {
  8334. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8335. if (target)
  8336. target->SetIllusionModel(model);
  8337. }
  8338. }
  8339. else {
  8340. if (!spawn) {
  8341. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8342. return 0;
  8343. }
  8344. spawn->SetIllusionModel(model);
  8345. }
  8346. return 0;
  8347. }
  8348. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8349. if (!lua_interface)
  8350. return 0;
  8351. Spawn* spawn = lua_interface->GetSpawn(state);
  8352. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8353. lua_interface->ResetFunctionStack(state);
  8354. if (spell && spell->spell && spell->targets.size() > 0) {
  8355. ZoneServer* zone = spell->caster->GetZone();
  8356. for (int32 i = 0; i < spell->targets.size(); i++) {
  8357. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8358. if (target)
  8359. target->SetIllusionModel(0);
  8360. }
  8361. }
  8362. else {
  8363. if (!spawn) {
  8364. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8365. return 0;
  8366. }
  8367. spawn->SetIllusionModel(0);
  8368. }
  8369. return 0;
  8370. }
  8371. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8372. if (!lua_interface)
  8373. return 0;
  8374. Spawn* caster = lua_interface->GetSpawn(state);
  8375. Spawn* target = lua_interface->GetSpawn(state, 2);
  8376. float chance = lua_interface->GetFloatValue(state, 3);
  8377. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8378. lua_interface->ResetFunctionStack(state);
  8379. if (!caster) {
  8380. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8381. return 0;
  8382. }
  8383. if (!caster->IsEntity()) {
  8384. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8385. return 0;
  8386. }
  8387. if (!target) {
  8388. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8389. return 0;
  8390. }
  8391. if (!target->IsEntity()) {
  8392. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8393. return 0;
  8394. }
  8395. if (chance <= 0) {
  8396. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8397. return 0;
  8398. }
  8399. if (!spell) {
  8400. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8401. return 0;
  8402. }
  8403. if(spell->resisted) {
  8404. return 0;
  8405. }
  8406. if (((Entity*)caster)->GetThreatTransfer()) {
  8407. return 0;
  8408. }
  8409. ThreatTransfer* transfer = new ThreatTransfer;
  8410. transfer->Target = target->GetID();
  8411. transfer->Amount = chance;
  8412. transfer->Spell = spell;
  8413. ((Entity*)caster)->SetThreatTransfer(transfer);
  8414. return 0;
  8415. }
  8416. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8417. if (!lua_interface)
  8418. return 0;
  8419. Spawn* spawn = lua_interface->GetSpawn(state);
  8420. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8421. lua_interface->ResetFunctionStack(state);
  8422. if (!spawn) {
  8423. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8424. return 0;
  8425. }
  8426. if (!spell) {
  8427. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8428. return 0;
  8429. }
  8430. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8431. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8432. if(transfer && transfer->Spell != spell) {
  8433. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8434. return 0;
  8435. }
  8436. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8437. }
  8438. return 0;
  8439. }
  8440. int EQ2Emu_lua_CureByType(lua_State* state) {
  8441. if (!lua_interface)
  8442. return 0;
  8443. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8444. int8 cure_count = lua_interface->GetInt8Value(state);
  8445. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8446. string cure_name = lua_interface->GetStringValue(state, 3);
  8447. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8448. Spawn* target = lua_interface->GetSpawn(state, 5);
  8449. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8450. lua_interface->ResetFunctionStack(state);
  8451. if(spell && spell->resisted) {
  8452. return 0;
  8453. }
  8454. if (target) {
  8455. if (!target->IsEntity()) {
  8456. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8457. return 0;
  8458. }
  8459. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8460. std::string alternate_name = "item";
  8461. if(spell)
  8462. alternate_name = std::string(spell->spell->GetName());
  8463. if(!caster && spell)
  8464. caster = (Spawn*)spell->caster;
  8465. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8466. }
  8467. }
  8468. else {
  8469. ZoneServer* zone = spell->caster->GetZone();
  8470. vector<int32> targets = spell->targets;
  8471. vector<Entity*> targets_to_cure;
  8472. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8473. for (int8 i = 0; i < targets.size(); i++) {
  8474. target = zone->GetSpawnByID(targets.at(i));
  8475. if (!target || !target->IsEntity())
  8476. continue;
  8477. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8478. targets_to_cure.push_back((Entity*)target);
  8479. }
  8480. }
  8481. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8482. vector<Entity*>::iterator itr;
  8483. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8484. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8485. }
  8486. }
  8487. return 0;
  8488. }
  8489. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8490. if (!lua_interface)
  8491. return 0;
  8492. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8493. if (!spell) {
  8494. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8495. lua_interface->ResetFunctionStack(state);
  8496. return 0;
  8497. }
  8498. if(spell->resisted) {
  8499. lua_interface->ResetFunctionStack(state);
  8500. return 0;
  8501. }
  8502. int8 cure_count = lua_interface->GetInt8Value(state);
  8503. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8504. string cure_name = lua_interface->GetStringValue(state, 3);
  8505. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8506. Spawn* target = lua_interface->GetSpawn(state, 5);
  8507. lua_interface->ResetFunctionStack(state);
  8508. if (target) {
  8509. if (!target->IsEntity()) {
  8510. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8511. return 0;
  8512. }
  8513. if (((Entity*)target)->GetDetCount() > 0)
  8514. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8515. }
  8516. else {
  8517. ZoneServer* zone = spell->caster->GetZone();
  8518. vector<int32> targets = spell->targets;
  8519. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8520. for (int8 i = 0; i < targets.size(); i++) {
  8521. target = zone->GetSpawnByID(targets.at(i));
  8522. if (!target || !target->IsEntity())
  8523. continue;
  8524. if (((Entity*)target)->GetDetCount() > 0)
  8525. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8526. }
  8527. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8528. }
  8529. return 0;
  8530. }
  8531. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8532. if (!lua_interface)
  8533. return 0;
  8534. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8535. lua_interface->ResetFunctionStack(state);
  8536. if (!spell) {
  8537. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8538. return 0;
  8539. }
  8540. if (!spell->caster) {
  8541. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8542. return 0;
  8543. }
  8544. if (!spell->caster->GetZone()) {
  8545. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8546. return 0;
  8547. }
  8548. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8549. return 0;
  8550. }
  8551. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8552. if (!lua_interface)
  8553. return 0;
  8554. Spawn* spawn = lua_interface->GetSpawn(state);
  8555. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8556. lua_interface->ResetFunctionStack(state);
  8557. if (!spell) {
  8558. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8559. return 0;
  8560. }
  8561. if (spawn && spawn->IsEntity())
  8562. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8563. else {
  8564. ZoneServer* zone = spell->caster->GetZone();
  8565. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8566. for (int32 i = 0; i < spell->targets.size(); i++) {
  8567. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8568. if (!spawn || !spawn->IsEntity())
  8569. continue;
  8570. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8571. }
  8572. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8573. }
  8574. return 0;
  8575. }
  8576. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8577. if (!lua_interface)
  8578. return 0;
  8579. Spawn* spawn = lua_interface->GetSpawn(state);
  8580. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8581. lua_interface->ResetFunctionStack(state);
  8582. if (!spell) {
  8583. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8584. return 0;
  8585. }
  8586. if (spawn && spawn->IsEntity())
  8587. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8588. else {
  8589. ZoneServer* zone = spell->caster->GetZone();
  8590. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8591. for (int32 i = 0; i < spell->targets.size(); i++) {
  8592. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8593. if (!spawn || !spawn->IsEntity())
  8594. continue;
  8595. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8596. }
  8597. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8598. }
  8599. return 0;
  8600. }
  8601. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8602. if (!lua_interface)
  8603. return 0;
  8604. Spawn* caster = lua_interface->GetSpawn(state);
  8605. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8606. lua_interface->ResetFunctionStack(state);
  8607. if (!caster) {
  8608. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8609. return 0;
  8610. }
  8611. if (!caster->IsPlayer()) {
  8612. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8613. return 0;
  8614. }
  8615. Spawn* target = caster->GetTarget();
  8616. if (!target) {
  8617. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8618. return 0;
  8619. }
  8620. Client* client = ((Player*)caster)->GetClient();
  8621. if (!client) {
  8622. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8623. return 0;
  8624. }
  8625. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8626. if (ho) {
  8627. ho->SetTarget(target->GetID());
  8628. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8629. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8630. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8631. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8632. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8633. deque<GroupMemberInfo*>::iterator itr;
  8634. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8635. if (group)
  8636. {
  8637. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8638. deque<GroupMemberInfo*>* members = group->GetMembers();
  8639. for (itr = members->begin(); itr != members->end(); itr++) {
  8640. if ((*itr)->client)
  8641. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8642. }
  8643. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8644. }
  8645. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8646. }
  8647. else
  8648. safe_delete(ho);
  8649. }
  8650. else {
  8651. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8652. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8653. }
  8654. else
  8655. safe_delete(ho);
  8656. }
  8657. }
  8658. return 0;
  8659. }
  8660. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8661. if (!lua_interface)
  8662. return 0;
  8663. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8664. if (!spell) {
  8665. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8666. return 0;
  8667. }
  8668. int16 triggerCount = lua_interface->GetInt16Value(state);
  8669. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8670. if (!triggerCount) {
  8671. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8672. return 0;
  8673. }
  8674. spell->num_triggers = triggerCount;
  8675. spell->had_triggers = true;
  8676. spell->cancel_after_all_triggers = cancel_after_triggers;
  8677. return 0;
  8678. }
  8679. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8680. if (!lua_interface)
  8681. return 0;
  8682. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8683. lua_interface->ResetFunctionStack(state);
  8684. if (!spell) {
  8685. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8686. return 0;
  8687. }
  8688. lua_interface->SetInt32Value(state, spell->num_triggers);
  8689. return 1;
  8690. }
  8691. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8692. if (!lua_interface)
  8693. return 0;
  8694. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8695. if (!spell) {
  8696. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8697. lua_interface->ResetFunctionStack(state);
  8698. return 0;
  8699. }
  8700. if (!spell->caster || !spell->caster->GetZone()) {
  8701. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8702. lua_interface->ResetFunctionStack(state);
  8703. return 0;
  8704. }
  8705. int16 remove_count = lua_interface->GetInt16Value(state);
  8706. lua_interface->ResetFunctionStack(state);
  8707. if (!remove_count)
  8708. remove_count = 1;
  8709. if (remove_count >= spell->num_triggers) {
  8710. spell->num_triggers = 0;
  8711. if (spell->cancel_after_all_triggers)
  8712. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8713. }
  8714. else {
  8715. spell->num_triggers -= remove_count;
  8716. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8717. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8718. }
  8719. return 0;
  8720. }
  8721. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8722. if (!lua_interface)
  8723. return 0;
  8724. Spawn* spawn = lua_interface->GetSpawn(state);
  8725. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8726. lua_interface->ResetFunctionStack(state);
  8727. if (!spawn) {
  8728. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8729. return 0;
  8730. }
  8731. if (!copy_spawn) {
  8732. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8733. return 0;
  8734. }
  8735. spawn->CopySpawnAppearance(copy_spawn);
  8736. return 0;
  8737. }
  8738. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8739. Spawn* spawn = lua_interface->GetSpawn(state);
  8740. int8 type = lua_interface->GetInt8Value(state, 2);
  8741. lua_interface->ResetFunctionStack(state);
  8742. if (!spawn) {
  8743. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8744. return 0;
  8745. }
  8746. else if (!spawn->IsEntity()) {
  8747. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8748. return 0;
  8749. }
  8750. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8751. return 1;
  8752. }
  8753. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8754. if (!lua_interface)
  8755. return 0;
  8756. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8757. int8 type = lua_interface->GetInt8Value(state);
  8758. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8759. lua_interface->ResetFunctionStack(state);
  8760. if (!spell) {
  8761. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8762. return 0;
  8763. }
  8764. if(spell->resisted) {
  8765. return 0;
  8766. }
  8767. if (spawn) {
  8768. if (!spawn->IsEntity()) {
  8769. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8770. return 0;
  8771. }
  8772. Entity* entity = ((Entity*)spawn);
  8773. entity->AddImmunity(spell, type);
  8774. }
  8775. else if(spell->caster && spell->caster->GetZone()) {
  8776. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8777. for (int8 i = 0; i < spell->targets.size(); i++) {
  8778. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8779. if (!spawn || !spawn->IsEntity())
  8780. continue;
  8781. Entity* entity = ((Entity*)spawn);
  8782. entity->AddImmunity(spell, type);
  8783. }
  8784. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8785. }
  8786. return 0;
  8787. }
  8788. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8789. if (!lua_interface)
  8790. return 0;
  8791. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8792. int8 type = lua_interface->GetInt8Value(state);
  8793. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8794. lua_interface->ResetFunctionStack(state);
  8795. if (!spell) {
  8796. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8797. return 0;
  8798. }
  8799. if (spawn) {
  8800. if (!spawn->IsEntity()) {
  8801. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8802. return 0;
  8803. }
  8804. Entity* entity = ((Entity*)spawn);
  8805. entity->RemoveImmunity(spell, type);
  8806. }
  8807. else if(spell->caster && spell->caster->GetZone()) {
  8808. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8809. for (int8 i = 0; i < spell->targets.size(); i++) {
  8810. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8811. if (!spawn || !spawn->IsEntity())
  8812. continue;
  8813. Entity* entity = ((Entity*)spawn);
  8814. entity->RemoveImmunity(spell, type);
  8815. }
  8816. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8817. }
  8818. return 0;
  8819. }
  8820. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8821. if (!lua_interface)
  8822. return 0;
  8823. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8824. if (!spell) {
  8825. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8826. lua_interface->ResetFunctionStack(state);
  8827. return 0;
  8828. }
  8829. if(spell->resisted) {
  8830. lua_interface->ResetFunctionStack(state);
  8831. return 0;
  8832. }
  8833. float snare = lua_interface->GetFloatValue(state);
  8834. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8835. lua_interface->ResetFunctionStack(state);
  8836. // convert the val to the speed multipler value (100 - val)
  8837. float val = 100.0 - snare;
  8838. val /= 100.0;
  8839. if (spawn) {
  8840. if (!spawn->IsEntity()) {
  8841. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8842. return 0;
  8843. }
  8844. ((Entity*)spawn)->SetSnareValue(spell, val);
  8845. }
  8846. else if(spell->caster && spell->caster->GetZone()) {
  8847. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8848. for (int8 i = 0; i < spell->targets.size(); i++) {
  8849. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8850. if (!spawn || !spawn->IsEntity())
  8851. continue;
  8852. ((Entity*)spawn)->SetSnareValue(spell, val);
  8853. }
  8854. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8855. }
  8856. return 0;
  8857. }
  8858. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8859. if (!lua_interface)
  8860. return 0;
  8861. Spawn* spawn = lua_interface->GetSpawn(state);
  8862. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8863. lua_interface->ResetFunctionStack(state);
  8864. if (!spawn) {
  8865. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8866. return 0;
  8867. }
  8868. if (race_id == 0) {
  8869. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8870. return 0;
  8871. }
  8872. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8873. return 1;
  8874. }
  8875. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8876. if (!lua_interface)
  8877. return 0;
  8878. Spawn* spawn = lua_interface->GetSpawn(state);
  8879. lua_interface->ResetFunctionStack(state);
  8880. if (!spawn) {
  8881. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8882. return 0;
  8883. }
  8884. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8885. return 1;
  8886. }
  8887. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8888. if (!lua_interface)
  8889. return 0;
  8890. Spawn* spawn = lua_interface->GetSpawn(state);
  8891. lua_interface->ResetFunctionStack(state);
  8892. if (!spawn) {
  8893. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8894. return 0;
  8895. }
  8896. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8897. return 1;
  8898. }
  8899. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8900. if (!lua_interface)
  8901. return 0;
  8902. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8903. lua_interface->ResetFunctionStack(state);
  8904. if (!spell) {
  8905. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8906. return 0;
  8907. }
  8908. lua_interface->SetStringValue(state, spell->spell->GetName());
  8909. return 1;
  8910. }
  8911. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8912. if (!lua_interface)
  8913. return 0;
  8914. Quest* quest = lua_interface->GetQuest(state);
  8915. lua_interface->ResetFunctionStack(state);
  8916. if (!quest) {
  8917. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8918. return 0;
  8919. }
  8920. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8921. return 1;
  8922. }
  8923. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8924. if (!lua_interface)
  8925. return 0;
  8926. Quest* quest = lua_interface->GetQuest(state);
  8927. int32 flags = lua_interface->GetInt32Value(state, 2);
  8928. lua_interface->ResetFunctionStack(state);
  8929. if (!quest) {
  8930. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8931. return 0;
  8932. }
  8933. quest->SetQuestFlags(flags);
  8934. return 0;
  8935. }
  8936. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8937. if (!lua_interface)
  8938. return 0;
  8939. Quest* quest = lua_interface->GetQuest(state);
  8940. Spawn* player = lua_interface->GetSpawn(state, 2);
  8941. int32 step = lua_interface->GetInt32Value(state, 3);
  8942. int32 duration = lua_interface->GetInt32Value(state, 4);
  8943. string action = lua_interface->GetStringValue(state, 5);
  8944. lua_interface->ResetFunctionStack(state);
  8945. if (!quest) {
  8946. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8947. return 0;
  8948. }
  8949. if (!player) {
  8950. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8951. return 0;
  8952. }
  8953. if (!player->IsPlayer()) {
  8954. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8955. return 0;
  8956. }
  8957. if (step == 0) {
  8958. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8959. return 0;
  8960. }
  8961. if (duration == 0) {
  8962. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8963. return 0;
  8964. }
  8965. if (action.length() == 0) {
  8966. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8967. return 0;
  8968. }
  8969. Client* client = ((Player*)player)->GetClient();
  8970. if (!client) {
  8971. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8972. return 0;
  8973. }
  8974. quest->SetTimerStep(step);
  8975. quest->AddFailedAction(step, action);
  8976. quest->SetStepTimer(duration);
  8977. client->AddQuestTimer(quest->GetQuestID());
  8978. return 0;
  8979. }
  8980. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8981. if (!lua_interface)
  8982. return 0;
  8983. Quest* quest = lua_interface->GetQuest(state);
  8984. Spawn* player = lua_interface->GetSpawn(state, 2);
  8985. lua_interface->ResetFunctionStack(state);
  8986. if (!quest) {
  8987. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8988. return 0;
  8989. }
  8990. if (!player) {
  8991. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8992. return 0;
  8993. }
  8994. if (!player->IsPlayer()) {
  8995. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8996. return 0;
  8997. }
  8998. Client* client = ((Player*)player)->GetClient();
  8999. if (!client) {
  9000. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  9001. return 0;
  9002. }
  9003. quest->SetTimerStep(0);
  9004. quest->SetStepTimer(0);
  9005. client->RemoveQuestTimer(quest->GetQuestID());
  9006. return 0;
  9007. }
  9008. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  9009. if (!lua_interface)
  9010. return 0;
  9011. Spawn* player = lua_interface->GetSpawn(state);
  9012. Quest* quest = lua_interface->GetQuest(state, 2);
  9013. int32 step = lua_interface->GetInt32Value(state, 3);
  9014. lua_interface->ResetFunctionStack(state);
  9015. if (!player) {
  9016. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9017. return 0;
  9018. }
  9019. if (!player->IsPlayer()) {
  9020. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9021. return 0;
  9022. }
  9023. if (!quest) {
  9024. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9025. return 0;
  9026. }
  9027. if (step == 0) {
  9028. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9029. return 0;
  9030. }
  9031. Client* client = ((Player*)player)->GetClient();
  9032. if (!client) {
  9033. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  9034. return 0;
  9035. }
  9036. if (quest->RemoveQuestStep(step, client)) {
  9037. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  9038. client->GetCurrentZone()->SendQuestUpdates(client);
  9039. }
  9040. else
  9041. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  9042. return 0;
  9043. }
  9044. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  9045. if (!lua_interface)
  9046. return 0;
  9047. Quest* quest = lua_interface->GetQuest(state, 1);
  9048. int32 step = lua_interface->GetInt32Value(state, 2);
  9049. string desc = lua_interface->GetStringValue(state, 3);
  9050. string task_group = lua_interface->GetStringValue(state, 4);
  9051. lua_interface->ResetFunctionStack(state);
  9052. if (!quest) {
  9053. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9054. return 0;
  9055. }
  9056. if (step == 0) {
  9057. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9058. return 0;
  9059. }
  9060. QuestStep* quest_step = quest->GetQuestStep(step);
  9061. if (!quest_step) {
  9062. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9063. return 0;
  9064. }
  9065. quest_step->SetStepProgress(0);
  9066. quest_step->SetTaskGroup(task_group);
  9067. quest_step->SetDescription(desc);
  9068. return 0;
  9069. }
  9070. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9071. if (!lua_interface)
  9072. return 0;
  9073. Quest* quest = lua_interface->GetQuest(state);
  9074. int32 step = lua_interface->GetInt32Value(state, 2);
  9075. string action = lua_interface->GetStringValue(state, 3);
  9076. lua_interface->ResetFunctionStack(state);
  9077. if (!quest) {
  9078. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9079. return 0;
  9080. }
  9081. if (step == 0) {
  9082. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9083. return 0;
  9084. }
  9085. if (action.length() == 0) {
  9086. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9087. return 0;
  9088. }
  9089. quest->AddFailedAction(step, action);
  9090. return 0;
  9091. }
  9092. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9093. if (!lua_interface)
  9094. return 0;
  9095. Spawn* player = lua_interface->GetSpawn(state);
  9096. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9097. int32 step = lua_interface->GetInt32Value(state, 3);
  9098. lua_interface->ResetFunctionStack(state);
  9099. if (!player) {
  9100. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9101. return 0;
  9102. }
  9103. if (!player->IsPlayer()) {
  9104. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9105. return 0;
  9106. }
  9107. if (quest_id == 0) {
  9108. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9109. return 0;
  9110. }
  9111. if (step == 0) {
  9112. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9113. return 0;
  9114. }
  9115. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9116. if (!quest) {
  9117. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9118. return 0;
  9119. }
  9120. quest->StepFailed(step);
  9121. return 0;
  9122. }
  9123. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9124. if (!lua_interface)
  9125. return 0;
  9126. Spawn* player = lua_interface->GetSpawn(state);
  9127. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9128. lua_interface->ResetFunctionStack(state);
  9129. if (!player) {
  9130. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9131. return 0;
  9132. }
  9133. if (!player->IsPlayer()) {
  9134. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9135. return 0;
  9136. }
  9137. if (quest_id == 0) {
  9138. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9139. return 0;
  9140. }
  9141. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9142. return 1;
  9143. }
  9144. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9145. if (!lua_interface)
  9146. return 0;
  9147. string name = lua_interface->GetStringValue(state);
  9148. string value = lua_interface->GetStringValue(state, 2);
  9149. string comment = lua_interface->GetStringValue(state, 3);
  9150. lua_interface->ResetFunctionStack(state);
  9151. if (name.length() == 0) {
  9152. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9153. return 0;
  9154. }
  9155. if (value.length() == 0) {
  9156. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9157. return 0;
  9158. }
  9159. string varname = string("lua_").append(name);
  9160. Variable* var = variables.FindVariable(varname);
  9161. if (var)
  9162. var->SetValue(value.c_str());
  9163. else {
  9164. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9165. variables.AddVariable(var);
  9166. }
  9167. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9168. return 0;
  9169. }
  9170. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9171. if (!lua_interface)
  9172. return 0;
  9173. string name = lua_interface->GetStringValue(state);
  9174. lua_interface->ResetFunctionStack(state);
  9175. if (name.length() == 0) {
  9176. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9177. return 0;
  9178. }
  9179. string varname = string("lua_").append(name);
  9180. Variable* var = variables.FindVariable(varname);
  9181. if (var)
  9182. lua_interface->SetStringValue(state, var->GetValue());
  9183. else
  9184. lua_interface->SetStringValue(state, "NULL");
  9185. return 1;
  9186. }
  9187. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9188. if (!lua_interface)
  9189. return 0;
  9190. Spawn* player = lua_interface->GetSpawn(state);
  9191. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9192. lua_interface->ResetFunctionStack(state);
  9193. if (!player) {
  9194. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9195. return 0;
  9196. }
  9197. if (!player->IsPlayer()) {
  9198. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9199. return 0;
  9200. }
  9201. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9202. return 1;
  9203. }
  9204. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9205. if (!lua_interface)
  9206. return 0;
  9207. Spawn* player = lua_interface->GetSpawn(state);
  9208. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9209. lua_interface->ResetFunctionStack(state);
  9210. if (!player) {
  9211. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9212. return 0;
  9213. }
  9214. if (!player->IsPlayer()) {
  9215. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9216. return 0;
  9217. }
  9218. Language* language = master_languages_list.GetLanguage(language_id);
  9219. if (language)
  9220. {
  9221. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9222. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9223. }
  9224. return 0;
  9225. }
  9226. int EQ2Emu_lua_IsNight(lua_State* state) {
  9227. if (!lua_interface)
  9228. return 0;
  9229. ZoneServer* zone = lua_interface->GetZone(state);
  9230. lua_interface->ResetFunctionStack(state);
  9231. if (!zone) {
  9232. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9233. return 0;
  9234. }
  9235. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9236. return 1;
  9237. }
  9238. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9239. if (!lua_interface)
  9240. return 0;
  9241. Spawn* spawn = lua_interface->GetSpawn(state);
  9242. lua_interface->ResetFunctionStack(state);
  9243. if (!spawn) {
  9244. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9245. return 0;
  9246. }
  9247. if (!spawn->IsWidget()) {
  9248. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9249. return 0;
  9250. }
  9251. ((Widget*)spawn)->SetMultiFloorLift(true);
  9252. if (spawn->GetZone())
  9253. spawn->GetZone()->AddTransportSpawn(spawn);
  9254. return 0;
  9255. }
  9256. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9257. if (!lua_interface)
  9258. return 0;
  9259. Spawn* player = lua_interface->GetSpawn(state);
  9260. int32 path = lua_interface->GetInt32Value(state, 2);
  9261. lua_interface->ResetFunctionStack(state);
  9262. if (!player) {
  9263. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9264. return 0;
  9265. }
  9266. if (!player->IsPlayer()) {
  9267. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9268. return 0;
  9269. }
  9270. if (path == 0) {
  9271. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9272. return 0;
  9273. }
  9274. Client* client = ((Player*)player)->GetClient();
  9275. if (!client) {
  9276. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9277. return 0;
  9278. }
  9279. client->SendFlightAutoMount(path);
  9280. return 0;
  9281. }
  9282. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9283. if (!lua_interface)
  9284. return 0;
  9285. Spawn* player = lua_interface->GetSpawn(state);
  9286. if (!player) {
  9287. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9288. return 0;
  9289. }
  9290. if (!player->IsPlayer()) {
  9291. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9292. return 0;
  9293. }
  9294. Client* client = ((Player*)player)->GetClient();
  9295. if (!client) {
  9296. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9297. return 0;
  9298. }
  9299. client->EndAutoMount();
  9300. return 0;
  9301. }
  9302. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9303. if (!lua_interface)
  9304. return 0;
  9305. Spawn* player = lua_interface->GetSpawn(state);
  9306. lua_interface->ResetFunctionStack(state);
  9307. if (!player) {
  9308. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9309. return 0;
  9310. }
  9311. if (!player->IsPlayer()) {
  9312. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9313. return 0;
  9314. }
  9315. Client* client = ((Player*)player)->GetClient();
  9316. if (!client) {
  9317. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9318. return 0;
  9319. }
  9320. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9321. return 1;
  9322. }
  9323. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9324. if (!lua_interface)
  9325. return 0;
  9326. Spawn* player = lua_interface->GetSpawn(state);
  9327. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9328. int32 value = lua_interface->GetInt32Value(state, 3);
  9329. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9330. lua_interface->ResetFunctionStack(state);
  9331. if (!player) {
  9332. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9333. return 0;
  9334. }
  9335. if (!player->IsPlayer()) {
  9336. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9337. return 0;
  9338. }
  9339. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9340. return 0;
  9341. }
  9342. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9343. if (!lua_interface)
  9344. return 0;
  9345. Spawn* player = lua_interface->GetSpawn(state);
  9346. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9347. lua_interface->ResetFunctionStack(state);
  9348. if (!player) {
  9349. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9350. return 0;
  9351. }
  9352. if (!player->IsPlayer()) {
  9353. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9354. return 0;
  9355. }
  9356. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9357. if (!hd)
  9358. return 0;
  9359. lua_interface->SetInt32Value(state, hd->Value);
  9360. lua_interface->SetInt32Value(state, hd->Value2);
  9361. return 2;
  9362. }
  9363. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9364. if (!lua_interface)
  9365. return 0;
  9366. Spawn* spawn = lua_interface->GetSpawn(state);
  9367. int32 grid = lua_interface->GetInt32Value(state, 2);
  9368. lua_interface->ResetFunctionStack(state);
  9369. if (!spawn) {
  9370. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9371. return 0;
  9372. }
  9373. if (grid == 0) {
  9374. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9375. return 0;
  9376. }
  9377. spawn->SetLocation(grid);
  9378. return 0;
  9379. }
  9380. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9381. if (!lua_interface)
  9382. return 0;
  9383. Spawn* spawn = lua_interface->GetSpawn(state);
  9384. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9385. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9386. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9387. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9388. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9389. lua_interface->ResetFunctionStack(state);
  9390. if (!spawn) {
  9391. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9392. return 0;
  9393. }
  9394. //Add this quest to the list of required quests for this spawn
  9395. spawn->SetRequiredHistory(event_id, value1, value2);
  9396. //If private spawn value set
  9397. if (private_spawn) {
  9398. //Set the spawn to be private when not granted access via history
  9399. spawn->AddAllowAccessSpawn(spawn);
  9400. spawn->SetPrivateQuestSpawn(true);
  9401. }
  9402. //This value will override vis_flags in the vis packet
  9403. if (flag_override > 0)
  9404. spawn->SetQuestsRequiredOverride(flag_override);
  9405. return 0;
  9406. }
  9407. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9408. if (!lua_interface)
  9409. return 0;
  9410. Spawn* player = lua_interface->GetSpawn(state);
  9411. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9412. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9413. lua_interface->ResetFunctionStack(state);
  9414. if (!player) {
  9415. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9416. return 0;
  9417. }
  9418. if (!player->IsPlayer()) {
  9419. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9420. return 0;
  9421. }
  9422. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9423. return 1;
  9424. }
  9425. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9426. if (!lua_interface)
  9427. return 0;
  9428. Spawn* player = lua_interface->GetSpawn(state);
  9429. int8 level = lua_interface->GetInt8Value(state, 2);
  9430. lua_interface->ResetFunctionStack(state);
  9431. if (!player) {
  9432. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9433. return 0;
  9434. }
  9435. if (!player->IsPlayer()) {
  9436. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9437. return 0;
  9438. }
  9439. if (level == 0) {
  9440. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9441. return 0;
  9442. }
  9443. Client* client = ((Player*)player)->GetClient();
  9444. if (!client) {
  9445. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9446. return 0;
  9447. }
  9448. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9449. return 0;
  9450. }
  9451. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9452. if (!lua_interface)
  9453. return 0;
  9454. Spawn* player = lua_interface->GetSpawn(state);
  9455. int32 amount = lua_interface->GetInt32Value(state, 2);
  9456. lua_interface->ResetFunctionStack(state);
  9457. if (!player) {
  9458. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9459. return 0;
  9460. }
  9461. if (!player->IsPlayer()) {
  9462. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9463. return 0;
  9464. }
  9465. if (amount == 0) {
  9466. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9467. return 0;
  9468. }
  9469. ((Player*)player)->AddCoins(amount);
  9470. return 0;
  9471. }
  9472. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9473. if (!lua_interface)
  9474. return 0;
  9475. Spawn* player = lua_interface->GetSpawn(state);
  9476. int32 amount = lua_interface->GetInt32Value(state, 2);
  9477. lua_interface->ResetFunctionStack(state);
  9478. if (!player) {
  9479. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9480. return 0;
  9481. }
  9482. if (!player->IsPlayer()) {
  9483. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9484. return 0;
  9485. }
  9486. if (amount == 0) {
  9487. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9488. return 0;
  9489. }
  9490. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9491. return 1;
  9492. }
  9493. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9494. if (!lua_interface)
  9495. return 0;
  9496. ZoneServer* zone = lua_interface->GetZone(state);
  9497. lua_interface->ResetFunctionStack(state);
  9498. if (!zone) {
  9499. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9500. return 0;
  9501. }
  9502. vector<Entity*> players = zone->GetPlayers();
  9503. if (players.size() == 0)
  9504. return 0;
  9505. lua_createtable(state, players.size(), 0);
  9506. int newTable = lua_gettop(state);
  9507. for (int32 i = 0; i < players.size(); i++) {
  9508. lua_interface->SetSpawnValue(state, players.at(i));
  9509. lua_rawseti(state, newTable, i + 1);
  9510. }
  9511. return 1;
  9512. }
  9513. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9514. if (!lua_interface)
  9515. return 0;
  9516. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9517. if (!zone) {
  9518. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9519. return 0;
  9520. }
  9521. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9522. int16 custom_level = lua_interface->GetInt32Value(state, 3);
  9523. lua_interface->ResetFunctionStack(state);
  9524. //Map of <placement_id, location_id>
  9525. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9526. map<int32, int32>::iterator itr;
  9527. vector<Spawn*> group;
  9528. Spawn* leader = 0;
  9529. if(locs == nullptr)
  9530. return 0;
  9531. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9532. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9533. if (!location) {
  9534. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9535. return 0;
  9536. }
  9537. Spawn* spawn = 0;
  9538. if (location->entities[0]) {
  9539. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9540. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9541. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9542. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9543. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9544. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9545. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9546. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9547. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9548. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9549. if(spawn && spawn->IsOmittedByDBFlag())
  9550. {
  9551. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  9552. safe_delete(spawn);
  9553. continue;
  9554. }
  9555. if (spawn) {
  9556. if(!leader)
  9557. leader = spawn;
  9558. if(leader)
  9559. leader->AddSpawnToGroup(spawn);
  9560. spawn->SetSpawnGroupID(group_id);
  9561. if(custom_level > 0 && custom_level != 0xFFFF) {
  9562. spawn->SetLevel(custom_level);
  9563. }
  9564. const char* script = 0;
  9565. for (int x = 0; x < 3; x++) {
  9566. switch (x) {
  9567. case 0:
  9568. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9569. break;
  9570. case 1:
  9571. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9572. break;
  9573. case 2:
  9574. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9575. break;
  9576. }
  9577. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9578. spawn->SetSpawnScript(string(script));
  9579. break;
  9580. }
  9581. }
  9582. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9583. lua_interface->SetSpawnValue(state, spawn);
  9584. group.push_back(spawn);
  9585. }
  9586. else {
  9587. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9588. safe_delete(spawn);
  9589. }
  9590. }
  9591. }
  9592. if (!group.empty()) {
  9593. lua_createtable(state, group.size(), 0);
  9594. int newTable = lua_gettop(state);
  9595. for (int32 i = 0; i < group.size(); i++) {
  9596. lua_interface->SetSpawnValue(state, group[i]);
  9597. lua_rawseti(state, newTable, i + 1);
  9598. }
  9599. }
  9600. else
  9601. lua_pushnil(state);
  9602. return 1;
  9603. }
  9604. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9605. if (!lua_interface)
  9606. return 0;
  9607. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9608. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9609. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9610. lua_interface->ResetFunctionStack(state);
  9611. if (!spawn) {
  9612. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9613. return 0;
  9614. }
  9615. if (anim_id == 0) {
  9616. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9617. return 0;
  9618. }
  9619. if (leeway == 0)
  9620. leeway = 5000;
  9621. spawn->SetSpawnAnim(anim_id);
  9622. spawn->SetSpawnAnimLeeway(leeway);
  9623. return 0;
  9624. }
  9625. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9626. if (!lua_interface)
  9627. return 0;
  9628. Spawn* player = lua_interface->GetSpawn(state);
  9629. lua_interface->ResetFunctionStack(state);
  9630. if (!player || !player->IsPlayer()) {
  9631. return 0;
  9632. }
  9633. Client* client = ((Player*)player)->GetClient();
  9634. if (!client) {
  9635. return 0;
  9636. }
  9637. lua_interface->SetInt32Value(state, client->GetVersion());
  9638. return 1;
  9639. }
  9640. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9641. if (!lua_interface)
  9642. return 0;
  9643. Item* item = lua_interface->GetItem(state);
  9644. lua_interface->ResetFunctionStack(state);
  9645. if (!item) {
  9646. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9647. return 0;
  9648. }
  9649. lua_interface->SetInt32Value(state, item->details.item_id);
  9650. return 1;
  9651. }
  9652. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9653. if (!lua_interface)
  9654. return 0;
  9655. Spawn* spawn = lua_interface->GetSpawn(state);
  9656. lua_interface->ResetFunctionStack(state);
  9657. if (!spawn) {
  9658. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9659. return 0;
  9660. }
  9661. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9662. return 1;
  9663. }
  9664. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9665. if (!lua_interface)
  9666. return 0;
  9667. Spawn* spawn = lua_interface->GetSpawn(state);
  9668. lua_interface->ResetFunctionStack(state);
  9669. if (!spawn) {
  9670. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9671. return 0;
  9672. }
  9673. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9674. return 1;
  9675. }
  9676. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9677. if (!lua_interface)
  9678. return 0;
  9679. Spawn* spawn = lua_interface->GetSpawn(state);
  9680. lua_interface->ResetFunctionStack(state);
  9681. if (!spawn) {
  9682. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9683. return 0;
  9684. }
  9685. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9686. return 1;
  9687. }
  9688. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9689. if (!lua_interface)
  9690. return 0;
  9691. Spawn* spawn = lua_interface->GetSpawn(state);
  9692. lua_interface->ResetFunctionStack(state);
  9693. if (!spawn) {
  9694. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9695. return 0;
  9696. }
  9697. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9698. return 1;
  9699. }
  9700. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9701. if (!lua_interface)
  9702. return 0;
  9703. Spawn* spawn = lua_interface->GetSpawn(state);
  9704. float pct = lua_interface->GetFloatValue(state, 2);
  9705. lua_interface->ResetFunctionStack(state);
  9706. if (!spawn) {
  9707. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9708. return 0;
  9709. }
  9710. if (pct == 0) {
  9711. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9712. return 0;
  9713. }
  9714. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9715. lua_interface->SetInt32Value(state, amount);
  9716. return 1;
  9717. }
  9718. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9719. if (!lua_interface)
  9720. return 0;
  9721. Spawn* spawn = lua_interface->GetSpawn(state);
  9722. float pct = lua_interface->GetFloatValue(state, 2);
  9723. lua_interface->ResetFunctionStack(state);
  9724. if (!spawn) {
  9725. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9726. return 0;
  9727. }
  9728. if (pct == 0) {
  9729. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9730. return 0;
  9731. }
  9732. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9733. lua_interface->SetInt32Value(state, amount);
  9734. return 1;
  9735. }
  9736. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9737. if (!lua_interface)
  9738. return 0;
  9739. Spawn* spawn = lua_interface->GetSpawn(state);
  9740. lua_interface->ResetFunctionStack(state);
  9741. if (!spawn) {
  9742. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9743. return 0;
  9744. }
  9745. if (!spawn->IsPlayer()) {
  9746. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9747. return 0;
  9748. }
  9749. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9750. return 1;
  9751. }
  9752. int EQ2Emu_lua_Evac(lua_State* state) {
  9753. if (!lua_interface)
  9754. return 0;
  9755. Spawn* target = lua_interface->GetSpawn(state);
  9756. if (target) {
  9757. float x = target->GetZone()->GetSafeX();
  9758. float y = target->GetZone()->GetSafeY();
  9759. float z = target->GetZone()->GetSafeZ();
  9760. float h = target->GetZone()->GetSafeHeading();
  9761. target->SetX(x);
  9762. target->SetY(y);
  9763. target->SetZ(z);
  9764. target->SetHeading(h);
  9765. target->SetSpawnOrigX(x);
  9766. target->SetSpawnOrigY(y);
  9767. target->SetSpawnOrigZ(z);
  9768. target->SetSpawnOrigHeading(h);
  9769. if (target->IsPlayer()) {
  9770. Client* client = ((Player*)target)->GetClient();
  9771. if (client) {
  9772. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9773. int numargs = lua_interface->GetNumberOfArgs(state);
  9774. if(numargs == 4) {
  9775. x = lua_interface->GetFloatValue(state,1);
  9776. y = lua_interface->GetFloatValue(state,2);
  9777. z = lua_interface->GetFloatValue(state,3);
  9778. h = lua_interface->GetFloatValue(state,4);
  9779. }
  9780. client->SetReloadingZone(true);
  9781. target->SetX(x);
  9782. target->SetY(y);
  9783. target->SetZ(z);
  9784. target->SetHeading(h);
  9785. target->SetSpawnOrigX(x);
  9786. target->SetSpawnOrigY(y);
  9787. target->SetSpawnOrigZ(z);
  9788. target->SetSpawnOrigHeading(h);
  9789. target->SetAppearancePosition(x,y,z);
  9790. client->SetZoningCoords(x,y,z,h);
  9791. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9792. if (packet)
  9793. {
  9794. packet->setDataByName("x", x);
  9795. packet->setDataByName("y", y);
  9796. packet->setDataByName("z", z);
  9797. client->QueuePacket(packet->serialize());
  9798. safe_delete(packet);
  9799. }
  9800. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9801. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9802. }
  9803. }
  9804. lua_interface->ResetFunctionStack(state);
  9805. }
  9806. else {
  9807. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9808. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9809. lua_interface->ResetFunctionStack(state);
  9810. return 0;
  9811. }
  9812. ZoneServer* zone = spell->caster->GetZone();
  9813. float x = spell->caster->GetZone()->GetSafeX();
  9814. float y = spell->caster->GetZone()->GetSafeY();
  9815. float z = spell->caster->GetZone()->GetSafeZ();
  9816. float h = spell->caster->GetZone()->GetSafeHeading();
  9817. int numargs = lua_interface->GetNumberOfArgs(state);
  9818. if(numargs == 4) {
  9819. x = lua_interface->GetFloatValue(state,1);
  9820. y = lua_interface->GetFloatValue(state,2);
  9821. z = lua_interface->GetFloatValue(state,3);
  9822. h = lua_interface->GetFloatValue(state,4);
  9823. }
  9824. lua_interface->ResetFunctionStack(state);
  9825. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9826. for (int32 i = 0; i < spell->targets.size(); i++) {
  9827. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9828. if (!target2)
  9829. continue;
  9830. if (target2->IsPlayer()) {
  9831. Client* client = ((Player*)target2)->GetClient();
  9832. if (client) {
  9833. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9834. client->SetReloadingZone(true);
  9835. target2->SetX(x);
  9836. target2->SetY(y);
  9837. target2->SetZ(z);
  9838. target2->SetHeading(h);
  9839. target2->SetSpawnOrigX(x);
  9840. target2->SetSpawnOrigY(y);
  9841. target2->SetSpawnOrigZ(z);
  9842. target2->SetSpawnOrigHeading(h);
  9843. target2->SetAppearancePosition(x,y,z);
  9844. client->SetZoningCoords(x,y,z,h);
  9845. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9846. if (packet)
  9847. {
  9848. packet->setDataByName("x", x);
  9849. packet->setDataByName("y", y);
  9850. packet->setDataByName("z", z);
  9851. client->QueuePacket(packet->serialize());
  9852. safe_delete(packet);
  9853. }
  9854. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9855. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9856. }
  9857. }
  9858. }
  9859. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9860. }
  9861. return 0;
  9862. }
  9863. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9864. if (!lua_interface)
  9865. return 0;
  9866. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9867. lua_interface->ResetFunctionStack(state);
  9868. if (!luaspell || !luaspell->spell) {
  9869. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9870. return 0;
  9871. }
  9872. int8 tier = luaspell->spell->GetSpellTier();
  9873. lua_interface->SetInt32Value(state, tier);
  9874. return 1;
  9875. }
  9876. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9877. if (!lua_interface)
  9878. return 0;
  9879. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9880. lua_interface->ResetFunctionStack(state);
  9881. if (!luaspell || !luaspell->spell) {
  9882. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9883. return 0;
  9884. }
  9885. int32 spell_id = luaspell->spell->GetSpellID();
  9886. lua_interface->SetInt32Value(state, spell_id);
  9887. return 1;
  9888. }
  9889. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9890. if (!lua_interface)
  9891. return 0;
  9892. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9893. lua_interface->ResetFunctionStack(state);
  9894. if (!spawn) {
  9895. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9896. return 0;
  9897. }
  9898. if (!spawn->IsPlayer()) {
  9899. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9900. return 0;
  9901. }
  9902. ZoneServer* zone = spawn->GetZone();
  9903. if (!zone) {
  9904. return 0;
  9905. }
  9906. Client* client = ((Player*)spawn)->GetClient();
  9907. if (!client) {
  9908. return 0;
  9909. }
  9910. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9911. return 0;
  9912. }
  9913. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9914. if (!lua_interface)
  9915. return 0;
  9916. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9917. lua_interface->ResetFunctionStack(state);
  9918. if (!spawn) {
  9919. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9920. return 0;
  9921. }
  9922. if (!spawn->IsPlayer()) {
  9923. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9924. return 0;
  9925. }
  9926. ZoneServer* zone = spawn->GetZone();
  9927. if (!zone) {
  9928. return 0;
  9929. }
  9930. Client* client = ((Player*)spawn)->GetClient();
  9931. if (!client) {
  9932. return 0;
  9933. }
  9934. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9935. return 0;
  9936. }
  9937. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9938. if (!lua_interface)
  9939. return 0;
  9940. Spawn* caster = lua_interface->GetSpawn(state);
  9941. Spawn* target = lua_interface->GetSpawn(state, 2);
  9942. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9943. string spell_name = lua_interface->GetStringValue(state, 4);
  9944. lua_interface->ResetFunctionStack(state);
  9945. if (!caster) {
  9946. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9947. return 0;
  9948. }
  9949. if (!caster->IsEntity()) {
  9950. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9951. return 0;
  9952. }
  9953. if (!target) {
  9954. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9955. return 0;
  9956. }
  9957. if (!target->IsEntity()) {
  9958. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9959. return 0;
  9960. }
  9961. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9962. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9963. return 0;
  9964. }
  9965. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9966. if (!lua_interface)
  9967. return 0;
  9968. Spawn* player = lua_interface->GetSpawn(state);
  9969. int32 amount = lua_interface->GetInt32Value(state, 2);
  9970. lua_interface->ResetFunctionStack(state);
  9971. if (player && player->IsPlayer() && amount > 0) {
  9972. ((Player*)player)->AddXP(amount);
  9973. }
  9974. return 0;
  9975. }
  9976. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9977. if (!lua_interface)
  9978. return 0;
  9979. Spawn* player = lua_interface->GetSpawn(state);
  9980. int8 type = lua_interface->GetInt8Value(state, 2);
  9981. string text = lua_interface->GetStringValue(state, 3);
  9982. lua_interface->ResetFunctionStack(state);
  9983. Client* client = 0;
  9984. if (player && player->IsPlayer())
  9985. client = ((Player*)player)->GetClient();
  9986. if (!client || text.length() == 0) {
  9987. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9988. return 0;
  9989. }
  9990. client->SimpleMessage(type, text.c_str());
  9991. return 0;
  9992. }
  9993. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9994. if (!lua_interface)
  9995. return 0;
  9996. Spawn* player = lua_interface->GetSpawn(state);
  9997. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9998. lua_interface->ResetFunctionStack(state);
  9999. Client* client = 0;
  10000. if (player && player->IsPlayer())
  10001. client = ((Player*)player)->GetClient();
  10002. if (!client || !spawn) {
  10003. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  10004. return 0;
  10005. }
  10006. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  10007. if (!items) {
  10008. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  10009. return 0;
  10010. }
  10011. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  10012. return 0;
  10013. }
  10014. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  10015. if (!lua_interface)
  10016. return 0;
  10017. Spawn* spawnref = lua_interface->GetSpawn(state);
  10018. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10019. lua_interface->ResetFunctionStack(state);
  10020. if (spawn_id > 0 && spawnref) {
  10021. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  10022. if (spawns.size() == 0) {
  10023. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10024. return 0;
  10025. }
  10026. Spawn* spawn = 0;
  10027. int16 index = MakeRandomInt(0, spawns.size());
  10028. if (index >= spawns.size() || index < 0)
  10029. index = 0;
  10030. spawn = spawns[index];
  10031. lua_interface->SetSpawnValue(state, spawn);
  10032. return 1;
  10033. }
  10034. else {
  10035. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  10036. }
  10037. return 0;
  10038. }
  10039. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  10040. Spawn* player = lua_interface->GetSpawn(state);
  10041. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10042. string name = lua_interface->GetStringValue(state, 3);
  10043. float distance = lua_interface->GetFloatValue(state, 4);
  10044. string command = lua_interface->GetStringValue(state, 5);
  10045. string error_text = lua_interface->GetStringValue(state, 6);
  10046. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  10047. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  10048. lua_interface->ResetFunctionStack(state);
  10049. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  10050. if (distance == 0)
  10051. distance = 10.0f;
  10052. if (command.length() == 0)
  10053. command = name;
  10054. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  10055. if (spawns.size() == 0) {
  10056. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10057. return 0;
  10058. }
  10059. Spawn* spawn = 0;
  10060. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  10061. spawn = *itr;
  10062. if (spawn) {
  10063. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  10064. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  10065. }
  10066. }
  10067. }
  10068. return 0;
  10069. }
  10070. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  10071. if (!lua_interface)
  10072. return 0;
  10073. Client* client = 0;
  10074. Spawn* player = lua_interface->GetSpawn(state);
  10075. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10076. lua_interface->ResetFunctionStack(state);
  10077. if (player && player->IsPlayer() && player->GetZone())
  10078. client = ((Player*)player)->GetClient();
  10079. else{
  10080. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10081. return 0;
  10082. }
  10083. if (client) {
  10084. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10085. if (packet) {
  10086. packet->setDataByName("goal_num", goal_num);
  10087. client->QueuePacket(packet->serialize());
  10088. safe_delete(packet);
  10089. }
  10090. }
  10091. return 0;
  10092. }
  10093. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10094. if (!lua_interface)
  10095. return 0;
  10096. Client* client = 0;
  10097. Spawn* player = lua_interface->GetSpawn(state);
  10098. lua_interface->ResetFunctionStack(state);
  10099. if (player && player->IsPlayer() && player->GetZone())
  10100. client = ((Player*)player)->GetClient();
  10101. else {
  10102. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10103. return 0;
  10104. }
  10105. if (client && client->GetVersion() >= 374) {
  10106. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10107. }
  10108. return 0;
  10109. }
  10110. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10111. if (!lua_interface)
  10112. return 0;
  10113. Client* client = 0;
  10114. Spawn* player = lua_interface->GetSpawn(state);
  10115. float duration = lua_interface->GetFloatValue(state, 2);
  10116. string text = lua_interface->GetStringValue(state, 3);
  10117. string voice = lua_interface->GetStringValue(state, 4);
  10118. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10119. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10120. string signal = lua_interface->GetStringValue(state, 7);
  10121. string goal1 = lua_interface->GetStringValue(state, 8);
  10122. string task1 = lua_interface->GetStringValue(state, 9);
  10123. string goal2 = lua_interface->GetStringValue(state, 10);
  10124. string task2 = lua_interface->GetStringValue(state, 11);
  10125. string goal3 = lua_interface->GetStringValue(state, 12);
  10126. string task3 = lua_interface->GetStringValue(state, 13);
  10127. string goal4 = lua_interface->GetStringValue(state, 14);
  10128. string task4 = lua_interface->GetStringValue(state, 15);
  10129. lua_interface->ResetFunctionStack(state);
  10130. if (!player) {
  10131. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10132. return 0;
  10133. }
  10134. if (!player->IsPlayer()) {
  10135. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10136. return 0;
  10137. }
  10138. else
  10139. client = ((Player*)player)->GetClient();
  10140. if (!client) {
  10141. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10142. return 0;
  10143. }
  10144. if (text.length() == 0) {
  10145. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10146. return 0;
  10147. }
  10148. if (duration >= 0 && duration < 2)
  10149. duration = 2;
  10150. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10151. if (packet) {
  10152. packet->setDataByName("open_seconds_max", duration);
  10153. packet->setDataByName("text", text.c_str());
  10154. packet->setDataByName("voice", voice.c_str());
  10155. int8 num_goals = 1;
  10156. if (task2.length() > 0)
  10157. num_goals++;
  10158. if (task3.length() > 0)
  10159. num_goals++;
  10160. if (task4.length() > 0)
  10161. num_goals++;
  10162. packet->setArrayLengthByName("num_goals", num_goals);
  10163. for (int8 i = 0; i < num_goals; i++) {
  10164. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10165. }
  10166. if (goal1.length() > 0)
  10167. packet->setArrayDataByName("goal_text", goal1.c_str());
  10168. if (goal2.length() > 0)
  10169. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10170. if (goal3.length() > 0)
  10171. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10172. if (goal4.length() > 0)
  10173. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10174. packet->setSubArrayDataByName("task_text", task1.c_str());
  10175. if (task2.length() > 0)
  10176. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10177. if (task3.length() > 0)
  10178. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10179. if (task4.length() > 0)
  10180. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10181. packet->setDataByName("complete_sound", "click");
  10182. packet->setDataByName("signal", signal.c_str());
  10183. packet->setDataByName("voice_key1", voice_key1);
  10184. packet->setDataByName("voice_key2", voice_key2);
  10185. client->QueuePacket(packet->serialize());
  10186. safe_delete(packet);
  10187. }
  10188. return 0;
  10189. }
  10190. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10191. if (!lua_interface)
  10192. return 0;
  10193. Client* client = 0;
  10194. Spawn* player = lua_interface->GetSpawn(state);
  10195. string window = lua_interface->GetStringValue(state, 2);
  10196. int8 show = lua_interface->GetInt8Value(state, 3);
  10197. lua_interface->ResetFunctionStack(state);
  10198. if (!player) {
  10199. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10200. return 0;
  10201. }
  10202. if (!player->IsPlayer()) {
  10203. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10204. return 0;
  10205. }
  10206. else
  10207. client = ((Player*)player)->GetClient();
  10208. if (!client) {
  10209. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10210. return 0;
  10211. }
  10212. if (window.length() == 0) {
  10213. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10214. return 0;
  10215. }
  10216. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10217. if (packet) {
  10218. packet->setDataByName("window", window.c_str());
  10219. packet->setDataByName("show", show);
  10220. client->QueuePacket(packet->serialize());
  10221. safe_delete(packet);
  10222. }
  10223. return 0;
  10224. }
  10225. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10226. //See GameEvents.txt for options that can be used for this function
  10227. if (!lua_interface)
  10228. return 0;
  10229. Client* client = 0;
  10230. Spawn* player = lua_interface->GetSpawn(state);
  10231. string event_name = lua_interface->GetStringValue(state, 2);
  10232. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10233. lua_interface->ResetFunctionStack(state);
  10234. if (!player || !player->IsPlayer()) {
  10235. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10236. return 0;
  10237. }
  10238. client = ((Player*)player)->GetClient();
  10239. if (!client) {
  10240. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10241. return 0;
  10242. }
  10243. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10244. if (packet) {
  10245. packet->setDataByName("event_name", event_name.c_str());
  10246. packet->setDataByName("enabled", enabled);
  10247. client->QueuePacket(packet->serialize());
  10248. safe_delete(packet);
  10249. }
  10250. return 0;
  10251. }
  10252. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10253. if (!lua_interface)
  10254. return 0;
  10255. Spawn* player = lua_interface->GetSpawn(state);
  10256. lua_interface->ResetFunctionStack(state);
  10257. if (player && player->IsPlayer()) {
  10258. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10259. return 1;
  10260. }
  10261. return 0;
  10262. }
  10263. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10264. if (!lua_interface)
  10265. return 0;
  10266. Spawn* player = lua_interface->GetSpawn(state);
  10267. int8 step = lua_interface->GetInt8Value(state, 2);
  10268. lua_interface->ResetFunctionStack(state);
  10269. if (player && player->IsPlayer() && step > 0) {
  10270. ((Player*)player)->SetTutorialStep(step);
  10271. }
  10272. return 0;
  10273. }
  10274. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10275. if (!lua_interface)
  10276. return 0;
  10277. Client* client = 0;
  10278. Spawn* player = lua_interface->GetSpawn(state);
  10279. string window = lua_interface->GetStringValue(state, 2);
  10280. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10281. lua_interface->ResetFunctionStack(state);
  10282. if (!player) {
  10283. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10284. return 0;
  10285. }
  10286. if (!player->IsPlayer()) {
  10287. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10288. return 0;
  10289. }
  10290. else
  10291. client = ((Player*)player)->GetClient();
  10292. if (!client) {
  10293. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10294. return 0;
  10295. }
  10296. if (window.length() == 0) {
  10297. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10298. return 0;
  10299. }
  10300. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10301. if (packet) {
  10302. packet->setDataByName("window", window.c_str());
  10303. packet->setDataByName("flash_seconds", flash_seconds);
  10304. client->QueuePacket(packet->serialize());
  10305. safe_delete(packet);
  10306. }
  10307. return 0;
  10308. }
  10309. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10310. if (!lua_interface)
  10311. return 0;
  10312. Spawn* spawn = lua_interface->GetSpawn(state);
  10313. Spawn* target = lua_interface->GetSpawn(state, 2);
  10314. lua_interface->ResetFunctionStack(state);
  10315. if (spawn && target)
  10316. return spawn->CheckLoS(target);
  10317. return 0;
  10318. }
  10319. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10320. if (!lua_interface)
  10321. return 0;
  10322. Spawn* spawn = lua_interface->GetSpawn(state);
  10323. float x = lua_interface->GetFloatValue(state, 2);
  10324. float y = lua_interface->GetFloatValue(state, 3);
  10325. float z = lua_interface->GetFloatValue(state, 4);
  10326. lua_interface->ResetFunctionStack(state);
  10327. if (spawn)
  10328. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10329. return 0;
  10330. }
  10331. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10332. if (!lua_interface)
  10333. return 0;
  10334. ZoneServer* zone = lua_interface->GetZone(state);
  10335. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10336. lua_interface->ResetFunctionStack(state);
  10337. if (zone)
  10338. zone->SetExpansionFlag(xpackFlag);
  10339. return 0;
  10340. }
  10341. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10342. if (!lua_interface)
  10343. return 0;
  10344. ZoneServer* zone = lua_interface->GetZone(state);
  10345. lua_interface->ResetFunctionStack(state);
  10346. if (zone) {
  10347. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10348. return 1;
  10349. }
  10350. return 0;
  10351. }
  10352. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10353. if (!lua_interface)
  10354. return 0;
  10355. ZoneServer* zone = lua_interface->GetZone(state);
  10356. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10357. lua_interface->ResetFunctionStack(state);
  10358. if (zone)
  10359. zone->SetHolidayFlag(holidayFlag);
  10360. return 0;
  10361. }
  10362. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10363. if (!lua_interface)
  10364. return 0;
  10365. ZoneServer* zone = lua_interface->GetZone(state);
  10366. lua_interface->ResetFunctionStack(state);
  10367. if (zone) {
  10368. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10369. return 1;
  10370. }
  10371. return 0;
  10372. }
  10373. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10374. if (!lua_interface)
  10375. return 0;
  10376. Spawn* spawn = lua_interface->GetSpawn(state);
  10377. bool canbind = lua_interface->GetInt32Value(state, 2);
  10378. lua_interface->ResetFunctionStack(state);
  10379. if(!spawn) {
  10380. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10381. return 0;
  10382. }
  10383. ZoneServer* zone = spawn->GetZone();
  10384. if (zone)
  10385. zone->SetCanBind(canbind);
  10386. return 0;
  10387. }
  10388. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10389. if (!lua_interface)
  10390. return 0;
  10391. Spawn* spawn = lua_interface->GetSpawn(state);
  10392. lua_interface->ResetFunctionStack(state);
  10393. if(!spawn) {
  10394. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10395. return 0;
  10396. }
  10397. ZoneServer* zone = spawn->GetZone();
  10398. if (zone) {
  10399. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10400. return 1;
  10401. }
  10402. return 0;
  10403. }
  10404. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10405. if (!lua_interface)
  10406. return 0;
  10407. Spawn* spawn = lua_interface->GetSpawn(state);
  10408. bool cangate = lua_interface->GetInt32Value(state, 2);
  10409. lua_interface->ResetFunctionStack(state);
  10410. if(!spawn) {
  10411. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10412. return 0;
  10413. }
  10414. ZoneServer* zone = spawn->GetZone();
  10415. if (zone)
  10416. zone->SetCanGate(cangate);
  10417. return 0;
  10418. }
  10419. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10420. if (!lua_interface)
  10421. return 0;
  10422. Spawn* spawn = lua_interface->GetSpawn(state);
  10423. lua_interface->ResetFunctionStack(state);
  10424. if(!spawn) {
  10425. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10426. return 0;
  10427. }
  10428. ZoneServer* zone = spawn->GetZone();
  10429. if (zone) {
  10430. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10431. return 1;
  10432. }
  10433. return 0;
  10434. }
  10435. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10436. if (!lua_interface)
  10437. return 0;
  10438. Spawn* spawn = lua_interface->GetSpawn(state);
  10439. bool canevac = lua_interface->GetInt32Value(state, 2);
  10440. lua_interface->ResetFunctionStack(state);
  10441. if(!spawn) {
  10442. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10443. return 0;
  10444. }
  10445. ZoneServer* zone = spawn->GetZone();
  10446. if (zone)
  10447. zone->SetCanEvac(canevac);
  10448. return 0;
  10449. }
  10450. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10451. if (!lua_interface)
  10452. return 0;
  10453. Spawn* spawn = lua_interface->GetSpawn(state);
  10454. lua_interface->ResetFunctionStack(state);
  10455. if(!spawn) {
  10456. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10457. return 0;
  10458. }
  10459. ZoneServer* zone = spawn->GetZone();
  10460. if (zone) {
  10461. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10462. return 1;
  10463. }
  10464. return 0;
  10465. }
  10466. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10467. if (!lua_interface)
  10468. return 0;
  10469. Spawn* spawn = lua_interface->GetSpawn(state);
  10470. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10471. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10472. float distance = lua_interface->GetFloatValue(state, 4);
  10473. string in_range_function = lua_interface->GetStringValue(state, 5);
  10474. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10475. lua_interface->ResetFunctionStack(state);
  10476. if (spawn && distance > 0 && in_range_function.length() > 0)
  10477. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10478. return 0;
  10479. }
  10480. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10481. if (!lua_interface)
  10482. return 0;
  10483. Spawn* spawn = lua_interface->GetSpawn(state);
  10484. Spawn* target = lua_interface->GetSpawn(state, 2);
  10485. lua_interface->ResetFunctionStack(state);
  10486. if (spawn && target)
  10487. {
  10488. if (spawn->IsPlayer() && target->IsEntity())
  10489. {
  10490. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10491. return 1;
  10492. }
  10493. else if (spawn->IsEntity() && target->IsEntity())
  10494. {
  10495. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10496. return 1;
  10497. }
  10498. }
  10499. return 0;
  10500. }
  10501. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10502. if (!lua_interface)
  10503. return 0;
  10504. Spawn* spawn = lua_interface->GetSpawn(state);
  10505. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10506. lua_interface->ResetFunctionStack(state);
  10507. if (spawn && spawn->IsEntity())
  10508. {
  10509. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10510. if (spawn->IsPlayer())
  10511. {
  10512. Client* client = ((Player*)spawn)->GetClient();
  10513. if (client)
  10514. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10515. }
  10516. }
  10517. return 0;
  10518. }
  10519. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10520. if (!lua_interface)
  10521. return 0;
  10522. Spawn* spawn = lua_interface->GetSpawn(state);
  10523. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10524. lua_interface->ResetFunctionStack(state);
  10525. if (spawn && spawn->IsEntity())
  10526. {
  10527. ((Entity*)spawn)->SetSeeHideSpell(val);
  10528. if (spawn->IsPlayer())
  10529. {
  10530. Client* client = ((Player*)spawn)->GetClient();
  10531. if (client)
  10532. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10533. }
  10534. }
  10535. return 0;
  10536. }
  10537. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10538. {
  10539. if (!lua_interface)
  10540. return 0;
  10541. Spawn* player = lua_interface->GetSpawn(state);
  10542. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10543. string command = lua_interface->GetStringValue(state, 3);
  10544. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10545. lua_interface->ResetFunctionStack(state);
  10546. if (spawn && player && player->IsPlayer())
  10547. {
  10548. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10549. bool res = false;
  10550. if (cmd)
  10551. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10552. lua_interface->SetBooleanValue(state, res);
  10553. return 1;
  10554. }
  10555. return 0;
  10556. }
  10557. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10558. {
  10559. if (!lua_interface)
  10560. return 0;
  10561. Spawn* spawn = lua_interface->GetSpawn(state);
  10562. int32 charID = lua_interface->GetInt32Value(state, 2);
  10563. string command = lua_interface->GetStringValue(state, 3);
  10564. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10565. lua_interface->ResetFunctionStack(state);
  10566. if (spawn && charID)
  10567. {
  10568. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10569. bool res = false;
  10570. if (cmd)
  10571. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10572. lua_interface->SetBooleanValue(state, res);
  10573. return 1;
  10574. }
  10575. return 0;
  10576. }
  10577. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10578. {
  10579. if (!lua_interface)
  10580. return 0;
  10581. Spawn* spawn = lua_interface->GetSpawn(state);
  10582. string command = lua_interface->GetStringValue(state, 2);
  10583. lua_interface->ResetFunctionStack(state);
  10584. if (spawn && command.length() > 0)
  10585. spawn->RemovePrimaryEntityCommand(command.c_str());
  10586. return 0;
  10587. }
  10588. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10589. if (!lua_interface)
  10590. return 0;
  10591. Spawn* spawn = lua_interface->GetSpawn(state);
  10592. float distance = lua_interface->GetFloatValue(state, 2);
  10593. string command = lua_interface->GetStringValue(state, 3);
  10594. Spawn* player = lua_interface->GetSpawn(state, 4);
  10595. lua_interface->ResetFunctionStack(state);
  10596. if (spawn) {
  10597. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10598. }
  10599. return 0;
  10600. }
  10601. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10602. if (!lua_interface)
  10603. return 0;
  10604. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10605. Spawn* spawn = lua_interface->GetSpawn(state);
  10606. Spawn* player = lua_interface->GetSpawn(state, 2);
  10607. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10608. lua_interface->ResetFunctionStack(state);
  10609. if (spawn && player && transport_id && player->IsPlayer()) {
  10610. Client* client = 0;
  10611. if (player && player->IsPlayer())
  10612. client = ((Player*)player)->GetClient();
  10613. if (!client)
  10614. return 0;
  10615. vector<TransportDestination*> destinations;
  10616. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10617. if (destinations.size())
  10618. {
  10619. client->SetTemporaryTransportID(transport_id);
  10620. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10621. }
  10622. else
  10623. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10624. }
  10625. return 0;
  10626. }
  10627. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10628. if (!lua_interface)
  10629. return 0;
  10630. Spawn* player = lua_interface->GetSpawn(state);
  10631. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10632. lua_interface->ResetFunctionStack(state);
  10633. if (player && player->IsPlayer()) {
  10634. Client* client = 0;
  10635. if (player && player->IsPlayer())
  10636. client = ((Player*)player)->GetClient();
  10637. if (!client)
  10638. return 0;
  10639. client->SetTemporaryTransportID(transport_id);
  10640. }
  10641. return 0;
  10642. }
  10643. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10644. if (!lua_interface)
  10645. return 0;
  10646. Spawn* player = lua_interface->GetSpawn(state);
  10647. lua_interface->ResetFunctionStack(state);
  10648. if (player && player->IsPlayer()) {
  10649. Client* client = 0;
  10650. if (player && player->IsPlayer())
  10651. client = ((Player*)player)->GetClient();
  10652. if (!client)
  10653. return 0;
  10654. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10655. return 1;
  10656. }
  10657. return 0;
  10658. }
  10659. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10660. if (!lua_interface)
  10661. return 0;
  10662. Spawn* spawn = lua_interface->GetSpawn(state);
  10663. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10664. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10665. if (!spawn) {
  10666. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10667. return 0;
  10668. }
  10669. if (!spawn->IsEntity()) {
  10670. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10671. return 0;
  10672. }
  10673. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10674. {
  10675. lua_interface->LogError("%s: LUA SetAlignment command error: alignment value beyond supported min: %i and max: %i", lua_interface->GetScriptName(state), SCHAR_MIN, SCHAR_MAX);
  10676. return 0;
  10677. }
  10678. lua_interface->ResetFunctionStack(state);
  10679. if (spell && spell->targets.size() > 0) {
  10680. ZoneServer* zone = spell->caster->GetZone();
  10681. for (int8 i = 0; i < spell->targets.size(); i++) {
  10682. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10683. if (target && target->IsEntity()) {
  10684. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10685. if (target->IsPlayer())
  10686. ((Player*)target)->SetCharSheetChanged(true);
  10687. }
  10688. }
  10689. }
  10690. else {
  10691. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10692. if (spawn->IsPlayer())
  10693. ((Player*)spawn)->SetCharSheetChanged(true);
  10694. }
  10695. return 0;
  10696. }
  10697. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10698. if (!lua_interface)
  10699. return 0;
  10700. Spawn* spawn = lua_interface->GetSpawn(state);
  10701. lua_interface->ResetFunctionStack(state);
  10702. if (!spawn) {
  10703. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10704. return 0;
  10705. }
  10706. if (!spawn->IsEntity()) {
  10707. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10708. return 0;
  10709. }
  10710. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10711. return 1;
  10712. }
  10713. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10714. if (!lua_interface)
  10715. return 0;
  10716. int32 spell_id = lua_interface->GetInt32Value(state);
  10717. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10718. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10719. if (spell_id > 0) {
  10720. if (spell_tier == 0)
  10721. spell_tier = 1;
  10722. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10723. if(!spell) {
  10724. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10725. lua_interface->ResetFunctionStack(state);
  10726. return 0;
  10727. }
  10728. LuaSpell* lua_spell = 0;
  10729. if(custom_lua_script.size() > 0)
  10730. {
  10731. // attempt to load the custom script since it isn't already loaded
  10732. // we will re-obtain the lua_spell further below
  10733. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10734. {
  10735. LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
  10736. lua_interface->LoadLuaSpell(custom_lua_script);
  10737. }
  10738. }
  10739. else
  10740. custom_lua_script = spell->GetSpellData()->lua_script;
  10741. if (!lua_spell && lua_interface)
  10742. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10743. lua_interface->ResetFunctionStack(state);
  10744. if (!lua_spell)
  10745. {
  10746. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10747. return 0;
  10748. }
  10749. lua_spell->spell = new Spell(spell);
  10750. lua_interface->AddCustomSpell(lua_spell);
  10751. lua_interface->SetSpellValue(state, lua_spell);
  10752. return 1;
  10753. }
  10754. return 0;
  10755. }
  10756. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10757. if (!lua_interface)
  10758. return 0;
  10759. LuaSpell* spell = lua_interface->GetSpell(state);
  10760. string field = lua_interface->GetStringValue(state, 2);
  10761. lua_interface->ResetFunctionStack(state);
  10762. if (!spell) {
  10763. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10764. return 0;
  10765. }
  10766. if (!spell->spell || !spell->spell->GetSpellData()) {
  10767. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10768. return 0;
  10769. }
  10770. boost::to_lower(field);
  10771. return spell->spell->GetSpellData(state, field);
  10772. }
  10773. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10774. if (!lua_interface)
  10775. return 0;
  10776. LuaSpell* spell = lua_interface->GetSpell(state);
  10777. string field = lua_interface->GetStringValue(state, 2);
  10778. int8 fieldArg = 3; // field value after the initial set
  10779. if (!spell) {
  10780. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10781. lua_interface->ResetFunctionStack(state);
  10782. return 0;
  10783. }
  10784. if (!spell->spell || !spell->spell->GetSpellData()) {
  10785. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10786. lua_interface->ResetFunctionStack(state);
  10787. return 0;
  10788. }
  10789. boost::to_lower(field);
  10790. bool valSet = false;
  10791. spell->spell->SetSpellData(state, field, fieldArg);
  10792. lua_interface->ResetFunctionStack(state);
  10793. return valSet;
  10794. }
  10795. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10796. if (!lua_interface)
  10797. return 0;
  10798. LuaSpell* spell = lua_interface->GetSpell(state);
  10799. int8 idx = lua_interface->GetInt32Value(state, 2);
  10800. if (!spell) {
  10801. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10802. lua_interface->ResetFunctionStack(state);
  10803. return 0;
  10804. }
  10805. if (!spell->spell || !spell->spell->GetSpellData()) {
  10806. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10807. lua_interface->ResetFunctionStack(state);
  10808. return 0;
  10809. }
  10810. if (spell->spell->lua_data.size() <= idx)
  10811. {
  10812. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10813. lua_interface->ResetFunctionStack(state);
  10814. return 0;
  10815. }
  10816. bool setVal = true;
  10817. LUAData* data = spell->spell->lua_data[idx];
  10818. switch (data->type)
  10819. {
  10820. case 0:
  10821. {
  10822. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10823. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10824. data->int_value = value;
  10825. data->int_value2 = value2;
  10826. break;
  10827. }
  10828. case 1:
  10829. {
  10830. float value = lua_interface->GetFloatValue(state, 3);
  10831. float value2 = lua_interface->GetFloatValue(state, 4);
  10832. data->float_value = value;
  10833. data->float_value2 = value2;
  10834. break;
  10835. }
  10836. case 2:
  10837. {
  10838. bool value = lua_interface->GetBooleanValue(state, 3);
  10839. data->bool_value = value;
  10840. break;
  10841. }
  10842. case 3:
  10843. {
  10844. string value = lua_interface->GetStringValue(state, 3);
  10845. string value2 = lua_interface->GetStringValue(state, 4);
  10846. data->string_value = value;
  10847. data->string_value2 = value2;
  10848. break;
  10849. }
  10850. default:
  10851. setVal = false;
  10852. }
  10853. lua_interface->ResetFunctionStack(state);
  10854. return setVal;
  10855. }
  10856. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10857. if (!lua_interface)
  10858. return 0;
  10859. LuaSpell* spell = lua_interface->GetSpell(state);
  10860. int8 idx = lua_interface->GetInt32Value(state, 2);
  10861. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10862. lua_interface->ResetFunctionStack(state);
  10863. if (!spell) {
  10864. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10865. return 0;
  10866. }
  10867. if (!spell->spell || !spell->spell->GetSpellData()) {
  10868. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10869. return 0;
  10870. }
  10871. if (spell->spell->lua_data.size() <= idx)
  10872. {
  10873. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10874. return 0;
  10875. }
  10876. bool setVal = true;
  10877. LUAData* data = spell->spell->lua_data[idx];
  10878. switch (data->type)
  10879. {
  10880. case 0:
  10881. {
  10882. if(!secondfield)
  10883. lua_interface->SetSInt32Value(state, data->int_value);
  10884. else
  10885. lua_interface->SetSInt32Value(state, data->int_value2);
  10886. break;
  10887. }
  10888. case 1:
  10889. {
  10890. if (!secondfield)
  10891. lua_interface->SetFloatValue(state, data->float_value);
  10892. else
  10893. lua_interface->SetFloatValue(state, data->float_value2);
  10894. break;
  10895. }
  10896. case 2:
  10897. {
  10898. lua_interface->SetBooleanValue(state, data->bool_value);
  10899. break;
  10900. }
  10901. case 3:
  10902. {
  10903. if (!secondfield)
  10904. lua_interface->SetStringValue(state, data->string_value.c_str());
  10905. else
  10906. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10907. break;
  10908. }
  10909. default:
  10910. setVal = false;
  10911. }
  10912. return setVal;
  10913. }
  10914. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10915. if (!lua_interface)
  10916. return 0;
  10917. LuaSpell* spell = lua_interface->GetSpell(state);
  10918. int8 idx = lua_interface->GetInt32Value(state, 2);
  10919. string field = lua_interface->GetStringValue(state, 3);
  10920. boost::to_lower(field);
  10921. if (!spell) {
  10922. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10923. lua_interface->ResetFunctionStack(state);
  10924. return 0;
  10925. }
  10926. if (!spell->spell || !spell->spell->GetSpellData()) {
  10927. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10928. lua_interface->ResetFunctionStack(state);
  10929. return 0;
  10930. }
  10931. if (spell->spell->effects.size() <= idx)
  10932. {
  10933. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10934. lua_interface->ResetFunctionStack(state);
  10935. return 0;
  10936. }
  10937. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10938. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10939. if (field == "description")
  10940. effect->description = string(lua_interface->GetStringValue(state, 4));
  10941. else if (field == "bullet")
  10942. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10943. else if (field == "percentage")
  10944. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10945. else { // no match
  10946. lua_interface->ResetFunctionStack(state);
  10947. return 0;
  10948. }
  10949. lua_interface->ResetFunctionStack(state);
  10950. return 1;
  10951. }
  10952. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10953. if (!lua_interface)
  10954. return 0;
  10955. LuaSpell* spell = lua_interface->GetSpell(state);
  10956. int8 idx = lua_interface->GetInt32Value(state, 2);
  10957. string field = lua_interface->GetStringValue(state, 3);
  10958. lua_interface->ResetFunctionStack(state);
  10959. boost::to_lower(field);
  10960. if (!spell) {
  10961. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10962. return 0;
  10963. }
  10964. if (!spell->spell || !spell->spell->GetSpellData()) {
  10965. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10966. return 0;
  10967. }
  10968. if (spell->spell->effects.size() <= idx)
  10969. {
  10970. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10971. return 0;
  10972. }
  10973. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10974. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10975. if (field == "description")
  10976. lua_interface->SetStringValue(state, effect->description.c_str());
  10977. else if (field == "bullet")
  10978. lua_interface->SetInt32Value(state, effect->subbullet);
  10979. else if (field == "percentage")
  10980. lua_interface->SetInt32Value(state, effect->percentage);
  10981. else // no match
  10982. return 0;
  10983. return 1;
  10984. }
  10985. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10986. if (!lua_interface)
  10987. return 0;
  10988. LuaSpell* spell = lua_interface->GetSpell(state);
  10989. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10990. Spawn* target = lua_interface->GetSpawn(state, 3);
  10991. lua_interface->ResetFunctionStack(state);
  10992. if (!target) {
  10993. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10994. return 0;
  10995. }
  10996. if (!target->IsEntity()) {
  10997. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10998. return 0;
  10999. }
  11000. if (!spell) {
  11001. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  11002. return 0;
  11003. }
  11004. if (caster && !caster->IsEntity()) {
  11005. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  11006. return 0;
  11007. }
  11008. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  11009. return 0;
  11010. }
  11011. int EQ2Emu_lua_InWater(lua_State* state) {
  11012. if (!lua_interface)
  11013. return 0;
  11014. Spawn* spawn = lua_interface->GetSpawn(state);
  11015. lua_interface->ResetFunctionStack(state);
  11016. if (spawn) {
  11017. lua_interface->SetBooleanValue(state, spawn->InWater());
  11018. return 1;
  11019. }
  11020. return 0;
  11021. }
  11022. int EQ2Emu_lua_InLava(lua_State* state) {
  11023. if (!lua_interface)
  11024. return 0;
  11025. Spawn* spawn = lua_interface->GetSpawn(state);
  11026. lua_interface->ResetFunctionStack(state);
  11027. if (spawn) {
  11028. lua_interface->SetBooleanValue(state, spawn->InLava());
  11029. return 1;
  11030. }
  11031. return 0;
  11032. }
  11033. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  11034. if (!lua_interface)
  11035. return 0;
  11036. Spawn* attacker = lua_interface->GetSpawn(state);
  11037. Spawn* victim = lua_interface->GetSpawn(state, 2);
  11038. int8 type = lua_interface->GetInt8Value(state, 3);
  11039. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  11040. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  11041. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  11042. string spell_name = lua_interface->GetStringValue(state, 7);
  11043. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  11044. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  11045. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  11046. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  11047. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  11048. lua_interface->ResetFunctionStack(state);
  11049. if (!attacker) {
  11050. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  11051. lua_interface->SetBooleanValue(state, false);
  11052. return 1;
  11053. }
  11054. if (!attacker->IsEntity()) {
  11055. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  11056. lua_interface->SetBooleanValue(state, false);
  11057. return 1;
  11058. }
  11059. if (!victim) {
  11060. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11061. lua_interface->SetBooleanValue(state, false);
  11062. return 1;
  11063. }
  11064. if (!victim->IsEntity()) {
  11065. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  11066. lua_interface->SetBooleanValue(state, false);
  11067. return 1;
  11068. }
  11069. bool has_damaged = ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker, take_power);
  11070. lua_interface->SetBooleanValue(state, has_damaged);
  11071. return 1;
  11072. }
  11073. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  11074. if (!lua_interface)
  11075. return 0;
  11076. Spawn* spawn = lua_interface->GetSpawn(state);
  11077. lua_interface->ResetFunctionStack(state);
  11078. if (spawn) {
  11079. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11080. return 1;
  11081. }
  11082. return 0;
  11083. }
  11084. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11085. if (!lua_interface)
  11086. return 0;
  11087. Spawn* spawn = lua_interface->GetSpawn(state);
  11088. bool invul = lua_interface->GetBooleanValue(state, 2);
  11089. lua_interface->ResetFunctionStack(state);
  11090. if (spawn) {
  11091. spawn->SetInvulnerable(invul);
  11092. }
  11093. return 0;
  11094. }
  11095. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11096. if (!lua_interface)
  11097. return 0;
  11098. string category = lua_interface->GetStringValue(state);
  11099. string name = lua_interface->GetStringValue(state, 2);
  11100. lua_interface->ResetFunctionStack(state);
  11101. Rule *ret = 0;
  11102. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11103. lua_interface->SetBooleanValue(state, ret->GetBool());
  11104. return 1;
  11105. }
  11106. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11107. return 0;
  11108. }
  11109. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11110. if (!lua_interface)
  11111. return 0;
  11112. string category = lua_interface->GetStringValue(state);
  11113. string name = lua_interface->GetStringValue(state, 2);
  11114. lua_interface->ResetFunctionStack(state);
  11115. Rule *ret = 0;
  11116. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11117. lua_interface->SetInt32Value(state, ret->GetInt32());
  11118. return 1;
  11119. }
  11120. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11121. return 0;
  11122. }
  11123. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11124. if (!lua_interface)
  11125. return 0;
  11126. string category = lua_interface->GetStringValue(state);
  11127. string name = lua_interface->GetStringValue(state, 2);
  11128. lua_interface->ResetFunctionStack(state);
  11129. Rule *ret = 0;
  11130. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11131. lua_interface->SetFloatValue(state, ret->GetFloat());
  11132. return 1;
  11133. }
  11134. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11135. return 0;
  11136. }
  11137. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11138. if (!lua_interface)
  11139. return 0;
  11140. Spawn* spawn = lua_interface->GetSpawn(state);
  11141. string type = lua_interface->GetStringValue(state, 2);
  11142. lua_interface->ResetFunctionStack(state);
  11143. if (spawn) {
  11144. int res = 1;
  11145. boost::to_lower(type);
  11146. if(type == "assigned_aa")
  11147. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11148. else if ( type == "unassigned_aa")
  11149. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11150. else if ( type == "assigned_tradeskill_aa")
  11151. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11152. else if ( type == "unassigned_tradeskill_aa")
  11153. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11154. else if ( type == "assigned_prestige_aa")
  11155. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11156. else if ( type == "unassigned_prestige_aa")
  11157. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11158. else if ( type == "assigned_tradeskill_prestige_aa")
  11159. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11160. else if ( type == "unassigned_tradeskill_prestige_aa")
  11161. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11162. else
  11163. res = 0;
  11164. return res;
  11165. }
  11166. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11167. return 0;
  11168. }
  11169. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11170. if (!lua_interface)
  11171. return 0;
  11172. Spawn* spawn = lua_interface->GetSpawn(state);
  11173. string type = lua_interface->GetStringValue(state, 2);
  11174. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11175. lua_interface->ResetFunctionStack(state);
  11176. if (spawn) {
  11177. boost::to_lower(type);
  11178. if(type == "assigned_aa")
  11179. spawn->SetAssignedAA((sint16)value);
  11180. else if ( type == "unassigned_aa")
  11181. spawn->SetUnassignedAA((sint16)value);
  11182. else if ( type == "assigned_tradeskill_aa")
  11183. spawn->SetTradeskillAA((sint16)value);
  11184. else if ( type == "unassigned_tradeskill_aa")
  11185. spawn->SetUnassignedTradeskillAA((sint16)value);
  11186. else if ( type == "assigned_prestige_aa")
  11187. spawn->SetPrestigeAA((sint16)value);
  11188. else if ( type == "unassigned_prestige_aa")
  11189. spawn->SetUnassignedPrestigeAA((sint16)value);
  11190. else if ( type == "assigned_tradeskill_prestige_aa")
  11191. spawn->SetTradeskillPrestigeAA((sint16)value);
  11192. else if ( type == "unassigned_tradeskill_prestige_aa")
  11193. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11194. if(spawn->IsPlayer())
  11195. ((Player*)spawn)->SetCharSheetChanged(true);
  11196. }
  11197. return 0;
  11198. }
  11199. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11200. if (!lua_interface)
  11201. return 0;
  11202. string titleName = lua_interface->GetStringValue(state);
  11203. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11204. lua_interface->ResetFunctionStack(state);
  11205. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11206. lua_interface->SetSInt32Value(state, index);
  11207. return 1;
  11208. }
  11209. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11210. if (!lua_interface)
  11211. return 0;
  11212. Spawn* spawn = lua_interface->GetSpawn(state);
  11213. string titleName = lua_interface->GetStringValue(state, 2);
  11214. lua_interface->ResetFunctionStack(state);
  11215. if(!spawn->IsPlayer())
  11216. {
  11217. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11218. lua_interface->SetSInt32Value(state, -1);
  11219. return 1;
  11220. }
  11221. Player* player = (Player*)spawn;
  11222. // check if player already has the title, don't need to add twice
  11223. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11224. if ( playerHasTitle)
  11225. {
  11226. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11227. return 1;
  11228. }
  11229. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11230. if(!title)
  11231. {
  11232. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11233. lua_interface->SetSInt32Value(state, -1);
  11234. return 1;
  11235. }
  11236. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11237. if(returnIdx < 0)
  11238. {
  11239. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11240. }
  11241. lua_interface->SetSInt32Value(state, returnIdx);
  11242. player->GetClient()->SendTitleUpdate();
  11243. return 1;
  11244. }
  11245. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11246. if (!lua_interface)
  11247. return 0;
  11248. Spawn* spawn = lua_interface->GetSpawn(state);
  11249. string titleName = lua_interface->GetStringValue(state, 2);
  11250. lua_interface->ResetFunctionStack(state);
  11251. if(!spawn->IsPlayer())
  11252. {
  11253. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11254. return 0;
  11255. }
  11256. Player* player = (Player*)spawn;
  11257. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11258. if(!title)
  11259. {
  11260. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11261. return 0;
  11262. }
  11263. if(title->GetPrefix())
  11264. {
  11265. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title with name '%s' is not valid as a suffix, only prefix", lua_interface->GetScriptName(state), titleName.c_str());
  11266. return 0;
  11267. }
  11268. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11269. player->GetClient()->SendTitleUpdate();
  11270. return 1;
  11271. }
  11272. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11273. if (!lua_interface)
  11274. return 0;
  11275. Spawn* spawn = lua_interface->GetSpawn(state);
  11276. string titleName = lua_interface->GetStringValue(state, 2);
  11277. lua_interface->ResetFunctionStack(state);
  11278. if(!spawn->IsPlayer())
  11279. {
  11280. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11281. return 0;
  11282. }
  11283. Player* player = (Player*)spawn;
  11284. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11285. if(!title)
  11286. {
  11287. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11288. return 0;
  11289. }
  11290. if(!title->GetPrefix())
  11291. {
  11292. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title with name '%s' is not valid as a prefix, only suffix", lua_interface->GetScriptName(state), titleName.c_str());
  11293. return 0;
  11294. }
  11295. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11296. player->GetClient()->SendTitleUpdate();
  11297. return 1;
  11298. }
  11299. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11300. if (!lua_interface)
  11301. return 0;
  11302. Spawn* spawn = lua_interface->GetSpawn(state);
  11303. lua_interface->ResetFunctionStack(state);
  11304. if(!spawn->IsPlayer())
  11305. {
  11306. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11307. return 0;
  11308. }
  11309. Player* player = (Player*)spawn;
  11310. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11311. player->GetClient()->SendTitleUpdate();
  11312. return 1;
  11313. }
  11314. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11315. if (!lua_interface)
  11316. return 0;
  11317. Spawn* spawn = lua_interface->GetSpawn(state);
  11318. lua_interface->ResetFunctionStack(state);
  11319. if(!spawn->IsPlayer())
  11320. {
  11321. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11322. return 0;
  11323. }
  11324. Player* player = (Player*)spawn;
  11325. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11326. player->GetClient()->SendTitleUpdate();
  11327. return 1;
  11328. }
  11329. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11330. if (!lua_interface)
  11331. return 0;
  11332. Spawn* spawn = lua_interface->GetSpawn(state);
  11333. string field = lua_interface->GetStringValue(state, 2);
  11334. lua_interface->ResetFunctionStack(state);
  11335. if(!spawn || !spawn->IsEntity())
  11336. {
  11337. lua_interface->LogError("%s: LUA GetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11338. return 0;
  11339. }
  11340. Entity* ent = (Entity*)spawn;
  11341. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11342. return 1;
  11343. }
  11344. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11345. if (!lua_interface)
  11346. return 0;
  11347. Spawn* spawn = lua_interface->GetSpawn(state);
  11348. string field = lua_interface->GetStringValue(state, 2);
  11349. lua_interface->ResetFunctionStack(state);
  11350. if(!spawn || !spawn->IsEntity())
  11351. {
  11352. lua_interface->LogError("%s: LUA GetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11353. return 0;
  11354. }
  11355. Entity* ent = (Entity*)spawn;
  11356. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11357. return 1;
  11358. }
  11359. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11360. if (!lua_interface)
  11361. return 0;
  11362. Spawn* spawn = lua_interface->GetSpawn(state);
  11363. string field = lua_interface->GetStringValue(state, 2);
  11364. lua_interface->ResetFunctionStack(state);
  11365. if(!spawn || !spawn->IsEntity())
  11366. {
  11367. lua_interface->LogError("%s: LUA GetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11368. return 0;
  11369. }
  11370. Entity* ent = (Entity*)spawn;
  11371. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11372. return 1;
  11373. }
  11374. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11375. if (!lua_interface)
  11376. return 0;
  11377. Spawn* spawn = lua_interface->GetSpawn(state);
  11378. string field = lua_interface->GetStringValue(state, 2);
  11379. lua_interface->ResetFunctionStack(state);
  11380. if(!spawn || !spawn->IsEntity())
  11381. {
  11382. lua_interface->LogError("%s: LUA GetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11383. return 0;
  11384. }
  11385. Entity* ent = (Entity*)spawn;
  11386. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11387. return 1;
  11388. }
  11389. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11390. if (!lua_interface)
  11391. return 0;
  11392. Spawn* spawn = lua_interface->GetSpawn(state);
  11393. string field = lua_interface->GetStringValue(state, 2);
  11394. string value = lua_interface->GetStringValue(state, 3);
  11395. lua_interface->ResetFunctionStack(state);
  11396. if(!spawn || !spawn->IsEntity())
  11397. {
  11398. lua_interface->LogError("%s: LUA SetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11399. return 0;
  11400. }
  11401. Entity* ent = (Entity*)spawn;
  11402. bool set_ = ent->SetInfoStructString(field, value);
  11403. lua_interface->SetBooleanValue(state, set_);
  11404. return 1;
  11405. }
  11406. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11407. if (!lua_interface)
  11408. return 0;
  11409. Spawn* spawn = lua_interface->GetSpawn(state);
  11410. string field = lua_interface->GetStringValue(state, 2);
  11411. int64 value = lua_interface->GetInt64Value(state, 3);
  11412. lua_interface->ResetFunctionStack(state);
  11413. if(!spawn || !spawn->IsEntity())
  11414. {
  11415. lua_interface->LogError("%s: LUA SetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11416. return 0;
  11417. }
  11418. Entity* ent = (Entity*)spawn;
  11419. bool set_ = ent->SetInfoStructUInt(field, value);
  11420. lua_interface->SetBooleanValue(state, set_);
  11421. return 1;
  11422. }
  11423. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11424. if (!lua_interface)
  11425. return 0;
  11426. Spawn* spawn = lua_interface->GetSpawn(state);
  11427. string field = lua_interface->GetStringValue(state, 2);
  11428. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11429. lua_interface->ResetFunctionStack(state);
  11430. if(!spawn || !spawn->IsEntity())
  11431. {
  11432. lua_interface->LogError("%s: LUA SetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11433. return 0;
  11434. }
  11435. Entity* ent = (Entity*)spawn;
  11436. bool set_ = ent->SetInfoStructSInt(field, value);
  11437. lua_interface->SetBooleanValue(state, set_);
  11438. return 1;
  11439. }
  11440. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11441. if (!lua_interface)
  11442. return 0;
  11443. Spawn* spawn = lua_interface->GetSpawn(state);
  11444. string field = lua_interface->GetStringValue(state, 2);
  11445. float value = lua_interface->GetFloatValue(state, 3);
  11446. lua_interface->ResetFunctionStack(state);
  11447. if(!spawn || !spawn->IsEntity())
  11448. {
  11449. lua_interface->LogError("%s: LUA SetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11450. return 0;
  11451. }
  11452. Entity* ent = (Entity*)spawn;
  11453. bool set_ = ent->SetInfoStructFloat(field, value);
  11454. lua_interface->SetBooleanValue(state, set_);
  11455. return 1;
  11456. }
  11457. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11458. if (!lua_interface)
  11459. return 0;
  11460. Spawn* spawn = lua_interface->GetSpawn(state);
  11461. bool value = lua_interface->GetBooleanValue(state, 2);
  11462. lua_interface->ResetFunctionStack(state);
  11463. if(!spawn || !spawn->IsPlayer())
  11464. {
  11465. lua_interface->LogError("%s: LUA SetCharSheetChanged command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  11466. return 0;
  11467. }
  11468. ((Player*)spawn)->SetCharSheetChanged(value);
  11469. return 0;
  11470. }
  11471. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11472. if (!lua_interface)
  11473. return 0;
  11474. Spawn* spawn = lua_interface->GetSpawn(state);
  11475. std::string fromName = lua_interface->GetStringValue(state, 2);
  11476. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11477. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11478. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11479. int32 copper = lua_interface->GetInt32Value(state, 6);
  11480. int32 silver = lua_interface->GetInt32Value(state, 7);
  11481. int32 gold = lua_interface->GetInt32Value(state, 8);
  11482. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11483. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11484. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11485. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11486. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11487. lua_interface->ResetFunctionStack(state);
  11488. if(!spawn || !spawn->IsPlayer())
  11489. {
  11490. lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  11491. lua_interface->SetBooleanValue(state, false);
  11492. return 1;
  11493. }
  11494. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11495. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11496. lua_interface->SetBooleanValue(state, true);
  11497. return 1;
  11498. }
  11499. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11500. if (!lua_interface)
  11501. return 0;
  11502. int32 char_id = lua_interface->GetInt32Value(state);
  11503. std::string fromName = lua_interface->GetStringValue(state, 2);
  11504. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11505. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11506. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11507. int32 copper = lua_interface->GetInt32Value(state, 6);
  11508. int32 silver = lua_interface->GetInt32Value(state, 7);
  11509. int32 gold = lua_interface->GetInt32Value(state, 8);
  11510. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11511. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11512. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11513. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11514. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11515. lua_interface->ResetFunctionStack(state);
  11516. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11517. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11518. lua_interface->SetBooleanValue(state, true);
  11519. return 1;
  11520. }
  11521. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11522. Spawn* widget;
  11523. if (lua_interface) {
  11524. widget = lua_interface->GetSpawn(state);
  11525. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11526. lua_interface->ResetFunctionStack(state);
  11527. if (widget && widget->IsWidget())
  11528. {
  11529. ((Widget*)widget)->OpenDoor();
  11530. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11531. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11532. }
  11533. else
  11534. lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  11535. }
  11536. return 0;
  11537. }
  11538. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11539. Spawn* widget;
  11540. if (lua_interface) {
  11541. widget = lua_interface->GetSpawn(state);
  11542. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11543. lua_interface->ResetFunctionStack(state);
  11544. if (widget && widget->IsWidget())
  11545. {
  11546. ((Widget*)widget)->CloseDoor();
  11547. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11548. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11549. }
  11550. else
  11551. lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  11552. }
  11553. return 0;
  11554. }
  11555. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11556. if (!lua_interface)
  11557. return 0;
  11558. Spawn* widget = lua_interface->GetSpawn(state);
  11559. lua_interface->ResetFunctionStack(state);
  11560. if (widget && widget->IsWidget())
  11561. {
  11562. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11563. return 1;
  11564. }
  11565. return 0;
  11566. }
  11567. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11568. if (!lua_interface)
  11569. return 0;
  11570. sint32 min = lua_interface->GetSInt32Value(state);
  11571. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11572. lua_interface->ResetFunctionStack(state);
  11573. sint32 result = MakeRandomInt(min, max);
  11574. lua_interface->SetSInt32Value(state, result);
  11575. return 1;
  11576. }
  11577. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11578. if (!lua_interface)
  11579. return 0;
  11580. float min = lua_interface->GetFloatValue(state);
  11581. float max = lua_interface->GetFloatValue(state, 2);
  11582. lua_interface->ResetFunctionStack(state);
  11583. float result = MakeRandomFloat(min, max);
  11584. lua_interface->SetFloatValue(state, result);
  11585. return 1;
  11586. }
  11587. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11588. if (!lua_interface)
  11589. return 0;
  11590. Spawn* spawn = lua_interface->GetSpawn(state);
  11591. int32 value = lua_interface->GetInt32Value(state, 2);
  11592. lua_interface->ResetFunctionStack(state);
  11593. if(!spawn)
  11594. {
  11595. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11596. lua_interface->SetBooleanValue(state, false);
  11597. return 1;
  11598. }
  11599. spawn->AddIconValue(value);
  11600. lua_interface->SetBooleanValue(state, true);
  11601. return 1;
  11602. }
  11603. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11604. if (!lua_interface)
  11605. return 0;
  11606. Spawn* spawn = lua_interface->GetSpawn(state);
  11607. int32 value = lua_interface->GetInt32Value(state, 2);
  11608. lua_interface->ResetFunctionStack(state);
  11609. if(!spawn)
  11610. {
  11611. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11612. lua_interface->SetBooleanValue(state, false);
  11613. return 1;
  11614. }
  11615. spawn->RemoveIconValue(value);
  11616. lua_interface->SetBooleanValue(state, true);
  11617. return 1;
  11618. }
  11619. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11620. Spawn* npc = lua_interface->GetSpawn(state);
  11621. lua_interface->ResetFunctionStack(state);
  11622. if (npc && npc->IsNPC()) {
  11623. NPC* shard = (NPC*)npc;
  11624. int32 shardid = shard->GetShardID();
  11625. lua_interface->SetInt32Value(state, shardid);
  11626. return 1;
  11627. }
  11628. lua_interface->SetInt32Value(state, 0);
  11629. return 1;
  11630. }
  11631. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11632. Spawn* npc = lua_interface->GetSpawn(state);
  11633. lua_interface->ResetFunctionStack(state);
  11634. if (npc && npc->IsNPC()) {
  11635. NPC* shard = (NPC*)npc;
  11636. int32 charid = shard->GetShardCharID();
  11637. lua_interface->SetInt32Value(state, charid);
  11638. return 1;
  11639. }
  11640. lua_interface->SetInt32Value(state, 0);
  11641. return 1;
  11642. }
  11643. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11644. Spawn* npc = lua_interface->GetSpawn(state);
  11645. lua_interface->ResetFunctionStack(state);
  11646. if (npc && npc->IsNPC()) {
  11647. NPC* shard = (NPC*)npc;
  11648. int64 timestamp = shard->GetShardCreatedTimestamp();
  11649. lua_interface->SetSInt64Value(state, timestamp);
  11650. return 1;
  11651. }
  11652. lua_interface->SetSInt64Value(state, 0);
  11653. return 1;
  11654. }
  11655. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11656. if (!lua_interface)
  11657. return 0;
  11658. int32 shardid = lua_interface->GetInt32Value(state);
  11659. lua_interface->ResetFunctionStack(state);
  11660. if(shardid < 1)
  11661. lua_interface->SetBooleanValue(state, false);
  11662. else
  11663. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11664. return 1;
  11665. }
  11666. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11667. if (!lua_interface)
  11668. return 0;
  11669. Spawn* spawn = lua_interface->GetSpawn(state);
  11670. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11671. if (spawn) {
  11672. spawn->PauseMovement(delay_in_ms);
  11673. }
  11674. lua_interface->ResetFunctionStack(state);
  11675. return 0;
  11676. }
  11677. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11678. if (!lua_interface)
  11679. return 0;
  11680. Spawn* spawn = lua_interface->GetSpawn(state);
  11681. if (spawn) {
  11682. spawn->ResetMovement();
  11683. }
  11684. lua_interface->ResetFunctionStack(state);
  11685. return 0;
  11686. }
  11687. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11688. Player* player = (Player*)lua_interface->GetSpawn(state);
  11689. int8 level = lua_interface->GetInt8Value(state, 2);
  11690. lua_interface->ResetFunctionStack(state);
  11691. if (player && player->IsPlayer() && level > 0) {
  11692. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11693. return 1;
  11694. }
  11695. return 0;
  11696. }
  11697. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11698. Player* player = (Player*)lua_interface->GetSpawn(state);
  11699. int8 level = lua_interface->GetInt8Value(state, 2);
  11700. lua_interface->ResetFunctionStack(state);
  11701. if (player && player->IsPlayer() && level > 0) {
  11702. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11703. return 1;
  11704. }
  11705. return 0;
  11706. }
  11707. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11708. ZoneServer* zone = lua_interface->GetZone(state);
  11709. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11710. lua_interface->ResetFunctionStack(state);
  11711. if (zone) {
  11712. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11713. if (spawn) {
  11714. lua_interface->SetSpawnValue(state, spawn);
  11715. return 1;
  11716. }
  11717. }
  11718. return 0;
  11719. }
  11720. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11721. if (!lua_interface)
  11722. return 0;
  11723. Spawn* spawn = lua_interface->GetSpawn(state);
  11724. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11725. lua_interface->ResetFunctionStack(state);
  11726. bool res = false;
  11727. if(spawn && spawn->IsTransportSpawn())
  11728. {
  11729. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11730. spawn->SetRailID(rail_id);
  11731. res = true;
  11732. }
  11733. else if (!spawn) {
  11734. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11735. }
  11736. else if(!spawn->IsTransportSpawn()) {
  11737. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  11738. }
  11739. lua_interface->SetBooleanValue(state, res);
  11740. return 1;
  11741. }
  11742. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11743. if (!lua_interface)
  11744. return 0;
  11745. ZoneServer* zone = lua_interface->GetZone(state);
  11746. lua_interface->ResetFunctionStack(state);
  11747. if (zone) {
  11748. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11749. return 1;
  11750. }
  11751. return 0;
  11752. }
  11753. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11754. if (!lua_interface)
  11755. return 0;
  11756. Spawn* spawn = lua_interface->GetSpawn(state);
  11757. lua_interface->ResetFunctionStack(state);
  11758. if (spawn) {
  11759. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11760. return 1;
  11761. }
  11762. return 0;
  11763. }
  11764. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11765. if (!lua_interface)
  11766. return 0;
  11767. Spawn* player = lua_interface->GetSpawn(state);
  11768. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11769. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11770. lua_interface->ResetFunctionStack(state);
  11771. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11772. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11773. }
  11774. else if(!zoneID) {
  11775. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11776. }
  11777. else
  11778. {
  11779. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11780. return 1;
  11781. }
  11782. return 0;
  11783. }
  11784. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11785. if (!lua_interface)
  11786. return 0;
  11787. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11788. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11789. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11790. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11791. lua_interface->ResetFunctionStack(state);
  11792. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11793. world.GetWorldTimeStruct()->year = newYear;
  11794. world.GetWorldTimeStruct()->month = newMonth;
  11795. world.GetWorldTimeStruct()->hour = newHour;
  11796. world.GetWorldTimeStruct()->minute = newMinute;
  11797. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11798. return 0;
  11799. }
  11800. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11801. if (!lua_interface)
  11802. return 0;
  11803. lua_interface->ResetFunctionStack(state);
  11804. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11805. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11806. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11807. return 1;
  11808. }
  11809. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11810. if (!lua_interface)
  11811. return 0;
  11812. lua_interface->ResetFunctionStack(state);
  11813. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11814. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11815. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11816. return 1;
  11817. }
  11818. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11819. if (!lua_interface)
  11820. return 0;
  11821. lua_interface->ResetFunctionStack(state);
  11822. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11823. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11824. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11825. return 1;
  11826. }
  11827. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11828. if (!lua_interface)
  11829. return 0;
  11830. lua_interface->ResetFunctionStack(state);
  11831. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11832. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11833. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11834. return 1;
  11835. }
  11836. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11837. if (!lua_interface)
  11838. return 0;
  11839. lua_interface->ResetFunctionStack(state);
  11840. world.SendTimeUpdate();
  11841. return 0;
  11842. }
  11843. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11844. bool update_result = false;
  11845. Faction* faction = 0;
  11846. Spawn* spawn = lua_interface->GetSpawn(state);
  11847. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11848. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11849. lua_interface->ResetFunctionStack(state);
  11850. if(!spawn || !spawn->IsPlayer()) {
  11851. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11852. return 0;
  11853. }
  11854. Player* player = (Player*)spawn;
  11855. Client* client = player->GetClient();
  11856. if (faction_id > 0) {
  11857. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11858. if(hasfaction == 0) {
  11859. //they do not have the faction. Lets get the default value and feed it in.
  11860. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11861. //add the default faction for the player.
  11862. player->SetFactionValue(faction_id, defaultfaction);
  11863. }
  11864. if(increase >= 0) {
  11865. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11866. faction = master_faction_list.GetFaction(faction_id);
  11867. if(faction && update_result)
  11868. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11869. else if(faction)
  11870. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11871. lua_interface->SetBooleanValue(state, true);
  11872. return 1;
  11873. }
  11874. if(increase < 0){
  11875. //change the negative to a positive, since thats how decreasefaction() likes it.
  11876. increase *= -1;
  11877. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11878. faction = master_faction_list.GetFaction(faction_id);
  11879. if(faction && update_result)
  11880. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11881. else if(faction)
  11882. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11883. lua_interface->SetBooleanValue(state, true);
  11884. return 1;
  11885. }
  11886. }
  11887. lua_interface->SetBooleanValue(state, false);
  11888. return 1;
  11889. }
  11890. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11891. bool hascoin = 0;
  11892. Player* player = (Player*)lua_interface->GetSpawn(state);
  11893. int32 coins = lua_interface->GetInt32Value(state, 2);
  11894. lua_interface->ResetFunctionStack(state);
  11895. if (player && player->IsPlayer()) {
  11896. hascoin = player->HasCoins(coins);
  11897. if(hascoin == 0) {
  11898. lua_interface->SetBooleanValue(state, false);
  11899. return 1;
  11900. }
  11901. if(hascoin == 1) {
  11902. lua_interface->SetBooleanValue(state, true);
  11903. return 1;
  11904. }
  11905. }
  11906. return 0;
  11907. }
  11908. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11909. int32 loot_tier = 0;
  11910. Spawn* spawn = lua_interface->GetSpawn(state);
  11911. lua_interface->ResetFunctionStack(state);
  11912. if (spawn) {
  11913. loot_tier = spawn->GetLootTier();
  11914. lua_interface->SetInt32Value(state, loot_tier);
  11915. return 1;
  11916. }
  11917. return 0;
  11918. }
  11919. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11920. if (!lua_interface)
  11921. return 0;
  11922. Spawn* spawn = lua_interface->GetSpawn(state);
  11923. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11924. lua_interface->ResetFunctionStack(state);
  11925. if (spawn) {
  11926. spawn->SetLootTier(loot_tier);
  11927. lua_interface->SetBooleanValue(state, true);
  11928. return 1;
  11929. }
  11930. lua_interface->SetBooleanValue(state, false);
  11931. return 1;
  11932. }
  11933. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11934. int32 loot_drop_type = 0;
  11935. Spawn* spawn = lua_interface->GetSpawn(state);
  11936. lua_interface->ResetFunctionStack(state);
  11937. if (spawn) {
  11938. loot_drop_type = spawn->GetLootDropType();
  11939. lua_interface->SetInt32Value(state, loot_drop_type);
  11940. return 1;
  11941. }
  11942. return 0;
  11943. }
  11944. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11945. if (!lua_interface)
  11946. return 0;
  11947. Spawn* spawn = lua_interface->GetSpawn(state);
  11948. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11949. lua_interface->ResetFunctionStack(state);
  11950. if (spawn) {
  11951. spawn->SetLootDropType(loot_drop_type);
  11952. lua_interface->SetBooleanValue(state, true);
  11953. return 1;
  11954. }
  11955. lua_interface->SetBooleanValue(state, false);
  11956. return 1;
  11957. }
  11958. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11959. if (!lua_interface)
  11960. return 0;
  11961. Spawn* spawn = lua_interface->GetSpawn(state);
  11962. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11963. if(damage_amount > 100) {
  11964. damage_amount = 100;
  11965. }
  11966. if (!spawn) {
  11967. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11968. lua_interface->ResetFunctionStack(state);
  11969. return 0;
  11970. }
  11971. lua_interface->ResetFunctionStack(state);
  11972. if (spawn->IsPlayer()) {
  11973. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11974. lua_interface->SetBooleanValue(state, true);
  11975. else
  11976. lua_interface->SetBooleanValue(state, false);
  11977. }
  11978. else {
  11979. lua_interface->SetBooleanValue(state, false);
  11980. }
  11981. return 1;
  11982. }
  11983. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11984. ZoneServer* zone = lua_interface->GetZone(state);
  11985. int32 version = lua_interface->GetInt32Value(state, 2);
  11986. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11987. if(region_map == nullptr) {
  11988. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11989. lua_interface->ResetFunctionStack(state);
  11990. return 0;
  11991. }
  11992. string region_name = lua_interface->GetStringValue(state, 3);
  11993. string env_name = lua_interface->GetStringValue(state, 4);
  11994. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11995. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11996. float dist = lua_interface->GetFloatValue(state, 7);
  11997. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11998. lua_interface->ResetFunctionStack(state);
  11999. lua_interface->SetBooleanValue(state, true);
  12000. return 1;
  12001. }
  12002. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  12003. ZoneServer* zone = lua_interface->GetZone(state);
  12004. int32 version = lua_interface->GetInt32Value(state, 2);
  12005. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  12006. if(region_map == nullptr) {
  12007. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  12008. lua_interface->ResetFunctionStack(state);
  12009. return 0;
  12010. }
  12011. string region_name = lua_interface->GetStringValue(state, 3);
  12012. region_map->RemoveRegionNode(region_name);
  12013. lua_interface->ResetFunctionStack(state);
  12014. lua_interface->SetBooleanValue(state, true);
  12015. return 1;
  12016. }
  12017. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  12018. Client* client = nullptr;
  12019. Spawn* player = lua_interface->GetSpawn(state);
  12020. if (!player) {
  12021. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  12022. lua_interface->SetBooleanValue(state, false);
  12023. lua_interface->ResetFunctionStack(state);
  12024. return 1;
  12025. }
  12026. if (!player->IsPlayer()) {
  12027. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  12028. lua_interface->SetBooleanValue(state, false);
  12029. lua_interface->ResetFunctionStack(state);
  12030. return 1;
  12031. }
  12032. client = player->GetClient();
  12033. if (!client) {
  12034. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  12035. lua_interface->SetBooleanValue(state, false);
  12036. lua_interface->ResetFunctionStack(state);
  12037. return 1;
  12038. }
  12039. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  12040. bool success_sight = client->SetPlayerPOVGhost(spawn);
  12041. lua_interface->ResetFunctionStack(state);
  12042. lua_interface->SetBooleanValue(state, success_sight);
  12043. return 1;
  12044. }
  12045. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  12046. if (!lua_interface)
  12047. return 0;
  12048. bool result = false;
  12049. Spawn* spawn = lua_interface->GetSpawn(state);
  12050. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  12051. lua_interface->ResetFunctionStack(state);
  12052. if (!spawn)
  12053. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12054. else if (!spawn->IsNPC())
  12055. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12056. else
  12057. {
  12058. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  12059. result = true;
  12060. }
  12061. lua_interface->SetBooleanValue(state, result);
  12062. return 1;
  12063. }
  12064. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  12065. if (!lua_interface)
  12066. return 0;
  12067. bool result = false;
  12068. Spawn* spawn = lua_interface->GetSpawn(state);
  12069. lua_interface->ResetFunctionStack(state);
  12070. if (!spawn)
  12071. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12072. else if (!spawn->IsNPC())
  12073. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12074. else
  12075. {
  12076. if(((NPC*)spawn)->cast_on_aggro_completed)
  12077. result = true;
  12078. }
  12079. lua_interface->SetBooleanValue(state, result);
  12080. return 1;
  12081. }
  12082. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12083. Client* client = nullptr;
  12084. Spawn* player = lua_interface->GetSpawn(state);
  12085. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12086. lua_interface->ResetFunctionStack(state);
  12087. if (!player) {
  12088. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12089. lua_interface->SetBooleanValue(state, false);
  12090. return 1;
  12091. }
  12092. if (!player->IsPlayer()) {
  12093. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12094. lua_interface->SetBooleanValue(state, false);
  12095. return 1;
  12096. }
  12097. client = player->GetClient();
  12098. if (!client) {
  12099. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12100. lua_interface->SetBooleanValue(state, false);
  12101. return 1;
  12102. }
  12103. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12104. lua_interface->SetBooleanValue(state, result);
  12105. return 1;
  12106. }
  12107. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12108. Client* client = nullptr;
  12109. Spawn* player = lua_interface->GetSpawn(state);
  12110. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12111. lua_interface->ResetFunctionStack(state);
  12112. if (!player) {
  12113. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12114. lua_interface->SetBooleanValue(state, false);
  12115. return 1;
  12116. }
  12117. if (!player->IsPlayer()) {
  12118. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12119. lua_interface->SetBooleanValue(state, false);
  12120. return 1;
  12121. }
  12122. client = player->GetClient();
  12123. if (!client) {
  12124. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12125. lua_interface->SetBooleanValue(state, false);
  12126. return 1;
  12127. }
  12128. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12129. lua_interface->SetBooleanValue(state, result);
  12130. return 1;
  12131. }
  12132. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12133. Client* client = nullptr;
  12134. Spawn* player = lua_interface->GetSpawn(state);
  12135. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12136. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12137. // rest are all optional fields
  12138. float x = lua_interface->GetFloatValue(state, 4);
  12139. float y = lua_interface->GetFloatValue(state, 5);
  12140. float z = lua_interface->GetFloatValue(state, 6);
  12141. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12142. lua_interface->ResetFunctionStack(state);
  12143. if (!player) {
  12144. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12145. lua_interface->SetBooleanValue(state, false);
  12146. return 1;
  12147. }
  12148. if (!player->IsPlayer()) {
  12149. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12150. lua_interface->SetBooleanValue(state, false);
  12151. return 1;
  12152. }
  12153. if(!player->GetZone()) {
  12154. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12155. lua_interface->SetBooleanValue(state, false);
  12156. return 1;
  12157. }
  12158. client = player->GetClient();
  12159. if (!client) {
  12160. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12161. lua_interface->SetBooleanValue(state, false);
  12162. return 1;
  12163. }
  12164. if(!client->IsReadyForUpdates()) {
  12165. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12166. lua_interface->SetBooleanValue(state, false);
  12167. return 1;
  12168. }
  12169. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12170. lua_interface->SetBooleanValue(state, true);
  12171. return 1;
  12172. }
  12173. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12174. Client* client = nullptr;
  12175. Spawn* spawn = lua_interface->GetSpawn(state);
  12176. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12177. lua_interface->ResetFunctionStack(state);
  12178. if (!spawn) {
  12179. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12180. lua_interface->SetBooleanValue(state, false);
  12181. return 1;
  12182. }
  12183. if(!spawn->GetZone()) {
  12184. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12185. lua_interface->SetBooleanValue(state, false);
  12186. return 1;
  12187. }
  12188. spawn->AddIgnoredWidget(widget_id);
  12189. lua_interface->SetBooleanValue(state, true);
  12190. return 1;
  12191. }
  12192. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12193. ZoneServer* zone = lua_interface->GetZone(state);
  12194. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12195. lua_interface->ResetFunctionStack(state);
  12196. if(!zone) {
  12197. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12198. lua_interface->SetBooleanValue(state, false);
  12199. return 1;
  12200. }
  12201. if(!zone->IsLoading()) {
  12202. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12203. lua_interface->SetBooleanValue(state, false);
  12204. return 1;
  12205. }
  12206. zone->AddIgnoredWidget(widget_id);
  12207. lua_interface->SetBooleanValue(state, true);
  12208. return 1;
  12209. }
  12210. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12211. if (!lua_interface)
  12212. return 0;
  12213. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12214. Spawn* spawn = lua_interface->GetSpawn(state);
  12215. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12216. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12217. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12218. Spawn* target = lua_interface->GetSpawn(state, 5);
  12219. lua_interface->ResetFunctionStack(state);
  12220. if(spell && spawn && spawn->IsEntity()) {
  12221. ZoneServer* zone = spawn->GetZone();
  12222. if(zone) {
  12223. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12224. }
  12225. }
  12226. else if (spawn) {
  12227. if (spawn->IsPlayer()) {
  12228. Client* client = ((Player*)spawn)->GetClient();
  12229. if (client) {
  12230. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12231. }
  12232. }
  12233. }
  12234. return 0;
  12235. }
  12236. int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
  12237. if (!lua_interface)
  12238. return 0;
  12239. Spawn* player = lua_interface->GetSpawn(state);
  12240. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12241. lua_interface->ResetFunctionStack(state);
  12242. if (!player) {
  12243. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12244. return 0;
  12245. }
  12246. if (!player->IsPlayer()) {
  12247. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12248. return 0;
  12249. }
  12250. bool ret = ((Player*)player)->get_character_flag(flag_id);
  12251. lua_interface->SetBooleanValue(state, ret);
  12252. return 1;
  12253. }
  12254. int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
  12255. if (!lua_interface)
  12256. return 0;
  12257. Spawn* player = lua_interface->GetSpawn(state);
  12258. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12259. lua_interface->ResetFunctionStack(state);
  12260. if (!player) {
  12261. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12262. return 0;
  12263. }
  12264. if (!player->IsPlayer()) {
  12265. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12266. return 0;
  12267. }
  12268. ((Player*)player)->toggle_character_flag(flag_id);
  12269. return 0;
  12270. }
  12271. int EQ2Emu_lua_GetSpellInitialTarget(lua_State* state) {
  12272. LuaSpell* spell = lua_interface->GetSpell(state);
  12273. if(!spell) {
  12274. spell = lua_interface->GetCurrentSpell(state);
  12275. }
  12276. lua_interface->ResetFunctionStack(state);
  12277. if (spell) {
  12278. if(!spell->caster) {
  12279. lua_interface->LogError("%s: LUA GetSpellTarget command error, caster does not exist.", lua_interface->GetScriptName(state));
  12280. return 0;
  12281. }
  12282. if(!spell->caster->GetZone()) {
  12283. lua_interface->LogError("%s: LUA GetSpellTarget command error, zone does not exist.", lua_interface->GetScriptName(state));
  12284. return 0;
  12285. }
  12286. Spawn* spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  12287. if (spawn) {
  12288. lua_interface->SetSpawnValue(state, spawn);
  12289. return 1;
  12290. }
  12291. else {
  12292. lua_interface->LogError("%s: LUA GetSpellTarget command error, could not find initial target %u to map to spawn.", lua_interface->GetScriptName(state), spell->initial_target);
  12293. }
  12294. }
  12295. return 0;
  12296. }