LuaFunctions.cpp 430 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019
  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() > 546 )
  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. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  685. lua_interface->SetBooleanValue(state, true);
  686. return 1;
  687. }
  688. lua_interface->SetBooleanValue(state, false);
  689. return 1;
  690. }
  691. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  692. Spawn* spawn = lua_interface->GetSpawn(state);
  693. lua_interface->ResetFunctionStack(state);
  694. if (spawn) {
  695. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. lua_interface->ResetFunctionStack(state);
  703. if (spawn) {
  704. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  710. Player* player = (Player*)lua_interface->GetSpawn(state);
  711. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  712. lua_interface->ResetFunctionStack(state);
  713. if (player && player->IsPlayer() && faction_id > 0) {
  714. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  720. if (!lua_interface)
  721. return 0;
  722. Spawn* spawn = lua_interface->GetSpawn(state);
  723. int32 value = lua_interface->GetInt32Value(state, 2);
  724. lua_interface->ResetFunctionStack(state);
  725. if (spawn) {
  726. spawn->SetFactionID(value);
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. lua_interface->ResetFunctionStack(state);
  733. if (spawn) {
  734. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  735. return 1;
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_GetGender(lua_State* state) {
  740. Spawn* spawn = lua_interface->GetSpawn(state);
  741. lua_interface->ResetFunctionStack(state);
  742. if (spawn) {
  743. lua_interface->SetInt32Value(state, spawn->GetGender());
  744. return 1;
  745. }
  746. return 0;
  747. }
  748. int EQ2Emu_lua_GetTarget(lua_State* state) {
  749. Spawn* spawn = lua_interface->GetSpawn(state);
  750. lua_interface->ResetFunctionStack(state);
  751. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  752. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  753. return 1;
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* spawn = lua_interface->GetSpawn(state);
  761. string mp3_string = lua_interface->GetStringValue(state, 2);
  762. int32 key1 = lua_interface->GetInt32Value(state, 3);
  763. int32 key2 = lua_interface->GetInt32Value(state, 4);
  764. Spawn* player = lua_interface->GetSpawn(state, 5);
  765. lua_interface->ResetFunctionStack(state);
  766. if (spawn && mp3_string.length() > 0) {
  767. Client* client = 0;
  768. if (player && player->IsPlayer())
  769. client = ((Player*)player)->GetClient();
  770. if (client) {
  771. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  772. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  773. }
  774. else
  775. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* spawn = lua_interface->GetSpawn(state);
  783. lua_interface->ResetFunctionStack(state);
  784. if (spawn) {
  785. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  786. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  788. return 3;
  789. }
  790. return 0;
  791. }
  792. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  793. if (!lua_interface)
  794. return 0;
  795. Spawn* spawn = lua_interface->GetSpawn(state);
  796. if (spawn) {
  797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  798. lua_interface->ResetFunctionStack(state);
  799. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  800. return 1;
  801. }
  802. lua_interface->ResetFunctionStack(state);
  803. return 0;
  804. }
  805. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  806. if (!lua_interface)
  807. return 0;
  808. Spawn* spawn = lua_interface->GetSpawn(state);
  809. if (spawn && spawn->IsEntity()) {
  810. int32 item_id = lua_interface->GetInt32Value(state, 2);
  811. int16 charges = lua_interface->GetInt16Value(state, 3);
  812. if (charges == 0)
  813. charges = 1;
  814. ((Entity*)spawn)->AddLootItem(item_id, charges);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* spawn = lua_interface->GetSpawn(state);
  823. if (spawn && spawn->IsEntity()) {
  824. int32 item_id = lua_interface->GetInt32Value(state, 2);
  825. Item* item = spawn->LootItem(item_id);
  826. lua_interface->SetLuaUserDataStale(item);
  827. safe_delete(item);
  828. }
  829. lua_interface->ResetFunctionStack(state);
  830. return 0;
  831. }
  832. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  833. if (!lua_interface)
  834. return 0;
  835. Spawn* spawn = lua_interface->GetSpawn(state);
  836. if (spawn) {
  837. int32 val = lua_interface->GetInt32Value(state, 2);
  838. spawn->AddLootCoins(val);
  839. }
  840. lua_interface->ResetFunctionStack(state);
  841. return 0;
  842. }
  843. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Spawn* entity = lua_interface->GetSpawn(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (entity && player && player->IsPlayer()) {
  849. int32 coins = lua_interface->GetInt32Value(state, 3);
  850. vector<Item*>* items = 0;
  851. int i = 0;
  852. int32 item_id = 0;
  853. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  854. if (items == 0)
  855. items = new vector<Item*>;
  856. if (master_item_list.GetItem(item_id))
  857. items->push_back(master_item_list.GetItem(item_id));
  858. i++;
  859. }
  860. Client* client = 0;
  861. client = ((Player*)player)->GetClient();
  862. if (client)
  863. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  864. if(coins > 0)
  865. entity->AddLootCoins(coins);
  866. safe_delete(items);
  867. }
  868. lua_interface->ResetFunctionStack(state);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* entity = lua_interface->GetSpawn(state);
  875. Spawn* player = lua_interface->GetSpawn(state, 2);
  876. int32 item_id = lua_interface->GetInt32Value(state, 3);
  877. lua_interface->ResetFunctionStack(state);
  878. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  879. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  885. if (!lua_interface)
  886. return 0;
  887. Spawn* entity = lua_interface->GetSpawn(state);
  888. Spawn* player = lua_interface->GetSpawn(state, 2);
  889. lua_interface->ResetFunctionStack(state);
  890. if (entity && player && player->IsPlayer()) {
  891. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  892. return 1;
  893. }
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  900. lua_interface->SetLuaUserDataStale(conversation);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. lua_interface->SetLuaUserDataStale(conversation);
  994. safe_delete(conversation);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. lua_interface->SetLuaUserDataStale(conversation);
  1020. safe_delete(conversation);
  1021. }
  1022. else
  1023. 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);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. lua_interface->ResetFunctionStack(state);
  1247. return 0;
  1248. }
  1249. Spawn* caster = luaspell->caster;
  1250. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1251. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1252. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1253. Spawn* target = lua_interface->GetSpawn(state, 4);
  1254. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1255. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1256. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1257. lua_interface->ResetFunctionStack(state);
  1258. boost::to_lower(heal_type);
  1259. if (caster && caster->IsEntity()) {
  1260. bool success = false;
  1261. luaspell->resisted = false;
  1262. if (target) {
  1263. float distance = caster->GetDistance(target, true);
  1264. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1265. success = true;
  1266. }
  1267. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1268. Spawn* target = 0;
  1269. ZoneServer* zone = luaspell->caster->GetZone();
  1270. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1271. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1272. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1273. float distance = caster->GetDistance(target, true);
  1274. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1275. }
  1276. }
  1277. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1278. success = true;
  1279. }
  1280. if (success) {
  1281. if (caster->GetZone())
  1282. caster->GetZone()->TriggerCharSheetTimer();
  1283. }
  1284. }
  1285. return 0;
  1286. }
  1287. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1288. if (!lua_interface)
  1289. return 0;
  1290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1291. if(!luaspell || luaspell->resisted) {
  1292. lua_interface->ResetFunctionStack(state);
  1293. return 0;
  1294. }
  1295. Spawn* caster = luaspell->caster;
  1296. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1297. float percentage = lua_interface->GetFloatValue(state, 2);
  1298. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1299. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1300. Spawn* target = lua_interface->GetSpawn(state, 5);
  1301. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1302. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1303. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1304. lua_interface->ResetFunctionStack(state);
  1305. boost::to_lower(heal_type);
  1306. int32 min_heal = 0, max_heal = 0;
  1307. if (caster && caster->IsEntity() && target) {
  1308. if(percentage <= 0.0f)
  1309. {
  1310. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1311. return 0;
  1312. }
  1313. if(heal_type == "power")
  1314. {
  1315. if(current_value)
  1316. {
  1317. if(caster_value)
  1318. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1319. else
  1320. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1321. }
  1322. else
  1323. {
  1324. if(caster_value)
  1325. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1326. else
  1327. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(current_value)
  1333. {
  1334. if(caster_value)
  1335. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1336. else
  1337. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1338. }
  1339. else
  1340. {
  1341. if(caster_value)
  1342. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1343. else
  1344. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1345. }
  1346. }
  1347. bool success = false;
  1348. luaspell->resisted = false;
  1349. if (target) {
  1350. float distance = caster->GetDistance(target, true);
  1351. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1352. success = true;
  1353. }
  1354. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1355. Spawn* target = 0;
  1356. ZoneServer* zone = luaspell->caster->GetZone();
  1357. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1358. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1359. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1360. float distance = caster->GetDistance(target, true);
  1361. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1362. }
  1363. }
  1364. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1365. success = true;
  1366. }
  1367. if (success) {
  1368. if (caster->GetZone())
  1369. caster->GetZone()->TriggerCharSheetTimer();
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. int EQ2Emu_lua_AddItem(lua_State* state) {
  1375. if (!lua_interface)
  1376. return 0;
  1377. Spawn* spawn = lua_interface->GetSpawn(state);
  1378. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1379. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1380. lua_interface->ResetFunctionStack(state);
  1381. // default of 1 quantity to add
  1382. if (quantity == 0)
  1383. quantity = 1;
  1384. if (spawn && spawn->IsPlayer()) {
  1385. Client* client = ((Player*)spawn)->GetClient();
  1386. if (client && item_id > 0) {
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1388. return 1;
  1389. }
  1390. }
  1391. lua_interface->SetBooleanValue(state, false);
  1392. return 1;
  1393. }
  1394. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. Spawn* spawn = lua_interface->GetSpawn(state);
  1398. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1399. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1400. string location = lua_interface->GetStringValue(state, 4);
  1401. int16 item_count = lua_interface->GetInt16Value(state,5);
  1402. //devn00b: if we dont have a count, assume 1 item.
  1403. if(!item_count) {
  1404. item_count = 1;
  1405. }
  1406. lua_interface->ResetFunctionStack(state);
  1407. if (spawn && spawn->IsPlayer()) {
  1408. Client* client = ((Player*)spawn)->GetClient();
  1409. if (client && item_id > 0) {
  1410. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1411. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1412. else
  1413. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1414. if (send_messages) {
  1415. Item* item = master_item_list.GetItem(item_id);
  1416. if (item) {
  1417. if(item_count > 1) {
  1418. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1419. string popup_text1 = "You receive "+ item_count;
  1420. string popup_text2 = " " + item->name;
  1421. string popup_text = popup_text1 + popup_text2;
  1422. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1423. // return 1;
  1424. } else {
  1425. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1426. string popup_text = "You receive " + item->name;
  1427. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1428. }
  1429. }
  1430. }
  1431. return 1;
  1432. }
  1433. }
  1434. lua_interface->SetBooleanValue(state, false);
  1435. return 1;
  1436. }
  1437. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1440. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1441. lua_interface->ResetFunctionStack(state);
  1442. // default of 1 to remove
  1443. if (quantity == 0)
  1444. quantity = 1;
  1445. Client* client;
  1446. Item* item;
  1447. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1448. if ((client = ((Player*)spawn)->GetClient())) {
  1449. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1450. if (client->RemoveItem(item, quantity)) {
  1451. lua_interface->SetBooleanValue(state, true);
  1452. return 1;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. lua_interface->SetBooleanValue(state, false);
  1458. return 1;
  1459. }
  1460. int EQ2Emu_lua_HasItem(lua_State* state) {
  1461. Spawn* player = lua_interface->GetSpawn(state);
  1462. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1463. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1464. lua_interface->ResetFunctionStack(state);
  1465. if (player && player->IsPlayer()) {
  1466. bool hasItem = false;
  1467. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1468. if (!hasItem)
  1469. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1470. lua_interface->SetBooleanValue(state, hasItem);
  1471. return 1;
  1472. }
  1473. lua_interface->SetBooleanValue(state, false);
  1474. return 1;
  1475. }
  1476. int EQ2Emu_lua_Spawn(lua_State* state) {
  1477. if (!lua_interface)
  1478. return 0;
  1479. ZoneServer* zone = lua_interface->GetZone(state);
  1480. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1481. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1482. float x = lua_interface->GetFloatValue(state, 4);
  1483. float y = lua_interface->GetFloatValue(state, 5);
  1484. float z = lua_interface->GetFloatValue(state, 6);
  1485. float heading = lua_interface->GetFloatValue(state, 7);
  1486. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1487. Spawn* spawn = zone->GetSpawn(spawn_id);
  1488. if (!spawn)
  1489. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1490. else {
  1491. spawn->SetX(x);
  1492. spawn->SetZ(z);
  1493. spawn->SetY(y,true,true);
  1494. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1495. spawn->SetHeading(heading);
  1496. if (restricted_npc)
  1497. spawn->AddAllowAccessSpawn(spawn);
  1498. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1499. bool scriptActive = false;
  1500. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1501. scriptActive = true;
  1502. spawn->SetSpawnScript(string(spawn_script));
  1503. }
  1504. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1505. zone->AddSpawn(spawn);
  1506. if (scriptActive) {
  1507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1508. }
  1509. lua_interface->ResetFunctionStack(state);
  1510. lua_interface->SetSpawnValue(state, spawn);
  1511. return 1;
  1512. }
  1513. }
  1514. else {
  1515. string output = "Invalid paramaters to LUA Spawn command: \n";
  1516. if (!zone)
  1517. output = output.append("\t").append("Missing zone reference. \n");
  1518. if (spawn_id == 0)
  1519. output = output.append("\t").append("Missing spawn_id.");
  1520. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1521. }
  1522. lua_interface->ResetFunctionStack(state);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. ZoneServer* zone = lua_interface->GetZone(state);
  1529. lua_interface->ResetFunctionStack(state);
  1530. if (zone) {
  1531. lua_interface->SetStringValue(state, zone->GetZoneName());
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. ZoneServer* zone = lua_interface->GetZone(state);
  1540. lua_interface->ResetFunctionStack(state);
  1541. if (zone) {
  1542. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1543. return 1;
  1544. }
  1545. return 0;
  1546. }
  1547. int EQ2Emu_lua_GetZone(lua_State* state) {
  1548. if (!lua_interface)
  1549. return 0;
  1550. int32 zone_id = lua_interface->GetInt32Value(state);
  1551. ZoneServer* zone = 0;
  1552. if (zone_id > 0)
  1553. zone = zone_list.Get(zone_id, true, false, false);
  1554. else {
  1555. string zone_name = lua_interface->GetStringValue(state);
  1556. if (zone_name.length() > 0) {
  1557. zone = zone_list.Get(zone_name.c_str(), true, false, false);
  1558. }
  1559. else {
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. if (spawn)
  1562. zone = spawn->GetZone();
  1563. }
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (zone) {
  1567. lua_interface->SetZoneValue(state, zone);
  1568. return 1;
  1569. }
  1570. return 0;
  1571. }
  1572. int EQ2Emu_lua_AddHate(lua_State* state) {
  1573. Spawn* entity = lua_interface->GetSpawn(state);
  1574. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1575. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1576. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if(luaspell && luaspell->resisted) {
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. if (entity && entity->IsEntity() && amount != 0) {
  1583. if (luaspell) {
  1584. ZoneServer* zone = luaspell->caster->GetZone();
  1585. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1586. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1587. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1588. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1589. entity->CheckEncounterState((Entity*)spawn);
  1590. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1591. if (send_packet)
  1592. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1593. }
  1594. }
  1595. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1596. }
  1597. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1598. entity->CheckEncounterState((Entity*)npc);
  1599. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1600. }
  1601. }
  1602. lua_interface->ResetFunctionStack(state);
  1603. return 0;
  1604. }
  1605. int EQ2Emu_lua_Zone(lua_State* state) {
  1606. if (!lua_interface)
  1607. return 0;
  1608. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1609. ZoneServer* zone = lua_interface->GetZone(state);
  1610. Spawn* player = lua_interface->GetSpawn(state, 2);
  1611. Client* client = 0;
  1612. if (player && player->IsPlayer())
  1613. client = ((Player*)player)->GetClient();
  1614. float x = lua_interface->GetFloatValue(state, 3);
  1615. float y = lua_interface->GetFloatValue(state, 4);
  1616. float z = lua_interface->GetFloatValue(state, 5);
  1617. float heading = lua_interface->GetFloatValue(state, 6);
  1618. if (zone && client) {
  1619. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1620. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1621. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1622. {
  1623. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1624. return 0;
  1625. }
  1626. if (x != 0 || y != 0 || z != 0) {
  1627. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1628. player->SetX(x);
  1629. player->SetY(y);
  1630. player->SetZ(z);
  1631. player->SetHeading(heading);
  1632. client->Zone(zone->GetZoneName(), false);
  1633. }
  1634. else
  1635. client->Zone(zone->GetZoneName());
  1636. }
  1637. else
  1638. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1639. lua_interface->ResetFunctionStack(state);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* spawn = lua_interface->GetSpawn(state);
  1646. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1647. if (spawn && spawn2)
  1648. spawn->AddAllowAccessSpawn(spawn2);
  1649. lua_interface->ResetFunctionStack(state);
  1650. return 0;
  1651. }
  1652. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1653. if (!lua_interface)
  1654. return 0;
  1655. Spawn* target = lua_interface->GetSpawn(state);
  1656. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1657. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1658. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1659. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1660. lua_interface->ResetFunctionStack(state);
  1661. if (!target) {
  1662. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1663. return 0;
  1664. }
  1665. if (!target->IsEntity()) {
  1666. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1667. return 0;
  1668. }
  1669. if (spell_id <= 0) {
  1670. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1671. return 0;
  1672. }
  1673. if (caster && !caster->IsEntity()) {
  1674. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1675. return 0;
  1676. }
  1677. if (spell_tier == 0)
  1678. spell_tier = 1;
  1679. if (!caster)
  1680. caster = target;
  1681. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1682. return 0;
  1683. }
  1684. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1685. if (!lua_interface)
  1686. return 0;
  1687. Spawn* target = lua_interface->GetSpawn(state);
  1688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1689. if(!luaspell || luaspell->resisted) {
  1690. lua_interface->ResetFunctionStack(state);
  1691. lua_interface->SetBooleanValue(state, false);
  1692. return 1;
  1693. }
  1694. Spawn* caster = luaspell->caster;
  1695. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1696. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1697. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1698. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1699. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1700. //lua_interface->ResetFunctionStack(state);
  1701. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1702. vector<int16> faction_req;
  1703. vector<int16> race_req;
  1704. int32 class_req = 0;
  1705. int32 i = 0;
  1706. int8 f = 0;
  1707. int8 r = 0;
  1708. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1709. if (class_id < 100) {
  1710. class_req += pow(2.0, double(class_id - 1));
  1711. }
  1712. else if (class_id > 100 && class_id < 1000) {
  1713. race_req.push_back(class_id);
  1714. r++;
  1715. }
  1716. else {
  1717. faction_req.push_back(class_id);
  1718. f++;
  1719. }
  1720. i++;
  1721. }
  1722. lua_interface->ResetFunctionStack(state);
  1723. if (caster && caster->IsEntity()) {
  1724. bool race_match = false;
  1725. bool success = false;
  1726. luaspell->resisted = false;
  1727. if (luaspell->targets.size() > 0) {
  1728. ZoneServer* zone = luaspell->caster->GetZone();
  1729. Spawn* target = 0;
  1730. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1731. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1732. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1733. if (race_req.size() > 0) {
  1734. for (int8 i = 0; i < race_req.size(); i++) {
  1735. if(race_req[i] == target->GetRace() ||
  1736. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1737. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1738. race_match = true;
  1739. }
  1740. }
  1741. }
  1742. else
  1743. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1744. if (race_match == true) {
  1745. float distance = caster->GetDistance(target, true);
  1746. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1747. }
  1748. }
  1749. }
  1750. success = true;
  1751. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1752. }
  1753. else if (target) {
  1754. //check class and race/faction here
  1755. if (race_req.size() > 0) {
  1756. for (int8 i = 0; i < race_req.size(); i++) {
  1757. if(race_req[i] == target->GetRace() ||
  1758. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1759. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1760. race_match = true;
  1761. }
  1762. }
  1763. }
  1764. else
  1765. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1766. if (race_match == true) {
  1767. float distance = caster->GetDistance(target, true);
  1768. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1769. success = true;
  1770. }
  1771. }
  1772. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1773. if (success) {
  1774. Spell* spell = luaspell->spell;
  1775. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1776. ((Player*)caster)->InCombat(true);
  1777. if (caster->GetZone())
  1778. caster->GetZone()->TriggerCharSheetTimer();
  1779. }
  1780. }
  1781. }
  1782. else {
  1783. lua_interface->SetBooleanValue(state, false);
  1784. }
  1785. return 1;
  1786. }
  1787. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1788. if (!lua_interface)
  1789. return 0;
  1790. Spawn* target = lua_interface->GetSpawn(state);
  1791. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1792. if(!luaspell || luaspell->resisted) {
  1793. lua_interface->ResetFunctionStack(state);
  1794. lua_interface->SetBooleanValue(state, false);
  1795. return 1;
  1796. }
  1797. Spawn* caster = luaspell->caster;
  1798. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1799. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1800. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1801. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1802. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1803. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1804. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1805. //lua_interface->ResetFunctionStack(state);
  1806. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1807. vector<int16> faction_req;
  1808. vector<int16> race_req;
  1809. int32 class_req = 0;
  1810. int32 i = 0;
  1811. int8 f = 0;
  1812. int8 r = 0;
  1813. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1814. if (class_id < 100) {
  1815. class_req += pow(2.0, double(class_id - 1));
  1816. }
  1817. else if (class_id > 100 && class_id < 1000) {
  1818. race_req.push_back(class_id);
  1819. r++;
  1820. }
  1821. else {
  1822. faction_req.push_back(class_id);
  1823. f++;
  1824. }
  1825. i++;
  1826. }
  1827. lua_interface->ResetFunctionStack(state);
  1828. if (caster && caster->IsEntity()) {
  1829. bool race_match = false;
  1830. bool success = false;
  1831. luaspell->resisted = false;
  1832. if (luaspell->targets.size() > 0) {
  1833. ZoneServer* zone = luaspell->caster->GetZone();
  1834. Spawn* target = 0;
  1835. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1836. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1837. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1838. if (race_req.size() > 0) {
  1839. for (int8 i = 0; i < race_req.size(); i++) {
  1840. if(race_req[i] == target->GetRace() ||
  1841. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1842. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1843. race_match = true;
  1844. }
  1845. }
  1846. }
  1847. else
  1848. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1849. if (race_match == true) {
  1850. float distance = caster->GetDistance(target, true);
  1851. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1852. }
  1853. }
  1854. }
  1855. success = true;
  1856. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1857. }
  1858. else if (target) {
  1859. //check class and race/faction here
  1860. if (race_req.size() > 0) {
  1861. for (int8 i = 0; i < race_req.size(); i++) {
  1862. if(race_req[i] == target->GetRace() ||
  1863. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1864. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1865. race_match = true;
  1866. }
  1867. }
  1868. }
  1869. else
  1870. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1871. if (race_match == true) {
  1872. float distance = caster->GetDistance(target, true);
  1873. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1874. success = true;
  1875. }
  1876. }
  1877. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1878. if (success) {
  1879. Spell* spell = luaspell->spell;
  1880. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1881. ((Player*)caster)->InCombat(true);
  1882. if (caster->GetZone())
  1883. caster->GetZone()->TriggerCharSheetTimer();
  1884. }
  1885. }
  1886. }
  1887. else {
  1888. lua_interface->SetBooleanValue(state, false);
  1889. }
  1890. return 1;
  1891. }
  1892. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1893. if (!lua_interface)
  1894. return 0;
  1895. Spawn* spawn = lua_interface->GetSpawn(state);
  1896. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1897. lua_interface->ResetFunctionStack(state);
  1898. if (spawn && value != 0) {
  1899. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1900. spawn->SetPower(spawn->GetTotalPower());
  1901. else
  1902. spawn->SetPower(spawn->GetPower() + value);
  1903. }
  1904. return 0;
  1905. }
  1906. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1907. if (!lua_interface)
  1908. return 0;
  1909. Spawn* spawn = lua_interface->GetSpawn(state);
  1910. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1911. lua_interface->ResetFunctionStack(state);
  1912. if (spawn && value != 0) {
  1913. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1914. spawn->SetHP(spawn->GetTotalHP());
  1915. else
  1916. spawn->SetHP(spawn->GetHP() + value);
  1917. }
  1918. return 0;
  1919. }
  1920. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1921. if (!lua_interface)
  1922. return 0;
  1923. Spawn* spawn = lua_interface->GetSpawn(state);
  1924. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1925. lua_interface->ResetFunctionStack(state);
  1926. if (spawn && value != 0) {
  1927. spawn->SetPower(spawn->GetPower() + value);
  1928. if (value > spawn->GetTotalHPBase())
  1929. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1930. }
  1931. return 0;
  1932. }
  1933. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1934. if (!lua_interface)
  1935. return 0;
  1936. Spawn* spawn = lua_interface->GetSpawn(state);
  1937. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1938. lua_interface->ResetFunctionStack(state);
  1939. if (spawn && value != 0) {
  1940. spawn->SetHP(spawn->GetHP() + value);
  1941. if (value > spawn->GetTotalHPBase())
  1942. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1943. }
  1944. return 0;
  1945. }
  1946. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1947. if (!lua_interface)
  1948. return 0;
  1949. Spawn* spawn = lua_interface->GetSpawn(state);
  1950. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1951. lua_interface->ResetFunctionStack(state);
  1952. if (spawn) {
  1953. spawn->SetHP(value);
  1954. if (value > spawn->GetTotalHPBase())
  1955. spawn->SetTotalHP(value);
  1956. }
  1957. return 0;
  1958. }
  1959. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1960. if (!lua_interface)
  1961. return 0;
  1962. Spawn* spawn = lua_interface->GetSpawn(state);
  1963. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1964. float value = lua_interface->GetFloatValue(state, 2);
  1965. lua_interface->ResetFunctionStack(state);
  1966. if (spawn && spawn->IsEntity() && value > 0)
  1967. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1968. if (spawn && spawn->IsPlayer())
  1969. ((Player*)spawn)->SetCharSheetChanged(true);
  1970. return 0;
  1971. }
  1972. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1973. if (!lua_interface)
  1974. return 0;
  1975. Spawn* spawn = lua_interface->GetSpawn(state);
  1976. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1977. lua_interface->ResetFunctionStack(state);
  1978. if (spawn && spawn->IsEntity() && value > 0)
  1979. ((Entity*)spawn)->SetTotalHPBase(value);
  1980. return 0;
  1981. }
  1982. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1983. if (!lua_interface)
  1984. return 0;
  1985. Spawn* spawn = lua_interface->GetSpawn(state);
  1986. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1987. lua_interface->ResetFunctionStack(state);
  1988. if (spawn && value > 0) {
  1989. spawn->SetPower(value);
  1990. if (value > spawn->GetTotalPowerBase())
  1991. spawn->SetTotalPower(value);
  1992. }
  1993. return 0;
  1994. }
  1995. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1996. if (!lua_interface)
  1997. return 0;
  1998. Spawn* spawn = lua_interface->GetSpawn(state);
  1999. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2000. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2001. lua_interface->ResetFunctionStack(state);
  2002. if (spawn && spawn->IsEntity() && value > 0)
  2003. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2004. return 0;
  2005. }
  2006. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2007. if (!lua_interface)
  2008. return 0;
  2009. Spawn* spawn = lua_interface->GetSpawn(state);
  2010. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2011. lua_interface->ResetFunctionStack(state);
  2012. if (spawn && spawn->IsEntity() && value > 0)
  2013. ((Entity*)spawn)->SetTotalPowerBase(value);
  2014. return 0;
  2015. }
  2016. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2017. if (!lua_interface)
  2018. return 0;
  2019. Spawn* spawn = lua_interface->GetSpawn(state);
  2020. float x = lua_interface->GetFloatValue(state, 2);
  2021. float y = lua_interface->GetFloatValue(state, 3);
  2022. float z = lua_interface->GetFloatValue(state, 4);
  2023. float heading = lua_interface->GetFloatValue(state, 5);
  2024. lua_interface->ResetFunctionStack(state);
  2025. if (spawn) {
  2026. spawn->SetX(x);
  2027. spawn->SetY(y);
  2028. spawn->SetZ(z);
  2029. if (heading != 0)
  2030. spawn->SetHeading(heading);
  2031. spawn->SetSpawnOrigX(spawn->GetX());
  2032. spawn->SetSpawnOrigY(spawn->GetY());
  2033. spawn->SetSpawnOrigZ(spawn->GetZ());
  2034. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2035. if (spawn->IsPlayer()) {
  2036. Client* client = ((Player*)spawn)->GetClient();
  2037. if (client) {
  2038. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2039. client->QueuePacket(packet);
  2040. }
  2041. }
  2042. }
  2043. return 0;
  2044. }
  2045. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2046. if (!lua_interface)
  2047. return 0;
  2048. Spawn* spawn = lua_interface->GetSpawn(state);
  2049. float value = lua_interface->GetFloatValue(state, 2);
  2050. lua_interface->ResetFunctionStack(state);
  2051. if (spawn) {
  2052. spawn->SetHeading(value);
  2053. if (spawn->IsPlayer()) {
  2054. Client* client = ((Player*)spawn)->GetClient();
  2055. if (client) {
  2056. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2057. client->QueuePacket(packet);
  2058. }
  2059. }
  2060. }
  2061. return 0;
  2062. }
  2063. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2064. if (!lua_interface)
  2065. return 0;
  2066. Spawn* spawn = lua_interface->GetSpawn(state);
  2067. int16 value = lua_interface->GetInt16Value(state, 2);
  2068. lua_interface->ResetFunctionStack(state);
  2069. if (spawn)
  2070. spawn->SetModelType(value);
  2071. return 0;
  2072. }
  2073. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2074. if (!lua_interface)
  2075. return 0;
  2076. Spawn* spawn = lua_interface->GetSpawn(state);
  2077. int8 value = lua_interface->GetInt8Value(state, 2);
  2078. lua_interface->ResetFunctionStack(state);
  2079. if (spawn) {
  2080. if (spawn->IsPlayer())
  2081. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2082. else
  2083. spawn->SetAdventureClass(value);
  2084. }
  2085. return 0;
  2086. }
  2087. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2088. if (!lua_interface)
  2089. return 0;
  2090. Spawn* spawn = lua_interface->GetSpawn(state);
  2091. int8 value = lua_interface->GetInt8Value(state, 2);
  2092. lua_interface->ResetFunctionStack(state);
  2093. if (spawn) {
  2094. spawn->SetTradeskillClass(value);
  2095. if (spawn->IsEntity()) {
  2096. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2097. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2098. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2099. }
  2100. if (spawn->IsPlayer())
  2101. ((Player*)spawn)->SetCharSheetChanged(true);
  2102. }
  2103. return 0;
  2104. }
  2105. int EQ2Emu_lua_SetMount(lua_State* state) {
  2106. if (!lua_interface)
  2107. return 0;
  2108. Spawn* spawn = lua_interface->GetSpawn(state);
  2109. int16 value = lua_interface->GetInt16Value(state, 2);
  2110. if (spawn && spawn->IsEntity()) {
  2111. ((Entity*)spawn)->SetMount(value);
  2112. EQ2_Color color;
  2113. color.red = 255;
  2114. color.green = 255;
  2115. color.blue = 255;
  2116. ((Entity*)spawn)->SetMountColor(&color);
  2117. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2118. }
  2119. return 0;
  2120. }
  2121. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2122. if (!lua_interface)
  2123. return 0;
  2124. Spawn* spawn = lua_interface->GetSpawn(state);
  2125. EQ2_Color mount_color;
  2126. EQ2_Color saddle_color;
  2127. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2128. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2129. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2130. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2131. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2132. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2133. if (spawn && spawn->IsEntity()) {
  2134. ((Entity*)spawn)->SetMountColor(&mount_color);
  2135. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2136. }
  2137. return 0;
  2138. }
  2139. int EQ2Emu_lua_GetMount(lua_State* state) {
  2140. if (!lua_interface)
  2141. return 0;
  2142. Spawn* spawn = lua_interface->GetSpawn(state);
  2143. if (spawn && spawn->IsEntity()) {
  2144. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2145. return 1;
  2146. }
  2147. return 0;
  2148. }
  2149. int EQ2Emu_lua_GetRace(lua_State* state) {
  2150. if (!lua_interface)
  2151. return 0;
  2152. Spawn* spawn = lua_interface->GetSpawn(state);
  2153. if (spawn)
  2154. {
  2155. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2156. lua_interface->SetInt32Value(state, spawn->GetRace());
  2157. return 1;
  2158. }
  2159. return 0;
  2160. }
  2161. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2162. if (!lua_interface)
  2163. return 0;
  2164. Spawn* spawn = lua_interface->GetSpawn(state);
  2165. if (spawn) {
  2166. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2167. return 1;
  2168. }
  2169. return 0;
  2170. }
  2171. int EQ2Emu_lua_GetClass(lua_State* state) {
  2172. Spawn* spawn = lua_interface->GetSpawn(state);
  2173. if (spawn) {
  2174. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2175. return 1;
  2176. }
  2177. return 0;
  2178. }
  2179. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2180. Spawn* spawn = lua_interface->GetSpawn(state);
  2181. if (spawn) {
  2182. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2183. return 1;
  2184. }
  2185. return 0;
  2186. }
  2187. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2188. if (!lua_interface)
  2189. return 0;
  2190. Spawn* spawn = lua_interface->GetSpawn(state);
  2191. float value = lua_interface->GetFloatValue(state, 2);
  2192. lua_interface->ResetFunctionStack(state);
  2193. if (spawn) {
  2194. spawn->SetSpeed(value);
  2195. if(spawn->IsEntity())
  2196. ((Entity*)spawn)->SetSpeed(value);
  2197. if (spawn->IsPlayer()) {
  2198. Client* client = ((Player*)spawn)->GetClient();
  2199. if (client) {
  2200. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2201. if (packet) {
  2202. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2203. packet->setDataByName("speed", value);
  2204. packet->setDataByName("size", 0.51);
  2205. EQ2Packet* app = packet->serialize();
  2206. client->QueuePacket(app);
  2207. safe_delete(packet);
  2208. }
  2209. }
  2210. }
  2211. }
  2212. return 0;
  2213. }
  2214. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2215. if (!lua_interface)
  2216. return 0;
  2217. Spawn* spawn = lua_interface->GetSpawn(state);
  2218. const int16 type = lua_interface->GetInt16Value(state, 2);
  2219. const float value = lua_interface->GetFloatValue(state, 3);
  2220. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2221. if(!luaspell || luaspell->resisted) {
  2222. lua_interface->ResetFunctionStack(state);
  2223. return 0;
  2224. }
  2225. int64 class_req = 0;
  2226. int32 class_id = 0;
  2227. vector<int16> faction_req;
  2228. vector<int16> race_req;
  2229. int32 i = 0;
  2230. int8 f = 0;
  2231. int8 r = 0;
  2232. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2233. if (class_id < 100) {
  2234. class_req += pow(2.0, double(class_id - 1));
  2235. }
  2236. else if (class_id > 100 && class_id < 1000) {
  2237. race_req.push_back(class_id);
  2238. r++;
  2239. }
  2240. else {
  2241. faction_req.push_back(class_id);
  2242. f++;
  2243. }
  2244. i++;
  2245. }
  2246. if (value != 0 && type >= 0) {
  2247. if (luaspell && luaspell->spell && luaspell->caster) {
  2248. ZoneServer* zone = luaspell->caster->GetZone();
  2249. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2250. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2251. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2252. if (target) {
  2253. if (target->IsPlayer()) {
  2254. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2255. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2256. if (((Player*)target)->GetGroupMemberInfo())
  2257. ((Player*)target)->UpdateGroupMemberInfo();
  2258. ((Player*)target)->SetCharSheetChanged(true);
  2259. }
  2260. else if (target->IsNPC())
  2261. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2262. else
  2263. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2264. }
  2265. }
  2266. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2267. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2268. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2269. }
  2270. else if (spawn && spawn->IsEntity()) {
  2271. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2272. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2273. if (spawn->IsPlayer())
  2274. ((Player*)spawn)->SetCharSheetChanged(true);
  2275. }
  2276. else
  2277. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2278. }
  2279. else
  2280. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2281. return 0;
  2282. }
  2283. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2284. if (!lua_interface)
  2285. return 0;
  2286. Spawn* spawn = lua_interface->GetSpawn(state);
  2287. int16 type = lua_interface->GetInt16Value(state, 2);
  2288. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2289. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2290. if (!spawn) {
  2291. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2292. return 0;
  2293. }
  2294. if (!spawn->IsEntity()) {
  2295. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2296. return 0;
  2297. }
  2298. if (value == 0) {
  2299. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2300. return 0;
  2301. }
  2302. if (!luaspell || !luaspell->spell) {
  2303. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2304. return 0;
  2305. }
  2306. if(luaspell->resisted) {
  2307. lua_interface->ResetFunctionStack(state);
  2308. return 0;
  2309. }
  2310. int32 class_req = 0;
  2311. vector<int16> faction_req;
  2312. vector<int16> race_req;
  2313. int32 class_id = 0;
  2314. int32 i = 0;
  2315. int8 f = 0;
  2316. int8 r = 0;
  2317. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2318. if (class_id < 100) {
  2319. class_req += pow(2.0, double(class_id - 1));
  2320. }
  2321. else if (class_id > 100 && class_id < 1000) {
  2322. race_req.push_back(class_id);
  2323. r++;
  2324. }
  2325. else {
  2326. faction_req.push_back(class_id);
  2327. f++;
  2328. }
  2329. i++;
  2330. }
  2331. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2332. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2333. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2334. if (spawn->IsPlayer())
  2335. ((Player*)spawn)->SetCharSheetChanged(true);
  2336. return 0;
  2337. }
  2338. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2339. if (!lua_interface)
  2340. return 0;
  2341. Spawn* spawn = lua_interface->GetSpawn(state);
  2342. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2343. if (!spawn) {
  2344. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2345. return 0;
  2346. }
  2347. if (!spawn->IsEntity()) {
  2348. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2349. return 0;
  2350. }
  2351. if (!luaspell || !luaspell->spell) {
  2352. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2353. return 0;
  2354. }
  2355. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2356. if (spawn->IsPlayer())
  2357. ((Player*)spawn)->SetCharSheetChanged(true);
  2358. return 0;
  2359. }
  2360. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2361. if (!lua_interface)
  2362. return 0;
  2363. Spawn* spawn = lua_interface->GetSpawn(state);
  2364. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2365. if (luaspell && luaspell->spell) {
  2366. ZoneServer* zone = luaspell->caster->GetZone();
  2367. if(!zone) {
  2368. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2369. }
  2370. Spawn* target = 0;
  2371. if(zone) {
  2372. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2373. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2374. target = zone->GetSpawnByID(luaspell->targets[i]);
  2375. if (target && target->IsEntity()) {
  2376. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2377. if (target->IsPlayer())
  2378. ((Player*)target)->SetCharSheetChanged(true);
  2379. }
  2380. }
  2381. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2382. }
  2383. else {
  2384. 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());
  2385. }
  2386. }
  2387. else if (spawn && spawn->IsEntity()) {
  2388. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2389. if (spawn->IsPlayer())
  2390. ((Player*)spawn)->SetCharSheetChanged(true);
  2391. }
  2392. return 0;
  2393. }
  2394. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2395. if (!lua_interface)
  2396. return 0;
  2397. Spawn* spawn = lua_interface->GetSpawn(state);
  2398. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2399. float value = lua_interface->GetFloatValue(state, 3);
  2400. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2401. if (value != 0) {
  2402. int32 spell_id = 0;
  2403. if (luaspell && luaspell->spell && luaspell->caster) {
  2404. if(luaspell->resisted) {
  2405. lua_interface->ResetFunctionStack(state);
  2406. return 0;
  2407. }
  2408. spell_id = luaspell->spell->GetSpellID();
  2409. ZoneServer* zone = luaspell->caster->GetZone();
  2410. Spawn* target = 0;
  2411. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2412. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2413. target = zone->GetSpawnByID(luaspell->targets[i]);
  2414. if (target && target->Alive()) {
  2415. if (target->IsPlayer()) {
  2416. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2417. Client* client = ((Player*)target)->GetClient();
  2418. if (client) {
  2419. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2420. if (packet)
  2421. client->QueuePacket(packet);
  2422. }
  2423. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2424. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2425. }
  2426. else if (target->IsNPC()) {
  2427. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2428. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2429. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2430. }
  2431. else
  2432. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2433. }
  2434. }
  2435. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2436. }
  2437. else if (spawn) {
  2438. if (spawn->IsPlayer()) {
  2439. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2440. Client* client = ((Player*)spawn)->GetClient();
  2441. if (client) {
  2442. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2443. if (packet)
  2444. client->QueuePacket(packet);
  2445. }
  2446. }
  2447. else if (spawn->IsNPC())
  2448. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2449. else
  2450. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2451. }
  2452. }
  2453. else
  2454. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2455. return 0;
  2456. }
  2457. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2458. if (!lua_interface)
  2459. return 0;
  2460. Spawn* spawn = lua_interface->GetSpawn(state);
  2461. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2462. if (spawn && spawn->IsPlayer()) {
  2463. int32 spell_id = 0;
  2464. if (luaspell && luaspell->spell) {
  2465. if(luaspell->resisted) {
  2466. lua_interface->ResetFunctionStack(state);
  2467. return 0;
  2468. }
  2469. spell_id = luaspell->spell->GetSpellID();
  2470. ZoneServer* zone = luaspell->caster->GetZone();
  2471. Spawn* target = 0;
  2472. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2473. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2474. target = zone->GetSpawnByID(luaspell->targets[i]);
  2475. if (target) {
  2476. if (target->IsPlayer()) {
  2477. ((Player*)target)->RemoveSkillBonus(spell_id);
  2478. Client* client = ((Player*)target)->GetClient();
  2479. if (client) {
  2480. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2481. if (packet)
  2482. client->QueuePacket(packet);
  2483. }
  2484. }
  2485. else if (target->IsNPC())
  2486. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2487. else
  2488. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2489. }
  2490. }
  2491. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2492. }
  2493. else if (spawn) {
  2494. if (spawn->IsPlayer()) {
  2495. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2496. Client* client = ((Player*)spawn)->GetClient();
  2497. if (client) {
  2498. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2499. if (packet)
  2500. client->QueuePacket(packet);
  2501. }
  2502. }
  2503. else if (spawn->IsNPC())
  2504. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2505. else
  2506. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2507. }
  2508. }
  2509. return 0;
  2510. }
  2511. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2512. if (!lua_interface)
  2513. return 0;
  2514. Spawn* spawn = lua_interface->GetSpawn(state);
  2515. int8 type = lua_interface->GetInt32Value(state, 2);
  2516. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2517. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2518. if(luaspell && luaspell->resisted) {
  2519. lua_interface->ResetFunctionStack(state);
  2520. return 0;
  2521. }
  2522. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2523. ZoneServer* zone = luaspell->caster->GetZone();
  2524. Spawn* target = 0;
  2525. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2526. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2527. target = zone->GetSpawnByID(luaspell->targets[i]);
  2528. if (target && target->IsEntity()) {
  2529. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2530. ((Entity*)target)->AddMezSpell(luaspell);
  2531. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2532. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2533. if (target->IsNPC())
  2534. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2535. }
  2536. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2537. ((Entity*)target)->AddStifleSpell(luaspell);
  2538. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2539. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2540. if (target->IsNPC())
  2541. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2542. }
  2543. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2544. ((Entity*)target)->AddDazeSpell(luaspell);
  2545. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2546. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2547. if (target->IsNPC())
  2548. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2549. }
  2550. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2551. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2552. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2553. ((Entity*)target)->AddStunSpell(luaspell);
  2554. if (target->IsNPC())
  2555. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2556. }
  2557. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2558. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2559. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2560. ((Entity*)target)->AddRootSpell(luaspell);
  2561. if (target->IsNPC())
  2562. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2563. }
  2564. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2565. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2566. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2567. ((Entity*)target)->AddFearSpell(luaspell);
  2568. if (target->IsNPC())
  2569. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2570. }
  2571. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2572. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2573. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2574. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2575. }
  2576. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2577. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2578. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2579. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2580. }
  2581. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2582. ((Entity*)target)->AddSnareSpell(luaspell);
  2583. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2584. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2585. if (target->IsNPC())
  2586. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2587. }
  2588. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2589. ((Entity*)target)->AddFlightSpell(luaspell);
  2590. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2591. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2592. }
  2593. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2594. ((Entity*)target)->AddGlideSpell(luaspell);
  2595. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2596. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2597. }
  2598. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2599. ((Entity*)target)->AddSafefallSpell(luaspell);
  2600. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2601. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2602. }
  2603. else
  2604. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2605. }
  2606. else
  2607. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2608. }
  2609. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2610. }
  2611. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2612. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2613. ((Entity*)spawn)->AddMezSpell(luaspell);
  2614. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2615. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2616. }
  2617. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2618. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2619. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2620. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2621. }
  2622. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2623. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2624. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2625. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2626. }
  2627. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2628. ((Entity*)spawn)->AddStunSpell(luaspell);
  2629. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2630. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2631. }
  2632. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2633. ((Entity*)spawn)->AddRootSpell(luaspell);
  2634. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2635. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2636. }
  2637. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2638. ((Entity*)spawn)->AddFearSpell(luaspell);
  2639. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2640. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2641. }
  2642. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2643. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2644. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2645. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2646. }
  2647. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2648. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2649. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2650. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2651. }
  2652. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2653. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2654. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2655. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2656. }
  2657. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2658. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2659. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2660. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2661. }
  2662. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2663. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2664. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2665. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2666. }
  2667. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2668. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2669. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2670. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2671. }
  2672. else
  2673. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2674. }
  2675. else
  2676. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2677. return 0;
  2678. }
  2679. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2680. if (!lua_interface)
  2681. return 0;
  2682. Spawn* spawn = lua_interface->GetSpawn(state);
  2683. int8 type = lua_interface->GetInt8Value(state, 2);
  2684. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2685. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2686. if (spawn && spawn->IsEntity()) {
  2687. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2688. ZoneServer* zone = luaspell->caster->GetZone();
  2689. Spawn* target = 0;
  2690. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2691. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2692. target = zone->GetSpawnByID(luaspell->targets[i]);
  2693. if (target) {
  2694. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2695. ((Entity*)target)->RemoveMezSpell(luaspell);
  2696. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2697. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2698. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2699. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2700. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2701. ((Entity*)target)->RemoveStunSpell(luaspell);
  2702. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2703. ((Entity*)target)->RemoveRootSpell(luaspell);
  2704. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2705. ((Entity*)target)->RemoveFearSpell(luaspell);
  2706. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2707. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2708. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2709. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2710. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2711. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2712. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2713. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2714. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2715. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2716. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2717. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2718. else
  2719. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2720. }
  2721. }
  2722. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2723. }
  2724. else if (only_remove_spawn) {
  2725. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2726. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2727. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2728. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2729. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2730. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2731. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2732. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2733. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2734. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2735. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2736. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2737. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2738. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2739. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2740. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2741. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2742. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2743. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2744. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2745. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2746. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2747. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2748. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2749. else
  2750. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2751. }
  2752. }
  2753. return 0;
  2754. }
  2755. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2756. if (!lua_interface)
  2757. return 0;
  2758. Spawn* spawn = lua_interface->GetSpawn(state);
  2759. int8 type = lua_interface->GetInt8Value(state, 2);
  2760. bool hasEffect = false;
  2761. if (!spawn)
  2762. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2763. else if (!spawn->IsEntity())
  2764. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2765. else if (type < CONTROL_MAX_EFFECTS)
  2766. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2767. else
  2768. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2769. lua_interface->SetBooleanValue(state, hasEffect);
  2770. return 1;
  2771. }
  2772. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2773. if (!lua_interface)
  2774. return 0;
  2775. Spawn* spawn = lua_interface->GetSpawn(state);
  2776. float distance = 0.0f;
  2777. if (!spawn)
  2778. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2779. else if (!spawn->IsNPC())
  2780. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2781. else
  2782. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2783. lua_interface->SetFloatValue(state, distance);
  2784. return 1;
  2785. }
  2786. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2787. if (!lua_interface)
  2788. return 0;
  2789. Spawn* spawn = lua_interface->GetSpawn(state);
  2790. float distance = 0.0f;
  2791. if (!spawn)
  2792. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2793. else if (!spawn->IsNPC())
  2794. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2795. else
  2796. distance = ((NPC*)spawn)->GetAggroRadius();
  2797. lua_interface->SetFloatValue(state, distance);
  2798. return 1;
  2799. }
  2800. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2801. if (!lua_interface)
  2802. return 0;
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. float distance = lua_interface->GetFloatValue(state, 2);
  2805. bool override = lua_interface->GetBooleanValue(state, 3);
  2806. bool result = false;
  2807. lua_interface->ResetFunctionStack(state);
  2808. if (!spawn)
  2809. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2810. else if (!spawn->IsNPC())
  2811. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2812. else
  2813. {
  2814. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2815. result = true;
  2816. }
  2817. lua_interface->SetBooleanValue(state, result);
  2818. return 1;
  2819. }
  2820. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. int16 value = lua_interface->GetInt16Value(state, 2);
  2825. if (spawn && spawn->IsEntity()) {
  2826. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2827. if (spawn->IsPlayer())
  2828. ((Player*)spawn)->SetCharSheetChanged(true);
  2829. }
  2830. return 0;
  2831. }
  2832. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2833. if (!lua_interface)
  2834. return 0;
  2835. Spawn* spawn = lua_interface->GetSpawn(state);
  2836. int16 value = lua_interface->GetInt16Value(state, 2);
  2837. if (spawn && spawn->IsEntity()) {
  2838. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2839. if (spawn->IsPlayer())
  2840. ((Player*)spawn)->SetCharSheetChanged(true);
  2841. }
  2842. return 0;
  2843. }
  2844. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2845. if (!lua_interface)
  2846. return 0;
  2847. Spawn* spawn = lua_interface->GetSpawn(state);
  2848. int16 value = lua_interface->GetInt16Value(state, 2);
  2849. if (spawn && spawn->IsEntity()) {
  2850. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2851. if (spawn->IsPlayer())
  2852. ((Player*)spawn)->SetCharSheetChanged(true);
  2853. }
  2854. return 0;
  2855. }
  2856. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2857. if (!lua_interface)
  2858. return 0;
  2859. Spawn* spawn = lua_interface->GetSpawn(state);
  2860. int16 value = lua_interface->GetInt16Value(state, 2);
  2861. if (spawn && spawn->IsEntity()) {
  2862. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2863. if (spawn->IsPlayer())
  2864. ((Player*)spawn)->SetCharSheetChanged(true);
  2865. }
  2866. return 0;
  2867. }
  2868. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2869. if (!lua_interface)
  2870. return 0;
  2871. Spawn* spawn = lua_interface->GetSpawn(state);
  2872. int16 value = lua_interface->GetInt16Value(state, 2);
  2873. if (spawn && spawn->IsEntity()) {
  2874. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2875. if (spawn->IsPlayer())
  2876. ((Player*)spawn)->SetCharSheetChanged(true);
  2877. }
  2878. return 0;
  2879. }
  2880. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2881. if (!lua_interface)
  2882. return 0;
  2883. Spawn* spawn = lua_interface->GetSpawn(state);
  2884. int8 value = lua_interface->GetInt8Value(state, 2);
  2885. if (spawn && spawn->IsEntity()) {
  2886. ((Entity*)spawn)->SetDeity(value);
  2887. if (spawn->IsPlayer())
  2888. ((Player*)spawn)->SetCharSheetChanged(true);
  2889. }
  2890. lua_interface->ResetFunctionStack(state);
  2891. return 0;
  2892. }
  2893. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2894. if (!lua_interface)
  2895. return 0;
  2896. Spawn* spawn = lua_interface->GetSpawn(state);
  2897. if (spawn && spawn->IsEntity()) {
  2898. int8 deity = ((Entity*)spawn)->GetDeity();
  2899. lua_interface->SetInt32Value(state, deity);
  2900. return 1;
  2901. }
  2902. return 0;
  2903. }
  2904. int EQ2Emu_lua_SetInt(lua_State* state) {
  2905. if (!lua_interface)
  2906. return 0;
  2907. Spawn* spawn = lua_interface->GetSpawn(state);
  2908. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2909. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2910. if (spawn && spawn->IsEntity()) {
  2911. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2912. if (spawn->IsPlayer())
  2913. ((Player*)spawn)->SetCharSheetChanged(true);
  2914. }
  2915. return 0;
  2916. }
  2917. int EQ2Emu_lua_SetWis(lua_State* state) {
  2918. if (!lua_interface)
  2919. return 0;
  2920. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2921. Spawn* spawn = lua_interface->GetSpawn(state);
  2922. float value = lua_interface->GetFloatValue(state, 2);
  2923. if (spawn && spawn->IsEntity()) {
  2924. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2925. if (spawn->IsPlayer())
  2926. ((Player*)spawn)->SetCharSheetChanged(true);
  2927. }
  2928. return 0;
  2929. }
  2930. int EQ2Emu_lua_SetSta(lua_State* state) {
  2931. if (!lua_interface)
  2932. return 0;
  2933. Spawn* spawn = lua_interface->GetSpawn(state);
  2934. float value = lua_interface->GetFloatValue(state, 2);
  2935. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2936. if (spawn && spawn->IsEntity()) {
  2937. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2938. if (spawn->IsPlayer())
  2939. ((Player*)spawn)->SetCharSheetChanged(true);
  2940. }
  2941. return 0;
  2942. }
  2943. int EQ2Emu_lua_SetStr(lua_State* state) {
  2944. if (!lua_interface)
  2945. return 0;
  2946. Spawn* spawn = lua_interface->GetSpawn(state);
  2947. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2948. float value = lua_interface->GetFloatValue(state, 2);
  2949. if (spawn && spawn->IsEntity()) {
  2950. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2951. if (spawn->IsPlayer())
  2952. ((Player*)spawn)->SetCharSheetChanged(true);
  2953. }
  2954. return 0;
  2955. }
  2956. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2957. if (!lua_interface)
  2958. return 0;
  2959. Spawn* spawn = lua_interface->GetSpawn(state);
  2960. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2961. float value = lua_interface->GetFloatValue(state, 2);
  2962. if (spawn && spawn->IsEntity()) {
  2963. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2964. if (spawn->IsPlayer())
  2965. ((Player*)spawn)->SetCharSheetChanged(true);
  2966. }
  2967. return 0;
  2968. }
  2969. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2970. if (!lua_interface)
  2971. return 0;
  2972. Spawn* spawn = lua_interface->GetSpawn(state);
  2973. if (spawn) {
  2974. lua_interface->SetInt32Value(state, spawn->GetHP());
  2975. return 1;
  2976. }
  2977. return 0;
  2978. }
  2979. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2980. if (!lua_interface)
  2981. return 0;
  2982. Spawn* spawn = lua_interface->GetSpawn(state);
  2983. if (spawn) {
  2984. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2985. return 1;
  2986. }
  2987. return 0;
  2988. }
  2989. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2990. if (!lua_interface)
  2991. return 0;
  2992. Spawn* spawn = lua_interface->GetSpawn(state);
  2993. if (spawn) {
  2994. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2995. return 1;
  2996. }
  2997. return 0;
  2998. }
  2999. int EQ2Emu_lua_GetName(lua_State* state) {
  3000. if (!lua_interface)
  3001. return 0;
  3002. Spawn* spawn = lua_interface->GetSpawn(state);
  3003. if (spawn) {
  3004. lua_interface->SetStringValue(state, spawn->GetName());
  3005. return 1;
  3006. }
  3007. return 0;
  3008. }
  3009. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3010. Spawn* spawn = lua_interface->GetSpawn(state);
  3011. if (spawn) {
  3012. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3013. return 1;
  3014. }
  3015. return 0;
  3016. }
  3017. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3018. Spawn* spawn = lua_interface->GetSpawn(state);
  3019. if (spawn) {
  3020. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3021. return 1;
  3022. }
  3023. return 0;
  3024. }
  3025. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3026. if (!lua_interface)
  3027. return 0;
  3028. Spawn* spawn = lua_interface->GetSpawn(state);
  3029. if (spawn) {
  3030. lua_interface->SetInt32Value(state, spawn->GetPower());
  3031. return 1;
  3032. }
  3033. return 0;
  3034. }
  3035. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3036. if (!lua_interface)
  3037. return 0;
  3038. Spawn* spawn = lua_interface->GetSpawn(state);
  3039. if (spawn) {
  3040. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3041. return 1;
  3042. }
  3043. return 0;
  3044. }
  3045. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3046. if (!lua_interface)
  3047. return 0;
  3048. Spawn* spawn = lua_interface->GetSpawn(state);
  3049. if (spawn) {
  3050. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3051. return 1;
  3052. }
  3053. return 0;
  3054. }
  3055. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3056. if (!lua_interface)
  3057. return 0;
  3058. Spawn* spawn = lua_interface->GetSpawn(state);
  3059. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3060. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3061. if (spawn && spawn2) {
  3062. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3063. lua_interface->SetFloatValue(state, distance);
  3064. return 1;
  3065. }
  3066. return 0;
  3067. }
  3068. int EQ2Emu_lua_GetX(lua_State* state) {
  3069. if (!lua_interface)
  3070. return 0;
  3071. Spawn* spawn = lua_interface->GetSpawn(state);
  3072. if (spawn) {
  3073. lua_interface->SetFloatValue(state, spawn->GetX());
  3074. return 1;
  3075. }
  3076. return 0;
  3077. }
  3078. int EQ2Emu_lua_GetY(lua_State* state) {
  3079. if (!lua_interface)
  3080. return 0;
  3081. Spawn* spawn = lua_interface->GetSpawn(state);
  3082. if (spawn) {
  3083. lua_interface->SetFloatValue(state, spawn->GetY());
  3084. return 1;
  3085. }
  3086. return 0;
  3087. }
  3088. int EQ2Emu_lua_GetZ(lua_State* state) {
  3089. if (!lua_interface)
  3090. return 0;
  3091. Spawn* spawn = lua_interface->GetSpawn(state);
  3092. if (spawn) {
  3093. lua_interface->SetFloatValue(state, spawn->GetZ());
  3094. return 1;
  3095. }
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3099. if (!lua_interface)
  3100. return 0;
  3101. Spawn* spawn = lua_interface->GetSpawn(state);
  3102. if (spawn) {
  3103. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3104. return 1;
  3105. }
  3106. return 0;
  3107. }
  3108. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3109. if (!lua_interface)
  3110. return 0;
  3111. Spawn* spawn = lua_interface->GetSpawn(state);
  3112. if (spawn) {
  3113. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3114. return 1;
  3115. }
  3116. return 0;
  3117. }
  3118. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3119. if (!lua_interface)
  3120. return 0;
  3121. Spawn* spawn = lua_interface->GetSpawn(state);
  3122. if (spawn) {
  3123. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3124. return 1;
  3125. }
  3126. return 0;
  3127. }
  3128. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3129. if (!lua_interface)
  3130. return 0;
  3131. Spawn* spawn = lua_interface->GetSpawn(state);
  3132. if (spawn && spawn->IsEntity()) {
  3133. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3134. return 1;
  3135. }
  3136. return 0;
  3137. }
  3138. int EQ2Emu_lua_GetInt(lua_State* state) {
  3139. if (!lua_interface)
  3140. return 0;
  3141. Spawn* spawn = lua_interface->GetSpawn(state);
  3142. if (spawn && spawn->IsEntity()) {
  3143. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3144. return 1;
  3145. }
  3146. return 0;
  3147. }
  3148. int EQ2Emu_lua_GetWis(lua_State* state) {
  3149. if (!lua_interface)
  3150. return 0;
  3151. Spawn* spawn = lua_interface->GetSpawn(state);
  3152. if (spawn && spawn->IsEntity()) {
  3153. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3154. return 1;
  3155. }
  3156. return 0;
  3157. }
  3158. int EQ2Emu_lua_GetSta(lua_State* state) {
  3159. if (!lua_interface)
  3160. return 0;
  3161. Spawn* spawn = lua_interface->GetSpawn(state);
  3162. if (spawn && spawn->IsEntity()) {
  3163. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3164. return 1;
  3165. }
  3166. return 0;
  3167. }
  3168. int EQ2Emu_lua_GetStr(lua_State* state) {
  3169. if (!lua_interface)
  3170. return 0;
  3171. Spawn* spawn = lua_interface->GetSpawn(state);
  3172. if (spawn && spawn->IsEntity()) {
  3173. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3174. return 1;
  3175. }
  3176. return 0;
  3177. }
  3178. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3179. if (!lua_interface)
  3180. return 0;
  3181. Spawn* spawn = lua_interface->GetSpawn(state);
  3182. if (spawn && spawn->IsEntity()) {
  3183. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3184. return 1;
  3185. }
  3186. return 0;
  3187. }
  3188. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3189. if (!lua_interface)
  3190. return 0;
  3191. Spawn* spawn = lua_interface->GetSpawn(state);
  3192. if (spawn && spawn->IsEntity()) {
  3193. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3194. return 1;
  3195. }
  3196. return 0;
  3197. }
  3198. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3199. if (!lua_interface)
  3200. return 0;
  3201. Spawn* spawn = lua_interface->GetSpawn(state);
  3202. if (spawn && spawn->IsEntity()) {
  3203. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3204. return 1;
  3205. }
  3206. return 0;
  3207. }
  3208. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3209. if (!lua_interface)
  3210. return 0;
  3211. Spawn* spawn = lua_interface->GetSpawn(state);
  3212. if (spawn && spawn->IsEntity()) {
  3213. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3214. return 1;
  3215. }
  3216. return 0;
  3217. }
  3218. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3219. if (!lua_interface)
  3220. return 0;
  3221. Spawn* spawn = lua_interface->GetSpawn(state);
  3222. if (spawn && spawn->IsEntity()) {
  3223. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3224. return 1;
  3225. }
  3226. return 0;
  3227. }
  3228. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3229. if (!lua_interface)
  3230. return 0;
  3231. Spawn* spawn = lua_interface->GetSpawn(state);
  3232. if (spawn && spawn->IsEntity()) {
  3233. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3234. return 1;
  3235. }
  3236. return 0;
  3237. }
  3238. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3239. if (!lua_interface)
  3240. return 0;
  3241. Spawn* player = lua_interface->GetSpawn(state);
  3242. if (!player || !player->IsPlayer()) {
  3243. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3244. return 0;
  3245. }
  3246. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3247. if (quest_id <= 0) {
  3248. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3249. return 0;
  3250. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3251. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3252. return 0;
  3253. }
  3254. int32 step = lua_interface->GetInt32Value(state, 3);
  3255. if (step > 0) {
  3256. Client* client = ((Player*)player)->GetClient();
  3257. if (client)
  3258. client->AddPendingQuestUpdate(quest_id, step);
  3259. } else {
  3260. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3261. }
  3262. return 0;
  3263. }
  3264. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3265. Spawn* player = lua_interface->GetSpawn(state);
  3266. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3267. int32 step = lua_interface->GetInt32Value(state, 3);
  3268. int32 progress = lua_interface->GetInt32Value(state, 4);
  3269. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3270. Client* client = ((Player*)player)->GetClient();
  3271. if (client)
  3272. client->AddPendingQuestUpdate(quest_id, step, progress);
  3273. }
  3274. return 0;
  3275. }
  3276. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3277. if (!lua_interface)
  3278. return 0;
  3279. Spawn* player = lua_interface->GetSpawn(state);
  3280. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3281. if (player && player->IsPlayer() && quest_id > 0) {
  3282. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3283. return 1;
  3284. }
  3285. return 0;
  3286. }
  3287. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3288. if (!lua_interface)
  3289. return 0;
  3290. Spawn* player = lua_interface->GetSpawn(state);
  3291. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3292. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3293. if (player && player->IsPlayer() && quest_id > 0) {
  3294. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3295. return 1;
  3296. }
  3297. return 0;
  3298. }
  3299. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3300. if (!lua_interface)
  3301. return 0;
  3302. Spawn* player = lua_interface->GetSpawn(state);
  3303. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3304. if (player && player->IsPlayer() && quest_id > 0) {
  3305. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3306. return 1;
  3307. }
  3308. return 0;
  3309. }
  3310. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3311. if (!lua_interface)
  3312. return 0;
  3313. Quest* quest = lua_interface->GetQuest(state);
  3314. string name = lua_interface->GetStringValue(state, 2);
  3315. string type = lua_interface->GetStringValue(state, 3);
  3316. string zone = lua_interface->GetStringValue(state, 4);
  3317. int16 level = lua_interface->GetInt16Value(state, 5);
  3318. string description = lua_interface->GetStringValue(state, 6);
  3319. bool load = true;
  3320. if (!quest) {
  3321. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3322. load = false;
  3323. }
  3324. if (load && name.length() == 0) {
  3325. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3326. load = false;
  3327. }
  3328. if (load && type.length() == 0) {
  3329. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3330. load = false;
  3331. }
  3332. if (load && zone.length() == 0) {
  3333. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3334. load = false;
  3335. }
  3336. if (load && description.length() == 0) {
  3337. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3338. load = false;
  3339. }
  3340. if (load && level == 0) {
  3341. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3342. load = false;
  3343. }
  3344. if (load)
  3345. quest->RegisterQuest(name, type, zone, level, description);
  3346. return 0;
  3347. }
  3348. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3349. if (!lua_interface)
  3350. return 0;
  3351. Quest* quest = lua_interface->GetQuest(state);
  3352. if (quest) {
  3353. int8 level = lua_interface->GetInt16Value(state, 2);
  3354. quest->SetPrereqLevel(level);
  3355. }
  3356. return 0;
  3357. }
  3358. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3359. if (!lua_interface)
  3360. return 0;
  3361. Quest* quest = lua_interface->GetQuest(state);
  3362. if (quest) {
  3363. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3364. quest->AddPrereqQuest(quest_id);
  3365. }
  3366. return 0;
  3367. }
  3368. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3369. if (!lua_interface)
  3370. return 0;
  3371. Quest* quest = lua_interface->GetQuest(state);
  3372. if (quest) {
  3373. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3374. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3375. if (quantity == 0)
  3376. quantity = 1;
  3377. Item* master_item = master_item_list.GetItem(item_id);
  3378. if (master_item) {
  3379. Item* item = new Item(master_item);
  3380. item->details.count = quantity;
  3381. quest->AddPrereqItem(item);
  3382. }
  3383. }
  3384. return 0;
  3385. }
  3386. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3387. if (!lua_interface)
  3388. return 0;
  3389. Spawn* player = lua_interface->GetSpawn(state);
  3390. if(!player || !player->IsPlayer()) {
  3391. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3392. return 0;
  3393. }
  3394. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3395. if (quest_id > 0) {
  3396. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) > 0));
  3397. return 1;
  3398. } else {
  3399. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3400. }
  3401. return 0;
  3402. }
  3403. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3404. if (!lua_interface)
  3405. return 0;
  3406. Quest* quest = lua_interface->GetQuest(state);
  3407. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3408. lua_interface->ResetFunctionStack(state);
  3409. if (quest && spawn_id > 0)
  3410. quest->SetQuestReturnNPC(spawn_id);
  3411. return 0;
  3412. }
  3413. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3414. if (!lua_interface)
  3415. return 0;
  3416. Spawn* spawn = lua_interface->GetSpawn(state);
  3417. int32 time = lua_interface->GetInt32Value(state, 2);
  3418. string function = lua_interface->GetStringValue(state, 3);
  3419. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3420. Spawn* player = lua_interface->GetSpawn(state, 5);
  3421. lua_interface->ResetFunctionStack(state);
  3422. if (!spawn) {
  3423. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3424. return 0;
  3425. }
  3426. if (time <= 0) {
  3427. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3428. return 0;
  3429. }
  3430. if (function.length() == 0) {
  3431. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3432. return 0;
  3433. }
  3434. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3435. if ( time < 10)
  3436. time = 10;
  3437. timer->timer = Timer::GetCurrentTime2() + time;
  3438. timer->function = function;
  3439. timer->spawn = spawn->GetID();
  3440. timer->player = player ? player->GetID() : 0;
  3441. if (max_count == 0)
  3442. max_count = 1;
  3443. timer->max_count = max_count;
  3444. timer->current_count = 0;
  3445. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3446. return 0;
  3447. }
  3448. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3449. if (!lua_interface)
  3450. return 0;
  3451. Spawn* spawn = lua_interface->GetSpawn(state);
  3452. string function = lua_interface->GetStringValue(state, 2);
  3453. lua_interface->ResetFunctionStack(state);
  3454. if (!spawn) {
  3455. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3456. return 0;
  3457. }
  3458. if(!spawn->GetZone()) {
  3459. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3460. return 0;
  3461. }
  3462. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3463. return 0;
  3464. }
  3465. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3466. if (!lua_interface)
  3467. return 0;
  3468. Spawn* player = lua_interface->GetSpawn(state);
  3469. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3470. lua_interface->ResetFunctionStack(state);
  3471. if (player && player->IsPlayer() && quest_id > 0) {
  3472. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3473. return 1;
  3474. }
  3475. return 0;
  3476. }
  3477. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3478. if (!lua_interface)
  3479. return 0;
  3480. Spawn* player = lua_interface->GetSpawn(state);
  3481. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3482. lua_interface->ResetFunctionStack(state);
  3483. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3484. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3485. if (quest)
  3486. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3487. return 1;
  3488. }
  3489. return 0;
  3490. }
  3491. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3492. if (!lua_interface)
  3493. return 0;
  3494. Spawn* player = lua_interface->GetSpawn(state);
  3495. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3496. lua_interface->ResetFunctionStack(state);
  3497. if (player && player->IsPlayer() && quest_id > 0) {
  3498. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3499. return 1;
  3500. }
  3501. return 0;
  3502. }
  3503. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3504. if (!lua_interface)
  3505. return 0;
  3506. Spawn* npc = lua_interface->GetSpawn(state);
  3507. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3508. lua_interface->ResetFunctionStack(state);
  3509. if (npc && !npc->IsPlayer() && quest_id > 0)
  3510. npc->AddProvidedQuest(quest_id);
  3511. return 0;
  3512. }
  3513. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3514. if (!lua_interface)
  3515. return 0;
  3516. Spawn* npc = lua_interface->GetSpawn(state);
  3517. Spawn* player = lua_interface->GetSpawn(state, 2);
  3518. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3519. bool forced = lua_interface->GetBooleanValue(state, 4);
  3520. lua_interface->ResetFunctionStack(state);
  3521. /* NPC is allowed to be null */
  3522. if (player && player->IsPlayer() && quest_id > 0) {
  3523. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3524. if (master_quest) {
  3525. Client* client = ((Player*)player)->GetClient();
  3526. if (!client) {
  3527. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3528. }
  3529. Quest* quest = new Quest(master_quest);
  3530. if (!quest) {
  3531. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3532. }
  3533. if (client && quest) {
  3534. if (npc)
  3535. quest->SetQuestGiver(npc->GetDatabaseID());
  3536. else
  3537. quest->SetQuestGiver(0);
  3538. client->AddPendingQuest(quest, forced);
  3539. }
  3540. }
  3541. else {
  3542. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3543. }
  3544. }
  3545. else {
  3546. 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);
  3547. }
  3548. return 0;
  3549. }
  3550. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3551. if (!lua_interface)
  3552. return 0;
  3553. Quest* quest = lua_interface->GetQuest(state);
  3554. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3555. lua_interface->ResetFunctionStack(state);
  3556. if (quest) {
  3557. quest->AddPrereqClass(class_id);
  3558. }
  3559. return 0;
  3560. }
  3561. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3562. if (!lua_interface)
  3563. return 0;
  3564. Quest* quest = lua_interface->GetQuest(state);
  3565. int8 race = lua_interface->GetInt8Value(state, 2);
  3566. lua_interface->ResetFunctionStack(state);
  3567. if (quest) {
  3568. quest->AddPrereqRace(race);
  3569. }
  3570. return 0;
  3571. }
  3572. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3573. if (!lua_interface)
  3574. return 0;
  3575. Quest* quest = lua_interface->GetQuest(state);
  3576. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3577. lua_interface->ResetFunctionStack(state);
  3578. if (quest) {
  3579. quest->AddPrereqModelType(model_type);
  3580. }
  3581. return 0;
  3582. }
  3583. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3584. if (!lua_interface)
  3585. return 0;
  3586. Quest* quest = lua_interface->GetQuest(state);
  3587. int8 level = lua_interface->GetInt8Value(state, 2);
  3588. lua_interface->ResetFunctionStack(state);
  3589. if (!quest) {
  3590. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3591. return 0;
  3592. }
  3593. quest->SetPrereqTSLevel(level);
  3594. return 0;
  3595. }
  3596. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3597. if (!lua_interface)
  3598. return 0;
  3599. Quest* quest = lua_interface->GetQuest(state);
  3600. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3601. lua_interface->ResetFunctionStack(state);
  3602. if (!quest) {
  3603. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3604. return 0;
  3605. }
  3606. quest->AddPrereqTradeskillClass(class_id);
  3607. return 0;
  3608. }
  3609. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3610. if (!lua_interface)
  3611. return 0;
  3612. Quest* quest = lua_interface->GetQuest(state);
  3613. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3614. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3615. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3616. lua_interface->ResetFunctionStack(state);
  3617. if (quest) {
  3618. quest->AddPrereqFaction(faction_id, min, max);
  3619. }
  3620. return 0;
  3621. }
  3622. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3623. if (!lua_interface)
  3624. return 0;
  3625. Quest* quest = lua_interface->GetQuest(state);
  3626. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3627. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3628. lua_interface->ResetFunctionStack(state);
  3629. if (quest) {
  3630. if (quantity == 0)
  3631. quantity = 1;
  3632. Item* master_item = master_item_list.GetItem(item_id);
  3633. if (master_item) {
  3634. Item* item = new Item(master_item);
  3635. item->details.count = quantity;
  3636. quest->AddSelectableRewardItem(item);
  3637. }
  3638. }
  3639. return 0;
  3640. }
  3641. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3642. if (!lua_interface)
  3643. return 0;
  3644. Quest* quest = lua_interface->GetQuest(state);
  3645. if (quest) {
  3646. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3647. vector<Item*>* items = quest->GetRewardItems();
  3648. if (items) {
  3649. vector<Item*>::iterator itr;
  3650. for (itr = items->begin(); itr != items->end(); itr++) {
  3651. if (*itr && (*itr)->details.item_id == item_id) {
  3652. lua_interface->SetBooleanValue(state, true);
  3653. return 1;
  3654. }
  3655. }
  3656. }
  3657. }
  3658. lua_interface->SetBooleanValue(state, false);
  3659. return 1;
  3660. }
  3661. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3662. if (!lua_interface)
  3663. return 0;
  3664. Quest* quest = lua_interface->GetQuest(state);
  3665. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3666. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3667. lua_interface->ResetFunctionStack(state);
  3668. if (quest) {
  3669. if (quantity == 0)
  3670. quantity = 1;
  3671. Item* master_item = master_item_list.GetItem(item_id);
  3672. if (master_item) {
  3673. Item* item = new Item(master_item);
  3674. item->details.count = quantity;
  3675. quest->AddRewardItem(item);
  3676. }
  3677. }
  3678. return 0;
  3679. }
  3680. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3681. if (!lua_interface)
  3682. return 0;
  3683. Quest* quest = lua_interface->GetQuest(state);
  3684. int32 copper = lua_interface->GetInt32Value(state, 2);
  3685. int32 silver = lua_interface->GetInt32Value(state, 3);
  3686. int32 gold = lua_interface->GetInt32Value(state, 4);
  3687. int32 plat = lua_interface->GetInt32Value(state, 5);
  3688. lua_interface->ResetFunctionStack(state);
  3689. if (quest) {
  3690. quest->AddRewardCoins(copper, silver, gold, plat);
  3691. }
  3692. return 0;
  3693. }
  3694. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3695. if (!lua_interface)
  3696. return 0;
  3697. Quest* quest = lua_interface->GetQuest(state);
  3698. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3699. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3700. lua_interface->ResetFunctionStack(state);
  3701. if (quest && faction_id > 0 && amount != 0)
  3702. quest->AddRewardFaction(faction_id, amount);
  3703. return 0;
  3704. }
  3705. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3706. if (!lua_interface)
  3707. return 0;
  3708. Quest* quest = lua_interface->GetQuest(state);
  3709. int32 status = lua_interface->GetInt32Value(state, 2);
  3710. lua_interface->ResetFunctionStack(state);
  3711. if (quest) {
  3712. quest->SetRewardStatus(status);
  3713. }
  3714. return 0;
  3715. }
  3716. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3717. if (!lua_interface)
  3718. return 0;
  3719. Quest* quest = lua_interface->GetQuest(state);
  3720. int32 status = lua_interface->GetInt32Value(state, 2);
  3721. lua_interface->ResetFunctionStack(state);
  3722. if (quest) {
  3723. quest->SetStatusTmpReward(status);
  3724. }
  3725. return 0;
  3726. }
  3727. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3728. if (!lua_interface)
  3729. return 0;
  3730. Quest* quest = lua_interface->GetQuest(state);
  3731. int64 coins = lua_interface->GetInt64Value(state, 2);
  3732. lua_interface->ResetFunctionStack(state);
  3733. if (quest) {
  3734. quest->SetCoinTmpReward(coins);
  3735. }
  3736. return 0;
  3737. }
  3738. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3739. if (!lua_interface)
  3740. return 0;
  3741. Quest* quest = lua_interface->GetQuest(state);
  3742. string comment = lua_interface->GetStringValue(state, 2);
  3743. lua_interface->ResetFunctionStack(state);
  3744. if (quest) {
  3745. quest->SetRewardComment(comment);
  3746. }
  3747. return 0;
  3748. }
  3749. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3750. if (!lua_interface)
  3751. return 0;
  3752. Quest* quest = lua_interface->GetQuest(state);
  3753. int32 exp = lua_interface->GetInt32Value(state, 2);
  3754. lua_interface->ResetFunctionStack(state);
  3755. if (quest) {
  3756. quest->SetRewardXP(exp);
  3757. }
  3758. return 0;
  3759. }
  3760. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3761. Quest* quest = lua_interface->GetQuest(state);
  3762. int32 step = lua_interface->GetInt32Value(state, 2);
  3763. string description = lua_interface->GetStringValue(state, 3);
  3764. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3765. float percentage = lua_interface->GetFloatValue(state, 5);
  3766. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3767. int16 icon = lua_interface->GetInt16Value(state, 7);
  3768. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3769. if (quest) {
  3770. const char* taskgroup = 0;
  3771. if (str_taskgroup.length() > 0)
  3772. taskgroup = str_taskgroup.c_str();
  3773. int32 id = 0;
  3774. vector<int32>* ids = 0;
  3775. int i = 0;
  3776. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3777. if (ids == 0)
  3778. ids = new vector<int32>;
  3779. ids->push_back(id);
  3780. i++;
  3781. }
  3782. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3783. if (quest_step && icon && quantity > 0)
  3784. quest_step->SetIcon(icon);
  3785. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3786. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3787. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3788. }
  3789. }
  3790. lua_interface->ResetFunctionStack(state);
  3791. return 0;
  3792. }
  3793. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3794. {
  3795. if (!lua_interface)
  3796. return 0;
  3797. Quest* quest = lua_interface->GetQuest(state);
  3798. int32 step = lua_interface->GetInt32Value(state, 2);
  3799. string description = lua_interface->GetStringValue(state, 3);
  3800. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3801. float percentage = lua_interface->GetFloatValue(state, 5);
  3802. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3803. int16 icon = lua_interface->GetInt16Value(state, 7);
  3804. if (quest) {
  3805. const char* taskgroup = 0;
  3806. if (str_taskgroup.length() > 0)
  3807. taskgroup = str_taskgroup.c_str();
  3808. int32 id = 0;
  3809. vector<int32>* ids = 0;
  3810. int i = 0;
  3811. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3812. if (ids == 0)
  3813. ids = new vector<int32>;
  3814. ids->push_back(id);
  3815. i++;
  3816. }
  3817. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3818. if (quest_step && icon > 0 && quantity > 0)
  3819. quest_step->SetIcon(icon);
  3820. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3821. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3822. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3823. }
  3824. safe_delete(ids);
  3825. }
  3826. lua_interface->ResetFunctionStack(state);
  3827. return 0;
  3828. }
  3829. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3830. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3831. }
  3832. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3833. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3834. }
  3835. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3836. if (!lua_interface)
  3837. return 0;
  3838. Quest* quest = lua_interface->GetQuest(state);
  3839. int32 step = lua_interface->GetInt32Value(state, 2);
  3840. string description = lua_interface->GetStringValue(state, 3);
  3841. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3842. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3843. int16 icon = lua_interface->GetInt16Value(state, 6);
  3844. if (quest) {
  3845. const char* taskgroup = 0;
  3846. if (str_taskgroup.length() > 0)
  3847. taskgroup = str_taskgroup.c_str();
  3848. int32 npc_id = 0;
  3849. vector<int32>* ids = 0;
  3850. int i = 0;
  3851. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3852. if (ids == 0)
  3853. ids = new vector<int32>;
  3854. ids->push_back(npc_id);
  3855. i++;
  3856. }
  3857. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3858. if (quest_step && icon > 0)
  3859. quest_step->SetIcon(icon);
  3860. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3861. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3862. if(client)
  3863. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3864. }
  3865. safe_delete(ids);
  3866. }
  3867. lua_interface->ResetFunctionStack(state);
  3868. return 0;
  3869. }
  3870. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3871. if (!lua_interface)
  3872. return 0;
  3873. Quest* quest = lua_interface->GetQuest(state);
  3874. int32 step = lua_interface->GetInt32Value(state, 2);
  3875. string description = lua_interface->GetStringValue(state, 3);
  3876. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3877. float percentage = lua_interface->GetFloatValue(state, 5);
  3878. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3879. int16 icon = lua_interface->GetInt16Value(state, 7);
  3880. if (quest) {
  3881. const char* taskgroup = 0;
  3882. if (str_taskgroup.length() > 0)
  3883. taskgroup = str_taskgroup.c_str();
  3884. int32 item_id = 0;
  3885. vector<int32>* ids = 0;
  3886. int i = 0;
  3887. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3888. if (ids == 0)
  3889. ids = new vector<int32>;
  3890. ids->push_back(item_id);
  3891. i++;
  3892. }
  3893. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3894. if (quest_step && icon > 0 && quantity > 0)
  3895. quest_step->SetIcon(icon);
  3896. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3897. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3898. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3899. }
  3900. safe_delete(ids);
  3901. }
  3902. lua_interface->ResetFunctionStack(state);
  3903. return 0;
  3904. }
  3905. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3906. if (!lua_interface)
  3907. return 0;
  3908. Quest* quest = lua_interface->GetQuest(state);
  3909. int32 step = lua_interface->GetInt32Value(state, 2);
  3910. string description = lua_interface->GetStringValue(state, 3);
  3911. float max_variation = lua_interface->GetFloatValue(state, 4);
  3912. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3913. int16 icon = lua_interface->GetInt16Value(state, 6);
  3914. if (quest) {
  3915. const char* taskgroup = 0;
  3916. if (str_taskgroup.length() > 0)
  3917. taskgroup = str_taskgroup.c_str();
  3918. vector<Location>* locations = 0;
  3919. int8 i = 7;
  3920. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3921. while (true) {
  3922. Location loc;
  3923. loc.x = lua_interface->GetFloatValue(state, i);
  3924. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3925. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3926. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3927. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3928. break;
  3929. if (locations == 0)
  3930. locations = new vector<Location>;
  3931. locations->push_back(loc);
  3932. i += 4;
  3933. }
  3934. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3935. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3936. if (quest_step && icon > 0)
  3937. quest_step->SetIcon(icon);
  3938. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3939. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3940. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3941. }
  3942. }
  3943. lua_interface->ResetFunctionStack(state);
  3944. return 0;
  3945. }
  3946. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3947. if (!lua_interface)
  3948. return 0;
  3949. Quest* quest = lua_interface->GetQuest(state);
  3950. int32 step = lua_interface->GetInt32Value(state, 2);
  3951. string description = lua_interface->GetStringValue(state, 3);
  3952. float max_variation = lua_interface->GetFloatValue(state, 4);
  3953. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3954. int16 icon = lua_interface->GetInt16Value(state, 6);
  3955. if (quest) {
  3956. const char* taskgroup = 0;
  3957. if (str_taskgroup.length() > 0)
  3958. taskgroup = str_taskgroup.c_str();
  3959. vector<Location>* locations = 0;
  3960. int8 i = 7;
  3961. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3962. while (true) {
  3963. Location loc;
  3964. loc.x = lua_interface->GetFloatValue(state, i);
  3965. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3966. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3967. loc.zone_id = 0;
  3968. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3969. break;
  3970. if (locations == 0)
  3971. locations = new vector<Location>;
  3972. locations->push_back(loc);
  3973. i += 3;
  3974. }
  3975. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3976. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3977. if (quest_step && icon > 0)
  3978. quest_step->SetIcon(icon);
  3979. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3980. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3981. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3982. }
  3983. }
  3984. lua_interface->ResetFunctionStack(state);
  3985. return 0;
  3986. }
  3987. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3988. if (!lua_interface)
  3989. return 0;
  3990. Quest* quest = lua_interface->GetQuest(state);
  3991. int32 step = lua_interface->GetInt32Value(state, 2);
  3992. string description = lua_interface->GetStringValue(state, 3);
  3993. float max_variation = lua_interface->GetFloatValue(state, 4);
  3994. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3995. int16 icon = lua_interface->GetInt16Value(state, 6);
  3996. if (quest) {
  3997. const char* taskgroup = 0;
  3998. if (str_taskgroup.length() > 0)
  3999. taskgroup = str_taskgroup.c_str();
  4000. vector<Location>* locations = 0;
  4001. int i = 7;
  4002. while (true) {
  4003. Location loc;
  4004. loc.x = lua_interface->GetFloatValue(state, i);
  4005. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4006. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4007. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4008. break;
  4009. if (locations == 0)
  4010. locations = new vector<Location>;
  4011. locations->push_back(loc);
  4012. i += 3;
  4013. }
  4014. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4015. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4016. if (quest_step && icon > 0)
  4017. quest_step->SetIcon(icon);
  4018. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4019. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4020. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4021. }
  4022. }
  4023. lua_interface->ResetFunctionStack(state);
  4024. return 0;
  4025. }
  4026. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4027. Quest* quest = lua_interface->GetQuest(state);
  4028. int32 step = lua_interface->GetInt32Value(state, 2);
  4029. string description = lua_interface->GetStringValue(state, 3);
  4030. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4031. float percentage = lua_interface->GetFloatValue(state, 5);
  4032. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4033. int16 icon = lua_interface->GetInt16Value(state, 7);
  4034. if (quest) {
  4035. const char* taskgroup = 0;
  4036. if (str_taskgroup.length() > 0)
  4037. taskgroup = str_taskgroup.c_str();
  4038. int32 spell_id = 0;
  4039. vector<int32>* ids = 0;
  4040. int i = 0;
  4041. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4042. if (ids == 0)
  4043. ids = new vector<int32>;
  4044. ids->push_back(spell_id);
  4045. i++;
  4046. }
  4047. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4048. if (quest_step && icon > 0 && quantity > 0)
  4049. quest_step->SetIcon(icon);
  4050. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4051. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4052. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4053. }
  4054. safe_delete(ids);
  4055. }
  4056. lua_interface->ResetFunctionStack(state);
  4057. return 0;
  4058. }
  4059. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4060. if (!lua_interface)
  4061. return 0;
  4062. Quest* quest = lua_interface->GetQuest(state);
  4063. int32 step = lua_interface->GetInt32Value(state, 2);
  4064. string description = lua_interface->GetStringValue(state, 3);
  4065. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4066. float percentage = lua_interface->GetFloatValue(state, 5);
  4067. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4068. int16 icon = lua_interface->GetInt16Value(state, 7);
  4069. if (quest) {
  4070. const char* taskgroup = 0;
  4071. if (str_taskgroup.length() > 0)
  4072. taskgroup = str_taskgroup.c_str();
  4073. int32 item_id = 0;
  4074. vector<int32>* ids = 0;
  4075. int i = 0;
  4076. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4077. if (ids == 0)
  4078. ids = new vector<int32>;
  4079. ids->push_back(item_id);
  4080. i++;
  4081. }
  4082. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4083. if (quest_step && icon > 0 && quantity > 0)
  4084. quest_step->SetIcon(icon);
  4085. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4086. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4087. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4088. }
  4089. safe_delete(ids);
  4090. }
  4091. lua_interface->ResetFunctionStack(state);
  4092. return 0;
  4093. }
  4094. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4095. if (!lua_interface)
  4096. return 0;
  4097. Quest* quest = lua_interface->GetQuest(state);
  4098. int32 step = lua_interface->GetInt32Value(state, 2);
  4099. string description = lua_interface->GetStringValue(state, 3);
  4100. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4101. float percentage = lua_interface->GetFloatValue(state, 5);
  4102. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4103. int16 icon = lua_interface->GetInt16Value(state, 7);
  4104. if (quest) {
  4105. const char* taskgroup = 0;
  4106. if (str_taskgroup.length() > 0)
  4107. taskgroup = str_taskgroup.c_str();
  4108. int32 item_id = 0;
  4109. vector<int32>* ids = 0;
  4110. int i = 0;
  4111. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4112. if (ids == 0)
  4113. ids = new vector<int32>;
  4114. ids->push_back(item_id);
  4115. i++;
  4116. }
  4117. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4118. if (quest_step && icon > 0 && quantity > 0)
  4119. quest_step->SetIcon(icon);
  4120. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4121. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4122. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4123. }
  4124. safe_delete(ids);
  4125. }
  4126. lua_interface->ResetFunctionStack(state);
  4127. return 0;
  4128. }
  4129. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4130. if (!lua_interface)
  4131. return 0;
  4132. Quest* quest = lua_interface->GetQuest(state);
  4133. string action = lua_interface->GetStringValue(state, 2);
  4134. lua_interface->ResetFunctionStack(state);
  4135. if (quest) {
  4136. if (action.length() > 0)
  4137. quest->SetCompleteAction(action);
  4138. }
  4139. return 0;
  4140. }
  4141. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4142. if (!lua_interface)
  4143. return 0;
  4144. Quest* quest = lua_interface->GetQuest(state);
  4145. int32 step = lua_interface->GetInt32Value(state, 2);
  4146. string action = lua_interface->GetStringValue(state, 3);
  4147. lua_interface->ResetFunctionStack(state);
  4148. if (quest) {
  4149. if (step > 0 && action.length() > 0)
  4150. quest->AddCompleteAction(step, action);
  4151. }
  4152. return 0;
  4153. }
  4154. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4155. if (!lua_interface)
  4156. return 0;
  4157. Quest* quest = lua_interface->GetQuest(state);
  4158. int32 step = lua_interface->GetInt32Value(state, 2);
  4159. string action = lua_interface->GetStringValue(state, 3);
  4160. lua_interface->ResetFunctionStack(state);
  4161. if (quest) {
  4162. if (step > 0 && action.length() > 0)
  4163. quest->AddProgressAction(step, action);
  4164. }
  4165. return 0;
  4166. }
  4167. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4168. if (!lua_interface)
  4169. return 0;
  4170. Quest* quest = lua_interface->GetQuest(state);
  4171. string description = lua_interface->GetStringValue(state, 2);
  4172. lua_interface->ResetFunctionStack(state);
  4173. if (quest && description.length() > 0)
  4174. quest->SetDescription(description);
  4175. return 0;
  4176. }
  4177. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4178. if (!lua_interface)
  4179. return 0;
  4180. Quest* quest = lua_interface->GetQuest(state);
  4181. string description = lua_interface->GetStringValue(state, 2);
  4182. lua_interface->ResetFunctionStack(state);
  4183. if (quest && description.length() > 0)
  4184. quest->SetCompletedDescription(description);
  4185. return 0;
  4186. }
  4187. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4188. if (!lua_interface)
  4189. return 0;
  4190. Quest* quest = lua_interface->GetQuest(state);
  4191. int32 step = lua_interface->GetInt32Value(state, 2);
  4192. string description = lua_interface->GetStringValue(state, 3);
  4193. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4194. lua_interface->ResetFunctionStack(state);
  4195. if (quest && step > 0 && description.length() > 0) {
  4196. quest->SetTaskGroupDescription(step, description, display_bullets);
  4197. }
  4198. return 0;
  4199. }
  4200. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4201. if (!lua_interface)
  4202. return 0;
  4203. Quest* quest = lua_interface->GetQuest(state);
  4204. int32 step = lua_interface->GetInt32Value(state, 2);
  4205. string description = lua_interface->GetStringValue(state, 3);
  4206. lua_interface->ResetFunctionStack(state);
  4207. if (quest && step > 0 && description.length() > 0) {
  4208. quest->SetStepDescription(step, description);
  4209. }
  4210. return 0;
  4211. }
  4212. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4213. Quest* quest = lua_interface->GetQuest(state);
  4214. string zone = lua_interface->GetStringValue(state, 2);
  4215. lua_interface->ResetFunctionStack(state);
  4216. if (quest && zone.length() > 0)
  4217. quest->SetZone(zone);
  4218. return 0;
  4219. }
  4220. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4221. if (!lua_interface)
  4222. return 0;
  4223. Quest* quest = lua_interface->GetQuest(state);
  4224. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4225. lua_interface->ResetFunctionStack(state);
  4226. if (quest && spawn) {
  4227. if (spawn->IsPlayer()) {
  4228. Client* client = ((Player*)spawn)->GetClient();
  4229. if (client) {
  4230. client->AddPendingQuestReward(quest);
  4231. }
  4232. }
  4233. }
  4234. return 0;
  4235. }
  4236. int EQ2Emu_lua_Harvest(lua_State* state) {
  4237. if (!lua_interface)
  4238. return 0;
  4239. Spawn* player = lua_interface->GetSpawn(state);
  4240. Spawn* node = lua_interface->GetSpawn(state, 2);
  4241. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4242. Client* client = ((Player*)player)->GetClient();
  4243. if (client) {
  4244. ((GroundSpawn*)node)->ProcessHarvest(client);
  4245. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4246. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4247. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4248. }
  4249. }
  4250. }
  4251. else if (player && player->IsPlayer()) {
  4252. Client* client = ((Player*)player)->GetClient();
  4253. if (client)
  4254. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4255. }
  4256. lua_interface->ResetFunctionStack(state);
  4257. return 0;
  4258. }
  4259. int EQ2Emu_lua_Bind(lua_State* state) {
  4260. if (!lua_interface)
  4261. return 0;
  4262. Spawn* spawn = lua_interface->GetSpawn(state);
  4263. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4264. float x = lua_interface->GetFloatValue(state, 3);
  4265. float y = lua_interface->GetFloatValue(state, 4);
  4266. float z = lua_interface->GetFloatValue(state, 5);
  4267. float h = lua_interface->GetFloatValue(state, 6);
  4268. lua_interface->ResetFunctionStack(state);
  4269. if (!spawn) {
  4270. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4271. return 0;
  4272. }
  4273. if (!spawn->IsPlayer()) {
  4274. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4275. return 0;
  4276. }
  4277. if (zone_id == 0) {
  4278. Client* client = ((Player*)spawn)->GetClient();
  4279. if (!client) {
  4280. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4281. return 0;
  4282. }
  4283. if (!client->Bind())
  4284. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4285. }
  4286. else {
  4287. Player* player = (Player*)spawn;
  4288. player->GetPlayerInfo()->SetBindZone(zone_id);
  4289. player->GetPlayerInfo()->SetBindX(x);
  4290. player->GetPlayerInfo()->SetBindY(y);
  4291. player->GetPlayerInfo()->SetBindZ(z);
  4292. player->GetPlayerInfo()->SetBindHeading(h);
  4293. }
  4294. return 0;
  4295. }
  4296. int EQ2Emu_lua_Gate(lua_State* state) {
  4297. if (!lua_interface)
  4298. return 0;
  4299. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4300. Spawn* spawn = lua_interface->GetSpawn(state);
  4301. lua_interface->ResetFunctionStack(state);
  4302. if (spawn) {
  4303. if (spawn->IsPlayer()) {
  4304. Client* client = ((Player*)spawn)->GetClient();
  4305. if (client) {
  4306. if (!client->Gate((spell != nullptr) ? true : false))
  4307. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4308. }
  4309. }
  4310. }
  4311. return 0;
  4312. }
  4313. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4314. if (!lua_interface)
  4315. return 0;
  4316. bool ret = false;
  4317. Spawn* spawn = lua_interface->GetSpawn(state);
  4318. lua_interface->ResetFunctionStack(state);
  4319. if (spawn) {
  4320. if (spawn->IsPlayer()) {
  4321. Client* client = ((Player*)spawn)->GetClient();
  4322. if (client)
  4323. ret = client->BindAllowed();
  4324. }
  4325. }
  4326. lua_interface->SetBooleanValue(state, ret);
  4327. return 1;
  4328. }
  4329. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4330. if (!lua_interface)
  4331. return 0;
  4332. bool ret = false;
  4333. Spawn* spawn = lua_interface->GetSpawn(state);
  4334. lua_interface->ResetFunctionStack(state);
  4335. if (spawn) {
  4336. if (spawn->IsPlayer()) {
  4337. Client* client = ((Player*)spawn)->GetClient();
  4338. ZoneServer* zone = lua_interface->GetZone(state);
  4339. if (client && zone){
  4340. ret = zone->GetCanGate();
  4341. }
  4342. }
  4343. }
  4344. lua_interface->SetBooleanValue(state, ret);
  4345. return 1;
  4346. }
  4347. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4348. Spawn* spawn = lua_interface->GetSpawn(state);
  4349. lua_interface->ResetFunctionStack(state);
  4350. if (spawn) {
  4351. lua_interface->SetBooleanValue(state, spawn->Alive());
  4352. return 1;
  4353. }
  4354. return 0;
  4355. }
  4356. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4357. if (!lua_interface)
  4358. return 0;
  4359. Spawn* spawn = lua_interface->GetSpawn(state);
  4360. lua_interface->ResetFunctionStack(state);
  4361. if (spawn && spawn->IsEntity()) {
  4362. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4363. return 1;
  4364. }
  4365. return 0;
  4366. }
  4367. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4368. Spawn* spawn = lua_interface->GetSpawn(state);
  4369. string message = lua_interface->GetStringValue(state, 2);
  4370. string color_str = lua_interface->GetStringValue(state, 3);
  4371. lua_interface->ResetFunctionStack(state);
  4372. int8 color = CHANNEL_NARRATIVE;
  4373. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4374. Client* client = ((Player*)spawn)->GetClient();
  4375. if (client) {
  4376. if (color_str.length() > 0) {
  4377. // leave for backwards compat, but all future should just use the number
  4378. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4379. color = CHANNEL_COLOR_RED;
  4380. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4381. color = CHANNEL_COLOR_YELLOW;
  4382. else
  4383. {
  4384. // use a number to specify the channel as per Commands/Commands.h defines
  4385. color = (int8)atoul(color_str.c_str());
  4386. }
  4387. }
  4388. client->SimpleMessage(color, message.c_str());
  4389. }
  4390. }
  4391. return 0;
  4392. }
  4393. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4394. Spawn* spawn = lua_interface->GetSpawn(state);
  4395. string message = lua_interface->GetStringValue(state, 2);
  4396. int8 red = lua_interface->GetInt8Value(state, 3);
  4397. int8 green = lua_interface->GetInt8Value(state, 4);
  4398. int8 blue = lua_interface->GetInt8Value(state, 5);
  4399. lua_interface->ResetFunctionStack(state);
  4400. if (!spawn) {
  4401. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4402. return 0;
  4403. }
  4404. if (!spawn->IsPlayer()) {
  4405. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4406. return 0;
  4407. }
  4408. int32 words = ::CountWordsInString(message.c_str());
  4409. if (words < 5)
  4410. words = 5;
  4411. Client* client = ((Player*)spawn)->GetClient();
  4412. if (client)
  4413. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4414. return 0;
  4415. }
  4416. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4417. Spawn* spawn = lua_interface->GetSpawn(state);
  4418. int8 param = lua_interface->GetInt8Value(state, 2);
  4419. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4420. int8 value = lua_interface->GetInt8Value(state, 4);
  4421. lua_interface->ResetFunctionStack(state);
  4422. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4423. Client* client = ((Player*)spawn)->GetClient();
  4424. if (client) {
  4425. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4426. switch (param) {
  4427. case 1: {
  4428. packet->setDataByName("parameter1", param_value);
  4429. break;
  4430. }
  4431. case 2: {
  4432. packet->setDataByName("parameter2", param_value);
  4433. break;
  4434. }
  4435. case 3: {
  4436. packet->setDataByName("parameter3", param_value);
  4437. break;
  4438. }
  4439. case 4: {
  4440. packet->setDataByName("parameter4", param_value);
  4441. break;
  4442. }
  4443. case 5: {
  4444. packet->setDataByName("parameter5", param_value);
  4445. break;
  4446. }
  4447. }
  4448. packet->setDataByName("value", value);
  4449. client->QueuePacket(packet->serialize());
  4450. safe_delete(packet);
  4451. }
  4452. }
  4453. return 0;
  4454. }
  4455. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4456. Spawn* spawn = lua_interface->GetSpawn(state);
  4457. lua_interface->ResetFunctionStack(state);
  4458. if (spawn && spawn->IsPlayer()) {
  4459. if (((Player*)spawn)->GetIsTracking())
  4460. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4461. else
  4462. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4463. }
  4464. return 0;
  4465. }
  4466. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4467. Spawn* player = lua_interface->GetSpawn(state);
  4468. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4469. string name = lua_interface->GetStringValue(state, 3);
  4470. float distance = lua_interface->GetFloatValue(state, 4);
  4471. string command = lua_interface->GetStringValue(state, 5);
  4472. string error_text = lua_interface->GetStringValue(state, 6);
  4473. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4474. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4475. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4476. lua_interface->ResetFunctionStack(state);
  4477. if (spawn) {
  4478. if (distance == 0)
  4479. distance = 10.0f;
  4480. if (command.length() == 0)
  4481. command = name;
  4482. if (command.length() < 1 && name.length() < 1)
  4483. {
  4484. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4485. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4486. spawn->RemovePrimaryCommands();
  4487. }
  4488. else
  4489. {
  4490. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4491. }
  4492. }
  4493. return 0;
  4494. }
  4495. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4496. if (!lua_interface)
  4497. return 0;
  4498. Spawn* player = lua_interface->GetSpawn(state);
  4499. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4500. int16 tier = lua_interface->GetInt16Value(state, 3);
  4501. lua_interface->ResetFunctionStack(state);
  4502. if (player && player->IsPlayer()) {
  4503. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4504. return 1;
  4505. }
  4506. return 0;
  4507. }
  4508. int EQ2Emu_lua_AddSpellBookEntry(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. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4515. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4516. bool add_to_hotbar = true;
  4517. if (num_args > 4) {
  4518. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4519. }
  4520. lua_interface->ResetFunctionStack(state);
  4521. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4522. if (player && spell && player->IsPlayer()) {
  4523. Client* client = player->GetClient();
  4524. if (client) {
  4525. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4526. {
  4527. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4528. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4529. client->GetPlayer()->UnlockSpell(spell);
  4530. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4531. }
  4532. else
  4533. {
  4534. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4535. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4536. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4537. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4538. client->GetPlayer()->UnlockSpell(spell);
  4539. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4540. }
  4541. //if (client ) {
  4542. // ((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);
  4543. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4544. if (outapp)
  4545. client->QueuePacket(outapp);
  4546. }
  4547. }
  4548. return 0;
  4549. }
  4550. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4551. if (!lua_interface)
  4552. return 0;
  4553. Spawn* player = lua_interface->GetSpawn(state);
  4554. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4555. lua_interface->ResetFunctionStack(state);
  4556. if (player && player->IsPlayer()) {
  4557. Client* client = player->GetClient();
  4558. if (client) {
  4559. ((Player*)player)->DeleteSpellBook(type_selection);
  4560. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4561. if (outapp)
  4562. client->QueuePacket(outapp);
  4563. }
  4564. }
  4565. return 0;
  4566. }
  4567. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4568. if (!lua_interface)
  4569. return 0;
  4570. Spawn* player = lua_interface->GetSpawn(state);
  4571. lua_interface->ResetFunctionStack(state);
  4572. if (player && player->IsPlayer()) {
  4573. Client* client = player->GetClient();
  4574. if (client) {
  4575. client->SendNewAdventureSpells();
  4576. }
  4577. }
  4578. return 0;
  4579. }
  4580. int EQ2Emu_lua_SendNewTradeskillSpells(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->SendNewTradeskillSpells();
  4589. }
  4590. }
  4591. return 0;
  4592. }
  4593. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. Spawn* player = lua_interface->GetSpawn(state);
  4597. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4598. lua_interface->ResetFunctionStack(state);
  4599. if (player && player->IsPlayer()) {
  4600. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4601. Client* client = player->GetClient();
  4602. if (sbe && client) {
  4603. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4604. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4605. if (outapp)
  4606. client->QueuePacket(outapp);
  4607. }
  4608. }
  4609. return 0;
  4610. }
  4611. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4612. if (!lua_interface)
  4613. return 0;
  4614. Spawn* player = lua_interface->GetSpawn(state);
  4615. lua_interface->ResetFunctionStack(state);
  4616. if (player && player->IsPlayer()) {
  4617. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4618. return 1;
  4619. }
  4620. return 0;
  4621. }
  4622. int EQ2Emu_lua_Attack(lua_State* state) {
  4623. if (lua_interface) {
  4624. Spawn* npc = lua_interface->GetSpawn(state);
  4625. Spawn* player = lua_interface->GetSpawn(state, 2);
  4626. lua_interface->ResetFunctionStack(state);
  4627. if (npc && player && npc->IsNPC() && player->IsEntity())
  4628. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4629. }
  4630. return 0;
  4631. }
  4632. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4633. if (lua_interface) {
  4634. Spawn* target = lua_interface->GetSpawn(state);
  4635. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4636. lua_interface->ResetFunctionStack(state);
  4637. if (target && target->GetZone())
  4638. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4639. }
  4640. return 0;
  4641. }
  4642. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4643. Spawn* player;
  4644. if (lua_interface) {
  4645. player = lua_interface->GetSpawn(state);
  4646. lua_interface->ResetFunctionStack(state);
  4647. if (player && player->IsPlayer()) {
  4648. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4649. return 1;
  4650. }
  4651. }
  4652. return 0;
  4653. }
  4654. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4655. Spawn* player;
  4656. Client* client;
  4657. if (lua_interface) {
  4658. player = lua_interface->GetSpawn(state);
  4659. lua_interface->ResetFunctionStack(state);
  4660. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4661. if ((client = ((Player*)player)->GetClient()))
  4662. client->HandInCollections();
  4663. }
  4664. return 0;
  4665. }
  4666. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4667. Spawn* widget;
  4668. if (lua_interface) {
  4669. widget = lua_interface->GetSpawn(state);
  4670. lua_interface->ResetFunctionStack(state);
  4671. if (widget && widget->IsWidget())
  4672. ((Widget*)widget)->HandleUse(nullptr, "");
  4673. }
  4674. return 0;
  4675. }
  4676. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4677. Spawn* spawn = 0;
  4678. int32 primary_list = 0;
  4679. int32 secondary_list = 0;
  4680. if (lua_interface) {
  4681. spawn = lua_interface->GetSpawn(state);
  4682. primary_list = lua_interface->GetInt32Value(state, 2);
  4683. secondary_list = lua_interface->GetInt32Value(state, 3);
  4684. lua_interface->ResetFunctionStack(state);
  4685. if (!spawn->IsNPC()) {
  4686. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4687. return 0;
  4688. }
  4689. NPC* npc = (NPC*)spawn;
  4690. npc->SetPrimarySpellList(primary_list);
  4691. npc->SetSecondarySpellList(secondary_list);
  4692. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4693. }
  4694. return 0;
  4695. }
  4696. int EQ2Emu_lua_GetPet(lua_State* state) {
  4697. if (!lua_interface)
  4698. return 0;
  4699. Spawn* spawn = lua_interface->GetSpawn(state);
  4700. lua_interface->ResetFunctionStack(state);
  4701. if (spawn) {
  4702. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4703. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4704. return 1;
  4705. }
  4706. }
  4707. return 0;
  4708. }
  4709. int EQ2Emu_lua_GetCharmedPet(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)->GetCharmedPet()) {
  4716. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4717. return 1;
  4718. }
  4719. }
  4720. return 0;
  4721. }
  4722. int EQ2Emu_lua_GetDeityPet(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)->GetDeityPet()) {
  4729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4730. return 1;
  4731. }
  4732. }
  4733. return 0;
  4734. }
  4735. int EQ2Emu_lua_GetCosmeticPet(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)->GetCosmeticPet()) {
  4742. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4743. return 1;
  4744. }
  4745. }
  4746. return 0;
  4747. }
  4748. int EQ2Emu_lua_Charm(lua_State* state) {
  4749. if (!lua_interface)
  4750. return 0;
  4751. Spawn* owner = lua_interface->GetSpawn(state);
  4752. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4753. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4754. lua_interface->ResetFunctionStack(state);
  4755. if (!luaspell) {
  4756. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4757. return 0;
  4758. }
  4759. if(luaspell->resisted) {
  4760. return 0;
  4761. }
  4762. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4763. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4764. pet->SetPet(true);
  4765. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4766. ((NPC*)pet)->SetOwner((Entity*)owner);
  4767. // If owner is player and player does not have a summoned pet set the players charsheet
  4768. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4769. Player* player = (Player*)owner;
  4770. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4771. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4772. player->GetInfoStruct()->set_pet_movement(2);
  4773. player->GetInfoStruct()->set_pet_behavior(3);
  4774. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4775. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4776. // Make sure the values get sent to the client
  4777. player->SetCharSheetChanged(true);
  4778. }
  4779. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4780. pet->SetSpawnScript("");
  4781. // Set faction to the same as the owner
  4782. pet->SetFactionID(owner->GetFactionID());
  4783. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4784. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4785. // Clear hate list
  4786. ((NPC*)pet)->Brain()->ClearHate();
  4787. // Set the brain to a pet brain
  4788. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4789. }
  4790. return 0;
  4791. }
  4792. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4793. if (!lua_interface)
  4794. return 0;
  4795. Spawn* spawn = lua_interface->GetSpawn(state);
  4796. lua_interface->ResetFunctionStack(state);
  4797. if (!spawn) {
  4798. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4799. return 0;
  4800. }
  4801. vector<Spawn*> groupMembers;
  4802. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4803. groupMembers = *spawn->GetSpawnGroup();
  4804. }
  4805. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4806. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4807. deque<GroupMemberInfo*>::iterator itr;
  4808. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4809. if (group)
  4810. {
  4811. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4812. deque<GroupMemberInfo*>* members = group->GetMembers();
  4813. GroupMemberInfo* info = 0;
  4814. for (itr = members->begin(); itr != members->end(); itr++) {
  4815. info = *itr;
  4816. if (info->client)
  4817. groupMembers.push_back(info->client->GetPlayer());
  4818. }
  4819. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4820. }
  4821. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4822. }
  4823. else
  4824. return 0;
  4825. lua_createtable(state, groupMembers.size(), 0);
  4826. int newTable = lua_gettop(state);
  4827. for (int32 i = 0; i < groupMembers.size(); i++) {
  4828. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4829. lua_rawseti(state, newTable, i + 1);
  4830. }
  4831. return 1;
  4832. }
  4833. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4834. if (!lua_interface)
  4835. return 0;
  4836. lua_interface->ResetFunctionStack(state);
  4837. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4838. lua_interface->SetOptionWindowValue(state, option_window);
  4839. return 1;
  4840. }
  4841. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4842. if (!lua_interface)
  4843. return 0;
  4844. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4845. if (option_window) {
  4846. OptionWindowOption option_window_option;
  4847. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4848. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4849. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4850. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4851. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4852. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4853. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4854. option_window->push_back(option_window_option);
  4855. }
  4856. lua_interface->ResetFunctionStack(state);
  4857. return 0;
  4858. }
  4859. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4860. if (!lua_interface)
  4861. return 0;
  4862. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4863. Spawn* player = lua_interface->GetSpawn(state, 2);
  4864. string window_title = lua_interface->GetStringValue(state, 3);
  4865. string cancel_command = lua_interface->GetStringValue(state, 4);
  4866. lua_interface->ResetFunctionStack(state);
  4867. if (!player->IsPlayer()) {
  4868. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4869. return 0;
  4870. }
  4871. Client* client = ((Player*)player)->GetClient();
  4872. if (option_window && window_title.length() > 0 && client) {
  4873. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4874. if (!packet)
  4875. return 0;
  4876. packet->setDataByName("title_text", window_title.c_str());
  4877. if (cancel_command.length() > 0)
  4878. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4879. packet->setArrayLengthByName("num_selections", option_window->size());
  4880. vector<OptionWindowOption>::iterator itr;
  4881. int8 i = 0;
  4882. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4883. OptionWindowOption opt = *itr;
  4884. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4885. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4886. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4887. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4888. if (opt.optionCommand.length() > 0)
  4889. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4890. if (opt.optionConfirmTitle.length() > 0)
  4891. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4892. i++;
  4893. }
  4894. client->QueuePacket(packet->serialize());
  4895. lua_interface->SetLuaUserDataStale(option_window);
  4896. safe_delete(option_window);
  4897. safe_delete(packet);
  4898. }
  4899. return 0;
  4900. }
  4901. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4902. if (!lua_interface)
  4903. return 0;
  4904. Spawn* spawn = lua_interface->GetSpawn(state);
  4905. lua_interface->ResetFunctionStack(state);
  4906. if (spawn) {
  4907. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4908. return 1;
  4909. }
  4910. else
  4911. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4912. return 0;
  4913. }
  4914. int EQ2Emu_lua_GetTradeskillLevel(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->GetTSLevel());
  4921. return 1;
  4922. }
  4923. else
  4924. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4925. return 0;
  4926. }
  4927. int EQ2Emu_lua_GetTradeskillClassName(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. int8 class_id = spawn->GetTradeskillClass();
  4934. // Need to add 42 for the offset in the array
  4935. class_id += 44;
  4936. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4937. return 1;
  4938. }
  4939. else
  4940. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4941. return 0;
  4942. }
  4943. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4944. if (!lua_interface)
  4945. return 0;
  4946. Spawn* spawn = lua_interface->GetSpawn(state);
  4947. int16 level = lua_interface->GetInt8Value(state, 2);
  4948. lua_interface->ResetFunctionStack(state);
  4949. if (spawn) {
  4950. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4951. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4952. else
  4953. spawn->SetTSLevel(level);
  4954. }
  4955. else
  4956. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4957. return 0;
  4958. }
  4959. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4960. if (!lua_interface)
  4961. return 0;
  4962. Spawn* spawn = lua_interface->GetSpawn(state);
  4963. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4964. lua_interface->ResetFunctionStack(state);
  4965. if (spawn) {
  4966. spawn->SetAttackable(attackable);
  4967. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4968. }
  4969. return 0;
  4970. }
  4971. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4972. // Check to see if we have a valid lua_interface
  4973. if (!lua_interface)
  4974. return 0;
  4975. // Get the spawn that is getting the pet
  4976. Spawn* spawn = lua_interface->GetSpawn(state);
  4977. // Get the DB ID of the pet
  4978. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4979. // The max level the pet can gain
  4980. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4981. // Get the spell that this command was called from
  4982. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4983. lua_interface->ResetFunctionStack(state);
  4984. // Check to make sure the spawn pointer is valid
  4985. if (!spawn) {
  4986. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4987. return 0;
  4988. }
  4989. // Check to make sure the spawn is an entity
  4990. if (!spawn->IsEntity()) {
  4991. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4992. return 0;
  4993. }
  4994. // Check to make sure the spawn doesn't already have a pet of this type
  4995. if (((Entity*)spawn)->GetPet()) {
  4996. if (spawn->IsPlayer()) {
  4997. Client* client = ((Player*)spawn)->GetClient();
  4998. if (client)
  4999. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5000. }
  5001. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5002. return 0;
  5003. }
  5004. // Check to see if the DB ID for the pet is set
  5005. if (pet_id == 0) {
  5006. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5007. return 0;
  5008. }
  5009. // Check to see if the pointer to the spell is valid
  5010. if (!luaspell) {
  5011. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5012. return 0;
  5013. }
  5014. if(luaspell->resisted) {
  5015. return 0;
  5016. }
  5017. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5018. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5019. if (!pet) {
  5020. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5021. return 0;
  5022. }
  5023. // Check to make sure the pet is an npc
  5024. if (!pet->IsNPC()) {
  5025. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5026. return 0;
  5027. }
  5028. // Spawn the pet at the same location as the owner
  5029. pet->SetX(spawn->GetX());
  5030. pet->SetY(spawn->GetY());
  5031. pet->SetZ(spawn->GetZ());
  5032. pet->SetLocation(spawn->GetLocation());
  5033. pet->SetHeading(spawn->GetHeading());
  5034. std::string petName = std::string("");
  5035. if(spawn->IsEntity()) {
  5036. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5037. }
  5038. if(petName.size() < 1) {
  5039. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5040. petName = spawn->GetZone()->pet_names.at(rand_index);
  5041. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5042. }
  5043. // If player set various values for the char sheet (pet window)
  5044. if (spawn->IsPlayer()) {
  5045. Player* player = (Player*)spawn;
  5046. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5047. player->GetInfoStruct()->set_pet_name(petName);
  5048. player->GetInfoStruct()->set_pet_movement(2);
  5049. player->GetInfoStruct()->set_pet_behavior(3);
  5050. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5051. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5052. // Make sure the values get sent to the client
  5053. player->SetCharSheetChanged(true);
  5054. }
  5055. // Set the pets name
  5056. pet->SetName(petName.c_str());
  5057. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5058. if (max_level > 0)
  5059. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5060. else
  5061. pet->SetLevel(spawn->GetLevel());
  5062. // Set the max level this pet can reach
  5063. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5064. ((NPC*)pet)->UpdateWeapons();
  5065. // Set the faction of the pet to the same faction as the owner
  5066. pet->SetFactionID(spawn->GetFactionID());
  5067. // Set the spawn as a pet
  5068. pet->SetPet(true);
  5069. // Give a pointer of the owner to the pet
  5070. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5071. // Give a pointer of the pet to the owner
  5072. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5073. // Set the pet type
  5074. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5075. // Set the spell id used to create this pet
  5076. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5077. // Set the spell tier used to create this pet
  5078. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5079. // Set the pets spawn type to 6
  5080. pet->SetSpawnType(6);
  5081. // Set the pets brain
  5082. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5083. // Check to see if the pet has a subtitle
  5084. if (strlen(pet->GetSubTitle()) > 0) {
  5085. // Add the players name to the front of the sub title
  5086. string pet_subtitle;
  5087. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5088. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5089. // Set the pets subtitle to the new one
  5090. pet->SetSubTitle(pet_subtitle.c_str());
  5091. }
  5092. // Add the "Pet Options" entity command to the pet
  5093. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5094. const char* spawn_script = world.GetSpawnScript(pet_id);
  5095. bool runScript = false;
  5096. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5097. runScript = true;
  5098. pet->SetSpawnScript(string(spawn_script));
  5099. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5100. }
  5101. spawn->GetZone()->AddSpawn(pet);
  5102. if(runScript){
  5103. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5104. }
  5105. // Set the pet as the return value for this function
  5106. lua_interface->SetSpawnValue(state, pet);
  5107. return 1;
  5108. }
  5109. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5110. if (!lua_interface)
  5111. return 0;
  5112. Spawn* spawn = lua_interface->GetSpawn(state);
  5113. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5114. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5115. lua_interface->ResetFunctionStack(state);
  5116. if (!spawn) {
  5117. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5118. return 0;
  5119. }
  5120. if (!spawn->IsEntity()) {
  5121. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5122. return 0;
  5123. }
  5124. if (((Entity*)spawn)->GetDeityPet()) {
  5125. if (spawn->IsPlayer()) {
  5126. Client* client = ((Player*)spawn)->GetClient();
  5127. if (client)
  5128. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5129. }
  5130. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5131. return 0;
  5132. }
  5133. if (pet_id == 0) {
  5134. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5135. return 0;
  5136. }
  5137. if (!luaspell) {
  5138. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5139. return 0;
  5140. }
  5141. if(luaspell->resisted) {
  5142. return 0;
  5143. }
  5144. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5145. if (!pet) {
  5146. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5147. return 0;
  5148. }
  5149. if (!pet->IsNPC()) {
  5150. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5151. return 0;
  5152. }
  5153. pet->SetX(spawn->GetX());
  5154. pet->SetY(spawn->GetY());
  5155. pet->SetZ(spawn->GetZ());
  5156. pet->SetLocation(spawn->GetLocation());
  5157. pet->SetHeading(spawn->GetHeading());
  5158. spawn->GetZone()->AddSpawn(pet);
  5159. string random_pet_name;
  5160. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5161. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5162. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5163. pet->SetName(random_pet_name.c_str());
  5164. pet->SetLevel(spawn->GetLevel());
  5165. pet->SetFactionID(spawn->GetFactionID());
  5166. pet->SetPet(true);
  5167. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5168. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5169. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5170. pet->SetSpawnType(6);
  5171. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5172. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5173. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5174. if (strlen(pet->GetSubTitle()) > 0) {
  5175. string pet_subtitle;
  5176. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5177. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5178. pet->SetSubTitle(pet_subtitle.c_str());
  5179. }
  5180. // deity and cosmetic pets are not attackable
  5181. pet->SetAttackable(false);
  5182. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5183. lua_interface->SetSpawnValue(state, pet);
  5184. return 1;
  5185. }
  5186. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5187. if (!lua_interface)
  5188. return 0;
  5189. Spawn* spawn = lua_interface->GetSpawn(state);
  5190. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5191. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5192. lua_interface->ResetFunctionStack(state);
  5193. if (!spawn) {
  5194. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5195. return 0;
  5196. }
  5197. if (!spawn->IsEntity()) {
  5198. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5199. return 0;
  5200. }
  5201. if (((Entity*)spawn)->GetCosmeticPet()) {
  5202. if (spawn->IsPlayer()) {
  5203. Client* client = ((Player*)spawn)->GetClient();
  5204. if (client)
  5205. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5206. }
  5207. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5208. return 0;
  5209. }
  5210. if (pet_id == 0) {
  5211. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5212. return 0;
  5213. }
  5214. if (!luaspell) {
  5215. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5216. return 0;
  5217. }
  5218. if(luaspell->resisted) {
  5219. return 0;
  5220. }
  5221. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5222. if (!pet) {
  5223. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5224. return 0;
  5225. }
  5226. if (!pet->IsNPC()) {
  5227. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5228. return 0;
  5229. }
  5230. pet->SetX(spawn->GetX());
  5231. pet->SetY(spawn->GetY());
  5232. pet->SetZ(spawn->GetZ());
  5233. pet->SetLocation(spawn->GetLocation());
  5234. pet->SetHeading(spawn->GetHeading());
  5235. spawn->GetZone()->AddSpawn(pet);
  5236. string random_pet_name;
  5237. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5238. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5239. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5240. pet->SetName(random_pet_name.c_str());
  5241. pet->SetLevel(spawn->GetLevel());
  5242. pet->SetFactionID(spawn->GetFactionID());
  5243. pet->SetPet(true);
  5244. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5245. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5246. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5247. pet->SetSpawnType(6);
  5248. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5249. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5250. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5251. if (strlen(pet->GetSubTitle()) > 0) {
  5252. string pet_subtitle;
  5253. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5254. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5255. pet->SetSubTitle(pet_subtitle.c_str());
  5256. }
  5257. pet->SetAttackable(false);
  5258. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5259. lua_interface->SetSpawnValue(state, pet);
  5260. return 1;
  5261. }
  5262. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5263. if (!lua_interface)
  5264. return 0;
  5265. Spawn* spawn = lua_interface->GetSpawn(state);
  5266. lua_interface->ResetFunctionStack(state);
  5267. if (!spawn) {
  5268. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5269. return 0;
  5270. }
  5271. if (!spawn->IsPet()) {
  5272. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5273. return 0;
  5274. }
  5275. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5276. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5277. return 0;
  5278. }
  5279. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5280. if (!lua_interface)
  5281. return 0;
  5282. Quest* quest = lua_interface->GetQuest(state);
  5283. if (!quest) {
  5284. 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));
  5285. lua_interface->ResetFunctionStack(state);
  5286. return 0;
  5287. }
  5288. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5289. lua_interface->ResetFunctionStack(state);
  5290. if (feather_color > 0)
  5291. quest->SetFeatherColor(feather_color);
  5292. return 0;
  5293. }
  5294. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5295. if (!lua_interface)
  5296. return 0;
  5297. Spawn* spawn = lua_interface->GetSpawn(state);
  5298. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5299. lua_interface->ResetFunctionStack(state);
  5300. if (!spawn) {
  5301. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5302. return 0;
  5303. }
  5304. if (!spawn2) {
  5305. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5306. return 0;
  5307. }
  5308. spawn->RemoveSpawnAccess(spawn2);
  5309. return 0;
  5310. }
  5311. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5312. if (!lua_interface)
  5313. return 0;
  5314. ZoneServer* zone = lua_interface->GetZone(state);
  5315. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5316. lua_interface->ResetFunctionStack(state);
  5317. if (!zone) {
  5318. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. if (location_id == 0) {
  5322. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5323. return 0;
  5324. }
  5325. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5326. if (!location) {
  5327. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5328. return 0;
  5329. }
  5330. Spawn* spawn = 0;
  5331. if (location->entities[0]) {
  5332. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5333. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5334. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5335. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5336. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5337. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5338. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5339. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5340. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5341. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5342. if(spawn && spawn->IsOmittedByDBFlag())
  5343. {
  5344. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5345. safe_delete(spawn);
  5346. spawn = 0;
  5347. return 0;
  5348. }
  5349. if (spawn) {
  5350. const char* script = 0;
  5351. for (int x = 0; x < 3; x++) {
  5352. switch (x) {
  5353. case 0:
  5354. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5355. break;
  5356. case 1:
  5357. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5358. break;
  5359. case 2:
  5360. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5361. break;
  5362. }
  5363. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5364. spawn->SetSpawnScript(string(script));
  5365. break;
  5366. }
  5367. }
  5368. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5369. lua_interface->SetSpawnValue(state, spawn);
  5370. return 1;
  5371. }
  5372. else {
  5373. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5374. safe_delete(spawn);
  5375. }
  5376. }
  5377. return 0;
  5378. }
  5379. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5380. if (!lua_interface)
  5381. return 0;
  5382. Spawn* caster = lua_interface->GetSpawn(state);
  5383. Spawn* target = lua_interface->GetSpawn(state, 2);
  5384. int32 id = lua_interface->GetInt32Value(state, 3);
  5385. string command = lua_interface->GetStringValue(state, 4);
  5386. lua_interface->ResetFunctionStack(state);
  5387. if (!caster) {
  5388. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5389. return 0;
  5390. }
  5391. if (!target) {
  5392. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5393. return 0;
  5394. }
  5395. if (!caster->IsPlayer()) {
  5396. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5397. return 0;
  5398. }
  5399. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5400. if (!entity_command) {
  5401. 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());
  5402. return 0;
  5403. }
  5404. Client* client = ((Player*)caster)->GetClient();
  5405. if (!client) {
  5406. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5407. return 0;
  5408. }
  5409. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5410. return 0;
  5411. }
  5412. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5413. if (!lua_interface)
  5414. return 0;
  5415. Spawn* spawn = lua_interface->GetSpawn(state);
  5416. lua_interface->ResetFunctionStack(state);
  5417. if (!spawn) {
  5418. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5419. return 0;
  5420. }
  5421. if (!spawn->IsNPC()) {
  5422. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5423. return 0;
  5424. }
  5425. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5426. return 0;
  5427. }
  5428. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5429. if (!lua_interface)
  5430. return 0;
  5431. Spawn* spawn = lua_interface->GetSpawn(state);
  5432. int16 tick = lua_interface->GetInt16Value(state, 2);
  5433. lua_interface->ResetFunctionStack(state);
  5434. if (!spawn) {
  5435. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5436. return 0;
  5437. }
  5438. if (!spawn->IsNPC()) {
  5439. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5440. return 0;
  5441. }
  5442. if (tick < 20) {
  5443. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5444. return 0;
  5445. }
  5446. ((NPC*)spawn)->Brain()->SetTick(tick);
  5447. return 0;
  5448. }
  5449. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5450. if (!lua_interface)
  5451. return 0;
  5452. Spawn* spawn = lua_interface->GetSpawn(state);
  5453. Spawn* target = lua_interface->GetSpawn(state, 2);
  5454. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5455. lua_interface->ResetFunctionStack(state);
  5456. if (!spawn) {
  5457. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5458. return 0;
  5459. }
  5460. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5461. spawn->SetFollowTarget(target, follow_distance);
  5462. return 0;
  5463. }
  5464. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5465. if (!lua_interface)
  5466. return 0;
  5467. Spawn* spawn = lua_interface->GetSpawn(state);
  5468. lua_interface->ResetFunctionStack(state);
  5469. if (!spawn) {
  5470. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5471. return 0;
  5472. }
  5473. Spawn* target = spawn->GetFollowTarget();
  5474. if (target) {
  5475. lua_interface->SetSpawnValue(state, target);
  5476. return 1;
  5477. }
  5478. return 0;
  5479. }
  5480. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5481. if (!lua_interface)
  5482. return 0;
  5483. Spawn* spawn = lua_interface->GetSpawn(state);
  5484. lua_interface->ResetFunctionStack(state);
  5485. if (!spawn) {
  5486. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5487. return 0;
  5488. }
  5489. if (spawn->following)
  5490. spawn->following = false;
  5491. else
  5492. spawn->following = true;
  5493. return 0;
  5494. }
  5495. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5496. if (!lua_interface)
  5497. return 0;
  5498. Spawn* spawn = lua_interface->GetSpawn(state);
  5499. lua_interface->ResetFunctionStack(state);
  5500. if (!spawn) {
  5501. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5502. return 0;
  5503. }
  5504. lua_interface->SetBooleanValue(state, spawn->following);
  5505. return 1;
  5506. }
  5507. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5508. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5509. // I will attempt to explain how this function works for future refrence
  5510. // Fist lets make sure lua_interface is valid, if not return out
  5511. if (!lua_interface)
  5512. return 0;
  5513. // Next we grab the first 2 params same as we usually would
  5514. Spawn* spawn = lua_interface->GetSpawn(state);
  5515. string var = lua_interface->GetStringValue(state, 2);
  5516. // 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
  5517. // 1 = Spawn
  5518. // 2 = Zone
  5519. // 3 = Item
  5520. // 4 = Quest
  5521. // 5 = String
  5522. // 6 = nil (null)
  5523. int8 dataType = 0;
  5524. // Define pointers for each potential type
  5525. Spawn* spawnVal = 0;
  5526. ZoneServer* zone = 0;
  5527. Item* item = 0;
  5528. Quest* quest = 0;
  5529. string val;
  5530. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5531. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5532. // options window are also light user data be we do not handle those.
  5533. // We check with lua_islightuserdata(lua_State*, index)
  5534. if (lua_islightuserdata(state, 3)) {
  5535. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5536. // and convert it to LUAUserData*
  5537. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5538. // Check to make sure the data we got is valid, if not give an error
  5539. if (!data || !data->IsCorrectlyInitialized()) {
  5540. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5541. }
  5542. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5543. else if (data->IsSpawn()) {
  5544. spawnVal = data->spawn;
  5545. dataType = 1;
  5546. }
  5547. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5548. else if (data->IsZone()) {
  5549. zone = data->zone;
  5550. dataType = 2;
  5551. }
  5552. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5553. else if (data->IsItem()) {
  5554. item = data->item;
  5555. dataType = 3;
  5556. }
  5557. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5558. else if (data->IsQuest()) {
  5559. quest = data->quest;
  5560. dataType = 4;
  5561. }
  5562. }
  5563. // Wasn't light user data, check if it is nil(null)
  5564. else if (lua_isnil(state, 3)) {
  5565. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5566. dataType = 6;
  5567. }
  5568. // Wasn't light user data or nil (null), must be a string
  5569. else {
  5570. // Set the string and dataType variable
  5571. val = lua_interface->GetStringValue(state, 3);
  5572. dataType = 5;
  5573. }
  5574. lua_interface->ResetFunctionStack(state);
  5575. // We now have all the params, lets check to make sure they are valid
  5576. if (!spawn) {
  5577. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5578. return 0;
  5579. }
  5580. if (var.length() == 0) {
  5581. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5582. return 0;
  5583. }
  5584. if (dataType == 0) {
  5585. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5586. return 0;
  5587. }
  5588. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5589. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5590. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5591. switch (dataType) {
  5592. case 1:
  5593. // 1 = Spawn
  5594. spawn->AddTempVariable(var, spawnVal);
  5595. break;
  5596. case 2:
  5597. // 2 = Zone
  5598. spawn->AddTempVariable(var, zone);
  5599. break;
  5600. case 3:
  5601. // 3 = Item
  5602. spawn->AddTempVariable(var, item);
  5603. break;
  5604. case 4:
  5605. // 4 = Quest
  5606. spawn->AddTempVariable(var, quest);
  5607. break;
  5608. case 5:
  5609. // 5 = String
  5610. spawn->AddTempVariable(var, val);
  5611. break;
  5612. case 6:
  5613. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5614. spawn->DeleteTempVariable(var);
  5615. break;
  5616. }
  5617. // And we are done so return out
  5618. return 0;
  5619. }
  5620. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5621. if (!lua_interface)
  5622. return 0;
  5623. Spawn* spawn = lua_interface->GetSpawn(state);
  5624. string var = lua_interface->GetStringValue(state, 2);
  5625. lua_interface->ResetFunctionStack(state);
  5626. if (!spawn) {
  5627. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5628. return 0;
  5629. }
  5630. if (var.length() == 0) {
  5631. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5632. return 0;
  5633. }
  5634. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5635. int8 type = spawn->GetTempVariableType(var);
  5636. Spawn* spawn2 = 0;
  5637. ZoneServer* zone = 0;
  5638. Item* item = 0;
  5639. Quest* quest = 0;
  5640. // Set the lua function return value based on the type of data the variable contains
  5641. switch (type) {
  5642. case 1:
  5643. spawn2 = spawn->GetTempVariableSpawn(var);
  5644. if (!spawn2)
  5645. return 0;
  5646. lua_interface->SetSpawnValue(state, spawn2);
  5647. break;
  5648. case 2:
  5649. zone = spawn->GetTempVariableZone(var);
  5650. if (!zone)
  5651. return 0;
  5652. lua_interface->SetZoneValue(state, zone);
  5653. break;
  5654. case 3:
  5655. item = spawn->GetTempVariableItem(var);
  5656. if (!item)
  5657. return 0;
  5658. lua_interface->SetItemValue(state, item);
  5659. break;
  5660. case 4:
  5661. quest = spawn->GetTempVariableQuest(var);
  5662. if (!quest)
  5663. return 0;
  5664. lua_interface->SetQuestValue(state, quest);
  5665. break;
  5666. case 5:
  5667. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5668. break;
  5669. default:
  5670. // Not a valid type then the variable was not set so return out
  5671. return 0;
  5672. }
  5673. // Return value was set so return out
  5674. return 1;
  5675. }
  5676. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5677. {
  5678. if (!lua_interface)
  5679. return 0;
  5680. Quest* quest = lua_interface->GetQuest(state);
  5681. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5682. string description = lua_interface->GetStringValue(state, 3);
  5683. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5684. if (!quest) {
  5685. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5686. lua_interface->ResetFunctionStack(state);
  5687. lua_interface->SetBooleanValue(state, false);
  5688. return 1;
  5689. }
  5690. if (!spawn) {
  5691. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5692. lua_interface->ResetFunctionStack(state);
  5693. lua_interface->SetBooleanValue(state, false);
  5694. return 1;
  5695. }
  5696. if (!spawn->IsPlayer()) {
  5697. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5698. lua_interface->ResetFunctionStack(state);
  5699. lua_interface->SetBooleanValue(state, false);
  5700. return 1;
  5701. }
  5702. if (item_id == 0) {
  5703. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5704. lua_interface->ResetFunctionStack(state);
  5705. lua_interface->SetBooleanValue(state, false);
  5706. return 1;
  5707. }
  5708. Client* client = ((Player*)spawn)->GetClient();
  5709. if (!client) {
  5710. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5711. lua_interface->ResetFunctionStack(state);
  5712. lua_interface->SetBooleanValue(state, false);
  5713. return 1;
  5714. }
  5715. Item* item = master_item_list.GetItem(item_id);
  5716. if (!item) {
  5717. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5718. lua_interface->ResetFunctionStack(state);
  5719. lua_interface->SetBooleanValue(state, false);
  5720. return 1;
  5721. }
  5722. Item* firstItem = new Item(item);
  5723. quest->AddTmpRewardItem(firstItem);
  5724. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5725. bool itemsAddedSuccessfully = true;
  5726. if(num_args > 4)
  5727. {
  5728. for(int8 n=5;n<num_args+1;n++)
  5729. {
  5730. int32 new_item = lua_interface->GetInt32Value(state, n);
  5731. Item* tmpItem = master_item_list.GetItem(new_item);
  5732. if(tmpItem)
  5733. {
  5734. Item* newTmpItem = new Item(tmpItem);
  5735. quest->AddTmpRewardItem(newTmpItem);
  5736. }
  5737. else
  5738. itemsAddedSuccessfully = false;
  5739. }
  5740. }
  5741. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5742. lua_interface->ResetFunctionStack(state);
  5743. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5744. return 1;
  5745. }
  5746. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5747. if (!lua_interface)
  5748. return 0;
  5749. Quest* quest = lua_interface->GetQuest(state);
  5750. lua_interface->ResetFunctionStack(state);
  5751. if (!quest) {
  5752. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5753. return 0;
  5754. }
  5755. quest->SetRepeatable(true);
  5756. return 0;
  5757. }
  5758. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5759. if (!lua_interface)
  5760. return 0;
  5761. Spawn* spawn = lua_interface->GetSpawn(state);
  5762. lua_interface->ResetFunctionStack(state);
  5763. if (!spawn) {
  5764. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5765. return 0;
  5766. }
  5767. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5768. string ret = classes.GetClassNameCase(base_class);
  5769. if (ret.length() > 0) {
  5770. lua_interface->SetStringValue(state, ret.c_str());
  5771. return 1;
  5772. }
  5773. return 0;
  5774. }
  5775. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5776. if (!lua_interface)
  5777. return 0;
  5778. Spawn* player = lua_interface->GetSpawn(state);
  5779. lua_interface->ResetFunctionStack(state);
  5780. if (player && player->IsPlayer()) {
  5781. Client* client = player->GetClient();
  5782. if (client)
  5783. client->SendWaypoints();
  5784. }
  5785. return 0;
  5786. }
  5787. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5788. if (!lua_interface)
  5789. return 0;
  5790. Spawn* player = lua_interface->GetSpawn(state);
  5791. string name = lua_interface->GetStringValue(state, 2);
  5792. int32 type = lua_interface->GetInt32Value(state, 3);
  5793. lua_interface->ResetFunctionStack(state);
  5794. if (type == 0)
  5795. type = 2;
  5796. if (name.length() > 0) {
  5797. if (player && player->IsPlayer()) {
  5798. Client* client = player->GetClient();
  5799. if (client)
  5800. client->AddWaypoint(name, type);
  5801. }
  5802. }
  5803. return 0;
  5804. }
  5805. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5806. if (!lua_interface)
  5807. return 0;
  5808. Spawn* player = lua_interface->GetSpawn(state);
  5809. string name = lua_interface->GetStringValue(state, 2);
  5810. lua_interface->ResetFunctionStack(state);
  5811. if (name.length() > 0) {
  5812. if (player && player->IsPlayer()) {
  5813. Client* client = player->GetClient();
  5814. if (client)
  5815. client->RemoveWaypoint(name);
  5816. }
  5817. }
  5818. return 0;
  5819. }
  5820. int EQ2Emu_lua_AddWard(lua_State* state) {
  5821. if (!lua_interface)
  5822. return 0;
  5823. int32 damage = lua_interface->GetInt32Value(state);
  5824. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5825. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5826. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5827. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5828. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5829. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5830. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5831. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5832. lua_interface->ResetFunctionStack(state);
  5833. if(!spell || spell->resisted) {
  5834. return 0;
  5835. }
  5836. bool ward_was_added = false;
  5837. ZoneServer* zone = spell->caster->GetZone();
  5838. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5839. for (int32 i = 0; i < spell->targets.size(); i++) {
  5840. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5841. if (!target)
  5842. continue;
  5843. if (target->IsEntity()) {
  5844. // If the ward is already active remove it
  5845. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5846. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5847. // Create new ward info
  5848. WardInfo* ward = new WardInfo;
  5849. ward->Spell = spell;
  5850. ward->BaseDamage = damage;
  5851. ward->DamageLeft = damage;
  5852. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5853. ward->keepWard = keepWard;
  5854. ward->WardType = wardType;
  5855. if (damageAbsorptionPercent > 100)
  5856. damageAbsorptionPercent = 100;
  5857. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5858. if (damageAbsorptionMaxHealthPercent > 100)
  5859. damageAbsorptionMaxHealthPercent = 100;
  5860. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5861. ward->RedirectDamagePercent = redirectDamagePercent;
  5862. ward->LastRedirectDamage = 0;
  5863. ward->LastAbsorbedDamage = 0;
  5864. ward->HitCount = 0;
  5865. spell->num_triggers = maxHitCount;
  5866. spell->had_triggers = true;
  5867. spell->cancel_after_all_triggers = false;
  5868. ward->MaxHitCount = maxHitCount;
  5869. ward->RoundTriggered = false;
  5870. if (wardType == WARD_TYPE_MAGICAL)
  5871. ward->DamageType = damageTypes;
  5872. // Add the ward to the entity
  5873. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5874. ward_was_added = true;
  5875. }
  5876. }
  5877. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5878. if (ward_was_added && spell->caster->IsPlayer()) {
  5879. spell->had_dmg_remaining = true;
  5880. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5881. }
  5882. return 0;
  5883. }
  5884. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5885. if (!lua_interface)
  5886. return 0;
  5887. int32 amount = lua_interface->GetInt32Value(state);
  5888. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5889. lua_interface->ResetFunctionStack(state);
  5890. WardInfo* ward = 0;
  5891. if(!spell || spell->resisted) {
  5892. return 0;
  5893. }
  5894. ZoneServer* zone = spell->caster->GetZone();
  5895. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5896. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5897. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5898. ward = target->GetWard(spell->spell->GetSpellID());
  5899. if (target && ward) {
  5900. ward->DamageLeft += amount;
  5901. if (ward->DamageLeft > ward->BaseDamage)
  5902. ward->DamageLeft = ward->BaseDamage;
  5903. for (int32 i = 0; i < spell->targets.size(); i++) {
  5904. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5905. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5906. }
  5907. }
  5908. }
  5909. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5910. if (ward && spell->caster->IsPlayer())
  5911. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5912. return 0;
  5913. }
  5914. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5915. if (!lua_interface)
  5916. return 0;
  5917. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5918. lua_interface->ResetFunctionStack(state);
  5919. if (!spell) {
  5920. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5921. return 0;
  5922. }
  5923. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5924. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5925. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5926. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5927. if (ward) {
  5928. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5929. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5930. return 1;
  5931. }
  5932. }
  5933. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5934. return 0;
  5935. }
  5936. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5937. if (!lua_interface)
  5938. return 0;
  5939. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5940. if (!spell) {
  5941. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5942. lua_interface->ResetFunctionStack(state);
  5943. return 0;
  5944. }
  5945. string type = lua_interface->GetStringValue(state, 2);
  5946. lua_interface->ResetFunctionStack(state);
  5947. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5948. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5949. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5950. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5951. if (ward) {
  5952. if (boost::iequals(type, "damageleft"))
  5953. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5954. else if (boost::iequals(type, "basedamage"))
  5955. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5956. else if (boost::iequals(type, "keepward"))
  5957. lua_interface->SetBooleanValue(state, ward->keepWard);
  5958. else if (boost::iequals(type, "wardtype"))
  5959. lua_interface->SetInt32Value(state, ward->WardType);
  5960. else if (boost::iequals(type, "dmgabsorptionpct"))
  5961. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5962. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5963. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5964. else if (boost::iequals(type, "redirectdamagepercent"))
  5965. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5966. else if (boost::iequals(type, "lastredirectdamage"))
  5967. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5968. else if (boost::iequals(type, "lastabsorbeddamage"))
  5969. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5970. else if (boost::iequals(type, "hitcount"))
  5971. lua_interface->SetInt32Value(state, ward->HitCount);
  5972. else if (boost::iequals(type, "maxhitcount"))
  5973. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5974. else
  5975. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5976. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5977. return 1;
  5978. }
  5979. }
  5980. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5981. return 0;
  5982. }
  5983. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5984. if (!lua_interface)
  5985. return 0;
  5986. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5987. lua_interface->ResetFunctionStack(state);
  5988. if(!spell) {
  5989. return 0;
  5990. }
  5991. ZoneServer* zone = spell->caster->GetZone();
  5992. Spawn* target = 0;
  5993. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5994. for (int32 i = 0; i < spell->targets.size(); i++) {
  5995. target = zone->GetSpawnByID(spell->targets.at(i));
  5996. if (target && target->IsEntity()) {
  5997. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5998. }
  5999. }
  6000. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6001. return 0;
  6002. }
  6003. int EQ2Emu_lua_Interrupt(lua_State* state)
  6004. {
  6005. if (!lua_interface)
  6006. return 0;
  6007. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6008. Spawn* target = lua_interface->GetSpawn(state, 2);
  6009. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6010. lua_interface->ResetFunctionStack(state);
  6011. if (!caster)
  6012. {
  6013. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6014. return 0;
  6015. }
  6016. if (!target)
  6017. {
  6018. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6019. return 0;
  6020. }
  6021. if (!spell) {
  6022. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6023. return 0;
  6024. }
  6025. if (!target->IsEntity() && !spell)
  6026. {
  6027. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6028. return 0;
  6029. }
  6030. if (!target && spell) {
  6031. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6032. for (int8 i = 0; i < spell->targets.size(); i++) {
  6033. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6034. if (!target || !target->IsEntity())
  6035. continue;
  6036. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6037. }
  6038. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6039. }
  6040. else
  6041. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6042. return 0;
  6043. }
  6044. int EQ2Emu_lua_Stealth(lua_State* state) {
  6045. if (!lua_interface)
  6046. return 0;
  6047. int8 type = lua_interface->GetInt8Value(state);
  6048. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6049. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6050. lua_interface->ResetFunctionStack(state);
  6051. if (!spell) {
  6052. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6053. return 0;
  6054. }
  6055. ZoneServer* zone = spell->caster->GetZone();
  6056. if (spawn) {
  6057. if (spawn->IsEntity()) {
  6058. if (type == 1) {
  6059. ((Entity*)spawn)->AddStealthSpell(spell);
  6060. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6061. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6062. }
  6063. else if (type == 2) {
  6064. ((Entity*)spawn)->AddInvisSpell(spell);
  6065. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6066. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6067. }
  6068. return 0;
  6069. }
  6070. else {
  6071. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6072. return 0;
  6073. }
  6074. }
  6075. else {
  6076. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6077. for (int32 i = 0; i < spell->targets.size(); i++) {
  6078. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6079. if (!spawn || !spawn->IsEntity())
  6080. continue;
  6081. if (type == 1) {
  6082. ((Entity*)spawn)->AddStealthSpell(spell);
  6083. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6084. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6085. }
  6086. else if (type == 2) {
  6087. ((Entity*)spawn)->AddInvisSpell(spell);
  6088. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6089. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6090. }
  6091. else {
  6092. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6093. break;
  6094. }
  6095. }
  6096. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6097. }
  6098. return 0;
  6099. }
  6100. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6101. if (!lua_interface)
  6102. return 0;
  6103. Spawn* spawn = lua_interface->GetSpawn(state);
  6104. lua_interface->ResetFunctionStack(state);
  6105. if (!spawn) {
  6106. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6107. return 0;
  6108. }
  6109. if (spawn->IsEntity()) {
  6110. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6111. return 1;
  6112. }
  6113. else
  6114. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6115. return 0;
  6116. }
  6117. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6118. if (!lua_interface)
  6119. return 0;
  6120. Spawn* spawn = lua_interface->GetSpawn(state);
  6121. lua_interface->ResetFunctionStack(state);
  6122. if (!spawn) {
  6123. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6124. return 0;
  6125. }
  6126. if (spawn->IsEntity()) {
  6127. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6128. return 1;
  6129. }
  6130. else
  6131. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6132. return 0;
  6133. }
  6134. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6135. if (!lua_interface)
  6136. return 0;
  6137. Spawn* player = lua_interface->GetSpawn(state);
  6138. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6139. lua_interface->ResetFunctionStack(state);
  6140. if (!player->IsPlayer()) {
  6141. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6142. return 0;
  6143. }
  6144. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6145. return 1;
  6146. }
  6147. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6148. if (!lua_interface)
  6149. return 0;
  6150. Spawn* spawn = lua_interface->GetSpawn(state);
  6151. int8 slot = lua_interface->GetInt8Value(state, 2);
  6152. lua_interface->ResetFunctionStack(state);
  6153. if (!spawn) {
  6154. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6155. return 0;
  6156. }
  6157. if (!spawn->IsEntity()) {
  6158. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6159. return 0;
  6160. }
  6161. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6162. if (!item) {
  6163. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6164. return 0;
  6165. }
  6166. lua_interface->SetItemValue(state, item);
  6167. return 1;
  6168. }
  6169. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6170. if (!lua_interface)
  6171. return 0;
  6172. Spawn* player = lua_interface->GetSpawn(state);
  6173. int32 id = lua_interface->GetInt32Value(state, 2);
  6174. lua_interface->ResetFunctionStack(state);
  6175. if (!player) {
  6176. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6177. return 0;
  6178. }
  6179. if (!player->IsPlayer()) {
  6180. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6181. return 0;
  6182. }
  6183. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6184. if (!item) {
  6185. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6186. return 0;
  6187. }
  6188. lua_interface->SetItemValue(state, item);
  6189. return 1;
  6190. }
  6191. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6192. if (!lua_interface)
  6193. return 0;
  6194. Spawn* spawn = lua_interface->GetSpawn(state);
  6195. int8 slot = lua_interface->GetInt8Value(state, 2);
  6196. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6197. lua_interface->ResetFunctionStack(state);
  6198. if (!spawn) {
  6199. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6200. return 0;
  6201. }
  6202. if (!spawn->IsEntity()) {
  6203. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6204. return 0;
  6205. }
  6206. Item* item = master_item_list.GetItem(item_id);
  6207. if (!item) {
  6208. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6209. return 0;
  6210. }
  6211. Item* copy = new Item(item);
  6212. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6213. if(result)
  6214. {
  6215. ((Entity*)spawn)->SetEquipment(copy, slot);
  6216. spawn->vis_changed = true;
  6217. if(spawn->IsPlayer())
  6218. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6219. }
  6220. else
  6221. {
  6222. safe_delete(copy);
  6223. }
  6224. lua_interface->SetBooleanValue(state, result);
  6225. return 1;
  6226. }
  6227. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6228. if (!lua_interface)
  6229. return 0;
  6230. Spawn* spawn = lua_interface->GetSpawn(state);
  6231. int8 slot = lua_interface->GetInt8Value(state, 2);
  6232. Item* item = lua_interface->GetItem(state, 3);
  6233. lua_interface->ResetFunctionStack(state);
  6234. if (!spawn) {
  6235. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. if (!spawn->IsEntity()) {
  6239. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. if (!item) {
  6243. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6244. return 0;
  6245. }
  6246. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6247. if(result)
  6248. {
  6249. ((Entity*)spawn)->SetEquipment(item, slot);
  6250. spawn->vis_changed = true;
  6251. if(spawn->IsPlayer())
  6252. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6253. }
  6254. lua_interface->SetBooleanValue(state, result);
  6255. return 1;
  6256. }
  6257. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6258. if (!lua_interface)
  6259. return 0;
  6260. Spawn* spawn = lua_interface->GetSpawn(state);
  6261. int8 slot = lua_interface->GetInt8Value(state, 2);
  6262. 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
  6263. lua_interface->ResetFunctionStack(state);
  6264. if (!spawn) {
  6265. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6266. return 0;
  6267. }
  6268. if (!spawn->IsEntity()) {
  6269. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. if(slot >= NUM_SLOTS) {
  6273. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6274. return 0;
  6275. }
  6276. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6277. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6278. if(item) {
  6279. item->save_needed = true;
  6280. if(no_delete_item) {
  6281. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6282. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6283. }
  6284. else{
  6285. Client* client = ((Player*)spawn)->GetClient();
  6286. client->UnequipItem(item->details.index);
  6287. }
  6288. }
  6289. }
  6290. else
  6291. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6292. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6293. spawn->vis_changed = true;
  6294. if(spawn->IsPlayer())
  6295. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6296. lua_interface->SetBooleanValue(state, true);
  6297. return 1;
  6298. }
  6299. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6300. if (!lua_interface)
  6301. return 0;
  6302. Spawn* spawn = lua_interface->GetSpawn(state);
  6303. int8 slot = lua_interface->GetInt8Value(state, 2);
  6304. int16 type = lua_interface->GetInt16Value(state, 3);
  6305. int8 r = lua_interface->GetInt8Value(state, 4);
  6306. int8 g = lua_interface->GetInt8Value(state, 5);
  6307. int8 b = lua_interface->GetInt8Value(state, 6);
  6308. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6309. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6310. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6311. lua_interface->ResetFunctionStack(state);
  6312. if (!spawn) {
  6313. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6314. return 0;
  6315. }
  6316. if (!spawn->IsEntity()) {
  6317. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6318. return 0;
  6319. }
  6320. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6321. spawn->vis_changed = true;
  6322. lua_interface->SetBooleanValue(state, true);
  6323. return 1;
  6324. }
  6325. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6326. if (!lua_interface)
  6327. return 0;
  6328. Spawn* player = lua_interface->GetSpawn(state);
  6329. int32 id = lua_interface->GetInt32Value(state, 2);
  6330. int8 count = lua_interface->GetInt8Value(state, 3);
  6331. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6332. lua_interface->ResetFunctionStack(state);
  6333. if (!player) {
  6334. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6335. return 0;
  6336. }
  6337. if (!player->IsPlayer()) {
  6338. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6339. return 0;
  6340. }
  6341. if (!count)
  6342. count = 1;
  6343. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6344. if (!item) {
  6345. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6346. return 0;
  6347. }
  6348. lua_interface->SetItemValue(state, item);
  6349. return 1;
  6350. }
  6351. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6352. if (!lua_interface)
  6353. return 0;
  6354. Spawn* spawn = lua_interface->GetSpawn(state);
  6355. int32 anim = lua_interface->GetInt32Value(state, 2);
  6356. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6357. int8 type = lua_interface->GetInt8Value(state, 4);
  6358. lua_interface->ResetFunctionStack(state);
  6359. if (!spawn) {
  6360. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6361. return 0;
  6362. }
  6363. if (spawn2) {
  6364. if (spawn2->IsPlayer()) {
  6365. if (type != 1 && type != 2)
  6366. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6367. else
  6368. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6369. return 0;
  6370. }
  6371. else {
  6372. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6373. return 0;
  6374. }
  6375. }
  6376. else
  6377. spawn->GetZone()->PlayAnimation(spawn, anim);
  6378. return 0;
  6379. }
  6380. int EQ2Emu_lua_IsPet(lua_State* state) {
  6381. if (!lua_interface)
  6382. return 0;
  6383. Spawn* spawn = lua_interface->GetSpawn(state);
  6384. lua_interface->ResetFunctionStack(state);
  6385. if (!spawn) {
  6386. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6387. return 0;
  6388. }
  6389. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6390. return 1;
  6391. }
  6392. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6393. if (!lua_interface)
  6394. return 0;
  6395. Spawn* spawn = lua_interface->GetSpawn(state);
  6396. lua_interface->ResetFunctionStack(state);
  6397. if (!spawn) {
  6398. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6399. return 0;
  6400. }
  6401. if (!spawn->IsNPC()) {
  6402. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6403. return 0;
  6404. }
  6405. if (((NPC*)spawn)->GetOwner()) {
  6406. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6407. return 1;
  6408. }
  6409. return 0;
  6410. }
  6411. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6412. if (!lua_interface)
  6413. return 0;
  6414. Spawn* spawn = lua_interface->GetSpawn(state);
  6415. Spawn* target = lua_interface->GetSpawn(state, 2);
  6416. lua_interface->ResetFunctionStack(state);
  6417. if (!spawn) {
  6418. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6419. return 0;
  6420. }
  6421. if (!spawn) {
  6422. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6423. return 0;
  6424. }
  6425. spawn->SetTarget(target);
  6426. return 0;
  6427. }
  6428. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6429. if (!lua_interface)
  6430. return 0;
  6431. Spawn* spawn = lua_interface->GetSpawn(state);
  6432. bool val = lua_interface->GetBooleanValue(state, 2);
  6433. lua_interface->ResetFunctionStack(state);
  6434. if (!spawn) {
  6435. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6436. return 0;
  6437. }
  6438. if (!spawn->IsEntity()) {
  6439. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6440. return 0;
  6441. }
  6442. ((Entity*)spawn)->InCombat(val);
  6443. if (val) {
  6444. spawn->ClearRunningLocations();
  6445. spawn->CalculateRunningLocation(true);
  6446. }
  6447. return 0;
  6448. }
  6449. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6450. if (!lua_interface)
  6451. return 0;
  6452. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6453. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6454. lua_interface->ResetFunctionStack(state);
  6455. if (!spawn1) {
  6456. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6457. return 0;
  6458. }
  6459. if (!spawn2) {
  6460. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6461. return 0;
  6462. }
  6463. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6464. return 1;
  6465. }
  6466. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6467. if (!lua_interface)
  6468. return 0;
  6469. Spawn* spawn = lua_interface->GetSpawn(state);
  6470. lua_interface->ResetFunctionStack(state);
  6471. if (!spawn) {
  6472. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6473. return 0;
  6474. }
  6475. if (!spawn->IsNPC()) {
  6476. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6477. return 0;
  6478. }
  6479. ((NPC*)spawn)->ClearRunback();
  6480. return 0;
  6481. }
  6482. int EQ2Emu_lua_Runback(lua_State* state) {
  6483. if (!lua_interface)
  6484. return 0;
  6485. Spawn* spawn = lua_interface->GetSpawn(state);
  6486. lua_interface->ResetFunctionStack(state);
  6487. if (!spawn) {
  6488. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6489. return 0;
  6490. }
  6491. if (!spawn->IsNPC()) {
  6492. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6493. return 0;
  6494. }
  6495. ((NPC*)spawn)->Runback();
  6496. return 0;
  6497. }
  6498. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6499. if (!lua_interface)
  6500. return 0;
  6501. Spawn* spawn = lua_interface->GetSpawn(state);
  6502. lua_interface->ResetFunctionStack(state);
  6503. if (!spawn) {
  6504. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6505. return 0;
  6506. }
  6507. if (!spawn->IsNPC()) {
  6508. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6509. return 0;
  6510. }
  6511. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6512. return 1;
  6513. }
  6514. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6515. if (!lua_interface)
  6516. return 0;
  6517. Spawn* spawn = lua_interface->GetSpawn(state);
  6518. lua_interface->ResetFunctionStack(state);
  6519. if (!spawn) {
  6520. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6521. return 0;
  6522. }
  6523. if (!spawn->IsEntity()) {
  6524. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6525. return 0;
  6526. }
  6527. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6528. return 1;
  6529. }
  6530. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6531. if (!lua_interface)
  6532. return 0;
  6533. Spawn* spawn = lua_interface->GetSpawn(state);
  6534. lua_interface->ResetFunctionStack(state);
  6535. if (!spawn) {
  6536. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6537. return 0;
  6538. }
  6539. if (!spawn->IsEntity()) {
  6540. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6541. return 0;
  6542. }
  6543. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6544. return 1;
  6545. }
  6546. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6547. if (!lua_interface)
  6548. return 0;
  6549. Spawn* spawn = lua_interface->GetSpawn(state);
  6550. lua_interface->ResetFunctionStack(state);
  6551. if (!spawn) {
  6552. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6553. return 0;
  6554. }
  6555. if (!spawn->IsEntity()) {
  6556. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6557. return 0;
  6558. }
  6559. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6560. return 1;
  6561. }
  6562. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6563. if (!lua_interface)
  6564. return 0;
  6565. Spawn* spawn = lua_interface->GetSpawn(state);
  6566. lua_interface->ResetFunctionStack(state);
  6567. if (!spawn) {
  6568. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6569. return 0;
  6570. }
  6571. if (!spawn->IsEntity()) {
  6572. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6573. return 0;
  6574. }
  6575. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6576. return 1;
  6577. }
  6578. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6579. if (!lua_interface)
  6580. return 0;
  6581. Spawn* spawn = lua_interface->GetSpawn(state);
  6582. Spawn* target = lua_interface->GetSpawn(state, 2);
  6583. float distance = lua_interface->GetFloatValue(state, 3);
  6584. lua_interface->ResetFunctionStack(state);
  6585. if (!spawn) {
  6586. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6587. return 0;
  6588. }
  6589. if (!target) {
  6590. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6591. return 0;
  6592. }
  6593. if (!spawn->IsNPC()) {
  6594. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6595. return 0;
  6596. }
  6597. if (!target->IsEntity()) {
  6598. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6599. return 0;
  6600. }
  6601. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6602. return 1;
  6603. }
  6604. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6605. if (!lua_interface)
  6606. return 0;
  6607. Spawn* spawn = lua_interface->GetSpawn(state);
  6608. Spawn* target = lua_interface->GetSpawn(state, 2);
  6609. float distance = lua_interface->GetFloatValue(state, 3);
  6610. lua_interface->ResetFunctionStack(state);
  6611. if (!spawn) {
  6612. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. if (!target) {
  6616. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6617. return 0;
  6618. }
  6619. if (!spawn->IsNPC()) {
  6620. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6621. return 0;
  6622. }
  6623. if (!target->IsEntity()) {
  6624. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6625. return 0;
  6626. }
  6627. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6628. return 0;
  6629. }
  6630. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6631. if (!lua_interface)
  6632. return 0;
  6633. Spawn* spawn = lua_interface->GetSpawn(state);
  6634. lua_interface->ResetFunctionStack(state);
  6635. if (!spawn) {
  6636. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6637. return 0;
  6638. }
  6639. if (!spawn->IsNPC()) {
  6640. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6641. return 0;
  6642. }
  6643. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6644. return 1;
  6645. }
  6646. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6647. if (!lua_interface)
  6648. return 0;
  6649. Spawn* spawn = lua_interface->GetSpawn(state);
  6650. lua_interface->ResetFunctionStack(state);
  6651. if (!spawn) {
  6652. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6653. return 0;
  6654. }
  6655. if (!spawn->IsNPC()) {
  6656. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6657. return 0;
  6658. }
  6659. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6660. return 1;
  6661. }
  6662. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6663. if (!lua_interface)
  6664. return 0;
  6665. Spawn* spawn = lua_interface->GetSpawn(state);
  6666. lua_interface->ResetFunctionStack(state);
  6667. if (!spawn) {
  6668. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6669. return 0;
  6670. }
  6671. if (!spawn->IsNPC()) {
  6672. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6673. return 0;
  6674. }
  6675. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6676. if (hated) {
  6677. lua_interface->SetSpawnValue(state, hated);
  6678. return 1;
  6679. }
  6680. return 0;
  6681. }
  6682. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6683. if (!lua_interface)
  6684. return 0;
  6685. Spawn* spawn = lua_interface->GetSpawn(state);
  6686. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6687. lua_interface->ResetFunctionStack(state);
  6688. if (!spawn) {
  6689. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6690. return 0;
  6691. }
  6692. if (!spawn->IsNPC()) {
  6693. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6694. return 0;
  6695. }
  6696. if (!hated) {
  6697. ((NPC*)spawn)->Brain()->ClearHate();
  6698. return 0;
  6699. }
  6700. else
  6701. {
  6702. if (!hated->IsEntity()) {
  6703. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6704. return 0;
  6705. }
  6706. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6707. return 0;
  6708. }
  6709. return 0;
  6710. }
  6711. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6712. if (!lua_interface)
  6713. return 0;
  6714. Spawn* spawn = lua_interface->GetSpawn(state);
  6715. lua_interface->ResetFunctionStack(state);
  6716. if (!spawn) {
  6717. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6718. return 0;
  6719. }
  6720. if (!spawn->IsNPC()) {
  6721. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6722. return 0;
  6723. }
  6724. ((NPC*)spawn)->Brain()->ClearEncounter();
  6725. return 0;
  6726. }
  6727. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6728. if (!lua_interface)
  6729. return 0;
  6730. Spawn* spawn = lua_interface->GetSpawn(state);
  6731. lua_interface->ResetFunctionStack(state);
  6732. if (!spawn) {
  6733. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6734. return 0;
  6735. }
  6736. if (!spawn->IsNPC()) {
  6737. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6738. return 0;
  6739. }
  6740. // Temp list to store hate list
  6741. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6742. if (encounterList->size() == 0) {
  6743. safe_delete(encounterList);
  6744. return 0;
  6745. }
  6746. lua_createtable(state, encounterList->size(), 0);
  6747. int newTable = lua_gettop(state);
  6748. for (int32 i = 0; i < encounterList->size(); i++) {
  6749. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6750. if (temp)
  6751. lua_interface->SetSpawnValue(state, temp);
  6752. lua_rawseti(state, newTable, i + 1);
  6753. }
  6754. safe_delete(encounterList);
  6755. return 1;
  6756. }
  6757. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6758. if (!lua_interface)
  6759. return 0;
  6760. Spawn* spawn = lua_interface->GetSpawn(state);
  6761. lua_interface->ResetFunctionStack(state);
  6762. if (!spawn) {
  6763. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6764. return 0;
  6765. }
  6766. if (!spawn->IsNPC()) {
  6767. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6768. return 0;
  6769. }
  6770. // Temp list to store hate list
  6771. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6772. if (hateList->size() == 0) {
  6773. safe_delete(hateList);
  6774. return 0;
  6775. }
  6776. lua_createtable(state, hateList->size(), 0);
  6777. int newTable = lua_gettop(state);
  6778. for (int32 i = 0; i < hateList->size(); i++) {
  6779. lua_interface->SetSpawnValue(state, hateList->at(i));
  6780. lua_rawseti(state, newTable, i + 1);
  6781. }
  6782. safe_delete(hateList);
  6783. return 1;
  6784. }
  6785. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6786. if (!lua_interface)
  6787. return 0;
  6788. Spawn* spawn = lua_interface->GetSpawn(state);
  6789. lua_interface->ResetFunctionStack(state);
  6790. if (!spawn) {
  6791. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6792. return 0;
  6793. }
  6794. if (spawn->IsPlayer()) {
  6795. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6796. lua_interface->SetBooleanValue(state, true);
  6797. else
  6798. lua_interface->SetBooleanValue(state, false);
  6799. return 1;
  6800. }
  6801. else {
  6802. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6803. return 1;
  6804. }
  6805. }
  6806. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6807. if (!lua_interface)
  6808. return 0;
  6809. Quest* quest = lua_interface->GetQuest(state);
  6810. lua_interface->ResetFunctionStack(state);
  6811. if (!quest) {
  6812. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6813. return 0;
  6814. }
  6815. quest->SetCompletedFlag(true);
  6816. return 0;
  6817. }
  6818. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6819. if (!lua_interface)
  6820. return 0;
  6821. Spawn* spawn = lua_interface->GetSpawn(state);
  6822. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6823. int8 tier = lua_interface->GetInt8Value(state, 3);
  6824. lua_interface->ResetFunctionStack(state);
  6825. if (!spawn) {
  6826. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6827. return 0;
  6828. }
  6829. if (!spawn->IsEntity()) {
  6830. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6831. return 0;
  6832. }
  6833. if (spellID == 0) {
  6834. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6835. return 0;
  6836. }
  6837. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6838. if (effect) {
  6839. if (tier > 0) {
  6840. // If a tier was passed chec to see if it is the same as the effect
  6841. if (tier == effect->tier)
  6842. lua_interface->SetBooleanValue(state, true);
  6843. else
  6844. lua_interface->SetBooleanValue(state, false);
  6845. return 1;
  6846. }
  6847. else {
  6848. // Have an effect but no tier was passed so return true
  6849. lua_interface->SetBooleanValue(state, true);
  6850. }
  6851. return 1;
  6852. }
  6853. // no effect so return false
  6854. lua_interface->SetBooleanValue(state, false);
  6855. return 1;
  6856. }
  6857. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6858. if (!lua_interface)
  6859. return 0;
  6860. Spawn* spawn = lua_interface->GetSpawn(state);
  6861. int32 id = lua_interface->GetInt32Value(state, 2);
  6862. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6863. lua_interface->ResetFunctionStack(state);
  6864. Spawn* spawn2 = 0;
  6865. vector<Spawn*> list;
  6866. if (!spawn) {
  6867. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6868. return 0;
  6869. }
  6870. //If zone not provided, use spawn's zone
  6871. if (!zone)
  6872. zone = spawn->GetZone();
  6873. list = zone->GetSpawnsByID(id);
  6874. if (list.size() == 0) {
  6875. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6876. return 0;
  6877. }
  6878. vector<Spawn*>::iterator itr = list.begin();
  6879. for (int8 i = 0; i < list.size(); i++) {
  6880. spawn2 = itr[i];
  6881. if (spawn2)
  6882. spawn2->AddAllowAccessSpawn(spawn);
  6883. }
  6884. return 0;
  6885. }
  6886. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6887. if (!lua_interface)
  6888. return 0;
  6889. Spawn* spawn = lua_interface->GetSpawn(state);
  6890. int32 id = lua_interface->GetInt32Value(state, 2);
  6891. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6892. lua_interface->ResetFunctionStack(state);
  6893. Spawn* spawn2 = 0;
  6894. if (!spawn) {
  6895. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6896. return 0;
  6897. }
  6898. //If zone not provided, use spawn's zone
  6899. if (!zone)
  6900. zone = spawn->GetZone();
  6901. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6902. vector<Spawn*>::iterator itr = list.begin();
  6903. if (list.size() == 0) {
  6904. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6905. return 0;
  6906. }
  6907. for (int8 i = 0; i < list.size(); i++) {
  6908. spawn2 = itr[i];
  6909. if (spawn2)
  6910. spawn2->RemoveSpawnAccess(spawn);
  6911. }
  6912. return 0;
  6913. }
  6914. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6915. if (!lua_interface)
  6916. return 0;
  6917. Quest* quest = lua_interface->GetQuest(state);
  6918. lua_interface->ResetFunctionStack(state);
  6919. if (!quest) {
  6920. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6921. return 0;
  6922. }
  6923. quest->SetYellowName(true);
  6924. return 0;
  6925. }
  6926. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6927. if (!lua_interface)
  6928. return 0;
  6929. Spawn* spawn = lua_interface->GetSpawn(state);
  6930. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6931. lua_interface->ResetFunctionStack(state);
  6932. if (!spawn) {
  6933. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6934. return 0;
  6935. }
  6936. if (!spawn->IsPlayer()) {
  6937. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6938. return 0;
  6939. }
  6940. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6941. return 1;
  6942. }
  6943. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6944. if (!lua_interface)
  6945. return 0;
  6946. Spawn* spawn = lua_interface->GetSpawn(state);
  6947. lua_interface->ResetFunctionStack(state);
  6948. if (!spawn) {
  6949. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6950. return 0;
  6951. }
  6952. if (!spawn->IsPlayer()) {
  6953. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6954. return 0;
  6955. }
  6956. ZoneServer* zone = spawn->GetZone();
  6957. if (!zone) {
  6958. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6959. return 0;
  6960. }
  6961. Instance_Type iType = zone->GetInstanceType();
  6962. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6963. iType == GROUP_LOCKOUT_INSTANCE ||
  6964. iType == RAID_LOCKOUT_INSTANCE ||
  6965. iType == SOLO_PERSIST_INSTANCE ||
  6966. iType == GROUP_PERSIST_INSTANCE ||
  6967. iType == RAID_PERSIST_INSTANCE) {
  6968. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6969. if (data) {
  6970. // Check to see if the timer has already been set, if it has return out.
  6971. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6972. return 0;
  6973. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6974. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6975. if(spawn->IsPlayer()) {
  6976. Client* client = ((Player*)spawn)->GetClient();
  6977. if (client) {
  6978. string time_msg = "";
  6979. int32 time = data->success_lockout_time;
  6980. int16 hour;
  6981. int8 min;
  6982. int8 sec;
  6983. hour = time / 3600;
  6984. time = time % 3600;
  6985. min = time / 60;
  6986. time = time % 60;
  6987. sec = time;
  6988. if (hour > 0) {
  6989. char temp[10];
  6990. sprintf(temp, " %i", hour);
  6991. time_msg.append(temp);
  6992. time_msg.append(" hour");
  6993. time_msg.append((hour > 1) ? "s" : "");
  6994. }
  6995. if (min > 0) {
  6996. char temp[5];
  6997. sprintf(temp, " %i", min);
  6998. time_msg.append(temp);
  6999. time_msg.append(" minute");
  7000. time_msg.append((min > 1) ? "s" : "");
  7001. }
  7002. // Only add seconds if minutes and hours are 0
  7003. if (hour == 0 && min == 0 && sec > 0) {
  7004. char temp[5];
  7005. sprintf(temp, " %i", sec);
  7006. time_msg.append(temp);
  7007. time_msg.append(" second");
  7008. time_msg.append((sec > 1) ? "s" : "");
  7009. }
  7010. 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());
  7011. }
  7012. else {
  7013. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7014. }
  7015. }
  7016. }
  7017. else
  7018. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7019. }
  7020. else
  7021. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7022. return 0;
  7023. }
  7024. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7025. if (!lua_interface)
  7026. return 0;
  7027. Spawn* spawn = lua_interface->GetSpawn(state);
  7028. lua_interface->ResetFunctionStack(state);
  7029. if (!spawn) {
  7030. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7031. return 0;
  7032. }
  7033. if (!spawn->IsPlayer()) {
  7034. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7035. return 0;
  7036. }
  7037. ZoneServer* zone = spawn->GetZone();
  7038. if (!zone) {
  7039. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7040. return 0;
  7041. }
  7042. Instance_Type iType = zone->GetInstanceType();
  7043. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7044. iType == GROUP_LOCKOUT_INSTANCE ||
  7045. iType == RAID_LOCKOUT_INSTANCE ||
  7046. iType == SOLO_PERSIST_INSTANCE ||
  7047. iType == GROUP_PERSIST_INSTANCE ||
  7048. iType == RAID_PERSIST_INSTANCE) {
  7049. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7050. if (data) {
  7051. // Check to see if the timer has already been set, if it has return out.
  7052. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7053. return 0;
  7054. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7055. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7056. if(spawn->IsPlayer()) {
  7057. Client* client = ((Player*)spawn)->GetClient();
  7058. if (client) {
  7059. string time_msg = "";
  7060. int32 time = data->failure_lockout_time;
  7061. int16 hour;
  7062. int8 min;
  7063. int8 sec;
  7064. hour = time / 3600;
  7065. time = time % 3600;
  7066. min = time / 60;
  7067. time = time % 60;
  7068. sec = time;
  7069. if (hour > 0) {
  7070. char temp[10];
  7071. sprintf(temp, " %i", hour);
  7072. time_msg.append(temp);
  7073. time_msg.append(" hour");
  7074. time_msg.append((hour > 1) ? "s" : "");
  7075. }
  7076. if (min > 0) {
  7077. char temp[5];
  7078. sprintf(temp, " %i", min);
  7079. time_msg.append(temp);
  7080. time_msg.append(" minute");
  7081. time_msg.append((min > 1) ? "s" : "");
  7082. }
  7083. // Only add seconds if minutes and hours are 0
  7084. if (hour == 0 && min == 0 && sec > 0) {
  7085. char temp[5];
  7086. sprintf(temp, " %i", sec);
  7087. time_msg.append(temp);
  7088. time_msg.append(" second");
  7089. time_msg.append((sec > 1) ? "s" : "");
  7090. }
  7091. 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());
  7092. }
  7093. }
  7094. else {
  7095. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7096. }
  7097. }
  7098. else
  7099. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7100. }
  7101. else
  7102. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7103. return 0;
  7104. }
  7105. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7106. if (!lua_interface)
  7107. return 0;
  7108. Spawn* spawn = lua_interface->GetSpawn(state);
  7109. lua_interface->ResetFunctionStack(state);
  7110. if (!spawn) {
  7111. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7112. return 0;
  7113. }
  7114. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7115. return 1;
  7116. }
  7117. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7118. if (!lua_interface)
  7119. return 0;
  7120. Spawn* player = lua_interface->GetSpawn(state);
  7121. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7122. if (!player) {
  7123. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7124. lua_interface->ResetFunctionStack(state);
  7125. return 0;
  7126. }
  7127. if (!player->IsPlayer()) {
  7128. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7129. lua_interface->ResetFunctionStack(state);
  7130. return 0;
  7131. }
  7132. if (!ground) {
  7133. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7134. lua_interface->ResetFunctionStack(state);
  7135. return 0;
  7136. }
  7137. if (!ground->IsGroundSpawn()) {
  7138. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7139. lua_interface->ResetFunctionStack(state);
  7140. return 0;
  7141. }
  7142. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7143. if (!groundspawn_entries) {
  7144. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7145. lua_interface->ResetFunctionStack(state);
  7146. return 0;
  7147. }
  7148. Skill* skill = 0;
  7149. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7150. if (collection_skill == "Collecting")
  7151. skill = ((Player*)player)->GetSkillByName("Gathering");
  7152. else
  7153. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7154. if (!skill) {
  7155. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7156. lua_interface->ResetFunctionStack(state);
  7157. return 0;
  7158. }
  7159. vector<GroundSpawnEntry*>::iterator itr;
  7160. GroundSpawnEntry* entry = 0;
  7161. bool can_harvest = false;
  7162. sint32 min_skill = -1;
  7163. int16 totalSkill = skill->current_val;
  7164. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7165. if(skillID != 0xFFFFFFFF)
  7166. {
  7167. ((Entity*)player)->MStats.lock();
  7168. totalSkill += ((Entity*)player)->stats[skillID];
  7169. ((Entity*)player)->MStats.unlock();
  7170. }
  7171. // first, iterate through groundspawn_entries, discard tables player cannot use
  7172. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7173. {
  7174. entry = *itr;
  7175. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7176. min_skill = entry->min_skill_level;
  7177. // if player lacks skill, skip table
  7178. if (entry->min_skill_level > totalSkill)
  7179. continue;
  7180. // if bonus, but player lacks level, skip table
  7181. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7182. continue;
  7183. can_harvest = true;
  7184. break;
  7185. }
  7186. lua_interface->SetBooleanValue(state, can_harvest);
  7187. // If false, send the message to the client
  7188. if (!can_harvest) {
  7189. Client* client = ((Player*)player)->GetClient();
  7190. if (client) {
  7191. string msg = "You do not have enough skill to ";
  7192. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7193. msg.append("gather");
  7194. else if (collection_skill == "Mining")
  7195. msg.append("mine");
  7196. else if (collection_skill == "Trapping")
  7197. msg.append("trap");
  7198. else if (collection_skill == "Foresting")
  7199. msg.append("forest");
  7200. else if (collection_skill == "Fishing")
  7201. msg.append("catch");
  7202. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7203. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7204. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7205. }
  7206. }
  7207. lua_interface->ResetFunctionStack(state);
  7208. return 1;
  7209. }
  7210. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7211. if (!lua_interface)
  7212. return 0;
  7213. Spawn* player = lua_interface->GetSpawn(state);
  7214. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7215. lua_interface->ResetFunctionStack(state);
  7216. if (!player) {
  7217. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7218. return 0;
  7219. }
  7220. if (!player->IsPlayer()) {
  7221. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7222. return 0;
  7223. }
  7224. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7225. lua_interface->SetBooleanValue(state, ret);
  7226. return 1;
  7227. }
  7228. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7229. // Check to see if we have a valid lua_interface
  7230. if (!lua_interface)
  7231. return 0;
  7232. // Get the spawn that is getting the pet
  7233. Spawn* spawn = lua_interface->GetSpawn(state);
  7234. Spawn* target = lua_interface->GetSpawn(state, 2);
  7235. // Get the DB ID of the pet
  7236. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7237. float x = lua_interface->GetFloatValue(state, 4);
  7238. float y = lua_interface->GetFloatValue(state, 5);
  7239. float z = lua_interface->GetFloatValue(state, 6);
  7240. // Get the spell that this command was called from
  7241. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7242. lua_interface->ResetFunctionStack(state);
  7243. // Check to make sure the spawn pointer is valid
  7244. if (!spawn) {
  7245. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7246. return 0;
  7247. }
  7248. // Check to make sure the spawn is an entity
  7249. if (!spawn->IsEntity()) {
  7250. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7251. return 0;
  7252. }
  7253. if (!target) {
  7254. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7255. return 0;
  7256. }
  7257. if (!target->IsEntity()) {
  7258. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7259. return 0;
  7260. }
  7261. // Check to see if the DB ID for the pet is set
  7262. if (pet_id == 0) {
  7263. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7264. return 0;
  7265. }
  7266. // Check to see if the pointer to the spell is valid
  7267. if (!luaspell) {
  7268. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7269. return 0;
  7270. }
  7271. if(luaspell->resisted) {
  7272. return 0;
  7273. }
  7274. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7275. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7276. if (!pet) {
  7277. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7278. return 0;
  7279. }
  7280. // Check to make sure the pet is an npc
  7281. if (!pet->IsNPC()) {
  7282. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7283. return 0;
  7284. }
  7285. if (x == 0)
  7286. x = spawn->GetX();
  7287. if (y == 0)
  7288. y = spawn->GetY();
  7289. if (z == 0)
  7290. z = spawn->GetZ();
  7291. // Spawn the pet at the same location as the owner
  7292. pet->SetX(x);
  7293. pet->SetY(y);
  7294. pet->SetZ(z);
  7295. pet->SetLocation(spawn->GetLocation());
  7296. pet->SetHeading(spawn->GetHeading());
  7297. spawn->GetZone()->AddSpawn(pet);
  7298. const char* spawn_script = world.GetSpawnScript(pet_id);
  7299. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7300. spawn->SetSpawnScript(string(spawn_script));
  7301. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7302. }
  7303. std::string petName = std::string("");
  7304. if(spawn->IsEntity()) {
  7305. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7306. }
  7307. if(petName.size() < 1) {
  7308. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7309. petName = spawn->GetZone()->pet_names.at(rand_index);
  7310. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7311. }
  7312. // Set the pets name
  7313. pet->SetName(petName.c_str());
  7314. // Set the level of the pet to the owners level
  7315. pet->SetLevel(spawn->GetLevel());
  7316. // Set the faction of the pet to the same faction as the owner
  7317. pet->SetFactionID(spawn->GetFactionID());
  7318. // Set the spawn as a pet
  7319. pet->SetPet(true);
  7320. // Give a pointer of the owner to the pet
  7321. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7322. // Set the pet type
  7323. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7324. // Set the spell id used to create this pet
  7325. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7326. // Set the spell tier used to create this pet
  7327. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7328. // Set the pets spawn type to 6
  7329. pet->SetSpawnType(6);
  7330. // Set the pets brain
  7331. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7332. // Check to see if the pet has a subtitle
  7333. if (strlen(pet->GetSubTitle()) > 0) {
  7334. // Add the players name to the front of the sub title
  7335. string pet_subtitle;
  7336. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7337. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7338. // Set the pets subtitle to the new one
  7339. pet->SetSubTitle(pet_subtitle.c_str());
  7340. }
  7341. // Set the pet as the return value for this function
  7342. lua_interface->SetSpawnValue(state, pet);
  7343. return 1;
  7344. }
  7345. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7346. if (!lua_interface)
  7347. return 0;
  7348. Spawn* spawn = lua_interface->GetSpawn(state);
  7349. Spawn* player = lua_interface->GetSpawn(state, 2);
  7350. float max_distance = lua_interface->GetFloatValue(state, 3);
  7351. string type = lua_interface->GetStringValue(state, 4);
  7352. lua_interface->ResetFunctionStack(state);
  7353. if (!spawn || (spawn && spawn->IsPlayer())) {
  7354. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7355. return 0;
  7356. }
  7357. if (!player || !player->IsPlayer()) {
  7358. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7359. return 0;
  7360. }
  7361. Client* client = ((Player*)player)->GetClient();
  7362. if (!client) {
  7363. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7364. return 0;
  7365. }
  7366. //Set max_distance to default if not set or not proper value
  7367. if (max_distance <= 0)
  7368. max_distance = 500;
  7369. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7370. if (packet) {
  7371. float unknown2_3 = 0;
  7372. int8 placement_mode = 0;
  7373. if (type == "wall") {
  7374. placement_mode = 2;
  7375. unknown2_3 = 150;
  7376. }
  7377. else if (type == "ceiling")
  7378. placement_mode = 1;
  7379. packet->setDataByName("placement_mode", placement_mode);
  7380. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7381. packet->setDataByName("model_type", spawn->GetModelType());
  7382. packet->setDataByName("unknown", 1); //size
  7383. packet->setDataByName("unknown2", 1); //size 2
  7384. packet->setDataByName("unknown2", .5, 1); //size 3
  7385. packet->setDataByName("unknown2", 3, 2);
  7386. packet->setDataByName("unknown2", unknown2_3, 3);
  7387. packet->setDataByName("max_distance", max_distance);
  7388. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7389. client->QueuePacket(packet->serialize());
  7390. safe_delete(packet);
  7391. }
  7392. return 0;
  7393. }
  7394. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7395. if (!lua_interface)
  7396. return 0;
  7397. Item* item = lua_interface->GetItem(state);
  7398. lua_interface->ResetFunctionStack(state);
  7399. if (!item) {
  7400. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7401. return 0;
  7402. }
  7403. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7404. return 1;
  7405. }
  7406. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7407. if (!lua_interface)
  7408. return 0;
  7409. Item* item = lua_interface->GetItem(state);
  7410. lua_interface->ResetFunctionStack(state);
  7411. if (!item) {
  7412. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7413. return 0;
  7414. }
  7415. lua_interface->SetInt32Value(state, item->effect_type);
  7416. return 1;
  7417. }
  7418. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7419. if (!lua_interface)
  7420. return 0;
  7421. Spawn* spawn = lua_interface->GetSpawn(state);
  7422. lua_interface->ResetFunctionStack(state);
  7423. if (!spawn) {
  7424. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7425. return 0;
  7426. }
  7427. if (spawn->GetZone())
  7428. spawn->GetZone()->AddTransportSpawn(spawn);
  7429. return 0;
  7430. }
  7431. int EQ2Emu_lua_IsTransportSpawn(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. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7441. return 1;
  7442. }
  7443. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7444. if (!lua_interface)
  7445. return 0;
  7446. Skill* skill = lua_interface->GetSkill(state);
  7447. lua_interface->ResetFunctionStack(state);
  7448. if (!skill) {
  7449. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7450. return 0;
  7451. }
  7452. lua_interface->SetInt32Value(state, skill->current_val);
  7453. return 1;
  7454. }
  7455. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7456. if (!lua_interface)
  7457. return 0;
  7458. Skill* skill = lua_interface->GetSkill(state);
  7459. lua_interface->ResetFunctionStack(state);
  7460. if (!skill) {
  7461. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7462. return 0;
  7463. }
  7464. lua_interface->SetInt32Value(state, skill->max_val);
  7465. return 1;
  7466. }
  7467. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7468. if (!lua_interface)
  7469. return 0;
  7470. Skill* skill = lua_interface->GetSkill(state);
  7471. lua_interface->ResetFunctionStack(state);
  7472. if (!skill) {
  7473. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7474. return 0;
  7475. }
  7476. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7477. return 1;
  7478. }
  7479. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7480. if (!lua_interface)
  7481. return 0;
  7482. Skill* skill = lua_interface->GetSkill(state);
  7483. int16 value = lua_interface->GetInt16Value(state, 2);
  7484. lua_interface->ResetFunctionStack(state);
  7485. if (!skill) {
  7486. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. skill->max_val = value;
  7490. if (skill->max_val < skill->current_val)
  7491. skill->current_val = skill->max_val;
  7492. return 0;
  7493. }
  7494. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7495. if (!lua_interface)
  7496. return 0;
  7497. Skill* skill = lua_interface->GetSkill(state);
  7498. int16 value = lua_interface->GetInt16Value(state, 2);
  7499. lua_interface->ResetFunctionStack(state);
  7500. if (!skill) {
  7501. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7502. return 0;
  7503. }
  7504. if (value > skill->max_val)
  7505. skill->current_val = skill->max_val;
  7506. else
  7507. skill->current_val = value;
  7508. return 0;
  7509. }
  7510. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7511. if (!lua_interface)
  7512. return 0;
  7513. Spawn* player = lua_interface->GetSpawn(state);
  7514. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7515. lua_interface->ResetFunctionStack(state);
  7516. if (skill_id > 0 && player && player->IsPlayer()) {
  7517. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7518. return 1;
  7519. }
  7520. return 0;
  7521. }
  7522. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7523. if (!lua_interface)
  7524. return 0;
  7525. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7526. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7527. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7528. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7529. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7530. lua_interface->ResetFunctionStack(state);
  7531. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7532. if (player_spawn && player_spawn->IsPlayer()) {
  7533. Player* player = (Player*)player_spawn;
  7534. bool added = false;
  7535. if (!player->skill_list.HasSkill(skill_id)) {
  7536. player->AddSkill(skill_id, current_val, max_val, true);
  7537. added = true;
  7538. }
  7539. 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
  7540. Client* client = player->GetClient();
  7541. if (client) {
  7542. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7543. if (packet)
  7544. client->QueuePacket(packet);
  7545. }
  7546. }
  7547. if (added) {
  7548. lua_interface->SetBooleanValue(state, true);
  7549. return 1;
  7550. }
  7551. }
  7552. else {
  7553. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7554. }
  7555. }
  7556. else {
  7557. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7558. }
  7559. lua_interface->SetBooleanValue(state, false);
  7560. return 1;
  7561. }
  7562. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7563. if (!lua_interface)
  7564. return 0;
  7565. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7566. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7567. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7568. lua_interface->ResetFunctionStack(state);
  7569. if (skill_id > 0) {
  7570. if (player_spawn && player_spawn->IsPlayer()) {
  7571. Player* player = (Player*)player_spawn;
  7572. if (player->skill_list.HasSkill(skill_id)) {
  7573. player->RemovePlayerSkill(skill_id, true);
  7574. if (!more_to_remove) {
  7575. Client* client = player->GetClient();
  7576. if (client) {
  7577. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7578. if (packet)
  7579. client->QueuePacket(packet);
  7580. }
  7581. }
  7582. }
  7583. }
  7584. else {
  7585. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7586. }
  7587. }
  7588. else {
  7589. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7590. }
  7591. return 0;
  7592. }
  7593. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7594. if (!lua_interface)
  7595. return 0;
  7596. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7597. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7598. int16 amount = lua_interface->GetInt8Value(state, 3);
  7599. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7600. lua_interface->ResetFunctionStack(state);
  7601. if (amount > 0 && skill_type < 100) {
  7602. if (player_spawn && player_spawn->IsPlayer()) {
  7603. Player* player = (Player*)player_spawn;
  7604. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7605. if (!more_to_increase) {
  7606. Client* client = player->GetClient();
  7607. if (client) {
  7608. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7609. if (packet)
  7610. client->QueuePacket(packet);
  7611. }
  7612. }
  7613. }
  7614. else {
  7615. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7616. }
  7617. }
  7618. else {
  7619. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7620. }
  7621. return 0;
  7622. }
  7623. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7624. if (!lua_interface)
  7625. return 0;
  7626. Spawn* spawn = lua_interface->GetSpawn(state);
  7627. string name = lua_interface->GetStringValue(state, 2);
  7628. lua_interface->ResetFunctionStack(state);
  7629. if (!spawn) {
  7630. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7631. return 0;
  7632. }
  7633. if (!spawn->IsEntity()) {
  7634. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7635. return 0;
  7636. }
  7637. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7638. if (skill) {
  7639. lua_interface->SetSkillValue(state, skill);
  7640. return 1;
  7641. }
  7642. return 0;
  7643. }
  7644. int EQ2Emu_lua_AddProc(lua_State* state) {
  7645. if (!lua_interface)
  7646. return 0;
  7647. Spawn* spawn = lua_interface->GetSpawn(state);
  7648. int8 type = lua_interface->GetInt8Value(state, 2);
  7649. float chance = lua_interface->GetFloatValue(state, 3);
  7650. Item* item = lua_interface->GetItem(state, 4);
  7651. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7652. LuaSpell* spell = 0;
  7653. if (!spawn && (!spell || !use_all_spelltargets)) {
  7654. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7655. return 0;
  7656. }
  7657. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7658. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7659. return 0;
  7660. }
  7661. if (!item)
  7662. spell = lua_interface->GetCurrentSpell(state);
  7663. if (!item && !spell) {
  7664. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7665. return 0;
  7666. }
  7667. if(spell && spell->resisted) {
  7668. return 0;
  7669. }
  7670. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7671. Spawn* target;
  7672. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7673. for (int8 i = 0; i < spell->targets.size(); i++) {
  7674. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7675. if (!target || !target->IsEntity())
  7676. continue;
  7677. ((Entity*)target)->AddProc(type, chance, item, spell);
  7678. }
  7679. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7680. }
  7681. else
  7682. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7683. return 0;
  7684. }
  7685. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7686. if (!lua_interface)
  7687. return 0;
  7688. Spawn* spawn = lua_interface->GetSpawn(state);
  7689. Item* item = lua_interface->GetItem(state, 2);
  7690. LuaSpell* spell = 0;
  7691. if (!spawn) {
  7692. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7693. lua_interface->ResetFunctionStack(state);
  7694. return 0;
  7695. }
  7696. if (!spawn->IsEntity()) {
  7697. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7698. lua_interface->ResetFunctionStack(state);
  7699. return 0;
  7700. }
  7701. if (!item)
  7702. spell = lua_interface->GetCurrentSpell(state);
  7703. lua_interface->ResetFunctionStack(state);
  7704. if (!item && !spell) {
  7705. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7706. return 0;
  7707. }
  7708. if (spell && spell->caster && spell->caster->GetZone()) {
  7709. Spawn* target;
  7710. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7711. for (int8 i = 0; i < spell->targets.size(); i++) {
  7712. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7713. if (!target || !target->IsEntity())
  7714. continue;
  7715. ((Entity*)target)->RemoveProc(item, spell);
  7716. }
  7717. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7718. spell->caster->RemoveProc(item, spell);
  7719. }
  7720. else
  7721. ((Entity*)spawn)->RemoveProc(item, spell);
  7722. return 0;
  7723. }
  7724. int EQ2Emu_lua_Knockback(lua_State* state) {
  7725. if (!lua_interface)
  7726. return 0;
  7727. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7728. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7729. int32 duration = lua_interface->GetInt32Value(state, 3);
  7730. float vertical = lua_interface->GetFloatValue(state, 4);
  7731. float horizontal = lua_interface->GetFloatValue(state, 5);
  7732. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7733. lua_interface->ResetFunctionStack(state);
  7734. if (!target_spawn) {
  7735. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7736. return 0;
  7737. }
  7738. if (!spawn) {
  7739. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7740. return 0;
  7741. }
  7742. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7743. Client* client = ((Player*)spawn)->GetClient();
  7744. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7745. if (packet) {
  7746. packet->setDataByName("target_x", target_spawn->GetX());
  7747. packet->setDataByName("target_y", target_spawn->GetY());
  7748. packet->setDataByName("target_z", target_spawn->GetZ());
  7749. packet->setDataByName("vertical_movement", vertical);
  7750. packet->setDataByName("horizontal_movement", horizontal);
  7751. if (use_heading)
  7752. packet->setDataByName("use_player_heading", 1);
  7753. client->QueuePacket(packet->serialize());
  7754. }
  7755. safe_delete(packet);
  7756. }
  7757. return 0;
  7758. }
  7759. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7760. if (!lua_interface)
  7761. return 0;
  7762. Spawn* spawn = lua_interface->GetSpawn(state);
  7763. lua_interface->ResetFunctionStack(state);
  7764. if (!spawn) {
  7765. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7766. return 0;
  7767. }
  7768. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7769. return 1;
  7770. }
  7771. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7772. if (!lua_interface)
  7773. return 0;
  7774. Spawn* caster = lua_interface->GetSpawn(state);
  7775. Spawn* target = lua_interface->GetSpawn(state, 2);
  7776. string name = lua_interface->GetStringValue(state, 3);
  7777. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7778. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7779. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7780. string success_msg = lua_interface->GetStringValue(state, 7);
  7781. string effect_msg = lua_interface->GetStringValue(state, 8);
  7782. lua_interface->ResetFunctionStack(state);
  7783. if (!caster) {
  7784. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7785. return 0;
  7786. }
  7787. if (!caster->IsEntity()) {
  7788. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7789. return 0;
  7790. }
  7791. if (!target) {
  7792. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7793. return 0;
  7794. }
  7795. if (!target->IsEntity()) {
  7796. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. if (name.length() == 0) {
  7800. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7801. return 0;
  7802. }
  7803. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7804. return 0;
  7805. }
  7806. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7807. if (!lua_interface)
  7808. return 0;
  7809. string name = lua_interface->GetStringValue(state);
  7810. lua_interface->ResetFunctionStack(state);
  7811. if (name.length() == 0) {
  7812. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7813. return 0;
  7814. }
  7815. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7816. if (!skill) {
  7817. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7818. return 0;
  7819. }
  7820. lua_interface->SetInt32Value(state, skill->skill_id);
  7821. return 1;
  7822. }
  7823. int EQ2Emu_lua_IsHeroic(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 IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7830. return 0;
  7831. }
  7832. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7833. return 1;
  7834. }
  7835. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7836. if (!lua_interface)
  7837. return 0;
  7838. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7839. lua_interface->ResetFunctionStack(state);
  7840. if (!luaspell) {
  7841. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7842. return 0;
  7843. }
  7844. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7845. return 1;
  7846. }
  7847. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7848. if (!lua_interface)
  7849. return 0;
  7850. Spawn* spawn = lua_interface->GetSpawn(state);
  7851. Spawn* target = lua_interface->GetSpawn(state, 2);
  7852. lua_interface->ResetFunctionStack(state);
  7853. if (!spawn) {
  7854. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7855. return 0;
  7856. }
  7857. if (!spawn->IsEntity()) {
  7858. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7859. return 0;
  7860. }
  7861. if (!target) {
  7862. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7863. return 0;
  7864. }
  7865. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7866. return 1;
  7867. }
  7868. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7869. if (!lua_interface)
  7870. return 0;
  7871. Spawn* spawn = lua_interface->GetSpawn(state);
  7872. Spawn* target = lua_interface->GetSpawn(state, 2);
  7873. lua_interface->ResetFunctionStack(state);
  7874. if (!spawn) {
  7875. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7876. return 0;
  7877. }
  7878. if (!spawn->IsEntity()) {
  7879. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7880. return 0;
  7881. }
  7882. if (!target) {
  7883. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7884. return 0;
  7885. }
  7886. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7887. return 1;
  7888. }
  7889. int EQ2Emu_lua_InFront(lua_State* state) {
  7890. if (!lua_interface)
  7891. return 0;
  7892. Spawn* spawn = lua_interface->GetSpawn(state);
  7893. Spawn* target = lua_interface->GetSpawn(state, 2);
  7894. lua_interface->ResetFunctionStack(state);
  7895. if (!spawn) {
  7896. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. if (!spawn->IsEntity()) {
  7900. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7901. return 0;
  7902. }
  7903. if (!target) {
  7904. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  7905. return 0;
  7906. }
  7907. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  7908. return 1;
  7909. }
  7910. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7911. if (!lua_interface)
  7912. return 0;
  7913. Item* item = lua_interface->GetItem(state);
  7914. lua_interface->ResetFunctionStack(state);
  7915. if (!item) {
  7916. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7917. return 0;
  7918. }
  7919. lua_interface->SetInt32Value(state, item->details.count);
  7920. return 1;
  7921. }
  7922. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7923. if (!lua_interface)
  7924. return 0;
  7925. Item* item = lua_interface->GetItem(state);
  7926. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7927. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7928. lua_interface->ResetFunctionStack(state);
  7929. if (!item) {
  7930. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7931. return 0;
  7932. }
  7933. if (!owner) {
  7934. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7935. return 0;
  7936. }
  7937. if (!owner->IsPlayer()) {
  7938. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7939. return 0;
  7940. }
  7941. if (item->stack_count < new_count) {
  7942. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7943. return 0;
  7944. }
  7945. if (new_count > 0) {
  7946. item->details.count = new_count;
  7947. item->save_needed = true;
  7948. }
  7949. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7950. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7951. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7952. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7953. else
  7954. {
  7955. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7956. return 0;
  7957. }
  7958. Client* client = ((Player*)owner)->GetClient();
  7959. if (!client)
  7960. return 0;
  7961. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7962. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7963. if (app)
  7964. client->QueuePacket(app);
  7965. return 0;
  7966. }
  7967. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7968. if (!lua_interface)
  7969. return 0;
  7970. int32 time = lua_interface->GetInt32Value(state);
  7971. string function = lua_interface->GetStringValue(state, 2);
  7972. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7973. Spawn* target = lua_interface->GetSpawn(state, 4);
  7974. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7975. lua_interface->ResetFunctionStack(state);
  7976. if (time == 0) {
  7977. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7978. return 0;
  7979. }
  7980. if (function.length() == 0) {
  7981. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7982. return 0;
  7983. }
  7984. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  7985. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7986. return 0;
  7987. }
  7988. SpellScriptTimer* timer = new SpellScriptTimer;
  7989. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7990. #ifdef WIN32
  7991. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7992. #else
  7993. bzero(timer, sizeof(SpellScriptTimer));
  7994. #endif*/
  7995. timer->caster = 0;
  7996. timer->deleteWhenDone = false;
  7997. timer->target = 0;
  7998. timer->time = Timer::GetCurrentTime2() + time;
  7999. timer->customFunction = function;
  8000. timer->spell = spell;
  8001. if (caster)
  8002. timer->caster = caster->GetID();
  8003. if (target)
  8004. timer->target = target->GetID();
  8005. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8006. return 0;
  8007. }
  8008. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8009. if (!lua_interface)
  8010. return 0;
  8011. float hp_perc = lua_interface->GetFloatValue(state);
  8012. float power_perc = lua_interface->GetFloatValue(state, 2);
  8013. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8014. Spawn* target = lua_interface->GetSpawn(state, 4);
  8015. string heal_name = lua_interface->GetStringValue(state, 5);
  8016. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8017. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8018. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8019. lua_interface->ResetFunctionStack(state);
  8020. if (!spell) {
  8021. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8022. return 0;
  8023. }
  8024. Entity* caster = spell->caster;
  8025. if (!caster) {
  8026. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8027. return 0;
  8028. }
  8029. Client* client = 0;
  8030. PendingResurrection* rez = 0;
  8031. ZoneServer* zone = spell->caster->GetZone();
  8032. if (!target) {
  8033. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8034. if (spell->targets.size() > 0) {
  8035. vector<int32> spell_targets = spell->targets;
  8036. for (int8 i = 0; i < spell_targets.size(); i++) {
  8037. target = zone->GetSpawnByID(spell_targets.at(i));
  8038. if (!target)
  8039. continue;
  8040. if (!target->IsPlayer())
  8041. continue;
  8042. client = ((Player*)target)->GetClient();
  8043. if (!client)
  8044. continue;
  8045. rez = client->GetCurrentRez();
  8046. if (rez->active)
  8047. continue;
  8048. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8049. rez->active = true;
  8050. rez->caster = caster;
  8051. rez->expire_timer = new Timer;
  8052. int32 duration = spell->spell->GetSpellDuration();
  8053. rez->expire_timer->Start(duration * 100);
  8054. rez->hp_perc = hp_perc;
  8055. rez->mp_perc = power_perc;
  8056. rez->range = spell->spell->GetSpellData()->range;
  8057. rez->spell_name = spell->spell->GetName();
  8058. if (heal_name.length() > 0)
  8059. rez->heal_name = heal_name;
  8060. else
  8061. rez->heal_name = rez->spell_name;
  8062. rez->no_calcs = no_calcs;
  8063. rez->crit_mod = crit_mod;
  8064. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8065. if (send_window)
  8066. client->SendResurrectionWindow();
  8067. else {
  8068. target->GetZone()->ResurrectSpawn(target, client);
  8069. rez->should_delete = true;
  8070. }
  8071. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8072. }
  8073. }
  8074. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8075. }
  8076. else {
  8077. if(!target->IsPlayer())
  8078. return 0;
  8079. client = ((Player*)target)->GetClient();
  8080. if (!client)
  8081. return 0;
  8082. rez = client->GetCurrentRez();
  8083. if (rez->active)
  8084. return 0;
  8085. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8086. rez->active = true;
  8087. rez->caster = caster;
  8088. rez->expire_timer = new Timer;
  8089. int32 duration = spell->spell->GetSpellDuration();
  8090. rez->expire_timer->Start(duration * 100);
  8091. rez->hp_perc = hp_perc;
  8092. rez->mp_perc = power_perc;
  8093. rez->range = spell->spell->GetSpellData()->range;
  8094. rez->spell_name = spell->spell->GetName();
  8095. if (heal_name.length() > 0)
  8096. rez->heal_name = heal_name;
  8097. else
  8098. rez->heal_name = rez->spell_name;
  8099. rez->no_calcs = no_calcs;
  8100. rez->crit_mod = crit_mod;
  8101. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8102. if (send_window)
  8103. client->SendResurrectionWindow();
  8104. else {
  8105. target->GetZone()->ResurrectSpawn(target, client);
  8106. rez->should_delete = true;
  8107. }
  8108. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8109. }
  8110. return 0;
  8111. }
  8112. int EQ2Emu_lua_SetVision(lua_State* state) {
  8113. if (!lua_interface)
  8114. return 0;
  8115. Spawn* spawn = lua_interface->GetSpawn(state);
  8116. int32 vision = lua_interface->GetInt32Value(state, 2);
  8117. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8118. lua_interface->ResetFunctionStack(state);
  8119. if (!spawn) {
  8120. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8121. return 0;
  8122. }
  8123. if (!spawn->IsEntity()) {
  8124. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8125. return 0;
  8126. }
  8127. if (spell && spell->targets.size() > 0) {
  8128. ZoneServer* zone = spell->caster->GetZone();
  8129. for (int8 i = 0; i < spell->targets.size(); i++) {
  8130. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8131. if (target && target->IsEntity()) {
  8132. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8133. if (target->IsPlayer())
  8134. ((Player*)target)->SetCharSheetChanged(true);
  8135. }
  8136. }
  8137. }
  8138. else {
  8139. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8140. if (spawn->IsPlayer())
  8141. ((Player*)spawn)->SetCharSheetChanged(true);
  8142. }
  8143. return 0;
  8144. }
  8145. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8146. if (!lua_interface)
  8147. return 0;
  8148. Spawn* spawn = lua_interface->GetSpawn(state);
  8149. float intensity = lua_interface->GetFloatValue(state, 2);
  8150. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8151. lua_interface->ResetFunctionStack(state);
  8152. if (!spawn) {
  8153. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8154. return 0;
  8155. }
  8156. if (!spawn->IsEntity()) {
  8157. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8158. return 0;
  8159. }
  8160. if (spell && spell->targets.size() > 0) {
  8161. ZoneServer* zone = spell->caster->GetZone();
  8162. for (int8 i = 0; i < spell->targets.size(); i++) {
  8163. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8164. if (target && target->IsEntity()) {
  8165. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8166. if (target->IsPlayer())
  8167. ((Player*)target)->SetCharSheetChanged(true);
  8168. }
  8169. }
  8170. }
  8171. else {
  8172. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8173. if (spawn->IsPlayer())
  8174. ((Player*)spawn)->SetCharSheetChanged(true);
  8175. }
  8176. return 0;
  8177. }
  8178. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8179. if (!lua_interface)
  8180. return 0;
  8181. Spawn* spawn = lua_interface->GetSpawn(state);
  8182. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8183. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8184. lua_interface->ResetFunctionStack(state);
  8185. if (!spawn) {
  8186. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8187. return 0;
  8188. }
  8189. if (!spawn->IsEntity()) {
  8190. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8191. return 0;
  8192. }
  8193. if (spell && spell->targets.size() > 0) {
  8194. ZoneServer* zone = spell->caster->GetZone();
  8195. for (int8 i = 0; i < spell->targets.size(); i++) {
  8196. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8197. if (target && target->IsEntity()) {
  8198. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8199. if (target->IsPlayer())
  8200. ((Player*)target)->SetCharSheetChanged(true);
  8201. }
  8202. }
  8203. }
  8204. else {
  8205. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8206. if (spawn->IsPlayer())
  8207. ((Player*)spawn)->SetCharSheetChanged(true);
  8208. }
  8209. return 0;
  8210. }
  8211. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8212. if (!lua_interface)
  8213. return 0;
  8214. Item* item = lua_interface->GetItem(state);
  8215. int8 type = lua_interface->GetInt32Value(state, 2);
  8216. lua_interface->ResetFunctionStack(state);
  8217. if (!item) {
  8218. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8219. return 0;
  8220. }
  8221. if (type == 1)
  8222. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8223. else if (type == 2)
  8224. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8225. return 1;
  8226. }
  8227. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8228. if (!lua_interface)
  8229. return 0;
  8230. Spawn* target = lua_interface->GetSpawn(state);
  8231. float val = lua_interface->GetFloatValue(state, 2);
  8232. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8233. lua_interface->ResetFunctionStack(state);
  8234. // Added from Gangrenous post
  8235. if (spell && spell->resisted)
  8236. return 0;
  8237. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8238. if (val > 1.0f)
  8239. val = 1.0f - (val / 100.0f);
  8240. if (spell && spell->spell && spell->targets.size() > 0) {
  8241. ZoneServer* zone = spell->caster->GetZone();
  8242. for (int32 i = 0; i != spell->targets.size(); i++) {
  8243. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8244. if (spawn && spawn->IsEntity()) {
  8245. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8246. if (spawn->IsPlayer())
  8247. ((Player*)spawn)->SetCharSheetChanged(true);
  8248. }
  8249. }
  8250. }
  8251. else {
  8252. if (target && target->IsEntity()) {
  8253. ((Entity*)target)->SetSpeedMultiplier(val);
  8254. if (target->IsPlayer())
  8255. ((Player*)target)->SetCharSheetChanged(true);
  8256. }
  8257. }
  8258. return 0;
  8259. }
  8260. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8261. if (!lua_interface)
  8262. return 0;
  8263. Spawn* spawn = lua_interface->GetSpawn(state);
  8264. int16 model = lua_interface->GetInt16Value(state, 2);
  8265. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8266. lua_interface->ResetFunctionStack(state);
  8267. if (spell && spell->spell && spell->targets.size() > 0) {
  8268. ZoneServer* zone = spell->caster->GetZone();
  8269. for (int32 i = 0; i < spell->targets.size(); i++) {
  8270. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8271. if (target)
  8272. target->SetIllusionModel(model);
  8273. }
  8274. }
  8275. else {
  8276. if (!spawn) {
  8277. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8278. return 0;
  8279. }
  8280. spawn->SetIllusionModel(model);
  8281. }
  8282. return 0;
  8283. }
  8284. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8285. if (!lua_interface)
  8286. return 0;
  8287. Spawn* spawn = lua_interface->GetSpawn(state);
  8288. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8289. lua_interface->ResetFunctionStack(state);
  8290. if (spell && spell->spell && spell->targets.size() > 0) {
  8291. ZoneServer* zone = spell->caster->GetZone();
  8292. for (int32 i = 0; i < spell->targets.size(); i++) {
  8293. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8294. if (target)
  8295. target->SetIllusionModel(0);
  8296. }
  8297. }
  8298. else {
  8299. if (!spawn) {
  8300. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8301. return 0;
  8302. }
  8303. spawn->SetIllusionModel(0);
  8304. }
  8305. return 0;
  8306. }
  8307. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8308. if (!lua_interface)
  8309. return 0;
  8310. Spawn* caster = lua_interface->GetSpawn(state);
  8311. Spawn* target = lua_interface->GetSpawn(state, 2);
  8312. float chance = lua_interface->GetFloatValue(state, 3);
  8313. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8314. lua_interface->ResetFunctionStack(state);
  8315. if (!caster) {
  8316. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8317. return 0;
  8318. }
  8319. if (!caster->IsEntity()) {
  8320. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8321. return 0;
  8322. }
  8323. if (!target) {
  8324. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. if (!target->IsEntity()) {
  8328. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8329. return 0;
  8330. }
  8331. if (chance <= 0) {
  8332. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8333. return 0;
  8334. }
  8335. if (!spell) {
  8336. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8337. return 0;
  8338. }
  8339. if(spell->resisted) {
  8340. return 0;
  8341. }
  8342. if (((Entity*)caster)->GetThreatTransfer()) {
  8343. return 0;
  8344. }
  8345. ThreatTransfer* transfer = new ThreatTransfer;
  8346. transfer->Target = target->GetID();
  8347. transfer->Amount = chance;
  8348. transfer->Spell = spell;
  8349. ((Entity*)caster)->SetThreatTransfer(transfer);
  8350. return 0;
  8351. }
  8352. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8353. if (!lua_interface)
  8354. return 0;
  8355. Spawn* spawn = lua_interface->GetSpawn(state);
  8356. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8357. lua_interface->ResetFunctionStack(state);
  8358. if (!spawn) {
  8359. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8360. return 0;
  8361. }
  8362. if (!spell) {
  8363. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8364. return 0;
  8365. }
  8366. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8367. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8368. if(transfer && transfer->Spell != spell) {
  8369. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8370. return 0;
  8371. }
  8372. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8373. }
  8374. return 0;
  8375. }
  8376. int EQ2Emu_lua_CureByType(lua_State* state) {
  8377. if (!lua_interface)
  8378. return 0;
  8379. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8380. int8 cure_count = lua_interface->GetInt8Value(state);
  8381. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8382. string cure_name = lua_interface->GetStringValue(state, 3);
  8383. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8384. Spawn* target = lua_interface->GetSpawn(state, 5);
  8385. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8386. lua_interface->ResetFunctionStack(state);
  8387. if(spell && spell->resisted) {
  8388. return 0;
  8389. }
  8390. if (target) {
  8391. if (!target->IsEntity()) {
  8392. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8393. return 0;
  8394. }
  8395. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8396. std::string alternate_name = "item";
  8397. if(spell)
  8398. alternate_name = std::string(spell->spell->GetName());
  8399. if(!caster && spell)
  8400. caster = (Spawn*)spell->caster;
  8401. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8402. }
  8403. }
  8404. else {
  8405. ZoneServer* zone = spell->caster->GetZone();
  8406. vector<int32> targets = spell->targets;
  8407. vector<Entity*> targets_to_cure;
  8408. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8409. for (int8 i = 0; i < targets.size(); i++) {
  8410. target = zone->GetSpawnByID(targets.at(i));
  8411. if (!target || !target->IsEntity())
  8412. continue;
  8413. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8414. targets_to_cure.push_back((Entity*)target);
  8415. }
  8416. }
  8417. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8418. vector<Entity*>::iterator itr;
  8419. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8420. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8421. }
  8422. }
  8423. return 0;
  8424. }
  8425. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8426. if (!lua_interface)
  8427. return 0;
  8428. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8429. if (!spell) {
  8430. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8431. lua_interface->ResetFunctionStack(state);
  8432. return 0;
  8433. }
  8434. if(spell->resisted) {
  8435. lua_interface->ResetFunctionStack(state);
  8436. return 0;
  8437. }
  8438. int8 cure_count = lua_interface->GetInt8Value(state);
  8439. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8440. string cure_name = lua_interface->GetStringValue(state, 3);
  8441. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8442. Spawn* target = lua_interface->GetSpawn(state, 5);
  8443. lua_interface->ResetFunctionStack(state);
  8444. if (target) {
  8445. if (!target->IsEntity()) {
  8446. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. if (((Entity*)target)->GetDetCount() > 0)
  8450. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8451. }
  8452. else {
  8453. ZoneServer* zone = spell->caster->GetZone();
  8454. vector<int32> targets = spell->targets;
  8455. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8456. for (int8 i = 0; i < targets.size(); i++) {
  8457. target = zone->GetSpawnByID(targets.at(i));
  8458. if (!target || !target->IsEntity())
  8459. continue;
  8460. if (((Entity*)target)->GetDetCount() > 0)
  8461. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8462. }
  8463. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8464. }
  8465. return 0;
  8466. }
  8467. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8468. if (!lua_interface)
  8469. return 0;
  8470. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8471. lua_interface->ResetFunctionStack(state);
  8472. if (!spell) {
  8473. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8474. return 0;
  8475. }
  8476. if (!spell->caster) {
  8477. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8478. return 0;
  8479. }
  8480. if (!spell->caster->GetZone()) {
  8481. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8482. return 0;
  8483. }
  8484. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8485. return 0;
  8486. }
  8487. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8488. if (!lua_interface)
  8489. return 0;
  8490. Spawn* spawn = lua_interface->GetSpawn(state);
  8491. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8492. lua_interface->ResetFunctionStack(state);
  8493. if (!spell) {
  8494. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8495. return 0;
  8496. }
  8497. if (spawn && spawn->IsEntity())
  8498. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8499. else {
  8500. ZoneServer* zone = spell->caster->GetZone();
  8501. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8502. for (int32 i = 0; i < spell->targets.size(); i++) {
  8503. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8504. if (!spawn || !spawn->IsEntity())
  8505. continue;
  8506. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8507. }
  8508. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8509. }
  8510. return 0;
  8511. }
  8512. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8513. if (!lua_interface)
  8514. return 0;
  8515. Spawn* spawn = lua_interface->GetSpawn(state);
  8516. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8517. lua_interface->ResetFunctionStack(state);
  8518. if (!spell) {
  8519. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8520. return 0;
  8521. }
  8522. if (spawn && spawn->IsEntity())
  8523. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8524. else {
  8525. ZoneServer* zone = spell->caster->GetZone();
  8526. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8527. for (int32 i = 0; i < spell->targets.size(); i++) {
  8528. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8529. if (!spawn || !spawn->IsEntity())
  8530. continue;
  8531. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8532. }
  8533. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8534. }
  8535. return 0;
  8536. }
  8537. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8538. if (!lua_interface)
  8539. return 0;
  8540. Spawn* caster = lua_interface->GetSpawn(state);
  8541. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8542. lua_interface->ResetFunctionStack(state);
  8543. if (!caster) {
  8544. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8545. return 0;
  8546. }
  8547. if (!caster->IsPlayer()) {
  8548. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8549. return 0;
  8550. }
  8551. Spawn* target = caster->GetTarget();
  8552. if (!target) {
  8553. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8554. return 0;
  8555. }
  8556. Client* client = ((Player*)caster)->GetClient();
  8557. if (!client) {
  8558. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8559. return 0;
  8560. }
  8561. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8562. if (ho) {
  8563. ho->SetTarget(target->GetID());
  8564. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8565. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8566. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8567. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8568. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8569. deque<GroupMemberInfo*>::iterator itr;
  8570. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8571. if (group)
  8572. {
  8573. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8574. deque<GroupMemberInfo*>* members = group->GetMembers();
  8575. for (itr = members->begin(); itr != members->end(); itr++) {
  8576. if ((*itr)->client)
  8577. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8578. }
  8579. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8580. }
  8581. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8582. }
  8583. else
  8584. safe_delete(ho);
  8585. }
  8586. else {
  8587. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8588. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8589. }
  8590. else
  8591. safe_delete(ho);
  8592. }
  8593. }
  8594. return 0;
  8595. }
  8596. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8597. if (!lua_interface)
  8598. return 0;
  8599. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8600. if (!spell) {
  8601. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8602. return 0;
  8603. }
  8604. int16 triggerCount = lua_interface->GetInt16Value(state);
  8605. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8606. if (!triggerCount) {
  8607. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8608. return 0;
  8609. }
  8610. spell->num_triggers = triggerCount;
  8611. spell->had_triggers = true;
  8612. spell->cancel_after_all_triggers = cancel_after_triggers;
  8613. return 0;
  8614. }
  8615. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8616. if (!lua_interface)
  8617. return 0;
  8618. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8619. lua_interface->ResetFunctionStack(state);
  8620. if (!spell) {
  8621. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8622. return 0;
  8623. }
  8624. lua_interface->SetInt32Value(state, spell->num_triggers);
  8625. return 1;
  8626. }
  8627. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8628. if (!lua_interface)
  8629. return 0;
  8630. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8631. if (!spell) {
  8632. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8633. lua_interface->ResetFunctionStack(state);
  8634. return 0;
  8635. }
  8636. if (!spell->caster || !spell->caster->GetZone()) {
  8637. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8638. lua_interface->ResetFunctionStack(state);
  8639. return 0;
  8640. }
  8641. int16 remove_count = lua_interface->GetInt16Value(state);
  8642. lua_interface->ResetFunctionStack(state);
  8643. if (!remove_count)
  8644. remove_count = 1;
  8645. if (remove_count >= spell->num_triggers) {
  8646. spell->num_triggers = 0;
  8647. if (spell->cancel_after_all_triggers)
  8648. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8649. }
  8650. else {
  8651. spell->num_triggers -= remove_count;
  8652. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8653. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8654. }
  8655. return 0;
  8656. }
  8657. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8658. if (!lua_interface)
  8659. return 0;
  8660. Spawn* spawn = lua_interface->GetSpawn(state);
  8661. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8662. lua_interface->ResetFunctionStack(state);
  8663. if (!spawn) {
  8664. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8665. return 0;
  8666. }
  8667. if (!copy_spawn) {
  8668. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8669. return 0;
  8670. }
  8671. spawn->CopySpawnAppearance(copy_spawn);
  8672. return 0;
  8673. }
  8674. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8675. Spawn* spawn = lua_interface->GetSpawn(state);
  8676. int8 type = lua_interface->GetInt8Value(state, 2);
  8677. lua_interface->ResetFunctionStack(state);
  8678. if (!spawn) {
  8679. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8680. return 0;
  8681. }
  8682. else if (!spawn->IsEntity()) {
  8683. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8684. return 0;
  8685. }
  8686. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8687. return 1;
  8688. }
  8689. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8690. if (!lua_interface)
  8691. return 0;
  8692. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8693. int8 type = lua_interface->GetInt8Value(state);
  8694. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8695. lua_interface->ResetFunctionStack(state);
  8696. if (!spell) {
  8697. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8698. return 0;
  8699. }
  8700. if(spell->resisted) {
  8701. return 0;
  8702. }
  8703. if (spawn) {
  8704. if (!spawn->IsEntity()) {
  8705. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8706. return 0;
  8707. }
  8708. Entity* entity = ((Entity*)spawn);
  8709. entity->AddImmunity(spell, type);
  8710. }
  8711. else if(spell->caster && spell->caster->GetZone()) {
  8712. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8713. for (int8 i = 0; i < spell->targets.size(); i++) {
  8714. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8715. if (!spawn || !spawn->IsEntity())
  8716. continue;
  8717. Entity* entity = ((Entity*)spawn);
  8718. entity->AddImmunity(spell, type);
  8719. }
  8720. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8721. }
  8722. return 0;
  8723. }
  8724. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8725. if (!lua_interface)
  8726. return 0;
  8727. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8728. int8 type = lua_interface->GetInt8Value(state);
  8729. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8730. lua_interface->ResetFunctionStack(state);
  8731. if (!spell) {
  8732. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8733. return 0;
  8734. }
  8735. if (spawn) {
  8736. if (!spawn->IsEntity()) {
  8737. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8738. return 0;
  8739. }
  8740. Entity* entity = ((Entity*)spawn);
  8741. entity->RemoveImmunity(spell, type);
  8742. }
  8743. else if(spell->caster && spell->caster->GetZone()) {
  8744. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8745. for (int8 i = 0; i < spell->targets.size(); i++) {
  8746. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8747. if (!spawn || !spawn->IsEntity())
  8748. continue;
  8749. Entity* entity = ((Entity*)spawn);
  8750. entity->RemoveImmunity(spell, type);
  8751. }
  8752. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8753. }
  8754. return 0;
  8755. }
  8756. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8757. if (!lua_interface)
  8758. return 0;
  8759. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8760. if (!spell) {
  8761. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8762. lua_interface->ResetFunctionStack(state);
  8763. return 0;
  8764. }
  8765. if(spell->resisted) {
  8766. lua_interface->ResetFunctionStack(state);
  8767. return 0;
  8768. }
  8769. float snare = lua_interface->GetFloatValue(state);
  8770. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8771. lua_interface->ResetFunctionStack(state);
  8772. // convert the val to the speed multipler value (100 - val)
  8773. float val = 100.0 - snare;
  8774. val /= 100.0;
  8775. if (spawn) {
  8776. if (!spawn->IsEntity()) {
  8777. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8778. return 0;
  8779. }
  8780. ((Entity*)spawn)->SetSnareValue(spell, val);
  8781. }
  8782. else if(spell->caster && spell->caster->GetZone()) {
  8783. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8784. for (int8 i = 0; i < spell->targets.size(); i++) {
  8785. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8786. if (!spawn || !spawn->IsEntity())
  8787. continue;
  8788. ((Entity*)spawn)->SetSnareValue(spell, val);
  8789. }
  8790. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8791. }
  8792. return 0;
  8793. }
  8794. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8795. if (!lua_interface)
  8796. return 0;
  8797. Spawn* spawn = lua_interface->GetSpawn(state);
  8798. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8799. lua_interface->ResetFunctionStack(state);
  8800. if (!spawn) {
  8801. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8802. return 0;
  8803. }
  8804. if (race_id == 0) {
  8805. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8806. return 0;
  8807. }
  8808. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8809. return 1;
  8810. }
  8811. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8812. if (!lua_interface)
  8813. return 0;
  8814. Spawn* spawn = lua_interface->GetSpawn(state);
  8815. lua_interface->ResetFunctionStack(state);
  8816. if (!spawn) {
  8817. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8818. return 0;
  8819. }
  8820. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8821. return 1;
  8822. }
  8823. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8824. if (!lua_interface)
  8825. return 0;
  8826. Spawn* spawn = lua_interface->GetSpawn(state);
  8827. lua_interface->ResetFunctionStack(state);
  8828. if (!spawn) {
  8829. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8830. return 0;
  8831. }
  8832. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8833. return 1;
  8834. }
  8835. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8836. if (!lua_interface)
  8837. return 0;
  8838. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8839. lua_interface->ResetFunctionStack(state);
  8840. if (!spell) {
  8841. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8842. return 0;
  8843. }
  8844. lua_interface->SetStringValue(state, spell->spell->GetName());
  8845. return 1;
  8846. }
  8847. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8848. if (!lua_interface)
  8849. return 0;
  8850. Quest* quest = lua_interface->GetQuest(state);
  8851. lua_interface->ResetFunctionStack(state);
  8852. if (!quest) {
  8853. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8854. return 0;
  8855. }
  8856. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8857. return 1;
  8858. }
  8859. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8860. if (!lua_interface)
  8861. return 0;
  8862. Quest* quest = lua_interface->GetQuest(state);
  8863. int32 flags = lua_interface->GetInt32Value(state, 2);
  8864. lua_interface->ResetFunctionStack(state);
  8865. if (!quest) {
  8866. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8867. return 0;
  8868. }
  8869. quest->SetQuestFlags(flags);
  8870. return 0;
  8871. }
  8872. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8873. if (!lua_interface)
  8874. return 0;
  8875. Quest* quest = lua_interface->GetQuest(state);
  8876. Spawn* player = lua_interface->GetSpawn(state, 2);
  8877. int32 step = lua_interface->GetInt32Value(state, 3);
  8878. int32 duration = lua_interface->GetInt32Value(state, 4);
  8879. string action = lua_interface->GetStringValue(state, 5);
  8880. lua_interface->ResetFunctionStack(state);
  8881. if (!quest) {
  8882. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8883. return 0;
  8884. }
  8885. if (!player) {
  8886. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8887. return 0;
  8888. }
  8889. if (!player->IsPlayer()) {
  8890. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8891. return 0;
  8892. }
  8893. if (step == 0) {
  8894. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8895. return 0;
  8896. }
  8897. if (duration == 0) {
  8898. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8899. return 0;
  8900. }
  8901. if (action.length() == 0) {
  8902. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8903. return 0;
  8904. }
  8905. Client* client = ((Player*)player)->GetClient();
  8906. if (!client) {
  8907. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8908. return 0;
  8909. }
  8910. quest->SetTimerStep(step);
  8911. quest->AddFailedAction(step, action);
  8912. quest->SetStepTimer(duration);
  8913. client->AddQuestTimer(quest->GetQuestID());
  8914. return 0;
  8915. }
  8916. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8917. if (!lua_interface)
  8918. return 0;
  8919. Quest* quest = lua_interface->GetQuest(state);
  8920. Spawn* player = lua_interface->GetSpawn(state, 2);
  8921. lua_interface->ResetFunctionStack(state);
  8922. if (!quest) {
  8923. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8924. return 0;
  8925. }
  8926. if (!player) {
  8927. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8928. return 0;
  8929. }
  8930. if (!player->IsPlayer()) {
  8931. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8932. return 0;
  8933. }
  8934. Client* client = ((Player*)player)->GetClient();
  8935. if (!client) {
  8936. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8937. return 0;
  8938. }
  8939. quest->SetTimerStep(0);
  8940. quest->SetStepTimer(0);
  8941. client->RemoveQuestTimer(quest->GetQuestID());
  8942. return 0;
  8943. }
  8944. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8945. if (!lua_interface)
  8946. return 0;
  8947. Spawn* player = lua_interface->GetSpawn(state);
  8948. Quest* quest = lua_interface->GetQuest(state, 2);
  8949. int32 step = lua_interface->GetInt32Value(state, 3);
  8950. lua_interface->ResetFunctionStack(state);
  8951. if (!player) {
  8952. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8953. return 0;
  8954. }
  8955. if (!player->IsPlayer()) {
  8956. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8957. return 0;
  8958. }
  8959. if (!quest) {
  8960. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8961. return 0;
  8962. }
  8963. if (step == 0) {
  8964. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8965. return 0;
  8966. }
  8967. Client* client = ((Player*)player)->GetClient();
  8968. if (!client) {
  8969. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8970. return 0;
  8971. }
  8972. if (quest->RemoveQuestStep(step, client)) {
  8973. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8974. client->GetCurrentZone()->SendQuestUpdates(client);
  8975. }
  8976. else
  8977. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8978. return 0;
  8979. }
  8980. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8981. if (!lua_interface)
  8982. return 0;
  8983. Quest* quest = lua_interface->GetQuest(state, 1);
  8984. int32 step = lua_interface->GetInt32Value(state, 2);
  8985. string desc = lua_interface->GetStringValue(state, 3);
  8986. string task_group = lua_interface->GetStringValue(state, 4);
  8987. lua_interface->ResetFunctionStack(state);
  8988. if (!quest) {
  8989. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8990. return 0;
  8991. }
  8992. if (step == 0) {
  8993. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8994. return 0;
  8995. }
  8996. QuestStep* quest_step = quest->GetQuestStep(step);
  8997. if (!quest_step) {
  8998. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8999. return 0;
  9000. }
  9001. quest_step->SetStepProgress(0);
  9002. quest_step->SetTaskGroup(task_group);
  9003. quest_step->SetDescription(desc);
  9004. return 0;
  9005. }
  9006. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9007. if (!lua_interface)
  9008. return 0;
  9009. Quest* quest = lua_interface->GetQuest(state);
  9010. int32 step = lua_interface->GetInt32Value(state, 2);
  9011. string action = lua_interface->GetStringValue(state, 3);
  9012. lua_interface->ResetFunctionStack(state);
  9013. if (!quest) {
  9014. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9015. return 0;
  9016. }
  9017. if (step == 0) {
  9018. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9019. return 0;
  9020. }
  9021. if (action.length() == 0) {
  9022. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9023. return 0;
  9024. }
  9025. quest->AddFailedAction(step, action);
  9026. return 0;
  9027. }
  9028. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9029. if (!lua_interface)
  9030. return 0;
  9031. Spawn* player = lua_interface->GetSpawn(state);
  9032. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9033. int32 step = lua_interface->GetInt32Value(state, 3);
  9034. lua_interface->ResetFunctionStack(state);
  9035. if (!player) {
  9036. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9037. return 0;
  9038. }
  9039. if (!player->IsPlayer()) {
  9040. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9041. return 0;
  9042. }
  9043. if (quest_id == 0) {
  9044. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9045. return 0;
  9046. }
  9047. if (step == 0) {
  9048. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9049. return 0;
  9050. }
  9051. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9052. if (!quest) {
  9053. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9054. return 0;
  9055. }
  9056. quest->StepFailed(step);
  9057. return 0;
  9058. }
  9059. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9060. if (!lua_interface)
  9061. return 0;
  9062. Spawn* player = lua_interface->GetSpawn(state);
  9063. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9064. lua_interface->ResetFunctionStack(state);
  9065. if (!player) {
  9066. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9067. return 0;
  9068. }
  9069. if (!player->IsPlayer()) {
  9070. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9071. return 0;
  9072. }
  9073. if (quest_id == 0) {
  9074. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9075. return 0;
  9076. }
  9077. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9078. return 1;
  9079. }
  9080. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9081. if (!lua_interface)
  9082. return 0;
  9083. string name = lua_interface->GetStringValue(state);
  9084. string value = lua_interface->GetStringValue(state, 2);
  9085. string comment = lua_interface->GetStringValue(state, 3);
  9086. lua_interface->ResetFunctionStack(state);
  9087. if (name.length() == 0) {
  9088. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9089. return 0;
  9090. }
  9091. if (value.length() == 0) {
  9092. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9093. return 0;
  9094. }
  9095. string varname = string("lua_").append(name);
  9096. Variable* var = variables.FindVariable(varname);
  9097. if (var)
  9098. var->SetValue(value.c_str());
  9099. else {
  9100. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9101. variables.AddVariable(var);
  9102. }
  9103. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9104. return 0;
  9105. }
  9106. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9107. if (!lua_interface)
  9108. return 0;
  9109. string name = lua_interface->GetStringValue(state);
  9110. lua_interface->ResetFunctionStack(state);
  9111. if (name.length() == 0) {
  9112. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9113. return 0;
  9114. }
  9115. string varname = string("lua_").append(name);
  9116. Variable* var = variables.FindVariable(varname);
  9117. if (var)
  9118. lua_interface->SetStringValue(state, var->GetValue());
  9119. else
  9120. lua_interface->SetStringValue(state, "NULL");
  9121. return 1;
  9122. }
  9123. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9124. if (!lua_interface)
  9125. return 0;
  9126. Spawn* player = lua_interface->GetSpawn(state);
  9127. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9128. lua_interface->ResetFunctionStack(state);
  9129. if (!player) {
  9130. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9131. return 0;
  9132. }
  9133. if (!player->IsPlayer()) {
  9134. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9135. return 0;
  9136. }
  9137. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9138. return 1;
  9139. }
  9140. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9141. if (!lua_interface)
  9142. return 0;
  9143. Spawn* player = lua_interface->GetSpawn(state);
  9144. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9145. lua_interface->ResetFunctionStack(state);
  9146. if (!player) {
  9147. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9148. return 0;
  9149. }
  9150. if (!player->IsPlayer()) {
  9151. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9152. return 0;
  9153. }
  9154. Language* language = master_languages_list.GetLanguage(language_id);
  9155. if (language)
  9156. {
  9157. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9158. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9159. }
  9160. return 0;
  9161. }
  9162. int EQ2Emu_lua_IsNight(lua_State* state) {
  9163. if (!lua_interface)
  9164. return 0;
  9165. ZoneServer* zone = lua_interface->GetZone(state);
  9166. lua_interface->ResetFunctionStack(state);
  9167. if (!zone) {
  9168. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9169. return 0;
  9170. }
  9171. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9172. return 1;
  9173. }
  9174. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9175. if (!lua_interface)
  9176. return 0;
  9177. Spawn* spawn = lua_interface->GetSpawn(state);
  9178. lua_interface->ResetFunctionStack(state);
  9179. if (!spawn) {
  9180. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9181. return 0;
  9182. }
  9183. if (!spawn->IsWidget()) {
  9184. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9185. return 0;
  9186. }
  9187. ((Widget*)spawn)->SetMultiFloorLift(true);
  9188. if (spawn->GetZone())
  9189. spawn->GetZone()->AddTransportSpawn(spawn);
  9190. return 0;
  9191. }
  9192. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9193. if (!lua_interface)
  9194. return 0;
  9195. Spawn* player = lua_interface->GetSpawn(state);
  9196. int32 path = lua_interface->GetInt32Value(state, 2);
  9197. lua_interface->ResetFunctionStack(state);
  9198. if (!player) {
  9199. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9200. return 0;
  9201. }
  9202. if (!player->IsPlayer()) {
  9203. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9204. return 0;
  9205. }
  9206. if (path == 0) {
  9207. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9208. return 0;
  9209. }
  9210. Client* client = ((Player*)player)->GetClient();
  9211. if (!client) {
  9212. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9213. return 0;
  9214. }
  9215. client->SendFlightAutoMount(path);
  9216. return 0;
  9217. }
  9218. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9219. if (!lua_interface)
  9220. return 0;
  9221. Spawn* player = lua_interface->GetSpawn(state);
  9222. if (!player) {
  9223. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9224. return 0;
  9225. }
  9226. if (!player->IsPlayer()) {
  9227. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9228. return 0;
  9229. }
  9230. Client* client = ((Player*)player)->GetClient();
  9231. if (!client) {
  9232. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9233. return 0;
  9234. }
  9235. client->EndAutoMount();
  9236. return 0;
  9237. }
  9238. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9239. if (!lua_interface)
  9240. return 0;
  9241. Spawn* player = lua_interface->GetSpawn(state);
  9242. lua_interface->ResetFunctionStack(state);
  9243. if (!player) {
  9244. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9245. return 0;
  9246. }
  9247. if (!player->IsPlayer()) {
  9248. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9249. return 0;
  9250. }
  9251. Client* client = ((Player*)player)->GetClient();
  9252. if (!client) {
  9253. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9254. return 0;
  9255. }
  9256. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9257. return 1;
  9258. }
  9259. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9260. if (!lua_interface)
  9261. return 0;
  9262. Spawn* player = lua_interface->GetSpawn(state);
  9263. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9264. int32 value = lua_interface->GetInt32Value(state, 3);
  9265. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9266. lua_interface->ResetFunctionStack(state);
  9267. if (!player) {
  9268. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9269. return 0;
  9270. }
  9271. if (!player->IsPlayer()) {
  9272. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9273. return 0;
  9274. }
  9275. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9276. return 0;
  9277. }
  9278. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9279. if (!lua_interface)
  9280. return 0;
  9281. Spawn* player = lua_interface->GetSpawn(state);
  9282. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9283. lua_interface->ResetFunctionStack(state);
  9284. if (!player) {
  9285. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9286. return 0;
  9287. }
  9288. if (!player->IsPlayer()) {
  9289. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9290. return 0;
  9291. }
  9292. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9293. if (!hd)
  9294. return 0;
  9295. lua_interface->SetInt32Value(state, hd->Value);
  9296. lua_interface->SetInt32Value(state, hd->Value2);
  9297. return 2;
  9298. }
  9299. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9300. if (!lua_interface)
  9301. return 0;
  9302. Spawn* spawn = lua_interface->GetSpawn(state);
  9303. int32 grid = lua_interface->GetInt32Value(state, 2);
  9304. lua_interface->ResetFunctionStack(state);
  9305. if (!spawn) {
  9306. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9307. return 0;
  9308. }
  9309. if (grid == 0) {
  9310. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9311. return 0;
  9312. }
  9313. spawn->SetLocation(grid);
  9314. return 0;
  9315. }
  9316. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9317. if (!lua_interface)
  9318. return 0;
  9319. Spawn* spawn = lua_interface->GetSpawn(state);
  9320. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9321. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9322. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9323. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9324. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9325. lua_interface->ResetFunctionStack(state);
  9326. if (!spawn) {
  9327. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9328. return 0;
  9329. }
  9330. //Add this quest to the list of required quests for this spawn
  9331. spawn->SetRequiredHistory(event_id, value1, value2);
  9332. //If private spawn value set
  9333. if (private_spawn) {
  9334. //Set the spawn to be private when not granted access via history
  9335. spawn->AddAllowAccessSpawn(spawn);
  9336. spawn->SetPrivateQuestSpawn(true);
  9337. }
  9338. //This value will override vis_flags in the vis packet
  9339. if (flag_override > 0)
  9340. spawn->SetQuestsRequiredOverride(flag_override);
  9341. return 0;
  9342. }
  9343. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9344. if (!lua_interface)
  9345. return 0;
  9346. Spawn* player = lua_interface->GetSpawn(state);
  9347. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9348. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9349. lua_interface->ResetFunctionStack(state);
  9350. if (!player) {
  9351. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9352. return 0;
  9353. }
  9354. if (!player->IsPlayer()) {
  9355. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9356. return 0;
  9357. }
  9358. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9359. return 1;
  9360. }
  9361. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9362. if (!lua_interface)
  9363. return 0;
  9364. Spawn* player = lua_interface->GetSpawn(state);
  9365. int8 level = lua_interface->GetInt8Value(state, 2);
  9366. lua_interface->ResetFunctionStack(state);
  9367. if (!player) {
  9368. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9369. return 0;
  9370. }
  9371. if (!player->IsPlayer()) {
  9372. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9373. return 0;
  9374. }
  9375. if (level == 0) {
  9376. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9377. return 0;
  9378. }
  9379. Client* client = ((Player*)player)->GetClient();
  9380. if (!client) {
  9381. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9382. return 0;
  9383. }
  9384. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9385. return 0;
  9386. }
  9387. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9388. if (!lua_interface)
  9389. return 0;
  9390. Spawn* player = lua_interface->GetSpawn(state);
  9391. int32 amount = lua_interface->GetInt32Value(state, 2);
  9392. lua_interface->ResetFunctionStack(state);
  9393. if (!player) {
  9394. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9395. return 0;
  9396. }
  9397. if (!player->IsPlayer()) {
  9398. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9399. return 0;
  9400. }
  9401. if (amount == 0) {
  9402. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9403. return 0;
  9404. }
  9405. ((Player*)player)->AddCoins(amount);
  9406. return 0;
  9407. }
  9408. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9409. if (!lua_interface)
  9410. return 0;
  9411. Spawn* player = lua_interface->GetSpawn(state);
  9412. int32 amount = lua_interface->GetInt32Value(state, 2);
  9413. lua_interface->ResetFunctionStack(state);
  9414. if (!player) {
  9415. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9416. return 0;
  9417. }
  9418. if (!player->IsPlayer()) {
  9419. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9420. return 0;
  9421. }
  9422. if (amount == 0) {
  9423. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9424. return 0;
  9425. }
  9426. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9427. return 1;
  9428. }
  9429. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9430. if (!lua_interface)
  9431. return 0;
  9432. ZoneServer* zone = lua_interface->GetZone(state);
  9433. lua_interface->ResetFunctionStack(state);
  9434. if (!zone) {
  9435. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9436. return 0;
  9437. }
  9438. vector<Entity*> players = zone->GetPlayers();
  9439. if (players.size() == 0)
  9440. return 0;
  9441. lua_createtable(state, players.size(), 0);
  9442. int newTable = lua_gettop(state);
  9443. for (int32 i = 0; i < players.size(); i++) {
  9444. lua_interface->SetSpawnValue(state, players.at(i));
  9445. lua_rawseti(state, newTable, i + 1);
  9446. }
  9447. return 1;
  9448. }
  9449. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9450. if (!lua_interface)
  9451. return 0;
  9452. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9453. if (!zone) {
  9454. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9455. return 0;
  9456. }
  9457. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9458. lua_interface->ResetFunctionStack(state);
  9459. //Map of <placement_id, location_id>
  9460. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9461. map<int32, int32>::iterator itr;
  9462. vector<Spawn*> group;
  9463. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9464. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9465. if (!location) {
  9466. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9467. return 0;
  9468. }
  9469. Spawn* spawn = 0;
  9470. if (location->entities[0]) {
  9471. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9472. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9473. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9474. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9475. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9476. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9477. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9478. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9479. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9480. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9481. if(spawn && spawn->IsOmittedByDBFlag())
  9482. {
  9483. 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);
  9484. safe_delete(spawn);
  9485. continue;
  9486. }
  9487. if (spawn) {
  9488. const char* script = 0;
  9489. for (int x = 0; x < 3; x++) {
  9490. switch (x) {
  9491. case 0:
  9492. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9493. break;
  9494. case 1:
  9495. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9496. break;
  9497. case 2:
  9498. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9499. break;
  9500. }
  9501. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9502. spawn->SetSpawnScript(string(script));
  9503. break;
  9504. }
  9505. }
  9506. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9507. lua_interface->SetSpawnValue(state, spawn);
  9508. group.push_back(spawn);
  9509. }
  9510. else {
  9511. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9512. safe_delete(spawn);
  9513. }
  9514. }
  9515. }
  9516. if (!group.empty()) {
  9517. lua_createtable(state, group.size(), 0);
  9518. int newTable = lua_gettop(state);
  9519. for (int32 i = 0; i < group.size(); i++) {
  9520. lua_interface->SetSpawnValue(state, group[i]);
  9521. lua_rawseti(state, newTable, i + 1);
  9522. }
  9523. }
  9524. else
  9525. lua_pushnil(state);
  9526. return 1;
  9527. }
  9528. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9529. if (!lua_interface)
  9530. return 0;
  9531. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9532. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9533. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9534. lua_interface->ResetFunctionStack(state);
  9535. if (!spawn) {
  9536. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9537. return 0;
  9538. }
  9539. if (anim_id == 0) {
  9540. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9541. return 0;
  9542. }
  9543. if (leeway == 0)
  9544. leeway = 5000;
  9545. spawn->SetSpawnAnim(anim_id);
  9546. spawn->SetSpawnAnimLeeway(leeway);
  9547. return 0;
  9548. }
  9549. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9550. if (!lua_interface)
  9551. return 0;
  9552. Spawn* player = lua_interface->GetSpawn(state);
  9553. lua_interface->ResetFunctionStack(state);
  9554. if (!player || !player->IsPlayer()) {
  9555. return 0;
  9556. }
  9557. Client* client = ((Player*)player)->GetClient();
  9558. if (!client) {
  9559. return 0;
  9560. }
  9561. lua_interface->SetInt32Value(state, client->GetVersion());
  9562. return 1;
  9563. }
  9564. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9565. if (!lua_interface)
  9566. return 0;
  9567. Item* item = lua_interface->GetItem(state);
  9568. lua_interface->ResetFunctionStack(state);
  9569. if (!item) {
  9570. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9571. return 0;
  9572. }
  9573. lua_interface->SetInt32Value(state, item->details.item_id);
  9574. return 1;
  9575. }
  9576. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9577. if (!lua_interface)
  9578. return 0;
  9579. Spawn* spawn = lua_interface->GetSpawn(state);
  9580. lua_interface->ResetFunctionStack(state);
  9581. if (!spawn) {
  9582. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9583. return 0;
  9584. }
  9585. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9586. return 1;
  9587. }
  9588. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9589. if (!lua_interface)
  9590. return 0;
  9591. Spawn* spawn = lua_interface->GetSpawn(state);
  9592. lua_interface->ResetFunctionStack(state);
  9593. if (!spawn) {
  9594. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9595. return 0;
  9596. }
  9597. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9598. return 1;
  9599. }
  9600. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9601. if (!lua_interface)
  9602. return 0;
  9603. Spawn* spawn = lua_interface->GetSpawn(state);
  9604. lua_interface->ResetFunctionStack(state);
  9605. if (!spawn) {
  9606. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9607. return 0;
  9608. }
  9609. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9610. return 1;
  9611. }
  9612. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9613. if (!lua_interface)
  9614. return 0;
  9615. Spawn* spawn = lua_interface->GetSpawn(state);
  9616. lua_interface->ResetFunctionStack(state);
  9617. if (!spawn) {
  9618. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9619. return 0;
  9620. }
  9621. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9622. return 1;
  9623. }
  9624. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9625. if (!lua_interface)
  9626. return 0;
  9627. Spawn* spawn = lua_interface->GetSpawn(state);
  9628. float pct = lua_interface->GetFloatValue(state, 2);
  9629. lua_interface->ResetFunctionStack(state);
  9630. if (!spawn) {
  9631. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9632. return 0;
  9633. }
  9634. if (pct == 0) {
  9635. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9636. return 0;
  9637. }
  9638. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9639. lua_interface->SetInt32Value(state, amount);
  9640. return 1;
  9641. }
  9642. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9643. if (!lua_interface)
  9644. return 0;
  9645. Spawn* spawn = lua_interface->GetSpawn(state);
  9646. float pct = lua_interface->GetFloatValue(state, 2);
  9647. lua_interface->ResetFunctionStack(state);
  9648. if (!spawn) {
  9649. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9650. return 0;
  9651. }
  9652. if (pct == 0) {
  9653. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9654. return 0;
  9655. }
  9656. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9657. lua_interface->SetInt32Value(state, amount);
  9658. return 1;
  9659. }
  9660. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9661. if (!lua_interface)
  9662. return 0;
  9663. Spawn* spawn = lua_interface->GetSpawn(state);
  9664. lua_interface->ResetFunctionStack(state);
  9665. if (!spawn) {
  9666. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9667. return 0;
  9668. }
  9669. if (!spawn->IsPlayer()) {
  9670. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9671. return 0;
  9672. }
  9673. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9674. return 1;
  9675. }
  9676. int EQ2Emu_lua_Evac(lua_State* state) {
  9677. if (!lua_interface)
  9678. return 0;
  9679. Spawn* target = lua_interface->GetSpawn(state);
  9680. if (target) {
  9681. float x = target->GetZone()->GetSafeX();
  9682. float y = target->GetZone()->GetSafeY();
  9683. float z = target->GetZone()->GetSafeZ();
  9684. float h = target->GetZone()->GetSafeHeading();
  9685. target->SetX(x);
  9686. target->SetY(y);
  9687. target->SetZ(z);
  9688. target->SetHeading(h);
  9689. target->SetSpawnOrigX(x);
  9690. target->SetSpawnOrigY(y);
  9691. target->SetSpawnOrigZ(z);
  9692. target->SetSpawnOrigHeading(h);
  9693. if (target->IsPlayer()) {
  9694. Client* client = ((Player*)target)->GetClient();
  9695. if (client) {
  9696. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9697. int numargs = lua_interface->GetNumberOfArgs(state);
  9698. if(numargs == 4) {
  9699. x = lua_interface->GetFloatValue(state,1);
  9700. y = lua_interface->GetFloatValue(state,2);
  9701. z = lua_interface->GetFloatValue(state,3);
  9702. h = lua_interface->GetFloatValue(state,4);
  9703. }
  9704. client->SetReloadingZone(true);
  9705. target->SetX(x);
  9706. target->SetY(y);
  9707. target->SetZ(z);
  9708. target->SetHeading(h);
  9709. target->SetSpawnOrigX(x);
  9710. target->SetSpawnOrigY(y);
  9711. target->SetSpawnOrigZ(z);
  9712. target->SetSpawnOrigHeading(h);
  9713. target->SetAppearancePosition(x,y,z);
  9714. client->SetZoningCoords(x,y,z,h);
  9715. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9716. if (packet)
  9717. {
  9718. packet->setDataByName("x", x);
  9719. packet->setDataByName("y", y);
  9720. packet->setDataByName("z", z);
  9721. client->QueuePacket(packet->serialize());
  9722. safe_delete(packet);
  9723. }
  9724. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9725. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9726. }
  9727. }
  9728. lua_interface->ResetFunctionStack(state);
  9729. }
  9730. else {
  9731. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9732. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9733. lua_interface->ResetFunctionStack(state);
  9734. return 0;
  9735. }
  9736. ZoneServer* zone = spell->caster->GetZone();
  9737. float x = spell->caster->GetZone()->GetSafeX();
  9738. float y = spell->caster->GetZone()->GetSafeY();
  9739. float z = spell->caster->GetZone()->GetSafeZ();
  9740. float h = spell->caster->GetZone()->GetSafeHeading();
  9741. int numargs = lua_interface->GetNumberOfArgs(state);
  9742. if(numargs == 4) {
  9743. x = lua_interface->GetFloatValue(state,1);
  9744. y = lua_interface->GetFloatValue(state,2);
  9745. z = lua_interface->GetFloatValue(state,3);
  9746. h = lua_interface->GetFloatValue(state,4);
  9747. }
  9748. lua_interface->ResetFunctionStack(state);
  9749. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9750. for (int32 i = 0; i < spell->targets.size(); i++) {
  9751. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9752. if (!target2)
  9753. continue;
  9754. if (target2->IsPlayer()) {
  9755. Client* client = ((Player*)target2)->GetClient();
  9756. if (client) {
  9757. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9758. client->SetReloadingZone(true);
  9759. target2->SetX(x);
  9760. target2->SetY(y);
  9761. target2->SetZ(z);
  9762. target2->SetHeading(h);
  9763. target2->SetSpawnOrigX(x);
  9764. target2->SetSpawnOrigY(y);
  9765. target2->SetSpawnOrigZ(z);
  9766. target2->SetSpawnOrigHeading(h);
  9767. target2->SetAppearancePosition(x,y,z);
  9768. client->SetZoningCoords(x,y,z,h);
  9769. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9770. if (packet)
  9771. {
  9772. packet->setDataByName("x", x);
  9773. packet->setDataByName("y", y);
  9774. packet->setDataByName("z", z);
  9775. client->QueuePacket(packet->serialize());
  9776. safe_delete(packet);
  9777. }
  9778. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9779. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9780. }
  9781. }
  9782. }
  9783. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9784. }
  9785. return 0;
  9786. }
  9787. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9788. if (!lua_interface)
  9789. return 0;
  9790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9791. lua_interface->ResetFunctionStack(state);
  9792. if (!luaspell) {
  9793. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9794. return 0;
  9795. }
  9796. int8 tier = luaspell->spell->GetSpellTier();
  9797. lua_interface->SetInt32Value(state, tier);
  9798. return 1;
  9799. }
  9800. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9801. if (!lua_interface)
  9802. return 0;
  9803. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9804. lua_interface->ResetFunctionStack(state);
  9805. if (!luaspell) {
  9806. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9807. return 0;
  9808. }
  9809. int32 spell_id = luaspell->spell->GetSpellID();
  9810. lua_interface->SetInt32Value(state, spell_id);
  9811. return 1;
  9812. }
  9813. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9814. if (!lua_interface)
  9815. return 0;
  9816. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9817. lua_interface->ResetFunctionStack(state);
  9818. if (!spawn) {
  9819. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9820. return 0;
  9821. }
  9822. if (!spawn->IsPlayer()) {
  9823. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9824. return 0;
  9825. }
  9826. ZoneServer* zone = spawn->GetZone();
  9827. if (!zone) {
  9828. return 0;
  9829. }
  9830. Client* client = ((Player*)spawn)->GetClient();
  9831. if (!client) {
  9832. return 0;
  9833. }
  9834. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9835. return 0;
  9836. }
  9837. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9838. if (!lua_interface)
  9839. return 0;
  9840. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9841. lua_interface->ResetFunctionStack(state);
  9842. if (!spawn) {
  9843. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9844. return 0;
  9845. }
  9846. if (!spawn->IsPlayer()) {
  9847. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9848. return 0;
  9849. }
  9850. ZoneServer* zone = spawn->GetZone();
  9851. if (!zone) {
  9852. return 0;
  9853. }
  9854. Client* client = ((Player*)spawn)->GetClient();
  9855. if (!client) {
  9856. return 0;
  9857. }
  9858. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9859. return 0;
  9860. }
  9861. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9862. if (!lua_interface)
  9863. return 0;
  9864. Spawn* caster = lua_interface->GetSpawn(state);
  9865. Spawn* target = lua_interface->GetSpawn(state, 2);
  9866. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9867. string spell_name = lua_interface->GetStringValue(state, 4);
  9868. lua_interface->ResetFunctionStack(state);
  9869. if (!caster) {
  9870. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9871. return 0;
  9872. }
  9873. if (!caster->IsEntity()) {
  9874. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9875. return 0;
  9876. }
  9877. if (!target) {
  9878. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9879. return 0;
  9880. }
  9881. if (!target->IsEntity()) {
  9882. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9883. return 0;
  9884. }
  9885. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9886. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9887. return 0;
  9888. }
  9889. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9890. if (!lua_interface)
  9891. return 0;
  9892. Spawn* player = lua_interface->GetSpawn(state);
  9893. int32 amount = lua_interface->GetInt32Value(state, 2);
  9894. lua_interface->ResetFunctionStack(state);
  9895. if (player && player->IsPlayer() && amount > 0) {
  9896. ((Player*)player)->AddXP(amount);
  9897. }
  9898. return 0;
  9899. }
  9900. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9901. if (!lua_interface)
  9902. return 0;
  9903. Spawn* player = lua_interface->GetSpawn(state);
  9904. int8 type = lua_interface->GetInt8Value(state, 2);
  9905. string text = lua_interface->GetStringValue(state, 3);
  9906. lua_interface->ResetFunctionStack(state);
  9907. Client* client = 0;
  9908. if (player && player->IsPlayer())
  9909. client = ((Player*)player)->GetClient();
  9910. if (!client || text.length() == 0) {
  9911. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9912. return 0;
  9913. }
  9914. client->SimpleMessage(type, text.c_str());
  9915. return 0;
  9916. }
  9917. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9918. if (!lua_interface)
  9919. return 0;
  9920. Spawn* player = lua_interface->GetSpawn(state);
  9921. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9922. lua_interface->ResetFunctionStack(state);
  9923. Client* client = 0;
  9924. if (player && player->IsPlayer())
  9925. client = ((Player*)player)->GetClient();
  9926. if (!client || !spawn) {
  9927. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9928. return 0;
  9929. }
  9930. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9931. if (!items) {
  9932. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9933. return 0;
  9934. }
  9935. client->Loot(spawn->GetLootCoins(), items, spawn);
  9936. return 0;
  9937. }
  9938. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9939. if (!lua_interface)
  9940. return 0;
  9941. Spawn* spawnref = lua_interface->GetSpawn(state);
  9942. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9943. lua_interface->ResetFunctionStack(state);
  9944. if (spawn_id > 0 && spawnref) {
  9945. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9946. if (spawns.size() == 0) {
  9947. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9948. return 0;
  9949. }
  9950. Spawn* spawn = 0;
  9951. int16 index = MakeRandomInt(0, spawns.size());
  9952. if (index >= spawns.size() || index < 0)
  9953. index = 0;
  9954. spawn = spawns[index];
  9955. lua_interface->SetSpawnValue(state, spawn);
  9956. return 1;
  9957. }
  9958. else {
  9959. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9960. }
  9961. return 0;
  9962. }
  9963. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9964. Spawn* player = lua_interface->GetSpawn(state);
  9965. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9966. string name = lua_interface->GetStringValue(state, 3);
  9967. float distance = lua_interface->GetFloatValue(state, 4);
  9968. string command = lua_interface->GetStringValue(state, 5);
  9969. string error_text = lua_interface->GetStringValue(state, 6);
  9970. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9971. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9972. lua_interface->ResetFunctionStack(state);
  9973. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9974. if (distance == 0)
  9975. distance = 10.0f;
  9976. if (command.length() == 0)
  9977. command = name;
  9978. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9979. if (spawns.size() == 0) {
  9980. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9981. return 0;
  9982. }
  9983. Spawn* spawn = 0;
  9984. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9985. spawn = *itr;
  9986. if (spawn) {
  9987. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9988. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9989. }
  9990. }
  9991. }
  9992. return 0;
  9993. }
  9994. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9995. if (!lua_interface)
  9996. return 0;
  9997. Client* client = 0;
  9998. Spawn* player = lua_interface->GetSpawn(state);
  9999. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10000. lua_interface->ResetFunctionStack(state);
  10001. if (player && player->IsPlayer() && player->GetZone())
  10002. client = ((Player*)player)->GetClient();
  10003. else{
  10004. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10005. return 0;
  10006. }
  10007. if (client) {
  10008. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10009. if (packet) {
  10010. packet->setDataByName("goal_num", goal_num);
  10011. client->QueuePacket(packet->serialize());
  10012. safe_delete(packet);
  10013. }
  10014. }
  10015. return 0;
  10016. }
  10017. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10018. if (!lua_interface)
  10019. return 0;
  10020. Client* client = 0;
  10021. Spawn* player = lua_interface->GetSpawn(state);
  10022. lua_interface->ResetFunctionStack(state);
  10023. if (player && player->IsPlayer() && player->GetZone())
  10024. client = ((Player*)player)->GetClient();
  10025. else {
  10026. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10027. return 0;
  10028. }
  10029. if (client) {
  10030. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10031. }
  10032. return 0;
  10033. }
  10034. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10035. if (!lua_interface)
  10036. return 0;
  10037. Client* client = 0;
  10038. Spawn* player = lua_interface->GetSpawn(state);
  10039. float duration = lua_interface->GetFloatValue(state, 2);
  10040. string text = lua_interface->GetStringValue(state, 3);
  10041. string voice = lua_interface->GetStringValue(state, 4);
  10042. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10043. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10044. string signal = lua_interface->GetStringValue(state, 7);
  10045. string goal1 = lua_interface->GetStringValue(state, 8);
  10046. string task1 = lua_interface->GetStringValue(state, 9);
  10047. string goal2 = lua_interface->GetStringValue(state, 10);
  10048. string task2 = lua_interface->GetStringValue(state, 11);
  10049. string goal3 = lua_interface->GetStringValue(state, 12);
  10050. string task3 = lua_interface->GetStringValue(state, 13);
  10051. string goal4 = lua_interface->GetStringValue(state, 14);
  10052. string task4 = lua_interface->GetStringValue(state, 15);
  10053. lua_interface->ResetFunctionStack(state);
  10054. if (!player) {
  10055. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10056. return 0;
  10057. }
  10058. if (!player->IsPlayer()) {
  10059. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10060. return 0;
  10061. }
  10062. else
  10063. client = ((Player*)player)->GetClient();
  10064. if (!client) {
  10065. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10066. return 0;
  10067. }
  10068. if (text.length() == 0) {
  10069. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10070. return 0;
  10071. }
  10072. if (duration >= 0 && duration < 2)
  10073. duration = 2;
  10074. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10075. if (packet) {
  10076. packet->setDataByName("open_seconds_max", duration);
  10077. packet->setDataByName("text", text.c_str());
  10078. packet->setDataByName("voice", voice.c_str());
  10079. int8 num_goals = 1;
  10080. if (task2.length() > 0)
  10081. num_goals++;
  10082. if (task3.length() > 0)
  10083. num_goals++;
  10084. if (task4.length() > 0)
  10085. num_goals++;
  10086. packet->setArrayLengthByName("num_goals", num_goals);
  10087. for (int8 i = 0; i < num_goals; i++) {
  10088. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10089. }
  10090. if (goal1.length() > 0)
  10091. packet->setArrayDataByName("goal_text", goal1.c_str());
  10092. if (goal2.length() > 0)
  10093. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10094. if (goal3.length() > 0)
  10095. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10096. if (goal4.length() > 0)
  10097. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10098. packet->setSubArrayDataByName("task_text", task1.c_str());
  10099. if (task2.length() > 0)
  10100. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10101. if (task3.length() > 0)
  10102. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10103. if (task4.length() > 0)
  10104. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10105. packet->setDataByName("complete_sound", "click");
  10106. packet->setDataByName("signal", signal.c_str());
  10107. packet->setDataByName("voice_key1", voice_key1);
  10108. packet->setDataByName("voice_key2", voice_key2);
  10109. client->QueuePacket(packet->serialize());
  10110. safe_delete(packet);
  10111. }
  10112. return 0;
  10113. }
  10114. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10115. if (!lua_interface)
  10116. return 0;
  10117. Client* client = 0;
  10118. Spawn* player = lua_interface->GetSpawn(state);
  10119. string window = lua_interface->GetStringValue(state, 2);
  10120. int8 show = lua_interface->GetInt8Value(state, 3);
  10121. lua_interface->ResetFunctionStack(state);
  10122. if (!player) {
  10123. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10124. return 0;
  10125. }
  10126. if (!player->IsPlayer()) {
  10127. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10128. return 0;
  10129. }
  10130. else
  10131. client = ((Player*)player)->GetClient();
  10132. if (!client) {
  10133. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10134. return 0;
  10135. }
  10136. if (window.length() == 0) {
  10137. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10138. return 0;
  10139. }
  10140. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10141. if (packet) {
  10142. packet->setDataByName("window", window.c_str());
  10143. packet->setDataByName("show", show);
  10144. client->QueuePacket(packet->serialize());
  10145. safe_delete(packet);
  10146. }
  10147. return 0;
  10148. }
  10149. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10150. //See GameEvents.txt for options that can be used for this function
  10151. if (!lua_interface)
  10152. return 0;
  10153. Client* client = 0;
  10154. Spawn* player = lua_interface->GetSpawn(state);
  10155. string event_name = lua_interface->GetStringValue(state, 2);
  10156. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10157. lua_interface->ResetFunctionStack(state);
  10158. if (!player || !player->IsPlayer()) {
  10159. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10160. return 0;
  10161. }
  10162. client = ((Player*)player)->GetClient();
  10163. if (!client) {
  10164. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10165. return 0;
  10166. }
  10167. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10168. if (packet) {
  10169. packet->setDataByName("event_name", event_name.c_str());
  10170. packet->setDataByName("enabled", enabled);
  10171. client->QueuePacket(packet->serialize());
  10172. safe_delete(packet);
  10173. }
  10174. return 0;
  10175. }
  10176. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10177. if (!lua_interface)
  10178. return 0;
  10179. Spawn* player = lua_interface->GetSpawn(state);
  10180. lua_interface->ResetFunctionStack(state);
  10181. if (player && player->IsPlayer()) {
  10182. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10183. return 1;
  10184. }
  10185. return 0;
  10186. }
  10187. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10188. if (!lua_interface)
  10189. return 0;
  10190. Spawn* player = lua_interface->GetSpawn(state);
  10191. int8 step = lua_interface->GetInt8Value(state, 2);
  10192. lua_interface->ResetFunctionStack(state);
  10193. if (player && player->IsPlayer() && step > 0) {
  10194. ((Player*)player)->SetTutorialStep(step);
  10195. }
  10196. return 0;
  10197. }
  10198. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10199. if (!lua_interface)
  10200. return 0;
  10201. Client* client = 0;
  10202. Spawn* player = lua_interface->GetSpawn(state);
  10203. string window = lua_interface->GetStringValue(state, 2);
  10204. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10205. lua_interface->ResetFunctionStack(state);
  10206. if (!player) {
  10207. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10208. return 0;
  10209. }
  10210. if (!player->IsPlayer()) {
  10211. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10212. return 0;
  10213. }
  10214. else
  10215. client = ((Player*)player)->GetClient();
  10216. if (!client) {
  10217. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10218. return 0;
  10219. }
  10220. if (window.length() == 0) {
  10221. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10222. return 0;
  10223. }
  10224. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10225. if (packet) {
  10226. packet->setDataByName("window", window.c_str());
  10227. packet->setDataByName("flash_seconds", flash_seconds);
  10228. client->QueuePacket(packet->serialize());
  10229. safe_delete(packet);
  10230. }
  10231. return 0;
  10232. }
  10233. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10234. if (!lua_interface)
  10235. return 0;
  10236. Spawn* spawn = lua_interface->GetSpawn(state);
  10237. Spawn* target = lua_interface->GetSpawn(state, 2);
  10238. lua_interface->ResetFunctionStack(state);
  10239. if (spawn && target)
  10240. return spawn->CheckLoS(target);
  10241. return 0;
  10242. }
  10243. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10244. if (!lua_interface)
  10245. return 0;
  10246. Spawn* spawn = lua_interface->GetSpawn(state);
  10247. float x = lua_interface->GetFloatValue(state, 2);
  10248. float y = lua_interface->GetFloatValue(state, 3);
  10249. float z = lua_interface->GetFloatValue(state, 4);
  10250. lua_interface->ResetFunctionStack(state);
  10251. if (spawn)
  10252. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10253. return 0;
  10254. }
  10255. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10256. if (!lua_interface)
  10257. return 0;
  10258. ZoneServer* zone = lua_interface->GetZone(state);
  10259. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10260. lua_interface->ResetFunctionStack(state);
  10261. if (zone)
  10262. zone->SetExpansionFlag(xpackFlag);
  10263. return 0;
  10264. }
  10265. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10266. if (!lua_interface)
  10267. return 0;
  10268. ZoneServer* zone = lua_interface->GetZone(state);
  10269. lua_interface->ResetFunctionStack(state);
  10270. if (zone) {
  10271. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10272. return 1;
  10273. }
  10274. return 0;
  10275. }
  10276. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10277. if (!lua_interface)
  10278. return 0;
  10279. ZoneServer* zone = lua_interface->GetZone(state);
  10280. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10281. lua_interface->ResetFunctionStack(state);
  10282. if (zone)
  10283. zone->SetHolidayFlag(holidayFlag);
  10284. return 0;
  10285. }
  10286. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10287. if (!lua_interface)
  10288. return 0;
  10289. ZoneServer* zone = lua_interface->GetZone(state);
  10290. lua_interface->ResetFunctionStack(state);
  10291. if (zone) {
  10292. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10293. return 1;
  10294. }
  10295. return 0;
  10296. }
  10297. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10298. if (!lua_interface)
  10299. return 0;
  10300. Spawn* spawn = lua_interface->GetSpawn(state);
  10301. bool canbind = lua_interface->GetInt32Value(state, 2);
  10302. lua_interface->ResetFunctionStack(state);
  10303. if(!spawn) {
  10304. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10305. return 0;
  10306. }
  10307. ZoneServer* zone = spawn->GetZone();
  10308. if (zone)
  10309. zone->SetCanBind(canbind);
  10310. return 0;
  10311. }
  10312. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10313. if (!lua_interface)
  10314. return 0;
  10315. Spawn* spawn = lua_interface->GetSpawn(state);
  10316. lua_interface->ResetFunctionStack(state);
  10317. if(!spawn) {
  10318. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10319. return 0;
  10320. }
  10321. ZoneServer* zone = spawn->GetZone();
  10322. if (zone) {
  10323. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10324. return 1;
  10325. }
  10326. return 0;
  10327. }
  10328. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10329. if (!lua_interface)
  10330. return 0;
  10331. Spawn* spawn = lua_interface->GetSpawn(state);
  10332. bool cangate = lua_interface->GetInt32Value(state, 2);
  10333. lua_interface->ResetFunctionStack(state);
  10334. if(!spawn) {
  10335. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10336. return 0;
  10337. }
  10338. ZoneServer* zone = spawn->GetZone();
  10339. if (zone)
  10340. zone->SetCanGate(cangate);
  10341. return 0;
  10342. }
  10343. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10344. if (!lua_interface)
  10345. return 0;
  10346. Spawn* spawn = lua_interface->GetSpawn(state);
  10347. lua_interface->ResetFunctionStack(state);
  10348. if(!spawn) {
  10349. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10350. return 0;
  10351. }
  10352. ZoneServer* zone = spawn->GetZone();
  10353. if (zone) {
  10354. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10355. return 1;
  10356. }
  10357. return 0;
  10358. }
  10359. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10360. if (!lua_interface)
  10361. return 0;
  10362. Spawn* spawn = lua_interface->GetSpawn(state);
  10363. bool canevac = lua_interface->GetInt32Value(state, 2);
  10364. lua_interface->ResetFunctionStack(state);
  10365. if(!spawn) {
  10366. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10367. return 0;
  10368. }
  10369. ZoneServer* zone = spawn->GetZone();
  10370. if (zone)
  10371. zone->SetCanEvac(canevac);
  10372. return 0;
  10373. }
  10374. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10375. if (!lua_interface)
  10376. return 0;
  10377. Spawn* spawn = lua_interface->GetSpawn(state);
  10378. lua_interface->ResetFunctionStack(state);
  10379. if(!spawn) {
  10380. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10381. return 0;
  10382. }
  10383. ZoneServer* zone = spawn->GetZone();
  10384. if (zone) {
  10385. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10386. return 1;
  10387. }
  10388. return 0;
  10389. }
  10390. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10391. if (!lua_interface)
  10392. return 0;
  10393. Spawn* spawn = lua_interface->GetSpawn(state);
  10394. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10395. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10396. float distance = lua_interface->GetFloatValue(state, 4);
  10397. string in_range_function = lua_interface->GetStringValue(state, 5);
  10398. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10399. lua_interface->ResetFunctionStack(state);
  10400. if (spawn && distance > 0 && in_range_function.length() > 0)
  10401. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10402. return 0;
  10403. }
  10404. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10405. if (!lua_interface)
  10406. return 0;
  10407. Spawn* spawn = lua_interface->GetSpawn(state);
  10408. Spawn* target = lua_interface->GetSpawn(state, 2);
  10409. lua_interface->ResetFunctionStack(state);
  10410. if (spawn && target)
  10411. {
  10412. if (spawn->IsPlayer() && target->IsEntity())
  10413. {
  10414. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10415. return 1;
  10416. }
  10417. else if (spawn->IsEntity() && target->IsEntity())
  10418. {
  10419. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10420. return 1;
  10421. }
  10422. }
  10423. return 0;
  10424. }
  10425. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10426. if (!lua_interface)
  10427. return 0;
  10428. Spawn* spawn = lua_interface->GetSpawn(state);
  10429. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10430. lua_interface->ResetFunctionStack(state);
  10431. if (spawn && spawn->IsEntity())
  10432. {
  10433. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10434. if (spawn->IsPlayer())
  10435. {
  10436. Client* client = ((Player*)spawn)->GetClient();
  10437. if (client)
  10438. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10439. }
  10440. }
  10441. return 0;
  10442. }
  10443. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10444. if (!lua_interface)
  10445. return 0;
  10446. Spawn* spawn = lua_interface->GetSpawn(state);
  10447. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10448. lua_interface->ResetFunctionStack(state);
  10449. if (spawn && spawn->IsEntity())
  10450. {
  10451. ((Entity*)spawn)->SetSeeHideSpell(val);
  10452. if (spawn->IsPlayer())
  10453. {
  10454. Client* client = ((Player*)spawn)->GetClient();
  10455. if (client)
  10456. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10457. }
  10458. }
  10459. return 0;
  10460. }
  10461. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10462. {
  10463. if (!lua_interface)
  10464. return 0;
  10465. Spawn* player = lua_interface->GetSpawn(state);
  10466. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10467. string command = lua_interface->GetStringValue(state, 3);
  10468. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10469. lua_interface->ResetFunctionStack(state);
  10470. if (spawn && player && player->IsPlayer())
  10471. {
  10472. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10473. bool res = false;
  10474. if (cmd)
  10475. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10476. lua_interface->SetBooleanValue(state, res);
  10477. return 1;
  10478. }
  10479. return 0;
  10480. }
  10481. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10482. {
  10483. if (!lua_interface)
  10484. return 0;
  10485. Spawn* spawn = lua_interface->GetSpawn(state);
  10486. int32 charID = lua_interface->GetInt32Value(state, 2);
  10487. string command = lua_interface->GetStringValue(state, 3);
  10488. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10489. lua_interface->ResetFunctionStack(state);
  10490. if (spawn && charID)
  10491. {
  10492. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10493. bool res = false;
  10494. if (cmd)
  10495. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10496. lua_interface->SetBooleanValue(state, res);
  10497. return 1;
  10498. }
  10499. return 0;
  10500. }
  10501. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10502. {
  10503. if (!lua_interface)
  10504. return 0;
  10505. Spawn* spawn = lua_interface->GetSpawn(state);
  10506. string command = lua_interface->GetStringValue(state, 2);
  10507. lua_interface->ResetFunctionStack(state);
  10508. if (spawn && command.length() > 0)
  10509. spawn->RemovePrimaryEntityCommand(command.c_str());
  10510. return 0;
  10511. }
  10512. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10513. if (!lua_interface)
  10514. return 0;
  10515. Spawn* spawn = lua_interface->GetSpawn(state);
  10516. float distance = lua_interface->GetFloatValue(state, 2);
  10517. string command = lua_interface->GetStringValue(state, 3);
  10518. Spawn* player = lua_interface->GetSpawn(state, 4);
  10519. lua_interface->ResetFunctionStack(state);
  10520. if (spawn) {
  10521. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10522. }
  10523. return 0;
  10524. }
  10525. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10526. if (!lua_interface)
  10527. return 0;
  10528. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10529. Spawn* spawn = lua_interface->GetSpawn(state);
  10530. Spawn* player = lua_interface->GetSpawn(state, 2);
  10531. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10532. lua_interface->ResetFunctionStack(state);
  10533. if (spawn && player && transport_id && player->IsPlayer()) {
  10534. Client* client = 0;
  10535. if (player && player->IsPlayer())
  10536. client = ((Player*)player)->GetClient();
  10537. if (!client)
  10538. return 0;
  10539. vector<TransportDestination*> destinations;
  10540. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10541. if (destinations.size())
  10542. {
  10543. client->SetTemporaryTransportID(transport_id);
  10544. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10545. }
  10546. else
  10547. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10548. }
  10549. return 0;
  10550. }
  10551. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10552. if (!lua_interface)
  10553. return 0;
  10554. Spawn* player = lua_interface->GetSpawn(state);
  10555. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10556. lua_interface->ResetFunctionStack(state);
  10557. if (player && player->IsPlayer()) {
  10558. Client* client = 0;
  10559. if (player && player->IsPlayer())
  10560. client = ((Player*)player)->GetClient();
  10561. if (!client)
  10562. return 0;
  10563. client->SetTemporaryTransportID(transport_id);
  10564. }
  10565. return 0;
  10566. }
  10567. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10568. if (!lua_interface)
  10569. return 0;
  10570. Spawn* player = lua_interface->GetSpawn(state);
  10571. lua_interface->ResetFunctionStack(state);
  10572. if (player && player->IsPlayer()) {
  10573. Client* client = 0;
  10574. if (player && player->IsPlayer())
  10575. client = ((Player*)player)->GetClient();
  10576. if (!client)
  10577. return 0;
  10578. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10579. return 1;
  10580. }
  10581. return 0;
  10582. }
  10583. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10584. if (!lua_interface)
  10585. return 0;
  10586. Spawn* spawn = lua_interface->GetSpawn(state);
  10587. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10588. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10589. if (!spawn) {
  10590. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10591. return 0;
  10592. }
  10593. if (!spawn->IsEntity()) {
  10594. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10595. return 0;
  10596. }
  10597. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10598. {
  10599. 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);
  10600. return 0;
  10601. }
  10602. lua_interface->ResetFunctionStack(state);
  10603. if (spell && spell->targets.size() > 0) {
  10604. ZoneServer* zone = spell->caster->GetZone();
  10605. for (int8 i = 0; i < spell->targets.size(); i++) {
  10606. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10607. if (target && target->IsEntity()) {
  10608. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10609. if (target->IsPlayer())
  10610. ((Player*)target)->SetCharSheetChanged(true);
  10611. }
  10612. }
  10613. }
  10614. else {
  10615. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10616. if (spawn->IsPlayer())
  10617. ((Player*)spawn)->SetCharSheetChanged(true);
  10618. }
  10619. return 0;
  10620. }
  10621. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10622. if (!lua_interface)
  10623. return 0;
  10624. Spawn* spawn = lua_interface->GetSpawn(state);
  10625. lua_interface->ResetFunctionStack(state);
  10626. if (!spawn) {
  10627. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10628. return 0;
  10629. }
  10630. if (!spawn->IsEntity()) {
  10631. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10632. return 0;
  10633. }
  10634. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10635. return 1;
  10636. }
  10637. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10638. if (!lua_interface)
  10639. return 0;
  10640. int32 spell_id = lua_interface->GetInt32Value(state);
  10641. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10642. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10643. if (spell_id > 0) {
  10644. if (spell_tier == 0)
  10645. spell_tier = 1;
  10646. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10647. if(!spell) {
  10648. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10649. lua_interface->ResetFunctionStack(state);
  10650. return 0;
  10651. }
  10652. LuaSpell* lua_spell = 0;
  10653. if(custom_lua_script.size() > 0)
  10654. {
  10655. // attempt to load the custom script since it isn't already loaded
  10656. // we will re-obtain the lua_spell further below
  10657. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10658. {
  10659. 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());
  10660. lua_interface->LoadLuaSpell(custom_lua_script);
  10661. }
  10662. }
  10663. else
  10664. custom_lua_script = spell->GetSpellData()->lua_script;
  10665. if (!lua_spell && lua_interface)
  10666. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10667. lua_interface->ResetFunctionStack(state);
  10668. if (!lua_spell)
  10669. {
  10670. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10671. return 0;
  10672. }
  10673. lua_spell->spell = new Spell(spell);
  10674. lua_interface->AddCustomSpell(lua_spell);
  10675. lua_interface->SetSpellValue(state, lua_spell);
  10676. return 1;
  10677. }
  10678. return 0;
  10679. }
  10680. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10681. if (!lua_interface)
  10682. return 0;
  10683. LuaSpell* spell = lua_interface->GetSpell(state);
  10684. string field = lua_interface->GetStringValue(state, 2);
  10685. lua_interface->ResetFunctionStack(state);
  10686. if (!spell) {
  10687. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10688. return 0;
  10689. }
  10690. if (!spell->spell || !spell->spell->GetSpellData()) {
  10691. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10692. return 0;
  10693. }
  10694. boost::to_lower(field);
  10695. return spell->spell->GetSpellData(state, field);
  10696. }
  10697. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10698. if (!lua_interface)
  10699. return 0;
  10700. LuaSpell* spell = lua_interface->GetSpell(state);
  10701. string field = lua_interface->GetStringValue(state, 2);
  10702. int8 fieldArg = 3; // field value after the initial set
  10703. if (!spell) {
  10704. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10705. lua_interface->ResetFunctionStack(state);
  10706. return 0;
  10707. }
  10708. if (!spell->spell || !spell->spell->GetSpellData()) {
  10709. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10710. lua_interface->ResetFunctionStack(state);
  10711. return 0;
  10712. }
  10713. boost::to_lower(field);
  10714. bool valSet = false;
  10715. spell->spell->SetSpellData(state, field, fieldArg);
  10716. lua_interface->ResetFunctionStack(state);
  10717. return valSet;
  10718. }
  10719. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10720. if (!lua_interface)
  10721. return 0;
  10722. LuaSpell* spell = lua_interface->GetSpell(state);
  10723. int8 idx = lua_interface->GetInt32Value(state, 2);
  10724. if (!spell) {
  10725. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10726. lua_interface->ResetFunctionStack(state);
  10727. return 0;
  10728. }
  10729. if (!spell->spell || !spell->spell->GetSpellData()) {
  10730. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10731. lua_interface->ResetFunctionStack(state);
  10732. return 0;
  10733. }
  10734. if (spell->spell->lua_data.size() <= idx)
  10735. {
  10736. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10737. lua_interface->ResetFunctionStack(state);
  10738. return 0;
  10739. }
  10740. bool setVal = true;
  10741. LUAData* data = spell->spell->lua_data[idx];
  10742. switch (data->type)
  10743. {
  10744. case 0:
  10745. {
  10746. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10747. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10748. data->int_value = value;
  10749. data->int_value2 = value2;
  10750. break;
  10751. }
  10752. case 1:
  10753. {
  10754. float value = lua_interface->GetFloatValue(state, 3);
  10755. float value2 = lua_interface->GetFloatValue(state, 4);
  10756. data->float_value = value;
  10757. data->float_value2 = value2;
  10758. break;
  10759. }
  10760. case 2:
  10761. {
  10762. bool value = lua_interface->GetBooleanValue(state, 3);
  10763. data->bool_value = value;
  10764. break;
  10765. }
  10766. case 3:
  10767. {
  10768. string value = lua_interface->GetStringValue(state, 3);
  10769. string value2 = lua_interface->GetStringValue(state, 4);
  10770. data->string_value = value;
  10771. data->string_value2 = value2;
  10772. break;
  10773. }
  10774. default:
  10775. setVal = false;
  10776. }
  10777. lua_interface->ResetFunctionStack(state);
  10778. return setVal;
  10779. }
  10780. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10781. if (!lua_interface)
  10782. return 0;
  10783. LuaSpell* spell = lua_interface->GetSpell(state);
  10784. int8 idx = lua_interface->GetInt32Value(state, 2);
  10785. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10786. lua_interface->ResetFunctionStack(state);
  10787. if (!spell) {
  10788. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10789. return 0;
  10790. }
  10791. if (!spell->spell || !spell->spell->GetSpellData()) {
  10792. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10793. return 0;
  10794. }
  10795. if (spell->spell->lua_data.size() <= idx)
  10796. {
  10797. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10798. return 0;
  10799. }
  10800. bool setVal = true;
  10801. LUAData* data = spell->spell->lua_data[idx];
  10802. switch (data->type)
  10803. {
  10804. case 0:
  10805. {
  10806. if(!secondfield)
  10807. lua_interface->SetSInt32Value(state, data->int_value);
  10808. else
  10809. lua_interface->SetSInt32Value(state, data->int_value2);
  10810. break;
  10811. }
  10812. case 1:
  10813. {
  10814. if (!secondfield)
  10815. lua_interface->SetFloatValue(state, data->float_value);
  10816. else
  10817. lua_interface->SetFloatValue(state, data->float_value2);
  10818. break;
  10819. }
  10820. case 2:
  10821. {
  10822. lua_interface->SetBooleanValue(state, data->bool_value);
  10823. break;
  10824. }
  10825. case 3:
  10826. {
  10827. if (!secondfield)
  10828. lua_interface->SetStringValue(state, data->string_value.c_str());
  10829. else
  10830. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10831. break;
  10832. }
  10833. default:
  10834. setVal = false;
  10835. }
  10836. return setVal;
  10837. }
  10838. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10839. if (!lua_interface)
  10840. return 0;
  10841. LuaSpell* spell = lua_interface->GetSpell(state);
  10842. int8 idx = lua_interface->GetInt32Value(state, 2);
  10843. string field = lua_interface->GetStringValue(state, 3);
  10844. boost::to_lower(field);
  10845. if (!spell) {
  10846. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10847. lua_interface->ResetFunctionStack(state);
  10848. return 0;
  10849. }
  10850. if (!spell->spell || !spell->spell->GetSpellData()) {
  10851. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10852. lua_interface->ResetFunctionStack(state);
  10853. return 0;
  10854. }
  10855. if (spell->spell->effects.size() <= idx)
  10856. {
  10857. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10858. lua_interface->ResetFunctionStack(state);
  10859. return 0;
  10860. }
  10861. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10862. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10863. if (field == "description")
  10864. effect->description = string(lua_interface->GetStringValue(state, 4));
  10865. else if (field == "bullet")
  10866. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10867. else if (field == "percentage")
  10868. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10869. else { // no match
  10870. lua_interface->ResetFunctionStack(state);
  10871. return 0;
  10872. }
  10873. lua_interface->ResetFunctionStack(state);
  10874. return 1;
  10875. }
  10876. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10877. if (!lua_interface)
  10878. return 0;
  10879. LuaSpell* spell = lua_interface->GetSpell(state);
  10880. int8 idx = lua_interface->GetInt32Value(state, 2);
  10881. string field = lua_interface->GetStringValue(state, 3);
  10882. lua_interface->ResetFunctionStack(state);
  10883. boost::to_lower(field);
  10884. if (!spell) {
  10885. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10886. return 0;
  10887. }
  10888. if (!spell->spell || !spell->spell->GetSpellData()) {
  10889. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10890. return 0;
  10891. }
  10892. if (spell->spell->effects.size() <= idx)
  10893. {
  10894. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10895. return 0;
  10896. }
  10897. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10898. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10899. if (field == "description")
  10900. lua_interface->SetStringValue(state, effect->description.c_str());
  10901. else if (field == "bullet")
  10902. lua_interface->SetInt32Value(state, effect->subbullet);
  10903. else if (field == "percentage")
  10904. lua_interface->SetInt32Value(state, effect->percentage);
  10905. else // no match
  10906. return 0;
  10907. return 1;
  10908. }
  10909. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10910. if (!lua_interface)
  10911. return 0;
  10912. LuaSpell* spell = lua_interface->GetSpell(state);
  10913. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10914. Spawn* target = lua_interface->GetSpawn(state, 3);
  10915. lua_interface->ResetFunctionStack(state);
  10916. if (!target) {
  10917. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10918. return 0;
  10919. }
  10920. if (!target->IsEntity()) {
  10921. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10922. return 0;
  10923. }
  10924. if (!spell) {
  10925. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10926. return 0;
  10927. }
  10928. if (caster && !caster->IsEntity()) {
  10929. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10930. return 0;
  10931. }
  10932. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10933. return 0;
  10934. }
  10935. int EQ2Emu_lua_InWater(lua_State* state) {
  10936. if (!lua_interface)
  10937. return 0;
  10938. Spawn* spawn = lua_interface->GetSpawn(state);
  10939. lua_interface->ResetFunctionStack(state);
  10940. if (spawn) {
  10941. lua_interface->SetBooleanValue(state, spawn->InWater());
  10942. return 1;
  10943. }
  10944. return 0;
  10945. }
  10946. int EQ2Emu_lua_InLava(lua_State* state) {
  10947. if (!lua_interface)
  10948. return 0;
  10949. Spawn* spawn = lua_interface->GetSpawn(state);
  10950. lua_interface->ResetFunctionStack(state);
  10951. if (spawn) {
  10952. lua_interface->SetBooleanValue(state, spawn->InLava());
  10953. return 1;
  10954. }
  10955. return 0;
  10956. }
  10957. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10958. if (!lua_interface)
  10959. return 0;
  10960. Spawn* attacker = lua_interface->GetSpawn(state);
  10961. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10962. int8 type = lua_interface->GetInt8Value(state, 3);
  10963. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10964. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10965. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10966. string spell_name = lua_interface->GetStringValue(state, 7);
  10967. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10968. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10969. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10970. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10971. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  10972. lua_interface->ResetFunctionStack(state);
  10973. if (!attacker) {
  10974. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10975. lua_interface->SetBooleanValue(state, false);
  10976. return 1;
  10977. }
  10978. if (!attacker->IsEntity()) {
  10979. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10980. lua_interface->SetBooleanValue(state, false);
  10981. return 1;
  10982. }
  10983. if (!victim) {
  10984. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10985. lua_interface->SetBooleanValue(state, false);
  10986. return 1;
  10987. }
  10988. if (!victim->IsEntity()) {
  10989. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10990. lua_interface->SetBooleanValue(state, false);
  10991. return 1;
  10992. }
  10993. 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);
  10994. lua_interface->SetBooleanValue(state, has_damaged);
  10995. return 1;
  10996. }
  10997. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10998. if (!lua_interface)
  10999. return 0;
  11000. Spawn* spawn = lua_interface->GetSpawn(state);
  11001. lua_interface->ResetFunctionStack(state);
  11002. if (spawn) {
  11003. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11004. return 1;
  11005. }
  11006. return 0;
  11007. }
  11008. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11009. if (!lua_interface)
  11010. return 0;
  11011. Spawn* spawn = lua_interface->GetSpawn(state);
  11012. bool invul = lua_interface->GetBooleanValue(state, 2);
  11013. lua_interface->ResetFunctionStack(state);
  11014. if (spawn) {
  11015. spawn->SetInvulnerable(invul);
  11016. }
  11017. return 0;
  11018. }
  11019. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11020. if (!lua_interface)
  11021. return 0;
  11022. string category = lua_interface->GetStringValue(state);
  11023. string name = lua_interface->GetStringValue(state, 2);
  11024. lua_interface->ResetFunctionStack(state);
  11025. Rule *ret = 0;
  11026. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11027. lua_interface->SetBooleanValue(state, ret->GetBool());
  11028. return 1;
  11029. }
  11030. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11031. return 0;
  11032. }
  11033. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11034. if (!lua_interface)
  11035. return 0;
  11036. string category = lua_interface->GetStringValue(state);
  11037. string name = lua_interface->GetStringValue(state, 2);
  11038. lua_interface->ResetFunctionStack(state);
  11039. Rule *ret = 0;
  11040. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11041. lua_interface->SetInt32Value(state, ret->GetInt32());
  11042. return 1;
  11043. }
  11044. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11045. return 0;
  11046. }
  11047. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11048. if (!lua_interface)
  11049. return 0;
  11050. string category = lua_interface->GetStringValue(state);
  11051. string name = lua_interface->GetStringValue(state, 2);
  11052. lua_interface->ResetFunctionStack(state);
  11053. Rule *ret = 0;
  11054. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11055. lua_interface->SetFloatValue(state, ret->GetFloat());
  11056. return 1;
  11057. }
  11058. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11059. return 0;
  11060. }
  11061. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11062. if (!lua_interface)
  11063. return 0;
  11064. Spawn* spawn = lua_interface->GetSpawn(state);
  11065. string type = lua_interface->GetStringValue(state, 2);
  11066. lua_interface->ResetFunctionStack(state);
  11067. if (spawn) {
  11068. int res = 1;
  11069. boost::to_lower(type);
  11070. if(type == "assigned_aa")
  11071. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11072. else if ( type == "unassigned_aa")
  11073. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11074. else if ( type == "assigned_tradeskill_aa")
  11075. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11076. else if ( type == "unassigned_tradeskill_aa")
  11077. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11078. else if ( type == "assigned_prestige_aa")
  11079. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11080. else if ( type == "unassigned_prestige_aa")
  11081. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11082. else if ( type == "assigned_tradeskill_prestige_aa")
  11083. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11084. else if ( type == "unassigned_tradeskill_prestige_aa")
  11085. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11086. else
  11087. res = 0;
  11088. return res;
  11089. }
  11090. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11091. return 0;
  11092. }
  11093. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11094. if (!lua_interface)
  11095. return 0;
  11096. Spawn* spawn = lua_interface->GetSpawn(state);
  11097. string type = lua_interface->GetStringValue(state, 2);
  11098. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11099. lua_interface->ResetFunctionStack(state);
  11100. if (spawn) {
  11101. boost::to_lower(type);
  11102. if(type == "assigned_aa")
  11103. spawn->SetAssignedAA((sint16)value);
  11104. else if ( type == "unassigned_aa")
  11105. spawn->SetUnassignedAA((sint16)value);
  11106. else if ( type == "assigned_tradeskill_aa")
  11107. spawn->SetTradeskillAA((sint16)value);
  11108. else if ( type == "unassigned_tradeskill_aa")
  11109. spawn->SetUnassignedTradeskillAA((sint16)value);
  11110. else if ( type == "assigned_prestige_aa")
  11111. spawn->SetPrestigeAA((sint16)value);
  11112. else if ( type == "unassigned_prestige_aa")
  11113. spawn->SetUnassignedPrestigeAA((sint16)value);
  11114. else if ( type == "assigned_tradeskill_prestige_aa")
  11115. spawn->SetTradeskillPrestigeAA((sint16)value);
  11116. else if ( type == "unassigned_tradeskill_prestige_aa")
  11117. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11118. if(spawn->IsPlayer())
  11119. ((Player*)spawn)->SetCharSheetChanged(true);
  11120. }
  11121. return 0;
  11122. }
  11123. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11124. if (!lua_interface)
  11125. return 0;
  11126. string titleName = lua_interface->GetStringValue(state);
  11127. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11128. lua_interface->ResetFunctionStack(state);
  11129. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11130. lua_interface->SetSInt32Value(state, index);
  11131. return 1;
  11132. }
  11133. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11134. if (!lua_interface)
  11135. return 0;
  11136. Spawn* spawn = lua_interface->GetSpawn(state);
  11137. string titleName = lua_interface->GetStringValue(state, 2);
  11138. lua_interface->ResetFunctionStack(state);
  11139. if(!spawn->IsPlayer())
  11140. {
  11141. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11142. lua_interface->SetSInt32Value(state, -1);
  11143. return 1;
  11144. }
  11145. Player* player = (Player*)spawn;
  11146. // check if player already has the title, don't need to add twice
  11147. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11148. if ( playerHasTitle)
  11149. {
  11150. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11151. return 1;
  11152. }
  11153. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11154. if(!title)
  11155. {
  11156. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11157. lua_interface->SetSInt32Value(state, -1);
  11158. return 1;
  11159. }
  11160. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11161. if(returnIdx < 0)
  11162. {
  11163. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11164. }
  11165. lua_interface->SetSInt32Value(state, returnIdx);
  11166. player->GetClient()->SendTitleUpdate();
  11167. return 1;
  11168. }
  11169. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11170. if (!lua_interface)
  11171. return 0;
  11172. Spawn* spawn = lua_interface->GetSpawn(state);
  11173. string titleName = lua_interface->GetStringValue(state, 2);
  11174. lua_interface->ResetFunctionStack(state);
  11175. if(!spawn->IsPlayer())
  11176. {
  11177. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11178. return 0;
  11179. }
  11180. Player* player = (Player*)spawn;
  11181. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11182. if(!title)
  11183. {
  11184. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11185. return 0;
  11186. }
  11187. if(title->GetPrefix())
  11188. {
  11189. 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());
  11190. return 0;
  11191. }
  11192. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11193. player->GetClient()->SendTitleUpdate();
  11194. return 1;
  11195. }
  11196. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11197. if (!lua_interface)
  11198. return 0;
  11199. Spawn* spawn = lua_interface->GetSpawn(state);
  11200. string titleName = lua_interface->GetStringValue(state, 2);
  11201. lua_interface->ResetFunctionStack(state);
  11202. if(!spawn->IsPlayer())
  11203. {
  11204. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11205. return 0;
  11206. }
  11207. Player* player = (Player*)spawn;
  11208. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11209. if(!title)
  11210. {
  11211. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11212. return 0;
  11213. }
  11214. if(!title->GetPrefix())
  11215. {
  11216. 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());
  11217. return 0;
  11218. }
  11219. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11220. player->GetClient()->SendTitleUpdate();
  11221. return 1;
  11222. }
  11223. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11224. if (!lua_interface)
  11225. return 0;
  11226. Spawn* spawn = lua_interface->GetSpawn(state);
  11227. lua_interface->ResetFunctionStack(state);
  11228. if(!spawn->IsPlayer())
  11229. {
  11230. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11231. return 0;
  11232. }
  11233. Player* player = (Player*)spawn;
  11234. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11235. player->GetClient()->SendTitleUpdate();
  11236. return 1;
  11237. }
  11238. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11239. if (!lua_interface)
  11240. return 0;
  11241. Spawn* spawn = lua_interface->GetSpawn(state);
  11242. lua_interface->ResetFunctionStack(state);
  11243. if(!spawn->IsPlayer())
  11244. {
  11245. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11246. return 0;
  11247. }
  11248. Player* player = (Player*)spawn;
  11249. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11250. player->GetClient()->SendTitleUpdate();
  11251. return 1;
  11252. }
  11253. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11254. if (!lua_interface)
  11255. return 0;
  11256. Spawn* spawn = lua_interface->GetSpawn(state);
  11257. string field = lua_interface->GetStringValue(state, 2);
  11258. lua_interface->ResetFunctionStack(state);
  11259. if(!spawn || !spawn->IsEntity())
  11260. {
  11261. 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));
  11262. return 0;
  11263. }
  11264. Entity* ent = (Entity*)spawn;
  11265. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11266. return 1;
  11267. }
  11268. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11269. if (!lua_interface)
  11270. return 0;
  11271. Spawn* spawn = lua_interface->GetSpawn(state);
  11272. string field = lua_interface->GetStringValue(state, 2);
  11273. lua_interface->ResetFunctionStack(state);
  11274. if(!spawn || !spawn->IsEntity())
  11275. {
  11276. 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));
  11277. return 0;
  11278. }
  11279. Entity* ent = (Entity*)spawn;
  11280. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11281. return 1;
  11282. }
  11283. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11284. if (!lua_interface)
  11285. return 0;
  11286. Spawn* spawn = lua_interface->GetSpawn(state);
  11287. string field = lua_interface->GetStringValue(state, 2);
  11288. lua_interface->ResetFunctionStack(state);
  11289. if(!spawn || !spawn->IsEntity())
  11290. {
  11291. 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));
  11292. return 0;
  11293. }
  11294. Entity* ent = (Entity*)spawn;
  11295. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11296. return 1;
  11297. }
  11298. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11299. if (!lua_interface)
  11300. return 0;
  11301. Spawn* spawn = lua_interface->GetSpawn(state);
  11302. string field = lua_interface->GetStringValue(state, 2);
  11303. lua_interface->ResetFunctionStack(state);
  11304. if(!spawn || !spawn->IsEntity())
  11305. {
  11306. 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));
  11307. return 0;
  11308. }
  11309. Entity* ent = (Entity*)spawn;
  11310. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11311. return 1;
  11312. }
  11313. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11314. if (!lua_interface)
  11315. return 0;
  11316. Spawn* spawn = lua_interface->GetSpawn(state);
  11317. string field = lua_interface->GetStringValue(state, 2);
  11318. string value = lua_interface->GetStringValue(state, 3);
  11319. lua_interface->ResetFunctionStack(state);
  11320. if(!spawn || !spawn->IsEntity())
  11321. {
  11322. 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));
  11323. return 0;
  11324. }
  11325. Entity* ent = (Entity*)spawn;
  11326. bool set_ = ent->SetInfoStructString(field, value);
  11327. lua_interface->SetBooleanValue(state, set_);
  11328. return 1;
  11329. }
  11330. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11331. if (!lua_interface)
  11332. return 0;
  11333. Spawn* spawn = lua_interface->GetSpawn(state);
  11334. string field = lua_interface->GetStringValue(state, 2);
  11335. int64 value = lua_interface->GetInt64Value(state, 3);
  11336. lua_interface->ResetFunctionStack(state);
  11337. if(!spawn || !spawn->IsEntity())
  11338. {
  11339. 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));
  11340. return 0;
  11341. }
  11342. Entity* ent = (Entity*)spawn;
  11343. bool set_ = ent->SetInfoStructUInt(field, value);
  11344. lua_interface->SetBooleanValue(state, set_);
  11345. return 1;
  11346. }
  11347. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11348. if (!lua_interface)
  11349. return 0;
  11350. Spawn* spawn = lua_interface->GetSpawn(state);
  11351. string field = lua_interface->GetStringValue(state, 2);
  11352. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11353. lua_interface->ResetFunctionStack(state);
  11354. if(!spawn || !spawn->IsEntity())
  11355. {
  11356. 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));
  11357. return 0;
  11358. }
  11359. Entity* ent = (Entity*)spawn;
  11360. bool set_ = ent->SetInfoStructSInt(field, value);
  11361. lua_interface->SetBooleanValue(state, set_);
  11362. return 1;
  11363. }
  11364. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11365. if (!lua_interface)
  11366. return 0;
  11367. Spawn* spawn = lua_interface->GetSpawn(state);
  11368. string field = lua_interface->GetStringValue(state, 2);
  11369. float value = lua_interface->GetFloatValue(state, 3);
  11370. lua_interface->ResetFunctionStack(state);
  11371. if(!spawn || !spawn->IsEntity())
  11372. {
  11373. 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));
  11374. return 0;
  11375. }
  11376. Entity* ent = (Entity*)spawn;
  11377. bool set_ = ent->SetInfoStructFloat(field, value);
  11378. lua_interface->SetBooleanValue(state, set_);
  11379. return 1;
  11380. }
  11381. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11382. if (!lua_interface)
  11383. return 0;
  11384. Spawn* spawn = lua_interface->GetSpawn(state);
  11385. bool value = lua_interface->GetBooleanValue(state, 2);
  11386. lua_interface->ResetFunctionStack(state);
  11387. if(!spawn || !spawn->IsPlayer())
  11388. {
  11389. 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));
  11390. return 0;
  11391. }
  11392. ((Player*)spawn)->SetCharSheetChanged(value);
  11393. return 0;
  11394. }
  11395. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11396. if (!lua_interface)
  11397. return 0;
  11398. Spawn* spawn = lua_interface->GetSpawn(state);
  11399. std::string fromName = lua_interface->GetStringValue(state, 2);
  11400. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11401. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11402. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11403. int32 copper = lua_interface->GetInt32Value(state, 6);
  11404. int32 silver = lua_interface->GetInt32Value(state, 7);
  11405. int32 gold = lua_interface->GetInt32Value(state, 8);
  11406. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11407. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11408. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11409. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11410. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11411. lua_interface->ResetFunctionStack(state);
  11412. if(!spawn || !spawn->IsPlayer())
  11413. {
  11414. 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));
  11415. lua_interface->SetBooleanValue(state, false);
  11416. return 1;
  11417. }
  11418. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11419. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11420. lua_interface->SetBooleanValue(state, true);
  11421. return 1;
  11422. }
  11423. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11424. if (!lua_interface)
  11425. return 0;
  11426. int32 char_id = lua_interface->GetInt32Value(state);
  11427. std::string fromName = lua_interface->GetStringValue(state, 2);
  11428. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11429. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11430. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11431. int32 copper = lua_interface->GetInt32Value(state, 6);
  11432. int32 silver = lua_interface->GetInt32Value(state, 7);
  11433. int32 gold = lua_interface->GetInt32Value(state, 8);
  11434. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11435. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11436. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11437. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11438. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11439. lua_interface->ResetFunctionStack(state);
  11440. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11441. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11442. lua_interface->SetBooleanValue(state, true);
  11443. return 1;
  11444. }
  11445. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11446. Spawn* widget;
  11447. if (lua_interface) {
  11448. widget = lua_interface->GetSpawn(state);
  11449. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11450. lua_interface->ResetFunctionStack(state);
  11451. if (widget && widget->IsWidget())
  11452. {
  11453. ((Widget*)widget)->OpenDoor();
  11454. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11455. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11456. }
  11457. else
  11458. 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));
  11459. }
  11460. return 0;
  11461. }
  11462. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11463. Spawn* widget;
  11464. if (lua_interface) {
  11465. widget = lua_interface->GetSpawn(state);
  11466. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11467. lua_interface->ResetFunctionStack(state);
  11468. if (widget && widget->IsWidget())
  11469. {
  11470. ((Widget*)widget)->CloseDoor();
  11471. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11472. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11473. }
  11474. else
  11475. 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));
  11476. }
  11477. return 0;
  11478. }
  11479. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11480. if (!lua_interface)
  11481. return 0;
  11482. Spawn* widget = lua_interface->GetSpawn(state);
  11483. lua_interface->ResetFunctionStack(state);
  11484. if (widget && widget->IsWidget())
  11485. {
  11486. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11487. return 1;
  11488. }
  11489. return 0;
  11490. }
  11491. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11492. if (!lua_interface)
  11493. return 0;
  11494. sint32 min = lua_interface->GetSInt32Value(state);
  11495. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11496. lua_interface->ResetFunctionStack(state);
  11497. sint32 result = MakeRandomInt(min, max);
  11498. lua_interface->SetSInt32Value(state, result);
  11499. return 1;
  11500. }
  11501. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11502. if (!lua_interface)
  11503. return 0;
  11504. float min = lua_interface->GetFloatValue(state);
  11505. float max = lua_interface->GetFloatValue(state, 2);
  11506. lua_interface->ResetFunctionStack(state);
  11507. float result = MakeRandomFloat(min, max);
  11508. lua_interface->SetFloatValue(state, result);
  11509. return 1;
  11510. }
  11511. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11512. if (!lua_interface)
  11513. return 0;
  11514. Spawn* spawn = lua_interface->GetSpawn(state);
  11515. int32 value = lua_interface->GetInt32Value(state, 2);
  11516. lua_interface->ResetFunctionStack(state);
  11517. if(!spawn)
  11518. {
  11519. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11520. lua_interface->SetBooleanValue(state, false);
  11521. return 1;
  11522. }
  11523. spawn->AddIconValue(value);
  11524. lua_interface->SetBooleanValue(state, true);
  11525. return 1;
  11526. }
  11527. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11528. if (!lua_interface)
  11529. return 0;
  11530. Spawn* spawn = lua_interface->GetSpawn(state);
  11531. int32 value = lua_interface->GetInt32Value(state, 2);
  11532. lua_interface->ResetFunctionStack(state);
  11533. if(!spawn)
  11534. {
  11535. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11536. lua_interface->SetBooleanValue(state, false);
  11537. return 1;
  11538. }
  11539. spawn->RemoveIconValue(value);
  11540. lua_interface->SetBooleanValue(state, true);
  11541. return 1;
  11542. }
  11543. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11544. Spawn* npc = lua_interface->GetSpawn(state);
  11545. lua_interface->ResetFunctionStack(state);
  11546. if (npc && npc->IsNPC()) {
  11547. NPC* shard = (NPC*)npc;
  11548. int32 shardid = shard->GetShardID();
  11549. lua_interface->SetInt32Value(state, shardid);
  11550. return 1;
  11551. }
  11552. lua_interface->SetInt32Value(state, 0);
  11553. return 1;
  11554. }
  11555. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11556. Spawn* npc = lua_interface->GetSpawn(state);
  11557. lua_interface->ResetFunctionStack(state);
  11558. if (npc && npc->IsNPC()) {
  11559. NPC* shard = (NPC*)npc;
  11560. int32 charid = shard->GetShardCharID();
  11561. lua_interface->SetInt32Value(state, charid);
  11562. return 1;
  11563. }
  11564. lua_interface->SetInt32Value(state, 0);
  11565. return 1;
  11566. }
  11567. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11568. Spawn* npc = lua_interface->GetSpawn(state);
  11569. lua_interface->ResetFunctionStack(state);
  11570. if (npc && npc->IsNPC()) {
  11571. NPC* shard = (NPC*)npc;
  11572. int64 timestamp = shard->GetShardCreatedTimestamp();
  11573. lua_interface->SetSInt64Value(state, timestamp);
  11574. return 1;
  11575. }
  11576. lua_interface->SetSInt64Value(state, 0);
  11577. return 1;
  11578. }
  11579. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11580. if (!lua_interface)
  11581. return 0;
  11582. int32 shardid = lua_interface->GetInt32Value(state);
  11583. lua_interface->ResetFunctionStack(state);
  11584. if(shardid < 1)
  11585. lua_interface->SetBooleanValue(state, false);
  11586. else
  11587. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11588. return 1;
  11589. }
  11590. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11591. if (!lua_interface)
  11592. return 0;
  11593. Spawn* spawn = lua_interface->GetSpawn(state);
  11594. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11595. if (spawn) {
  11596. spawn->PauseMovement(delay_in_ms);
  11597. }
  11598. lua_interface->ResetFunctionStack(state);
  11599. return 0;
  11600. }
  11601. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11602. if (!lua_interface)
  11603. return 0;
  11604. Spawn* spawn = lua_interface->GetSpawn(state);
  11605. if (spawn) {
  11606. spawn->StopMovement();
  11607. }
  11608. lua_interface->ResetFunctionStack(state);
  11609. return 0;
  11610. }
  11611. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11612. Player* player = (Player*)lua_interface->GetSpawn(state);
  11613. int8 level = lua_interface->GetInt8Value(state, 2);
  11614. lua_interface->ResetFunctionStack(state);
  11615. if (player && player->IsPlayer() && level > 0) {
  11616. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11617. return 1;
  11618. }
  11619. return 0;
  11620. }
  11621. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11622. Player* player = (Player*)lua_interface->GetSpawn(state);
  11623. int8 level = lua_interface->GetInt8Value(state, 2);
  11624. lua_interface->ResetFunctionStack(state);
  11625. if (player && player->IsPlayer() && level > 0) {
  11626. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11627. return 1;
  11628. }
  11629. return 0;
  11630. }
  11631. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11632. ZoneServer* zone = lua_interface->GetZone(state);
  11633. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11634. lua_interface->ResetFunctionStack(state);
  11635. if (zone) {
  11636. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11637. if (spawn) {
  11638. lua_interface->SetSpawnValue(state, spawn);
  11639. return 1;
  11640. }
  11641. }
  11642. return 0;
  11643. }
  11644. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11645. if (!lua_interface)
  11646. return 0;
  11647. Spawn* spawn = lua_interface->GetSpawn(state);
  11648. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11649. lua_interface->ResetFunctionStack(state);
  11650. bool res = false;
  11651. if(spawn && spawn->IsTransportSpawn())
  11652. {
  11653. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11654. spawn->SetRailID(rail_id);
  11655. res = true;
  11656. }
  11657. else if (!spawn) {
  11658. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11659. }
  11660. else if(!spawn->IsTransportSpawn()) {
  11661. 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());
  11662. }
  11663. lua_interface->SetBooleanValue(state, res);
  11664. return 1;
  11665. }
  11666. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11667. if (!lua_interface)
  11668. return 0;
  11669. ZoneServer* zone = lua_interface->GetZone(state);
  11670. lua_interface->ResetFunctionStack(state);
  11671. if (zone) {
  11672. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11673. return 1;
  11674. }
  11675. return 0;
  11676. }
  11677. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11678. if (!lua_interface)
  11679. return 0;
  11680. Spawn* spawn = lua_interface->GetSpawn(state);
  11681. lua_interface->ResetFunctionStack(state);
  11682. if (spawn) {
  11683. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11684. return 1;
  11685. }
  11686. return 0;
  11687. }
  11688. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11689. if (!lua_interface)
  11690. return 0;
  11691. Spawn* player = lua_interface->GetSpawn(state);
  11692. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11693. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11694. lua_interface->ResetFunctionStack(state);
  11695. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11696. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11697. }
  11698. else if(!zoneID) {
  11699. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11700. }
  11701. else
  11702. {
  11703. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11704. return 1;
  11705. }
  11706. return 0;
  11707. }
  11708. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11709. if (!lua_interface)
  11710. return 0;
  11711. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11712. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11713. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11714. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11715. lua_interface->ResetFunctionStack(state);
  11716. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11717. world.GetWorldTimeStruct()->year = newYear;
  11718. world.GetWorldTimeStruct()->month = newMonth;
  11719. world.GetWorldTimeStruct()->hour = newHour;
  11720. world.GetWorldTimeStruct()->minute = newMinute;
  11721. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11722. return 0;
  11723. }
  11724. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11725. if (!lua_interface)
  11726. return 0;
  11727. lua_interface->ResetFunctionStack(state);
  11728. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11729. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11730. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11731. return 1;
  11732. }
  11733. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11734. if (!lua_interface)
  11735. return 0;
  11736. lua_interface->ResetFunctionStack(state);
  11737. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11738. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11739. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11740. return 1;
  11741. }
  11742. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11743. if (!lua_interface)
  11744. return 0;
  11745. lua_interface->ResetFunctionStack(state);
  11746. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11747. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11748. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11749. return 1;
  11750. }
  11751. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11752. if (!lua_interface)
  11753. return 0;
  11754. lua_interface->ResetFunctionStack(state);
  11755. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11756. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11757. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11758. return 1;
  11759. }
  11760. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11761. if (!lua_interface)
  11762. return 0;
  11763. lua_interface->ResetFunctionStack(state);
  11764. world.SendTimeUpdate();
  11765. return 0;
  11766. }
  11767. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11768. bool update_result = false;
  11769. Faction* faction = 0;
  11770. Spawn* spawn = lua_interface->GetSpawn(state);
  11771. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11772. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11773. lua_interface->ResetFunctionStack(state);
  11774. if(!spawn || !spawn->IsPlayer()) {
  11775. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11776. return 0;
  11777. }
  11778. Player* player = (Player*)spawn;
  11779. Client* client = player->GetClient();
  11780. if (faction_id > 0) {
  11781. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11782. if(hasfaction == 0) {
  11783. //they do not have the faction. Lets get the default value and feed it in.
  11784. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11785. //add the default faction for the player.
  11786. player->SetFactionValue(faction_id, defaultfaction);
  11787. }
  11788. if(increase >= 0) {
  11789. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11790. faction = master_faction_list.GetFaction(faction_id);
  11791. if(faction && update_result)
  11792. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11793. else if(faction)
  11794. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11795. lua_interface->SetBooleanValue(state, true);
  11796. return 1;
  11797. }
  11798. if(increase < 0){
  11799. //change the negative to a positive, since thats how decreasefaction() likes it.
  11800. increase *= -1;
  11801. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11802. faction = master_faction_list.GetFaction(faction_id);
  11803. if(faction && update_result)
  11804. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11805. else if(faction)
  11806. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11807. lua_interface->SetBooleanValue(state, true);
  11808. return 1;
  11809. }
  11810. }
  11811. lua_interface->SetBooleanValue(state, false);
  11812. return 1;
  11813. }
  11814. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11815. bool hascoin = 0;
  11816. Player* player = (Player*)lua_interface->GetSpawn(state);
  11817. int32 coins = lua_interface->GetInt32Value(state, 2);
  11818. lua_interface->ResetFunctionStack(state);
  11819. if (player && player->IsPlayer()) {
  11820. hascoin = player->HasCoins(coins);
  11821. if(hascoin == 0) {
  11822. lua_interface->SetBooleanValue(state, false);
  11823. return 1;
  11824. }
  11825. if(hascoin == 1) {
  11826. lua_interface->SetBooleanValue(state, true);
  11827. return 1;
  11828. }
  11829. }
  11830. return 0;
  11831. }
  11832. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11833. int32 loot_tier = 0;
  11834. Spawn* spawn = lua_interface->GetSpawn(state);
  11835. lua_interface->ResetFunctionStack(state);
  11836. if (spawn) {
  11837. loot_tier = spawn->GetLootTier();
  11838. lua_interface->SetInt32Value(state, loot_tier);
  11839. return 1;
  11840. }
  11841. return 0;
  11842. }
  11843. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11844. if (!lua_interface)
  11845. return 0;
  11846. Spawn* spawn = lua_interface->GetSpawn(state);
  11847. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11848. lua_interface->ResetFunctionStack(state);
  11849. if (spawn) {
  11850. spawn->SetLootTier(loot_tier);
  11851. lua_interface->SetBooleanValue(state, true);
  11852. return 1;
  11853. }
  11854. lua_interface->SetBooleanValue(state, false);
  11855. return 1;
  11856. }
  11857. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11858. int32 loot_drop_type = 0;
  11859. Spawn* spawn = lua_interface->GetSpawn(state);
  11860. lua_interface->ResetFunctionStack(state);
  11861. if (spawn) {
  11862. loot_drop_type = spawn->GetLootDropType();
  11863. lua_interface->SetInt32Value(state, loot_drop_type);
  11864. return 1;
  11865. }
  11866. return 0;
  11867. }
  11868. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11869. if (!lua_interface)
  11870. return 0;
  11871. Spawn* spawn = lua_interface->GetSpawn(state);
  11872. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11873. lua_interface->ResetFunctionStack(state);
  11874. if (spawn) {
  11875. spawn->SetLootDropType(loot_drop_type);
  11876. lua_interface->SetBooleanValue(state, true);
  11877. return 1;
  11878. }
  11879. lua_interface->SetBooleanValue(state, false);
  11880. return 1;
  11881. }
  11882. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11883. if (!lua_interface)
  11884. return 0;
  11885. Spawn* spawn = lua_interface->GetSpawn(state);
  11886. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11887. if(damage_amount > 100) {
  11888. damage_amount = 100;
  11889. }
  11890. if (!spawn) {
  11891. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11892. lua_interface->ResetFunctionStack(state);
  11893. return 0;
  11894. }
  11895. lua_interface->ResetFunctionStack(state);
  11896. if (spawn->IsPlayer()) {
  11897. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11898. lua_interface->SetBooleanValue(state, true);
  11899. else
  11900. lua_interface->SetBooleanValue(state, false);
  11901. }
  11902. else {
  11903. lua_interface->SetBooleanValue(state, false);
  11904. }
  11905. return 1;
  11906. }
  11907. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11908. ZoneServer* zone = lua_interface->GetZone(state);
  11909. int32 version = lua_interface->GetInt32Value(state, 2);
  11910. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11911. if(region_map == nullptr) {
  11912. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11913. lua_interface->ResetFunctionStack(state);
  11914. return 0;
  11915. }
  11916. string region_name = lua_interface->GetStringValue(state, 3);
  11917. string env_name = lua_interface->GetStringValue(state, 4);
  11918. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11919. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11920. float dist = lua_interface->GetFloatValue(state, 7);
  11921. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11922. lua_interface->ResetFunctionStack(state);
  11923. lua_interface->SetBooleanValue(state, true);
  11924. return 1;
  11925. }
  11926. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11927. ZoneServer* zone = lua_interface->GetZone(state);
  11928. int32 version = lua_interface->GetInt32Value(state, 2);
  11929. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11930. if(region_map == nullptr) {
  11931. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11932. lua_interface->ResetFunctionStack(state);
  11933. return 0;
  11934. }
  11935. string region_name = lua_interface->GetStringValue(state, 3);
  11936. region_map->RemoveRegionNode(region_name);
  11937. lua_interface->ResetFunctionStack(state);
  11938. lua_interface->SetBooleanValue(state, true);
  11939. return 1;
  11940. }
  11941. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11942. Client* client = nullptr;
  11943. Spawn* player = lua_interface->GetSpawn(state);
  11944. if (!player) {
  11945. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11946. lua_interface->SetBooleanValue(state, false);
  11947. lua_interface->ResetFunctionStack(state);
  11948. return 1;
  11949. }
  11950. if (!player->IsPlayer()) {
  11951. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11952. lua_interface->SetBooleanValue(state, false);
  11953. lua_interface->ResetFunctionStack(state);
  11954. return 1;
  11955. }
  11956. client = player->GetClient();
  11957. if (!client) {
  11958. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11959. lua_interface->SetBooleanValue(state, false);
  11960. lua_interface->ResetFunctionStack(state);
  11961. return 1;
  11962. }
  11963. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11964. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11965. lua_interface->ResetFunctionStack(state);
  11966. lua_interface->SetBooleanValue(state, success_sight);
  11967. return 1;
  11968. }
  11969. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11970. if (!lua_interface)
  11971. return 0;
  11972. bool result = false;
  11973. Spawn* spawn = lua_interface->GetSpawn(state);
  11974. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11975. lua_interface->ResetFunctionStack(state);
  11976. if (!spawn)
  11977. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11978. else if (!spawn->IsNPC())
  11979. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11980. else
  11981. {
  11982. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11983. result = true;
  11984. }
  11985. lua_interface->SetBooleanValue(state, result);
  11986. return 1;
  11987. }
  11988. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11989. if (!lua_interface)
  11990. return 0;
  11991. bool result = false;
  11992. Spawn* spawn = lua_interface->GetSpawn(state);
  11993. lua_interface->ResetFunctionStack(state);
  11994. if (!spawn)
  11995. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11996. else if (!spawn->IsNPC())
  11997. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11998. else
  11999. {
  12000. if(((NPC*)spawn)->cast_on_aggro_completed)
  12001. result = true;
  12002. }
  12003. lua_interface->SetBooleanValue(state, result);
  12004. return 1;
  12005. }
  12006. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12007. Client* client = nullptr;
  12008. Spawn* player = lua_interface->GetSpawn(state);
  12009. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12010. lua_interface->ResetFunctionStack(state);
  12011. if (!player) {
  12012. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12013. lua_interface->SetBooleanValue(state, false);
  12014. return 1;
  12015. }
  12016. if (!player->IsPlayer()) {
  12017. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12018. lua_interface->SetBooleanValue(state, false);
  12019. return 1;
  12020. }
  12021. client = player->GetClient();
  12022. if (!client) {
  12023. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12024. lua_interface->SetBooleanValue(state, false);
  12025. return 1;
  12026. }
  12027. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12028. lua_interface->SetBooleanValue(state, result);
  12029. return 1;
  12030. }
  12031. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12032. Client* client = nullptr;
  12033. Spawn* player = lua_interface->GetSpawn(state);
  12034. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12035. lua_interface->ResetFunctionStack(state);
  12036. if (!player) {
  12037. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12038. lua_interface->SetBooleanValue(state, false);
  12039. return 1;
  12040. }
  12041. if (!player->IsPlayer()) {
  12042. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12043. lua_interface->SetBooleanValue(state, false);
  12044. return 1;
  12045. }
  12046. client = player->GetClient();
  12047. if (!client) {
  12048. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12049. lua_interface->SetBooleanValue(state, false);
  12050. return 1;
  12051. }
  12052. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12053. lua_interface->SetBooleanValue(state, result);
  12054. return 1;
  12055. }
  12056. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12057. Client* client = nullptr;
  12058. Spawn* player = lua_interface->GetSpawn(state);
  12059. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12060. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12061. // rest are all optional fields
  12062. float x = lua_interface->GetFloatValue(state, 4);
  12063. float y = lua_interface->GetFloatValue(state, 5);
  12064. float z = lua_interface->GetFloatValue(state, 6);
  12065. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12066. lua_interface->ResetFunctionStack(state);
  12067. if (!player) {
  12068. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12069. lua_interface->SetBooleanValue(state, false);
  12070. return 1;
  12071. }
  12072. if (!player->IsPlayer()) {
  12073. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12074. lua_interface->SetBooleanValue(state, false);
  12075. return 1;
  12076. }
  12077. if(!player->GetZone()) {
  12078. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12079. lua_interface->SetBooleanValue(state, false);
  12080. return 1;
  12081. }
  12082. client = player->GetClient();
  12083. if (!client) {
  12084. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12085. lua_interface->SetBooleanValue(state, false);
  12086. return 1;
  12087. }
  12088. if(!client->IsReadyForUpdates()) {
  12089. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12090. lua_interface->SetBooleanValue(state, false);
  12091. return 1;
  12092. }
  12093. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12094. lua_interface->SetBooleanValue(state, true);
  12095. return 1;
  12096. }
  12097. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12098. Client* client = nullptr;
  12099. Spawn* spawn = lua_interface->GetSpawn(state);
  12100. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12101. lua_interface->ResetFunctionStack(state);
  12102. if (!spawn) {
  12103. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12104. lua_interface->SetBooleanValue(state, false);
  12105. return 1;
  12106. }
  12107. if(!spawn->GetZone()) {
  12108. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12109. lua_interface->SetBooleanValue(state, false);
  12110. return 1;
  12111. }
  12112. spawn->AddIgnoredWidget(widget_id);
  12113. lua_interface->SetBooleanValue(state, true);
  12114. return 1;
  12115. }
  12116. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12117. ZoneServer* zone = lua_interface->GetZone(state);
  12118. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12119. lua_interface->ResetFunctionStack(state);
  12120. if(!zone) {
  12121. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12122. lua_interface->SetBooleanValue(state, false);
  12123. return 1;
  12124. }
  12125. if(!zone->IsLoading()) {
  12126. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12127. lua_interface->SetBooleanValue(state, false);
  12128. return 1;
  12129. }
  12130. zone->AddIgnoredWidget(widget_id);
  12131. lua_interface->SetBooleanValue(state, true);
  12132. return 1;
  12133. }
  12134. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12135. if (!lua_interface)
  12136. return 0;
  12137. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12138. Spawn* spawn = lua_interface->GetSpawn(state);
  12139. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12140. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12141. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12142. Spawn* target = lua_interface->GetSpawn(state, 5);
  12143. lua_interface->ResetFunctionStack(state);
  12144. if(spell && spawn && spawn->IsEntity()) {
  12145. ZoneServer* zone = spawn->GetZone();
  12146. if(zone) {
  12147. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12148. }
  12149. }
  12150. else if (spawn) {
  12151. if (spawn->IsPlayer()) {
  12152. Client* client = ((Player*)spawn)->GetClient();
  12153. if (client) {
  12154. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12155. }
  12156. }
  12157. }
  12158. return 0;
  12159. }