LuaFunctions.cpp 396 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008
  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 = spawn->GetZone()->GetClientBySpawn(player);
  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_PlaySound(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. string sound_string = lua_interface->GetStringValue(state, 2);
  183. float x = lua_interface->GetFloatValue(state, 3);
  184. float y = lua_interface->GetFloatValue(state, 4);
  185. float z = lua_interface->GetFloatValue(state, 5);
  186. Spawn* player = lua_interface->GetSpawn(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn && sound_string.length() > 0) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = spawn->GetZone()->GetClientBySpawn(player);
  192. if (client)
  193. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  194. else
  195. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  196. }
  197. return 0;
  198. }
  199. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  200. if (!lua_interface)
  201. return 0;
  202. Spawn* spawn = lua_interface->GetSpawn(state);
  203. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  204. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  205. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  206. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  207. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  208. lua_interface->ResetFunctionStack(state);
  209. if (!spawn) {
  210. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  211. return 0;
  212. }
  213. if (quest_id > 0) {
  214. //Add this quest to the list of required quests for this spawn
  215. spawn->SetQuestsRequired(quest_id, quest_step);
  216. //If private spawn value set
  217. if (private_spawn) {
  218. //Set the spawn to be private when not granted access through this quest
  219. spawn->AddAllowAccessSpawn(spawn);
  220. spawn->SetPrivateQuestSpawn(true);
  221. }
  222. //This value allows access after a quest step, or the whole quest has been completed
  223. if (continued_access)
  224. spawn->SetQuestsRequiredContinuedAccess(true);
  225. //This value will override vis_flags in the vis packet
  226. if (flag_override > 0)
  227. spawn->SetQuestsRequiredOverride(flag_override);
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. Spawn* spawn = lua_interface->GetSpawn(state);
  235. float max_distance = lua_interface->GetFloatValue(state, 2);
  236. string variable = lua_interface->GetStringValue(state, 3);
  237. string value = lua_interface->GetStringValue(state, 4);
  238. lua_interface->ResetFunctionStack(state);
  239. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  240. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  241. return 0;
  242. }
  243. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  244. if (!lua_interface)
  245. return 0;
  246. Client* client = 0;
  247. Spawn* player = lua_interface->GetSpawn(state);
  248. if (!player) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  250. return 0;
  251. }
  252. if (!player->IsPlayer()) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  254. return 0;
  255. }
  256. if (player->GetZone())
  257. client = player->GetZone()->GetClientBySpawn(player);
  258. if (!client) {
  259. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  260. return 0;
  261. }
  262. float intensity = lua_interface->GetFloatValue(state, 2);
  263. int8 direction = lua_interface->GetInt8Value(state, 3);
  264. lua_interface->ResetFunctionStack(state);
  265. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  266. if (packet) {
  267. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  268. v1 = *(float *)(a1 + 4);
  269. if ( v1 > 0.0 )
  270. v2 = fminf(v1, 1.0);
  271. else
  272. v2 = 0.1;
  273. */
  274. packet->setDataByName("intensity", intensity);
  275. if ( client->GetVersion() > 546 )
  276. packet->setDataByName("direction", direction);
  277. client->QueuePacket(packet->serialize());
  278. safe_delete(packet);
  279. }
  280. return 0;
  281. }
  282. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  283. if (!lua_interface)
  284. return 0;
  285. Spawn* dead = lua_interface->GetSpawn(state);
  286. Spawn* killer = lua_interface->GetSpawn(state, 2);
  287. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  288. lua_interface->ResetFunctionStack(state);
  289. if (dead && dead->Alive() && dead->GetZone())
  290. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  291. return 0;
  292. }
  293. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  294. if (!lua_interface)
  295. return 0;
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. float max_distance = lua_interface->GetFloatValue(state, 2);
  298. bool include_players = lua_interface->GetInt8Value(state, 3);
  299. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  300. lua_interface->ResetFunctionStack(state);
  301. if (max_distance > 0 && spawn && spawn->GetZone())
  302. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_Despawn(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int32 delay = lua_interface->GetInt32Value(state, 2);
  310. lua_interface->ResetFunctionStack(state);
  311. if (spawn && spawn->GetZone())
  312. spawn->GetZone()->Despawn(spawn, delay);
  313. return 0;
  314. }
  315. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  316. if (!lua_interface)
  317. return 0;
  318. Spawn* spawn = lua_interface->GetSpawn(state);
  319. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  320. lua_interface->ResetFunctionStack(state);
  321. if (spawn) {
  322. spawn->info_changed = true;
  323. spawn->SetShowHandIcon(displayHandIcon);
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //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
  329. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. lua_interface->ResetFunctionStack(state);
  334. if (spawn) {
  335. spawn->vis_changed = true;
  336. spawn->GetZone()->AddChangedSpawn(spawn);
  337. }
  338. return 0;
  339. }
  340. //this function is used to force an update packet to be sent.
  341. //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
  342. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. lua_interface->ResetFunctionStack(state);
  347. if (spawn) {
  348. spawn->info_changed = true;
  349. spawn->GetZone()->AddChangedSpawn(spawn);
  350. }
  351. return 0;
  352. }
  353. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  354. if (!lua_interface)
  355. return 0;
  356. Spawn* spawn = lua_interface->GetSpawn(state);
  357. int32 new_state = lua_interface->GetInt32Value(state, 2);
  358. Spawn* player = lua_interface->GetSpawn(state, 3);
  359. lua_interface->ResetFunctionStack(state);
  360. if (spawn) {
  361. if(player)
  362. {
  363. if(player->IsPlayer())
  364. {
  365. Client* client = ((Player*)player)->GetClient();
  366. if(client)
  367. {
  368. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  369. lua_interface->SetBooleanValue(state, true);
  370. return 1;
  371. }
  372. else
  373. 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());
  374. }
  375. else
  376. 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());
  377. }
  378. else
  379. {
  380. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  381. lua_interface->SetBooleanValue(state, true);
  382. return 1;
  383. }
  384. }
  385. lua_interface->SetBooleanValue(state, false);
  386. return 1;
  387. }
  388. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  389. if (!lua_interface)
  390. return 0;
  391. Spawn* spawn = lua_interface->GetSpawn(state);
  392. string variable = lua_interface->GetStringValue(state, 2);
  393. string value = lua_interface->GetStringValue(state, 3);
  394. 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.
  395. bool temporary_flag = true;
  396. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  397. int8 index = 0;
  398. if(num_args >= 5)
  399. {
  400. 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
  401. index = lua_interface->GetInt8Value(state, 6);
  402. }
  403. lua_interface->ResetFunctionStack(state);
  404. int32 type = commands.GetSpawnSetType(variable);
  405. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  406. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  407. return 0;
  408. }
  409. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  410. if (!lua_interface)
  411. return 0;
  412. Spawn* spawn = lua_interface->GetSpawn(state);
  413. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  414. lua_interface->ResetFunctionStack(state);
  415. if (spawn && spawn_id > 0) {
  416. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  417. if (closest_spawn) {
  418. lua_interface->SetSpawnValue(state, closest_spawn);
  419. return 1;
  420. }
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. int32 position = lua_interface->GetInt32Value(state, 2);
  429. lua_interface->ResetFunctionStack(state);
  430. if (spawnList) {
  431. if (spawnList->size() > position) {
  432. lua_interface->SetSpawnValue(state, spawnList->at(position));
  433. return 1;
  434. }
  435. else {
  436. return 0;
  437. }
  438. return spawnList->size();
  439. }
  440. return 0;
  441. }
  442. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  443. if (!lua_interface)
  444. return 0;
  445. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  446. lua_interface->ResetFunctionStack(state);
  447. if (spawnList) {
  448. return spawnList->size();
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = new vector<Spawn*>();
  456. lua_interface->SetSpawnListValue(state, spawnList);
  457. return 1;
  458. }
  459. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  460. if (!lua_interface)
  461. return 0;
  462. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  463. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  464. lua_interface->ResetFunctionStack(state);
  465. if (spawnList) {
  466. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  467. if (it == spawnList->end())
  468. spawnList->push_back(spawn);
  469. }
  470. return 0;
  471. }
  472. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  473. if (!lua_interface)
  474. return 0;
  475. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  476. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  477. lua_interface->ResetFunctionStack(state);
  478. if (spawnList) {
  479. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  480. if(it != spawnList->end())
  481. spawnList->erase(it);
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* spawn = lua_interface->GetSpawn(state);
  489. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  490. lua_interface->ResetFunctionStack(state);
  491. if (spawn) {
  492. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  493. if (spawns.size() > 0) {
  494. vector<Spawn*>* spawnList = new vector<Spawn*>();
  495. vector<Spawn*>::iterator itr;
  496. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  497. spawnList->push_back(*itr);
  498. }
  499. lua_interface->SetSpawnListValue(state, spawnList);
  500. return 1;
  501. }
  502. }
  503. return 0;
  504. }
  505. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. Spawn* spawn = lua_interface->GetSpawn(state);
  509. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  510. lua_interface->ResetFunctionStack(state);
  511. if (spawn) {
  512. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  513. if (spawns.size() > 0) {
  514. vector<Spawn*>* spawnList = new vector<Spawn*>();
  515. vector<Spawn*>::iterator itr;
  516. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  517. spawnList->push_back(*itr);
  518. }
  519. lua_interface->SetSpawnListValue(state, spawnList);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  526. if (!lua_interface)
  527. return 0;
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. lua_interface->ResetFunctionStack(state);
  530. if (spawn) {
  531. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  532. if (spawns.size() > 0) {
  533. lua_createtable(state, spawns.size(), 0);
  534. int newTable = lua_gettop(state);
  535. for (int32 i = 0; i < spawns.size(); i++) {
  536. lua_interface->SetSpawnValue(state, spawns.at(i));
  537. lua_rawseti(state, newTable, i + 1);
  538. }
  539. return 1;
  540. }
  541. }
  542. return 0;
  543. }
  544. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  545. if (!lua_interface)
  546. return 0;
  547. string variable_name = lua_interface->GetStringValue(state);
  548. lua_interface->ResetFunctionStack(state);
  549. Variable* var = variables.FindVariable(variable_name);
  550. if (var) {
  551. lua_interface->SetStringValue(state, var->GetValue());
  552. return 1;
  553. }
  554. return 0;
  555. }
  556. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  557. if (!lua_interface)
  558. return 0;
  559. int32 total_coins = lua_interface->GetInt32Value(state);
  560. lua_interface->ResetFunctionStack(state);
  561. if (total_coins == 0) {
  562. lua_interface->SetStringValue(state, "0 copper");
  563. return 1;
  564. }
  565. char tmp[64] = { 0 };
  566. string message = "";
  567. int32 val = 0;
  568. if (total_coins >= 1000000) {
  569. val = total_coins / 1000000;
  570. total_coins -= 1000000 * val;
  571. sprintf(tmp, " %u Platinum", val);
  572. message.append(tmp);
  573. memset(tmp, 0, 64);
  574. }
  575. if (total_coins >= 10000) {
  576. val = total_coins / 10000;
  577. total_coins -= 10000 * val;
  578. sprintf(tmp, " %u Gold", val);
  579. message.append(tmp);
  580. memset(tmp, 0, 64);
  581. }
  582. if (total_coins >= 100) {
  583. val = total_coins / 100;
  584. total_coins -= 100 * val;
  585. sprintf(tmp, " %u Silver", val);
  586. message.append(tmp);
  587. memset(tmp, 0, 64);
  588. }
  589. if (total_coins > 0) {
  590. sprintf(tmp, " %u Copper", (int32)total_coins);
  591. message.append(tmp);
  592. }
  593. lua_interface->SetStringValue(state, message.c_str());
  594. return 1;
  595. }
  596. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  597. ZoneServer* zone = lua_interface->GetZone(state);
  598. int32 group_id = lua_interface->GetInt32Value(state, 2);
  599. lua_interface->ResetFunctionStack(state);
  600. if (zone) {
  601. Spawn* spawn = zone->GetSpawnGroup(group_id);
  602. if (spawn) {
  603. lua_interface->SetSpawnValue(state, spawn);
  604. return 1;
  605. }
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  610. ZoneServer* zone = lua_interface->GetZone(state);
  611. int32 location_id = lua_interface->GetInt32Value(state, 2);
  612. lua_interface->ResetFunctionStack(state);
  613. if (zone) {
  614. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  615. if (spawn) {
  616. lua_interface->SetSpawnValue(state, spawn);
  617. return 1;
  618. }
  619. }
  620. return 0;
  621. }
  622. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. lua_interface->ResetFunctionStack(state);
  625. if (spawn) {
  626. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  632. Spawn* spawn = lua_interface->GetSpawn(state);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  636. return 1;
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  645. lua_interface->ResetFunctionStack(state);
  646. if (spawn) {
  647. spawn->SetSpawnGroupID(new_group_id);
  648. lua_interface->SetBooleanValue(state, true);
  649. return 1;
  650. }
  651. lua_interface->SetBooleanValue(state, false);
  652. return 1;
  653. }
  654. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  659. lua_interface->ResetFunctionStack(state);
  660. if (spawn) {
  661. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  662. lua_interface->SetBooleanValue(state, true);
  663. return 1;
  664. }
  665. lua_interface->SetBooleanValue(state, false);
  666. return 1;
  667. }
  668. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  669. Spawn* spawn = lua_interface->GetSpawn(state);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  673. return 1;
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. lua_interface->ResetFunctionStack(state);
  680. if (spawn) {
  681. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  682. return 1;
  683. }
  684. return 0;
  685. }
  686. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  687. Player* player = (Player*)lua_interface->GetSpawn(state);
  688. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  689. lua_interface->ResetFunctionStack(state);
  690. if (player && player->IsPlayer() && faction_id > 0) {
  691. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  692. return 1;
  693. }
  694. return 0;
  695. }
  696. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  697. if (!lua_interface)
  698. return 0;
  699. Spawn* spawn = lua_interface->GetSpawn(state);
  700. int32 value = lua_interface->GetInt32Value(state, 2);
  701. lua_interface->ResetFunctionStack(state);
  702. if (spawn) {
  703. spawn->SetFactionID(value);
  704. }
  705. return 0;
  706. }
  707. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  708. Spawn* spawn = lua_interface->GetSpawn(state);
  709. lua_interface->ResetFunctionStack(state);
  710. if (spawn) {
  711. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_GetGender(lua_State* state) {
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. lua_interface->ResetFunctionStack(state);
  719. if (spawn) {
  720. lua_interface->SetInt32Value(state, spawn->GetGender());
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_GetTarget(lua_State* state) {
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. lua_interface->ResetFunctionStack(state);
  728. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  730. return 1;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. string mp3_string = lua_interface->GetStringValue(state, 2);
  739. int32 key1 = lua_interface->GetInt32Value(state, 3);
  740. int32 key2 = lua_interface->GetInt32Value(state, 4);
  741. Spawn* player = lua_interface->GetSpawn(state, 5);
  742. lua_interface->ResetFunctionStack(state);
  743. if (spawn && mp3_string.length() > 0) {
  744. Client* client = 0;
  745. if (player && player->IsPlayer())
  746. client = spawn->GetZone()->GetClientBySpawn(player);
  747. if (client) {
  748. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  749. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  750. }
  751. else
  752. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  753. }
  754. return 0;
  755. }
  756. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  757. if (!lua_interface)
  758. return 0;
  759. Spawn* spawn = lua_interface->GetSpawn(state);
  760. lua_interface->ResetFunctionStack(state);
  761. if (spawn) {
  762. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  763. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  764. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  765. return 3;
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 item_id = lua_interface->GetInt32Value(state, 2);
  775. lua_interface->ResetFunctionStack(state);
  776. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  777. return 1;
  778. }
  779. lua_interface->ResetFunctionStack(state);
  780. return 0;
  781. }
  782. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  783. if (!lua_interface)
  784. return 0;
  785. Spawn* spawn = lua_interface->GetSpawn(state);
  786. if (spawn && spawn->IsEntity()) {
  787. int32 item_id = lua_interface->GetInt32Value(state, 2);
  788. int16 charges = lua_interface->GetInt16Value(state, 3);
  789. if (charges == 0)
  790. charges = 1;
  791. ((Entity*)spawn)->AddLootItem(item_id, charges);
  792. }
  793. lua_interface->ResetFunctionStack(state);
  794. return 0;
  795. }
  796. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn && spawn->IsEntity()) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. Item* item = spawn->LootItem(item_id);
  803. safe_delete(item);
  804. }
  805. lua_interface->ResetFunctionStack(state);
  806. return 0;
  807. }
  808. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  809. if (!lua_interface)
  810. return 0;
  811. Spawn* spawn = lua_interface->GetSpawn(state);
  812. if (spawn) {
  813. int32 val = lua_interface->GetInt32Value(state, 2);
  814. spawn->AddLootCoins(val);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* entity = lua_interface->GetSpawn(state);
  823. Spawn* player = lua_interface->GetSpawn(state, 2);
  824. if (entity && player && player->IsPlayer()) {
  825. int32 coins = lua_interface->GetInt32Value(state, 3);
  826. vector<Item*>* items = 0;
  827. int i = 0;
  828. int32 item_id = 0;
  829. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  830. if (items == 0)
  831. items = new vector<Item*>;
  832. if (master_item_list.GetItem(item_id))
  833. items->push_back(master_item_list.GetItem(item_id));
  834. i++;
  835. }
  836. Client* client = 0;
  837. client = player->GetZone()->GetClientBySpawn(player);
  838. if (client)
  839. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  840. if(coins > 0)
  841. entity->AddLootCoins(coins);
  842. safe_delete(items);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. int32 item_id = lua_interface->GetInt32Value(state, 3);
  853. lua_interface->ResetFunctionStack(state);
  854. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  855. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  856. return 1;
  857. }
  858. return 0;
  859. }
  860. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* entity = lua_interface->GetSpawn(state);
  864. Spawn* player = lua_interface->GetSpawn(state, 2);
  865. lua_interface->ResetFunctionStack(state);
  866. if (entity && player && player->IsPlayer()) {
  867. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  868. return 1;
  869. }
  870. return 0;
  871. }
  872. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  876. safe_delete(conversation);
  877. lua_interface->ResetFunctionStack(state);
  878. conversation = new vector<ConversationOption>();
  879. lua_interface->SetConversationValue(state, conversation);
  880. return 1;
  881. }
  882. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  883. if (!lua_interface)
  884. return 0;
  885. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  886. if (conversation) {
  887. ConversationOption conv_option;
  888. conv_option.option = lua_interface->GetStringValue(state, 2);
  889. conv_option.function = lua_interface->GetStringValue(state, 3);
  890. if (conv_option.option.length() > 0)
  891. conversation->push_back(conv_option);
  892. }
  893. lua_interface->ResetFunctionStack(state);
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. Spawn* npc = lua_interface->GetSpawn(state);
  900. Spawn* player = lua_interface->GetSpawn(state, 2);
  901. lua_interface->ResetFunctionStack(state);
  902. if (npc && player && player->IsPlayer() && player->GetZone()) {
  903. Client* client = player->GetZone()->GetClientBySpawn(player);
  904. if (client) {
  905. int32 conversation_id = client->GetConversationID(npc, 0);
  906. client->CloseDialog(conversation_id);
  907. }
  908. }
  909. return 0;
  910. }
  911. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. Item* item = lua_interface->GetItem(state);
  915. Spawn* player = lua_interface->GetSpawn(state, 2);
  916. lua_interface->ResetFunctionStack(state);
  917. if (item && player && player->IsPlayer() && player->GetZone()) {
  918. Client* client = player->GetZone()->GetClientBySpawn(player);
  919. if (client) {
  920. int32 conversation_id = client->GetConversationID(0, item);
  921. client->CloseDialog(conversation_id);
  922. }
  923. }
  924. return 0;
  925. }
  926. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  927. if (!lua_interface)
  928. return 0;
  929. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  930. Spawn* spawn = 0;
  931. Item* item = 0;
  932. int8 type = lua_interface->GetInt8Value(state, 2);
  933. if (type == 1 || type == 3)
  934. spawn = lua_interface->GetSpawn(state, 3);
  935. else if (type == 2 || type == 4)
  936. item = lua_interface->GetItem(state, 3);
  937. Spawn* player = lua_interface->GetSpawn(state, 4);
  938. string text = lua_interface->GetStringValue(state, 5);
  939. string mp3 = lua_interface->GetStringValue(state, 6);
  940. int32 key1 = lua_interface->GetInt32Value(state, 7);
  941. int32 key2 = lua_interface->GetInt32Value(state, 8);
  942. lua_interface->ResetFunctionStack(state);
  943. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  944. Client* client = player->GetZone()->GetClientBySpawn(player);
  945. if (client) {
  946. if (spawn) {
  947. // Need to do this so the function works the same as it did before
  948. if (type == 1)
  949. type++;
  950. if (mp3.length() > 0)
  951. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  952. else
  953. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  954. }
  955. else {
  956. if (mp3.length() > 0)
  957. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  958. else
  959. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  960. }
  961. }
  962. }
  963. safe_delete(conversation);
  964. lua_interface->SetConversationValue(state, NULL);
  965. return 0;
  966. }
  967. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  968. if(!lua_interface)
  969. return 0;
  970. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  971. Item* item = lua_interface->GetItem(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. string text = lua_interface->GetStringValue(state, 4);
  974. string mp3 = lua_interface->GetStringValue(state, 5);
  975. int32 key1 = lua_interface->GetInt32Value(state, 6);
  976. int32 key2 = lua_interface->GetInt32Value(state, 7);
  977. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  978. Client* client = player->GetZone()->GetClientBySpawn(player);
  979. if(client){
  980. if(mp3.length() > 0)
  981. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  982. else
  983. client->DisplayConversation(item, conversation, (char*)text.c_str());
  984. }
  985. safe_delete(conversation);
  986. }
  987. return 0;
  988. }*/
  989. int EQ2Emu_lua_StartConversation(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  993. Spawn* source = lua_interface->GetSpawn(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. string text = lua_interface->GetStringValue(state, 4);
  996. string mp3 = lua_interface->GetStringValue(state, 5);
  997. int32 key1 = lua_interface->GetInt32Value(state, 6);
  998. int32 key2 = lua_interface->GetInt32Value(state, 7);
  999. lua_interface->ResetFunctionStack(state);
  1000. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1001. Client* client = source->GetZone()->GetClientBySpawn(player);
  1002. if (mp3.length() > 0)
  1003. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  1004. else
  1005. client->DisplayConversation(source, 1, conversation, text.c_str());
  1006. safe_delete(conversation);
  1007. lua_interface->SetConversationValue(state, NULL);
  1008. }
  1009. else
  1010. 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);
  1011. return 0;
  1012. }
  1013. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1014. if (!lua_interface)
  1015. return 0;
  1016. Spawn* spawn = lua_interface->GetSpawn(state);
  1017. float distance = lua_interface->GetFloatValue(state, 2);
  1018. string in_range_function = lua_interface->GetStringValue(state, 3);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1020. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1021. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1022. return 0;
  1023. }
  1024. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1025. ZoneServer* zone = lua_interface->GetZone(state);
  1026. float x = lua_interface->GetFloatValue(state, 2);
  1027. float y = lua_interface->GetFloatValue(state, 3);
  1028. float z = lua_interface->GetFloatValue(state, 4);
  1029. float max_variation = lua_interface->GetFloatValue(state, 5);
  1030. string in_range_function = lua_interface->GetStringValue(state, 6);
  1031. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1032. lua_interface->ResetFunctionStack(state);
  1033. if (zone && in_range_function.length() > 0)
  1034. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1038. if (!lua_interface)
  1039. return 0;
  1040. Spawn* spawn = lua_interface->GetSpawn(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. int32 val = lua_interface->GetInt32Value(state, 2);
  1043. ((Entity*)spawn)->SetLootCoins(val);
  1044. }
  1045. lua_interface->ResetFunctionStack(state);
  1046. return 0;
  1047. }
  1048. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1049. if (!lua_interface)
  1050. return 0;
  1051. Spawn* spawn = lua_interface->GetSpawn(state);
  1052. lua_interface->ResetFunctionStack(state);
  1053. if (spawn && spawn->IsEntity()) {
  1054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1060. if (!lua_interface)
  1061. return 0;
  1062. Spawn* spawn = lua_interface->GetSpawn(state);
  1063. float x = lua_interface->GetFloatValue(state, 2);
  1064. float y = lua_interface->GetFloatValue(state, 3);
  1065. float z = lua_interface->GetFloatValue(state, 4);
  1066. float speed = lua_interface->GetFloatValue(state, 5);
  1067. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1068. string function = lua_interface->GetStringValue(state, 7);
  1069. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1070. float heading = lua_interface->GetFloatValue(state, 8);
  1071. if (spawn) {
  1072. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1073. spawn->GetZone()->AddMovementNPC(spawn);
  1074. }
  1075. lua_interface->ResetFunctionStack(state);
  1076. return 0;
  1077. }
  1078. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1079. if (!lua_interface)
  1080. return 0;
  1081. Spawn* spawn = lua_interface->GetSpawn(state);
  1082. lua_interface->ResetFunctionStack(state);
  1083. if (spawn) {
  1084. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1085. return 1;
  1086. }
  1087. return 0;
  1088. }
  1089. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. lua_interface->ResetFunctionStack(state);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1096. return 1;
  1097. }
  1098. lua_interface->SetInt32Value(state, 0);
  1099. return 1;
  1100. }
  1101. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1102. if (!lua_interface)
  1103. return 0;
  1104. Spawn* spawn = lua_interface->GetSpawn(state);
  1105. Spawn* target = lua_interface->GetSpawn(state, 2);
  1106. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1107. bool reset_action_state = true;
  1108. if(num_args > 2)
  1109. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1110. if (spawn && target) {
  1111. if (spawn->IsEntity())
  1112. // ((Entity*)spawn)->FaceTarget(target);
  1113. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1114. }
  1115. lua_interface->ResetFunctionStack(state);
  1116. return 0;
  1117. }
  1118. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. float x = lua_interface->GetFloatValue(state, 2);
  1123. float y = lua_interface->GetFloatValue(state, 3);
  1124. float z = lua_interface->GetFloatValue(state, 4);
  1125. float speed = lua_interface->GetFloatValue(state, 5);
  1126. string lua_function = lua_interface->GetStringValue(state, 6);
  1127. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1128. if (spawn) {
  1129. if (speed == 0)
  1130. speed = spawn->GetSpeed();
  1131. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1132. }
  1133. lua_interface->ResetFunctionStack(state);
  1134. return 0;
  1135. }
  1136. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1137. if (!lua_interface)
  1138. return 0;
  1139. Spawn* spawn = lua_interface->GetSpawn(state);
  1140. lua_interface->ResetFunctionStack(state);
  1141. if (spawn) {
  1142. spawn->ClearRunningLocations();
  1143. }
  1144. return 0;
  1145. }
  1146. int EQ2Emu_lua_Say(lua_State* state) {
  1147. if (!lua_interface)
  1148. return 0;
  1149. Spawn* spawn = lua_interface->GetSpawn(state);
  1150. string message = lua_interface->GetStringValue(state, 2);
  1151. Spawn* player = lua_interface->GetSpawn(state, 3);
  1152. int32 language = lua_interface->GetInt32Value(state, 4);
  1153. if (spawn && message.length() > 0) {
  1154. Client* client = 0;
  1155. if (player && player->IsPlayer())
  1156. client = spawn->GetZone()->GetClientBySpawn(player);
  1157. if (client)
  1158. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1159. else
  1160. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1161. }
  1162. lua_interface->ResetFunctionStack(state);
  1163. return 0;
  1164. }
  1165. int EQ2Emu_lua_Shout(lua_State* state) {
  1166. if (!lua_interface)
  1167. return 0;
  1168. Spawn* spawn = lua_interface->GetSpawn(state);
  1169. string message = lua_interface->GetStringValue(state, 2);
  1170. Spawn* player = lua_interface->GetSpawn(state, 3);
  1171. float dist = lua_interface->GetFloatValue(state, 4);
  1172. if (spawn && message.length() > 0) {
  1173. Client* client = 0;
  1174. if (player && player->IsPlayer())
  1175. client = spawn->GetZone()->GetClientBySpawn(player);
  1176. if (client)
  1177. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1178. else
  1179. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1180. }
  1181. lua_interface->ResetFunctionStack(state);
  1182. return 0;
  1183. }
  1184. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1185. if (!lua_interface)
  1186. return 0;
  1187. Spawn* spawn = lua_interface->GetSpawn(state);
  1188. string message = lua_interface->GetStringValue(state, 2);
  1189. Spawn* player = lua_interface->GetSpawn(state, 3);
  1190. if (spawn && message.length() > 0) {
  1191. Client* client = 0;
  1192. if (player && player->IsPlayer())
  1193. client = spawn->GetZone()->GetClientBySpawn(player);
  1194. if (client)
  1195. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1196. else
  1197. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1198. }
  1199. lua_interface->ResetFunctionStack(state);
  1200. return 0;
  1201. }
  1202. int EQ2Emu_lua_Emote(lua_State* state) {
  1203. if (!lua_interface)
  1204. return 0;
  1205. Spawn* spawn = lua_interface->GetSpawn(state);
  1206. string message = lua_interface->GetStringValue(state, 2);
  1207. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1208. Spawn* player = lua_interface->GetSpawn(state, 4);
  1209. char* to = 0;
  1210. if (spawn2)
  1211. to = spawn2->GetName();
  1212. if (spawn && message.length() > 0) {
  1213. Client* client = 0;
  1214. if (player && player->IsPlayer())
  1215. client = spawn->GetZone()->GetClientBySpawn(player);
  1216. if (client)
  1217. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1218. else
  1219. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1220. }
  1221. lua_interface->ResetFunctionStack(state);
  1222. return 0;
  1223. }
  1224. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1225. if (!lua_interface)
  1226. return 0;
  1227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1228. if(!luaspell || luaspell->resisted) {
  1229. return 0;
  1230. }
  1231. Spawn* caster = luaspell->caster;
  1232. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1233. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1234. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1235. Spawn* target = lua_interface->GetSpawn(state, 4);
  1236. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1237. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1238. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1239. lua_interface->ResetFunctionStack(state);
  1240. boost::to_lower(heal_type);
  1241. if (caster && caster->IsEntity()) {
  1242. bool success = false;
  1243. luaspell->resisted = false;
  1244. if (target) {
  1245. float distance = caster->GetDistance(target, true);
  1246. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1247. success = true;
  1248. }
  1249. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1250. Spawn* target = 0;
  1251. ZoneServer* zone = luaspell->caster->GetZone();
  1252. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1253. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1254. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1255. float distance = caster->GetDistance(target, true);
  1256. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1257. }
  1258. }
  1259. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1260. success = true;
  1261. }
  1262. if (success) {
  1263. if (caster->GetZone())
  1264. caster->GetZone()->TriggerCharSheetTimer();
  1265. }
  1266. }
  1267. return 0;
  1268. }
  1269. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1270. if (!lua_interface)
  1271. return 0;
  1272. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1273. if(!luaspell || luaspell->resisted) {
  1274. return 0;
  1275. }
  1276. Spawn* caster = luaspell->caster;
  1277. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1278. float percentage = lua_interface->GetFloatValue(state, 2);
  1279. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1280. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1281. Spawn* target = lua_interface->GetSpawn(state, 5);
  1282. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1283. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1284. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1285. lua_interface->ResetFunctionStack(state);
  1286. boost::to_lower(heal_type);
  1287. int32 min_heal = 0, max_heal = 0;
  1288. if (caster && caster->IsEntity() && target) {
  1289. if(percentage <= 0.0f)
  1290. {
  1291. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1292. return 0;
  1293. }
  1294. if(heal_type == "power")
  1295. {
  1296. if(current_value)
  1297. {
  1298. if(caster_value)
  1299. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1300. else
  1301. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1302. }
  1303. else
  1304. {
  1305. if(caster_value)
  1306. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1307. else
  1308. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if(current_value)
  1314. {
  1315. if(caster_value)
  1316. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1317. else
  1318. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1319. }
  1320. else
  1321. {
  1322. if(caster_value)
  1323. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1324. else
  1325. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1326. }
  1327. }
  1328. bool success = false;
  1329. luaspell->resisted = false;
  1330. if (target) {
  1331. float distance = caster->GetDistance(target, true);
  1332. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1333. success = true;
  1334. }
  1335. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1336. Spawn* target = 0;
  1337. ZoneServer* zone = luaspell->caster->GetZone();
  1338. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1339. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1340. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1341. float distance = caster->GetDistance(target, true);
  1342. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1343. }
  1344. }
  1345. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1346. success = true;
  1347. }
  1348. if (success) {
  1349. if (caster->GetZone())
  1350. caster->GetZone()->TriggerCharSheetTimer();
  1351. }
  1352. }
  1353. return 0;
  1354. }
  1355. int EQ2Emu_lua_AddItem(lua_State* state) {
  1356. if (!lua_interface)
  1357. return 0;
  1358. Spawn* spawn = lua_interface->GetSpawn(state);
  1359. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1360. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1361. lua_interface->ResetFunctionStack(state);
  1362. // default of 1 quantity to add
  1363. if (quantity == 0)
  1364. quantity = 1;
  1365. if (spawn && spawn->IsPlayer()) {
  1366. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1367. if (client && item_id > 0) {
  1368. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1369. return 1;
  1370. }
  1371. }
  1372. lua_interface->SetBooleanValue(state, false);
  1373. return 1;
  1374. }
  1375. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1376. if (!lua_interface)
  1377. return 0;
  1378. Spawn* spawn = lua_interface->GetSpawn(state);
  1379. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1380. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1381. string location = lua_interface->GetStringValue(state, 4);
  1382. int16 item_count = lua_interface->GetInt16Value(state,5);
  1383. //devn00b: if we dont have a count, assume 1 item.
  1384. if(!item_count) {
  1385. item_count = 1;
  1386. }
  1387. lua_interface->ResetFunctionStack(state);
  1388. if (spawn && spawn->IsPlayer()) {
  1389. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1390. if (client && item_id > 0) {
  1391. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1392. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1393. else
  1394. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1395. if (send_messages) {
  1396. Item* item = master_item_list.GetItem(item_id);
  1397. if (item) {
  1398. if(item_count > 1) {
  1399. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1400. string popup_text1 = "You receive "+ item_count;
  1401. string popup_text2 = " " + item->name;
  1402. string popup_text = popup_text1 + popup_text2;
  1403. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1404. // return 1;
  1405. } else {
  1406. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1407. string popup_text = "You receive " + item->name;
  1408. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1409. }
  1410. }
  1411. }
  1412. return 1;
  1413. }
  1414. }
  1415. lua_interface->SetBooleanValue(state, false);
  1416. return 1;
  1417. }
  1418. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1419. Spawn* spawn = lua_interface->GetSpawn(state);
  1420. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1421. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1422. lua_interface->ResetFunctionStack(state);
  1423. // default of 1 to remove
  1424. if (quantity == 0)
  1425. quantity = 1;
  1426. Client* client;
  1427. Item* item;
  1428. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1429. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1430. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1431. if (client->RemoveItem(item, quantity)) {
  1432. lua_interface->SetBooleanValue(state, true);
  1433. return 1;
  1434. }
  1435. }
  1436. }
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_HasItem(lua_State* state) {
  1442. Spawn* player = lua_interface->GetSpawn(state);
  1443. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1444. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1445. lua_interface->ResetFunctionStack(state);
  1446. if (player && player->IsPlayer()) {
  1447. bool hasItem = false;
  1448. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1449. if (!hasItem)
  1450. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1451. lua_interface->SetBooleanValue(state, hasItem);
  1452. return 1;
  1453. }
  1454. lua_interface->SetBooleanValue(state, false);
  1455. return 1;
  1456. }
  1457. int EQ2Emu_lua_Spawn(lua_State* state) {
  1458. if (!lua_interface)
  1459. return 0;
  1460. ZoneServer* zone = lua_interface->GetZone(state);
  1461. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1462. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1463. float x = lua_interface->GetFloatValue(state, 4);
  1464. float y = lua_interface->GetFloatValue(state, 5);
  1465. float z = lua_interface->GetFloatValue(state, 6);
  1466. float heading = lua_interface->GetFloatValue(state, 7);
  1467. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1468. Spawn* spawn = zone->GetSpawn(spawn_id);
  1469. if (!spawn)
  1470. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1471. else {
  1472. spawn->SetX(x);
  1473. spawn->SetZ(z);
  1474. spawn->SetY(y,true,true);
  1475. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1476. spawn->SetHeading(heading);
  1477. if (restricted_npc)
  1478. spawn->AddAllowAccessSpawn(spawn);
  1479. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1480. bool scriptActive = false;
  1481. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1482. scriptActive = true;
  1483. spawn->SetSpawnScript(string(spawn_script));
  1484. }
  1485. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1486. zone->AddSpawn(spawn);
  1487. if (scriptActive) {
  1488. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1489. }
  1490. lua_interface->ResetFunctionStack(state);
  1491. lua_interface->SetSpawnValue(state, spawn);
  1492. return 1;
  1493. }
  1494. }
  1495. else {
  1496. string output = "Invalid paramaters to LUA Spawn command: \n";
  1497. if (!zone)
  1498. output = output.append("\t").append("Missing zone reference. \n");
  1499. if (spawn_id == 0)
  1500. output = output.append("\t").append("Missing spawn_id.");
  1501. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1502. }
  1503. lua_interface->ResetFunctionStack(state);
  1504. return 0;
  1505. }
  1506. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1507. if (!lua_interface)
  1508. return 0;
  1509. ZoneServer* zone = lua_interface->GetZone(state);
  1510. lua_interface->ResetFunctionStack(state);
  1511. if (zone) {
  1512. lua_interface->SetStringValue(state, zone->GetZoneName());
  1513. return 1;
  1514. }
  1515. return 0;
  1516. }
  1517. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1518. if (!lua_interface)
  1519. return 0;
  1520. ZoneServer* zone = lua_interface->GetZone(state);
  1521. lua_interface->ResetFunctionStack(state);
  1522. if (zone) {
  1523. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1524. return 1;
  1525. }
  1526. return 0;
  1527. }
  1528. int EQ2Emu_lua_GetZone(lua_State* state) {
  1529. if (!lua_interface)
  1530. return 0;
  1531. int32 zone_id = lua_interface->GetInt32Value(state);
  1532. ZoneServer* zone = 0;
  1533. if (zone_id > 0)
  1534. zone = zone_list.Get(zone_id);
  1535. else {
  1536. string zone_name = lua_interface->GetStringValue(state);
  1537. if (zone_name.length() > 0) {
  1538. zone = zone_list.Get(zone_name.c_str());
  1539. }
  1540. else {
  1541. Spawn* spawn = lua_interface->GetSpawn(state);
  1542. if (spawn)
  1543. zone = spawn->GetZone();
  1544. }
  1545. }
  1546. lua_interface->ResetFunctionStack(state);
  1547. if (zone) {
  1548. lua_interface->SetZoneValue(state, zone);
  1549. return 1;
  1550. }
  1551. return 0;
  1552. }
  1553. int EQ2Emu_lua_AddHate(lua_State* state) {
  1554. Spawn* entity = lua_interface->GetSpawn(state);
  1555. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1556. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1557. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1558. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1559. if(!luaspell || luaspell->resisted) {
  1560. return 0;
  1561. }
  1562. if (entity && entity->IsEntity() && amount != 0) {
  1563. if (luaspell) {
  1564. ZoneServer* zone = luaspell->caster->GetZone();
  1565. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1566. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1567. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1568. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1569. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1570. if (send_packet)
  1571. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1572. }
  1573. }
  1574. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1575. }
  1576. else if (npc && npc->IsNPC() && npc->GetZone())
  1577. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1578. }
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. int EQ2Emu_lua_Zone(lua_State* state) {
  1583. if (!lua_interface)
  1584. return 0;
  1585. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1586. ZoneServer* zone = lua_interface->GetZone(state);
  1587. Spawn* player = lua_interface->GetSpawn(state, 2);
  1588. Client* client = 0;
  1589. if (player && player->IsPlayer())
  1590. client = player->GetZone()->GetClientBySpawn(player);
  1591. float x = lua_interface->GetFloatValue(state, 3);
  1592. float y = lua_interface->GetFloatValue(state, 4);
  1593. float z = lua_interface->GetFloatValue(state, 5);
  1594. float heading = lua_interface->GetFloatValue(state, 6);
  1595. if (zone && client) {
  1596. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1597. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1598. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1599. {
  1600. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1601. return 0;
  1602. }
  1603. if (x != 0 || y != 0 || z != 0) {
  1604. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1605. player->SetX(x);
  1606. player->SetY(y);
  1607. player->SetZ(z);
  1608. player->SetHeading(heading);
  1609. client->Zone(zone->GetZoneName(), false);
  1610. }
  1611. else
  1612. client->Zone(zone->GetZoneName());
  1613. }
  1614. else
  1615. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1616. lua_interface->ResetFunctionStack(state);
  1617. return 0;
  1618. }
  1619. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1620. if (!lua_interface)
  1621. return 0;
  1622. Spawn* spawn = lua_interface->GetSpawn(state);
  1623. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1624. if (spawn && spawn2)
  1625. spawn->AddAllowAccessSpawn(spawn2);
  1626. lua_interface->ResetFunctionStack(state);
  1627. return 0;
  1628. }
  1629. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1630. if (!lua_interface)
  1631. return 0;
  1632. Spawn* target = lua_interface->GetSpawn(state);
  1633. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1634. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1635. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1636. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1637. lua_interface->ResetFunctionStack(state);
  1638. if (!target) {
  1639. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1640. return 0;
  1641. }
  1642. if (!target->IsEntity()) {
  1643. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1644. return 0;
  1645. }
  1646. if (spell_id <= 0) {
  1647. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1648. return 0;
  1649. }
  1650. if (caster && !caster->IsEntity()) {
  1651. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1652. return 0;
  1653. }
  1654. if (spell_tier == 0)
  1655. spell_tier = 1;
  1656. if (!caster)
  1657. caster = target;
  1658. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1659. return 0;
  1660. }
  1661. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1662. if (!lua_interface)
  1663. return 0;
  1664. Spawn* target = lua_interface->GetSpawn(state);
  1665. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1666. if(!luaspell || luaspell->resisted) {
  1667. return 0;
  1668. }
  1669. Spawn* caster = luaspell->caster;
  1670. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1671. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1672. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1673. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1674. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1675. //lua_interface->ResetFunctionStack(state);
  1676. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1677. vector<int16> faction_req;
  1678. vector<int16> race_req;
  1679. int32 class_req = 0;
  1680. int32 i = 0;
  1681. int8 f = 0;
  1682. int8 r = 0;
  1683. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1684. if (class_id < 100) {
  1685. class_req += pow(2.0, double(class_id - 1));
  1686. }
  1687. else if (class_id > 100 && class_id < 1000) {
  1688. race_req.push_back(class_id);
  1689. r++;
  1690. }
  1691. else {
  1692. faction_req.push_back(class_id);
  1693. f++;
  1694. }
  1695. i++;
  1696. }
  1697. lua_interface->ResetFunctionStack(state);
  1698. if (caster && caster->IsEntity()) {
  1699. bool race_match = false;
  1700. bool success = false;
  1701. luaspell->resisted = false;
  1702. if (luaspell->targets.size() > 0) {
  1703. ZoneServer* zone = luaspell->caster->GetZone();
  1704. Spawn* target = 0;
  1705. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1706. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1707. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1708. if (race_req.size() > 0) {
  1709. for (int8 i = 0; i < race_req.size(); i++) {
  1710. if (target->GetLuaRaceId() == race_req[i]) {
  1711. race_match = true;
  1712. }
  1713. }
  1714. }
  1715. else
  1716. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1717. if (race_match == true) {
  1718. float distance = caster->GetDistance(target, true);
  1719. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1720. }
  1721. }
  1722. }
  1723. success = true;
  1724. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1725. }
  1726. else if (target) {
  1727. //check class and race/faction here
  1728. if (race_req.size() > 0) {
  1729. for (int8 i = 0; i < race_req.size(); i++) {
  1730. if (target->GetLuaRaceId() == race_req[i]) {
  1731. race_match = true;
  1732. }
  1733. }
  1734. }
  1735. else
  1736. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1737. if (race_match == true) {
  1738. float distance = caster->GetDistance(target, true);
  1739. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1740. success = true;
  1741. }
  1742. }
  1743. if (success) {
  1744. Spell* spell = luaspell->spell;
  1745. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1746. ((Player*)caster)->InCombat(true);
  1747. if (caster->GetZone())
  1748. caster->GetZone()->TriggerCharSheetTimer();
  1749. }
  1750. }
  1751. }
  1752. return 0;
  1753. }
  1754. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1755. if (!lua_interface)
  1756. return 0;
  1757. Spawn* spawn = lua_interface->GetSpawn(state);
  1758. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1759. lua_interface->ResetFunctionStack(state);
  1760. if (spawn && value != 0) {
  1761. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1762. spawn->SetPower(spawn->GetTotalPower());
  1763. else
  1764. spawn->SetPower(spawn->GetPower() + value);
  1765. }
  1766. return 0;
  1767. }
  1768. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1769. if (!lua_interface)
  1770. return 0;
  1771. Spawn* spawn = lua_interface->GetSpawn(state);
  1772. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1773. lua_interface->ResetFunctionStack(state);
  1774. if (spawn && value != 0) {
  1775. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1776. spawn->SetHP(spawn->GetTotalHP());
  1777. else
  1778. spawn->SetHP(spawn->GetHP() + value);
  1779. }
  1780. return 0;
  1781. }
  1782. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1783. if (!lua_interface)
  1784. return 0;
  1785. Spawn* spawn = lua_interface->GetSpawn(state);
  1786. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1787. lua_interface->ResetFunctionStack(state);
  1788. if (spawn && value != 0) {
  1789. spawn->SetPower(spawn->GetPower() + value);
  1790. if (value > spawn->GetTotalHPBase())
  1791. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1792. }
  1793. return 0;
  1794. }
  1795. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1796. if (!lua_interface)
  1797. return 0;
  1798. Spawn* spawn = lua_interface->GetSpawn(state);
  1799. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1800. lua_interface->ResetFunctionStack(state);
  1801. if (spawn && value != 0) {
  1802. spawn->SetHP(spawn->GetHP() + value);
  1803. if (value > spawn->GetTotalHPBase())
  1804. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1805. }
  1806. return 0;
  1807. }
  1808. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1809. if (!lua_interface)
  1810. return 0;
  1811. Spawn* spawn = lua_interface->GetSpawn(state);
  1812. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1813. lua_interface->ResetFunctionStack(state);
  1814. if (spawn) {
  1815. spawn->SetHP(value);
  1816. if (value > spawn->GetTotalHPBase())
  1817. spawn->SetTotalHP(value);
  1818. }
  1819. return 0;
  1820. }
  1821. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1822. if (!lua_interface)
  1823. return 0;
  1824. Spawn* spawn = lua_interface->GetSpawn(state);
  1825. float value = lua_interface->GetFloatValue(state, 2);
  1826. lua_interface->ResetFunctionStack(state);
  1827. if (spawn && spawn->IsEntity() && value > 0)
  1828. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1829. if (spawn->IsPlayer())
  1830. ((Player*)spawn)->SetCharSheetChanged(true);
  1831. return 0;
  1832. }
  1833. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1834. if (!lua_interface)
  1835. return 0;
  1836. Spawn* spawn = lua_interface->GetSpawn(state);
  1837. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1838. lua_interface->ResetFunctionStack(state);
  1839. if (spawn && spawn->IsEntity() && value > 0)
  1840. ((Entity*)spawn)->SetTotalHPBase(value);
  1841. return 0;
  1842. }
  1843. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1844. if (!lua_interface)
  1845. return 0;
  1846. Spawn* spawn = lua_interface->GetSpawn(state);
  1847. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1848. lua_interface->ResetFunctionStack(state);
  1849. if (spawn && value > 0) {
  1850. spawn->SetPower(value);
  1851. if (value > spawn->GetTotalPowerBase())
  1852. spawn->SetTotalPower(value);
  1853. }
  1854. return 0;
  1855. }
  1856. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1857. if (!lua_interface)
  1858. return 0;
  1859. Spawn* spawn = lua_interface->GetSpawn(state);
  1860. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1861. lua_interface->ResetFunctionStack(state);
  1862. if (spawn && spawn->IsEntity() && value > 0)
  1863. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1864. return 0;
  1865. }
  1866. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1867. if (!lua_interface)
  1868. return 0;
  1869. Spawn* spawn = lua_interface->GetSpawn(state);
  1870. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1871. lua_interface->ResetFunctionStack(state);
  1872. if (spawn && spawn->IsEntity() && value > 0)
  1873. ((Entity*)spawn)->SetTotalPowerBase(value);
  1874. return 0;
  1875. }
  1876. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1877. if (!lua_interface)
  1878. return 0;
  1879. Spawn* spawn = lua_interface->GetSpawn(state);
  1880. float x = lua_interface->GetFloatValue(state, 2);
  1881. float y = lua_interface->GetFloatValue(state, 3);
  1882. float z = lua_interface->GetFloatValue(state, 4);
  1883. float heading = lua_interface->GetFloatValue(state, 5);
  1884. lua_interface->ResetFunctionStack(state);
  1885. if (spawn) {
  1886. spawn->SetX(x);
  1887. spawn->SetY(y);
  1888. spawn->SetZ(z);
  1889. if (heading != 0)
  1890. spawn->SetHeading(heading);
  1891. spawn->SetSpawnOrigX(spawn->GetX());
  1892. spawn->SetSpawnOrigY(spawn->GetY());
  1893. spawn->SetSpawnOrigZ(spawn->GetZ());
  1894. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1895. if (spawn->IsPlayer()) {
  1896. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1897. if (client) {
  1898. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1899. client->QueuePacket(packet);
  1900. }
  1901. }
  1902. }
  1903. return 0;
  1904. }
  1905. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1906. if (!lua_interface)
  1907. return 0;
  1908. Spawn* spawn = lua_interface->GetSpawn(state);
  1909. float value = lua_interface->GetFloatValue(state, 2);
  1910. lua_interface->ResetFunctionStack(state);
  1911. if (spawn) {
  1912. spawn->SetHeading(value);
  1913. if (spawn->IsPlayer()) {
  1914. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1915. if (client) {
  1916. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1917. client->QueuePacket(packet);
  1918. }
  1919. }
  1920. }
  1921. return 0;
  1922. }
  1923. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1924. if (!lua_interface)
  1925. return 0;
  1926. Spawn* spawn = lua_interface->GetSpawn(state);
  1927. int16 value = lua_interface->GetInt16Value(state, 2);
  1928. lua_interface->ResetFunctionStack(state);
  1929. if (spawn)
  1930. spawn->SetModelType(value);
  1931. return 0;
  1932. }
  1933. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1934. if (!lua_interface)
  1935. return 0;
  1936. Spawn* spawn = lua_interface->GetSpawn(state);
  1937. int8 value = lua_interface->GetInt8Value(state, 2);
  1938. lua_interface->ResetFunctionStack(state);
  1939. if (spawn) {
  1940. if (spawn->IsPlayer())
  1941. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1942. else
  1943. spawn->SetAdventureClass(value);
  1944. }
  1945. return 0;
  1946. }
  1947. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1948. if (!lua_interface)
  1949. return 0;
  1950. Spawn* spawn = lua_interface->GetSpawn(state);
  1951. int8 value = lua_interface->GetInt8Value(state, 2);
  1952. lua_interface->ResetFunctionStack(state);
  1953. if (spawn) {
  1954. spawn->SetTradeskillClass(value);
  1955. if (spawn->IsEntity()) {
  1956. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1957. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1958. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1959. }
  1960. if (spawn->IsPlayer())
  1961. ((Player*)spawn)->SetCharSheetChanged(true);
  1962. }
  1963. return 0;
  1964. }
  1965. int EQ2Emu_lua_SetMount(lua_State* state) {
  1966. if (!lua_interface)
  1967. return 0;
  1968. Spawn* spawn = lua_interface->GetSpawn(state);
  1969. int16 value = lua_interface->GetInt16Value(state, 2);
  1970. if (spawn && spawn->IsEntity()) {
  1971. ((Entity*)spawn)->SetMount(value);
  1972. EQ2_Color color;
  1973. color.red = 255;
  1974. color.green = 255;
  1975. color.blue = 255;
  1976. ((Entity*)spawn)->SetMountColor(&color);
  1977. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1978. }
  1979. return 0;
  1980. }
  1981. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1982. if (!lua_interface)
  1983. return 0;
  1984. Spawn* spawn = lua_interface->GetSpawn(state);
  1985. EQ2_Color mount_color;
  1986. EQ2_Color saddle_color;
  1987. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1988. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1989. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1990. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1991. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1992. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1993. if (spawn && spawn->IsEntity()) {
  1994. ((Entity*)spawn)->SetMountColor(&mount_color);
  1995. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1996. }
  1997. return 0;
  1998. }
  1999. int EQ2Emu_lua_GetMount(lua_State* state) {
  2000. if (!lua_interface)
  2001. return 0;
  2002. Spawn* spawn = lua_interface->GetSpawn(state);
  2003. if (spawn && spawn->IsEntity()) {
  2004. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2005. return 1;
  2006. }
  2007. return 0;
  2008. }
  2009. int EQ2Emu_lua_GetRace(lua_State* state) {
  2010. if (!lua_interface)
  2011. return 0;
  2012. Spawn* spawn = lua_interface->GetSpawn(state);
  2013. if (spawn)
  2014. {
  2015. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2016. lua_interface->SetInt32Value(state, spawn->GetRace());
  2017. return 1;
  2018. }
  2019. return 0;
  2020. }
  2021. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2022. if (!lua_interface)
  2023. return 0;
  2024. Spawn* spawn = lua_interface->GetSpawn(state);
  2025. if (spawn) {
  2026. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2027. return 1;
  2028. }
  2029. return 0;
  2030. }
  2031. int EQ2Emu_lua_GetClass(lua_State* state) {
  2032. Spawn* spawn = lua_interface->GetSpawn(state);
  2033. if (spawn) {
  2034. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2035. return 1;
  2036. }
  2037. return 0;
  2038. }
  2039. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2040. Spawn* spawn = lua_interface->GetSpawn(state);
  2041. if (spawn) {
  2042. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2043. return 1;
  2044. }
  2045. return 0;
  2046. }
  2047. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2048. if (!lua_interface)
  2049. return 0;
  2050. Spawn* spawn = lua_interface->GetSpawn(state);
  2051. float value = lua_interface->GetFloatValue(state, 2);
  2052. lua_interface->ResetFunctionStack(state);
  2053. if (spawn) {
  2054. spawn->SetSpeed(value);
  2055. if(spawn->IsEntity())
  2056. ((Entity*)spawn)->SetSpeed(value);
  2057. if (spawn->IsPlayer()) {
  2058. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2059. if (client) {
  2060. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2061. if (packet) {
  2062. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2063. packet->setDataByName("speed", value);
  2064. packet->setDataByName("size", 0.51);
  2065. EQ2Packet* app = packet->serialize();
  2066. client->QueuePacket(app);
  2067. safe_delete(packet);
  2068. }
  2069. }
  2070. }
  2071. }
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. const int16 type = lua_interface->GetInt16Value(state, 2);
  2079. const float value = lua_interface->GetFloatValue(state, 3);
  2080. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2081. if(!luaspell || luaspell->resisted) {
  2082. return 0;
  2083. }
  2084. int64 class_req = 0;
  2085. int32 class_id = 0;
  2086. vector<int16> faction_req;
  2087. vector<int16> race_req;
  2088. int32 i = 0;
  2089. int8 f = 0;
  2090. int8 r = 0;
  2091. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2092. if (class_id < 100) {
  2093. class_req += pow(2.0, double(class_id - 1));
  2094. }
  2095. else if (class_id > 100 && class_id < 1000) {
  2096. race_req.push_back(class_id);
  2097. r++;
  2098. }
  2099. else {
  2100. faction_req.push_back(class_id);
  2101. f++;
  2102. }
  2103. i++;
  2104. }
  2105. if (value != 0 && type >= 0) {
  2106. if (luaspell && luaspell->spell && luaspell->caster) {
  2107. ZoneServer* zone = luaspell->caster->GetZone();
  2108. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2109. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2110. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2111. if (target) {
  2112. if (target->IsPlayer()) {
  2113. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2114. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2115. if (((Player*)target)->GetGroupMemberInfo())
  2116. ((Player*)target)->UpdateGroupMemberInfo();
  2117. ((Player*)target)->SetCharSheetChanged(true);
  2118. }
  2119. else if (target->IsNPC())
  2120. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2121. else
  2122. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2123. }
  2124. }
  2125. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2126. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2127. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2128. }
  2129. else if (spawn && spawn->IsEntity()) {
  2130. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2131. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2132. if (spawn->IsPlayer())
  2133. ((Player*)spawn)->SetCharSheetChanged(true);
  2134. }
  2135. else
  2136. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2137. }
  2138. else
  2139. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2140. return 0;
  2141. }
  2142. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2143. if (!lua_interface)
  2144. return 0;
  2145. Spawn* spawn = lua_interface->GetSpawn(state);
  2146. int16 type = lua_interface->GetInt16Value(state, 2);
  2147. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2148. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2149. if (!spawn) {
  2150. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2151. return 0;
  2152. }
  2153. if (!spawn->IsEntity()) {
  2154. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2155. return 0;
  2156. }
  2157. if (value == 0) {
  2158. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2159. return 0;
  2160. }
  2161. if (!luaspell || !luaspell->spell) {
  2162. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2163. return 0;
  2164. }
  2165. if(luaspell->resisted) {
  2166. return 0;
  2167. }
  2168. int32 class_req = 0;
  2169. vector<int16> faction_req;
  2170. vector<int16> race_req;
  2171. int32 class_id = 0;
  2172. int32 i = 0;
  2173. int8 f = 0;
  2174. int8 r = 0;
  2175. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2176. if (class_id < 100) {
  2177. class_req += pow(2.0, double(class_id - 1));
  2178. }
  2179. else if (class_id > 100 && class_id < 1000) {
  2180. race_req.push_back(class_id);
  2181. r++;
  2182. }
  2183. else {
  2184. faction_req.push_back(class_id);
  2185. f++;
  2186. }
  2187. i++;
  2188. }
  2189. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2190. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2191. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2192. if (spawn->IsPlayer())
  2193. ((Player*)spawn)->SetCharSheetChanged(true);
  2194. return 0;
  2195. }
  2196. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2197. if (!lua_interface)
  2198. return 0;
  2199. Spawn* spawn = lua_interface->GetSpawn(state);
  2200. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2201. if (!spawn) {
  2202. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2203. return 0;
  2204. }
  2205. if (!spawn->IsEntity()) {
  2206. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2207. return 0;
  2208. }
  2209. if (!luaspell || !luaspell->spell) {
  2210. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2211. return 0;
  2212. }
  2213. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2214. if (spawn->IsPlayer())
  2215. ((Player*)spawn)->SetCharSheetChanged(true);
  2216. return 0;
  2217. }
  2218. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2219. if (!lua_interface)
  2220. return 0;
  2221. Spawn* spawn = lua_interface->GetSpawn(state);
  2222. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2223. if (luaspell && luaspell->spell) {
  2224. ZoneServer* zone = luaspell->caster->GetZone();
  2225. Spawn* target = 0;
  2226. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2227. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2228. target = zone->GetSpawnByID(luaspell->targets[i]);
  2229. if (target && target->IsEntity()) {
  2230. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2231. if (target->IsPlayer())
  2232. ((Player*)target)->SetCharSheetChanged(true);
  2233. }
  2234. }
  2235. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2236. }
  2237. else if (spawn && spawn->IsEntity()) {
  2238. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2239. if (spawn->IsPlayer())
  2240. ((Player*)spawn)->SetCharSheetChanged(true);
  2241. }
  2242. return 0;
  2243. }
  2244. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2245. if (!lua_interface)
  2246. return 0;
  2247. Spawn* spawn = lua_interface->GetSpawn(state);
  2248. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2249. float value = lua_interface->GetFloatValue(state, 3);
  2250. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2251. if (value != 0) {
  2252. int32 spell_id = 0;
  2253. if (luaspell && luaspell->spell && luaspell->caster) {
  2254. if(luaspell->resisted) {
  2255. return 0;
  2256. }
  2257. spell_id = luaspell->spell->GetSpellID();
  2258. ZoneServer* zone = luaspell->caster->GetZone();
  2259. Spawn* target = 0;
  2260. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2261. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2262. target = zone->GetSpawnByID(luaspell->targets[i]);
  2263. if (target && target->Alive()) {
  2264. if (target->IsPlayer()) {
  2265. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2266. Client* client = target->GetZone()->GetClientBySpawn(target);
  2267. if (client) {
  2268. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2269. if (packet)
  2270. client->QueuePacket(packet);
  2271. }
  2272. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2273. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2274. }
  2275. else if (target->IsNPC()) {
  2276. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2277. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2278. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2279. }
  2280. else
  2281. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2282. }
  2283. }
  2284. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2285. }
  2286. else if (spawn) {
  2287. if (spawn->IsPlayer()) {
  2288. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2289. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2290. if (client) {
  2291. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2292. if (packet)
  2293. client->QueuePacket(packet);
  2294. }
  2295. }
  2296. else if (spawn->IsNPC())
  2297. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2298. else
  2299. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2300. }
  2301. }
  2302. else
  2303. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2304. return 0;
  2305. }
  2306. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2307. if (!lua_interface)
  2308. return 0;
  2309. Spawn* spawn = lua_interface->GetSpawn(state);
  2310. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2311. if (spawn && spawn->IsPlayer()) {
  2312. int32 spell_id = 0;
  2313. if (luaspell && luaspell->spell) {
  2314. if(luaspell->resisted) {
  2315. return 0;
  2316. }
  2317. spell_id = luaspell->spell->GetSpellID();
  2318. ZoneServer* zone = luaspell->caster->GetZone();
  2319. Spawn* target = 0;
  2320. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2321. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2322. target = zone->GetSpawnByID(luaspell->targets[i]);
  2323. if (target) {
  2324. if (target->IsPlayer()) {
  2325. ((Player*)target)->RemoveSkillBonus(spell_id);
  2326. Client* client = target->GetZone()->GetClientBySpawn(target);
  2327. if (client) {
  2328. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2329. if (packet)
  2330. client->QueuePacket(packet);
  2331. }
  2332. }
  2333. else if (target->IsNPC())
  2334. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2335. else
  2336. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2337. }
  2338. }
  2339. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2340. }
  2341. else if (spawn) {
  2342. if (spawn->IsPlayer()) {
  2343. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2344. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2345. if (client) {
  2346. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2347. if (packet)
  2348. client->QueuePacket(packet);
  2349. }
  2350. }
  2351. else if (spawn->IsNPC())
  2352. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2353. else
  2354. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2355. }
  2356. }
  2357. return 0;
  2358. }
  2359. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2360. if (!lua_interface)
  2361. return 0;
  2362. Spawn* spawn = lua_interface->GetSpawn(state);
  2363. int8 type = lua_interface->GetInt32Value(state, 2);
  2364. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2365. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2366. if(luaspell && luaspell->resisted) {
  2367. return 0;
  2368. }
  2369. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2370. ZoneServer* zone = luaspell->caster->GetZone();
  2371. Spawn* target = 0;
  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. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2377. ((Entity*)target)->AddMezSpell(luaspell);
  2378. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2379. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2380. if (target->IsNPC())
  2381. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2382. }
  2383. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2384. ((Entity*)target)->AddStifleSpell(luaspell);
  2385. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2386. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2387. if (target->IsNPC())
  2388. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2389. }
  2390. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2391. ((Entity*)target)->AddDazeSpell(luaspell);
  2392. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2393. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2394. if (target->IsNPC())
  2395. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2396. }
  2397. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2398. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2399. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2400. ((Entity*)target)->AddStunSpell(luaspell);
  2401. if (target->IsNPC())
  2402. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2403. }
  2404. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2405. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2406. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2407. ((Entity*)target)->AddRootSpell(luaspell);
  2408. if (target->IsNPC())
  2409. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2410. }
  2411. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2412. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2413. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2414. ((Entity*)target)->AddFearSpell(luaspell);
  2415. if (target->IsNPC())
  2416. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2417. }
  2418. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2419. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2420. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2421. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2422. }
  2423. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2424. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2425. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2426. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2427. }
  2428. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2429. ((Entity*)target)->AddSnareSpell(luaspell);
  2430. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2431. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2432. if (target->IsNPC())
  2433. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2434. }
  2435. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2436. ((Entity*)target)->AddFlightSpell(luaspell);
  2437. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2438. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2439. }
  2440. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2441. ((Entity*)target)->AddGlideSpell(luaspell);
  2442. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2443. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2444. }
  2445. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2446. ((Entity*)target)->AddSafefallSpell(luaspell);
  2447. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2448. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2449. }
  2450. else
  2451. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2452. }
  2453. else
  2454. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2455. }
  2456. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2457. }
  2458. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2459. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2460. ((Entity*)spawn)->AddMezSpell(luaspell);
  2461. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2462. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2463. }
  2464. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2465. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2466. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2467. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2468. }
  2469. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2470. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2471. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2472. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2473. }
  2474. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2475. ((Entity*)spawn)->AddStunSpell(luaspell);
  2476. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2477. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2478. }
  2479. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2480. ((Entity*)spawn)->AddRootSpell(luaspell);
  2481. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2482. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2483. }
  2484. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2485. ((Entity*)spawn)->AddFearSpell(luaspell);
  2486. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2487. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2488. }
  2489. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2490. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2491. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2492. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2493. }
  2494. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2495. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2496. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2497. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2498. }
  2499. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2500. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2501. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2502. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2503. }
  2504. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2505. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2506. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2507. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2508. }
  2509. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2510. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2511. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2512. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2513. }
  2514. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2515. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2516. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2517. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2518. }
  2519. else
  2520. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2521. }
  2522. else
  2523. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2524. return 0;
  2525. }
  2526. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2527. if (!lua_interface)
  2528. return 0;
  2529. Spawn* spawn = lua_interface->GetSpawn(state);
  2530. int8 type = lua_interface->GetInt8Value(state, 2);
  2531. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2532. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2533. if (spawn && spawn->IsEntity()) {
  2534. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2535. ZoneServer* zone = luaspell->caster->GetZone();
  2536. Spawn* target = 0;
  2537. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2538. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2539. target = zone->GetSpawnByID(luaspell->targets[i]);
  2540. if (target) {
  2541. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2542. ((Entity*)target)->RemoveMezSpell(luaspell);
  2543. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2544. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2545. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2546. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2547. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2548. ((Entity*)target)->RemoveStunSpell(luaspell);
  2549. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2550. ((Entity*)target)->RemoveRootSpell(luaspell);
  2551. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2552. ((Entity*)target)->RemoveFearSpell(luaspell);
  2553. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2554. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2555. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2556. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2557. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2558. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2559. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2560. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2561. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2562. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2563. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2564. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2565. else
  2566. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2567. }
  2568. }
  2569. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2570. }
  2571. else if (only_remove_spawn) {
  2572. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2573. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2574. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2575. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2576. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2577. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2579. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2581. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2583. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2585. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2587. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2588. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2589. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2590. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2591. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2592. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2593. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2594. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2595. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2596. else
  2597. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2598. }
  2599. }
  2600. return 0;
  2601. }
  2602. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2603. if (!lua_interface)
  2604. return 0;
  2605. Spawn* spawn = lua_interface->GetSpawn(state);
  2606. int8 type = lua_interface->GetInt8Value(state, 2);
  2607. bool hasEffect = false;
  2608. if (!spawn)
  2609. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2610. else if (!spawn->IsEntity())
  2611. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2612. else if (type < CONTROL_MAX_EFFECTS)
  2613. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2614. else
  2615. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2616. lua_interface->SetBooleanValue(state, hasEffect);
  2617. return 1;
  2618. }
  2619. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2620. if (!lua_interface)
  2621. return 0;
  2622. Spawn* spawn = lua_interface->GetSpawn(state);
  2623. float distance = 0.0f;
  2624. if (!spawn)
  2625. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2626. else if (!spawn->IsNPC())
  2627. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2628. else
  2629. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2630. lua_interface->SetFloatValue(state, distance);
  2631. return 1;
  2632. }
  2633. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2634. if (!lua_interface)
  2635. return 0;
  2636. Spawn* spawn = lua_interface->GetSpawn(state);
  2637. float distance = 0.0f;
  2638. if (!spawn)
  2639. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2640. else if (!spawn->IsNPC())
  2641. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2642. else
  2643. distance = ((NPC*)spawn)->GetAggroRadius();
  2644. lua_interface->SetFloatValue(state, distance);
  2645. return 1;
  2646. }
  2647. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2648. if (!lua_interface)
  2649. return 0;
  2650. Spawn* spawn = lua_interface->GetSpawn(state);
  2651. float distance = lua_interface->GetFloatValue(state, 2);
  2652. bool override = lua_interface->GetBooleanValue(state, 3);
  2653. bool result = false;
  2654. lua_interface->ResetFunctionStack(state);
  2655. if (!spawn)
  2656. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2657. else if (!spawn->IsNPC())
  2658. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2659. else
  2660. {
  2661. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2662. result = true;
  2663. }
  2664. lua_interface->SetBooleanValue(state, result);
  2665. return 1;
  2666. }
  2667. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2668. if (!lua_interface)
  2669. return 0;
  2670. Spawn* spawn = lua_interface->GetSpawn(state);
  2671. int16 value = lua_interface->GetInt16Value(state, 2);
  2672. if (spawn && spawn->IsEntity()) {
  2673. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2674. if (spawn->IsPlayer())
  2675. ((Player*)spawn)->SetCharSheetChanged(true);
  2676. }
  2677. return 0;
  2678. }
  2679. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2680. if (!lua_interface)
  2681. return 0;
  2682. Spawn* spawn = lua_interface->GetSpawn(state);
  2683. int16 value = lua_interface->GetInt16Value(state, 2);
  2684. if (spawn && spawn->IsEntity()) {
  2685. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2686. if (spawn->IsPlayer())
  2687. ((Player*)spawn)->SetCharSheetChanged(true);
  2688. }
  2689. return 0;
  2690. }
  2691. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2692. if (!lua_interface)
  2693. return 0;
  2694. Spawn* spawn = lua_interface->GetSpawn(state);
  2695. int16 value = lua_interface->GetInt16Value(state, 2);
  2696. if (spawn && spawn->IsEntity()) {
  2697. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2698. if (spawn->IsPlayer())
  2699. ((Player*)spawn)->SetCharSheetChanged(true);
  2700. }
  2701. return 0;
  2702. }
  2703. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2704. if (!lua_interface)
  2705. return 0;
  2706. Spawn* spawn = lua_interface->GetSpawn(state);
  2707. int16 value = lua_interface->GetInt16Value(state, 2);
  2708. if (spawn && spawn->IsEntity()) {
  2709. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2710. if (spawn->IsPlayer())
  2711. ((Player*)spawn)->SetCharSheetChanged(true);
  2712. }
  2713. return 0;
  2714. }
  2715. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2716. if (!lua_interface)
  2717. return 0;
  2718. Spawn* spawn = lua_interface->GetSpawn(state);
  2719. int16 value = lua_interface->GetInt16Value(state, 2);
  2720. if (spawn && spawn->IsEntity()) {
  2721. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2722. if (spawn->IsPlayer())
  2723. ((Player*)spawn)->SetCharSheetChanged(true);
  2724. }
  2725. return 0;
  2726. }
  2727. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2728. if (!lua_interface)
  2729. return 0;
  2730. Spawn* spawn = lua_interface->GetSpawn(state);
  2731. int8 value = lua_interface->GetInt8Value(state, 2);
  2732. if (spawn && spawn->IsEntity()) {
  2733. ((Entity*)spawn)->SetDeity(value);
  2734. if (spawn->IsPlayer())
  2735. ((Player*)spawn)->SetCharSheetChanged(true);
  2736. }
  2737. lua_interface->ResetFunctionStack(state);
  2738. return 0;
  2739. }
  2740. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2741. if (!lua_interface)
  2742. return 0;
  2743. Spawn* spawn = lua_interface->GetSpawn(state);
  2744. if (spawn && spawn->IsEntity()) {
  2745. int8 deity = ((Entity*)spawn)->GetDeity();
  2746. lua_interface->SetInt32Value(state, deity);
  2747. return 1;
  2748. }
  2749. return 0;
  2750. }
  2751. int EQ2Emu_lua_SetInt(lua_State* state) {
  2752. if (!lua_interface)
  2753. return 0;
  2754. Spawn* spawn = lua_interface->GetSpawn(state);
  2755. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2756. if (spawn && spawn->IsEntity()) {
  2757. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2758. if (spawn->IsPlayer())
  2759. ((Player*)spawn)->SetCharSheetChanged(true);
  2760. }
  2761. return 0;
  2762. }
  2763. int EQ2Emu_lua_SetWis(lua_State* state) {
  2764. if (!lua_interface)
  2765. return 0;
  2766. Spawn* spawn = lua_interface->GetSpawn(state);
  2767. float value = lua_interface->GetFloatValue(state, 2);
  2768. if (spawn && spawn->IsEntity()) {
  2769. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2770. if (spawn->IsPlayer())
  2771. ((Player*)spawn)->SetCharSheetChanged(true);
  2772. }
  2773. return 0;
  2774. }
  2775. int EQ2Emu_lua_SetSta(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. float value = lua_interface->GetFloatValue(state, 2);
  2780. if (spawn && spawn->IsEntity()) {
  2781. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2782. if (spawn->IsPlayer())
  2783. ((Player*)spawn)->SetCharSheetChanged(true);
  2784. }
  2785. return 0;
  2786. }
  2787. int EQ2Emu_lua_SetStr(lua_State* state) {
  2788. if (!lua_interface)
  2789. return 0;
  2790. Spawn* spawn = lua_interface->GetSpawn(state);
  2791. float value = lua_interface->GetFloatValue(state, 2);
  2792. if (spawn && spawn->IsEntity()) {
  2793. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2794. if (spawn->IsPlayer())
  2795. ((Player*)spawn)->SetCharSheetChanged(true);
  2796. }
  2797. return 0;
  2798. }
  2799. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. Spawn* spawn = lua_interface->GetSpawn(state);
  2803. float value = lua_interface->GetFloatValue(state, 2);
  2804. if (spawn && spawn->IsEntity()) {
  2805. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2806. if (spawn->IsPlayer())
  2807. ((Player*)spawn)->SetCharSheetChanged(true);
  2808. }
  2809. return 0;
  2810. }
  2811. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2812. if (!lua_interface)
  2813. return 0;
  2814. Spawn* spawn = lua_interface->GetSpawn(state);
  2815. if (spawn) {
  2816. lua_interface->SetInt32Value(state, spawn->GetHP());
  2817. return 1;
  2818. }
  2819. return 0;
  2820. }
  2821. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2822. if (!lua_interface)
  2823. return 0;
  2824. Spawn* spawn = lua_interface->GetSpawn(state);
  2825. if (spawn) {
  2826. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2827. return 1;
  2828. }
  2829. return 0;
  2830. }
  2831. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2832. if (!lua_interface)
  2833. return 0;
  2834. Spawn* spawn = lua_interface->GetSpawn(state);
  2835. if (spawn) {
  2836. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2837. return 1;
  2838. }
  2839. return 0;
  2840. }
  2841. int EQ2Emu_lua_GetName(lua_State* state) {
  2842. if (!lua_interface)
  2843. return 0;
  2844. Spawn* spawn = lua_interface->GetSpawn(state);
  2845. if (spawn) {
  2846. lua_interface->SetStringValue(state, spawn->GetName());
  2847. return 1;
  2848. }
  2849. return 0;
  2850. }
  2851. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2852. Spawn* spawn = lua_interface->GetSpawn(state);
  2853. if (spawn) {
  2854. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2855. return 1;
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. if (spawn) {
  2864. lua_interface->SetInt32Value(state, spawn->GetPower());
  2865. return 1;
  2866. }
  2867. return 0;
  2868. }
  2869. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2870. if (!lua_interface)
  2871. return 0;
  2872. Spawn* spawn = lua_interface->GetSpawn(state);
  2873. if (spawn) {
  2874. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2875. return 1;
  2876. }
  2877. return 0;
  2878. }
  2879. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2880. if (!lua_interface)
  2881. return 0;
  2882. Spawn* spawn = lua_interface->GetSpawn(state);
  2883. if (spawn) {
  2884. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2885. return 1;
  2886. }
  2887. return 0;
  2888. }
  2889. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2890. if (!lua_interface)
  2891. return 0;
  2892. Spawn* spawn = lua_interface->GetSpawn(state);
  2893. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2894. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2895. if (spawn && spawn2) {
  2896. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2897. lua_interface->SetFloatValue(state, distance);
  2898. return 1;
  2899. }
  2900. return 0;
  2901. }
  2902. int EQ2Emu_lua_GetX(lua_State* state) {
  2903. if (!lua_interface)
  2904. return 0;
  2905. Spawn* spawn = lua_interface->GetSpawn(state);
  2906. if (spawn) {
  2907. lua_interface->SetFloatValue(state, spawn->GetX());
  2908. return 1;
  2909. }
  2910. return 0;
  2911. }
  2912. int EQ2Emu_lua_GetY(lua_State* state) {
  2913. if (!lua_interface)
  2914. return 0;
  2915. Spawn* spawn = lua_interface->GetSpawn(state);
  2916. if (spawn) {
  2917. lua_interface->SetFloatValue(state, spawn->GetY());
  2918. return 1;
  2919. }
  2920. return 0;
  2921. }
  2922. int EQ2Emu_lua_GetZ(lua_State* state) {
  2923. if (!lua_interface)
  2924. return 0;
  2925. Spawn* spawn = lua_interface->GetSpawn(state);
  2926. if (spawn) {
  2927. lua_interface->SetFloatValue(state, spawn->GetZ());
  2928. return 1;
  2929. }
  2930. return 0;
  2931. }
  2932. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2933. if (!lua_interface)
  2934. return 0;
  2935. Spawn* spawn = lua_interface->GetSpawn(state);
  2936. if (spawn) {
  2937. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2938. return 1;
  2939. }
  2940. return 0;
  2941. }
  2942. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2943. if (!lua_interface)
  2944. return 0;
  2945. Spawn* spawn = lua_interface->GetSpawn(state);
  2946. if (spawn) {
  2947. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2948. return 1;
  2949. }
  2950. return 0;
  2951. }
  2952. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2953. if (!lua_interface)
  2954. return 0;
  2955. Spawn* spawn = lua_interface->GetSpawn(state);
  2956. if (spawn) {
  2957. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2958. return 1;
  2959. }
  2960. return 0;
  2961. }
  2962. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2963. if (!lua_interface)
  2964. return 0;
  2965. Spawn* spawn = lua_interface->GetSpawn(state);
  2966. if (spawn && spawn->IsEntity()) {
  2967. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2968. return 1;
  2969. }
  2970. return 0;
  2971. }
  2972. int EQ2Emu_lua_GetInt(lua_State* state) {
  2973. if (!lua_interface)
  2974. return 0;
  2975. Spawn* spawn = lua_interface->GetSpawn(state);
  2976. if (spawn && spawn->IsEntity()) {
  2977. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetWis(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* spawn = lua_interface->GetSpawn(state);
  2986. if (spawn && spawn->IsEntity()) {
  2987. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2988. return 1;
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_GetSta(lua_State* state) {
  2993. if (!lua_interface)
  2994. return 0;
  2995. Spawn* spawn = lua_interface->GetSpawn(state);
  2996. if (spawn && spawn->IsEntity()) {
  2997. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2998. return 1;
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_GetStr(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Spawn* spawn = lua_interface->GetSpawn(state);
  3006. if (spawn && spawn->IsEntity()) {
  3007. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3008. return 1;
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3013. if (!lua_interface)
  3014. return 0;
  3015. Spawn* spawn = lua_interface->GetSpawn(state);
  3016. if (spawn && spawn->IsEntity()) {
  3017. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3018. return 1;
  3019. }
  3020. return 0;
  3021. }
  3022. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3023. if (!lua_interface)
  3024. return 0;
  3025. Spawn* spawn = lua_interface->GetSpawn(state);
  3026. if (spawn && spawn->IsEntity()) {
  3027. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3028. return 1;
  3029. }
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Spawn* spawn = lua_interface->GetSpawn(state);
  3036. if (spawn && spawn->IsEntity()) {
  3037. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3038. return 1;
  3039. }
  3040. return 0;
  3041. }
  3042. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3043. if (!lua_interface)
  3044. return 0;
  3045. Spawn* spawn = lua_interface->GetSpawn(state);
  3046. if (spawn && spawn->IsEntity()) {
  3047. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3048. return 1;
  3049. }
  3050. return 0;
  3051. }
  3052. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3053. if (!lua_interface)
  3054. return 0;
  3055. Spawn* spawn = lua_interface->GetSpawn(state);
  3056. if (spawn && spawn->IsEntity()) {
  3057. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3058. return 1;
  3059. }
  3060. return 0;
  3061. }
  3062. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3063. if (!lua_interface)
  3064. return 0;
  3065. Spawn* spawn = lua_interface->GetSpawn(state);
  3066. if (spawn && spawn->IsEntity()) {
  3067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3068. return 1;
  3069. }
  3070. return 0;
  3071. }
  3072. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3073. if (!lua_interface)
  3074. return 0;
  3075. Spawn* player = lua_interface->GetSpawn(state);
  3076. if (!player || !player->IsPlayer()) {
  3077. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3078. return 0;
  3079. }
  3080. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3081. if (quest_id <= 0) {
  3082. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3083. return 0;
  3084. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3085. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3086. return 0;
  3087. }
  3088. int32 step = lua_interface->GetInt32Value(state, 3);
  3089. if (step > 0) {
  3090. Client* client = player->GetZone()->GetClientBySpawn(player);
  3091. if (client)
  3092. client->AddPendingQuestUpdate(quest_id, step);
  3093. } else {
  3094. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3095. }
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3099. Spawn* player = lua_interface->GetSpawn(state);
  3100. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3101. int32 step = lua_interface->GetInt32Value(state, 3);
  3102. int32 progress = lua_interface->GetInt32Value(state, 4);
  3103. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3104. Client* client = player->GetZone()->GetClientBySpawn(player);
  3105. if (client)
  3106. client->AddPendingQuestUpdate(quest_id, step, progress);
  3107. }
  3108. return 0;
  3109. }
  3110. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3111. if (!lua_interface)
  3112. return 0;
  3113. Spawn* player = lua_interface->GetSpawn(state);
  3114. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3115. if (player && player->IsPlayer() && quest_id > 0) {
  3116. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3117. return 1;
  3118. }
  3119. return 0;
  3120. }
  3121. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3122. if (!lua_interface)
  3123. return 0;
  3124. Spawn* player = lua_interface->GetSpawn(state);
  3125. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3126. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3127. if (player && player->IsPlayer() && quest_id > 0) {
  3128. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3129. return 1;
  3130. }
  3131. return 0;
  3132. }
  3133. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3134. if (!lua_interface)
  3135. return 0;
  3136. Spawn* player = lua_interface->GetSpawn(state);
  3137. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3138. if (player && player->IsPlayer() && quest_id > 0) {
  3139. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3140. return 1;
  3141. }
  3142. return 0;
  3143. }
  3144. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3145. if (!lua_interface)
  3146. return 0;
  3147. Quest* quest = lua_interface->GetQuest(state);
  3148. string name = lua_interface->GetStringValue(state, 2);
  3149. string type = lua_interface->GetStringValue(state, 3);
  3150. string zone = lua_interface->GetStringValue(state, 4);
  3151. int16 level = lua_interface->GetInt16Value(state, 5);
  3152. string description = lua_interface->GetStringValue(state, 6);
  3153. bool load = true;
  3154. if (!quest) {
  3155. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3156. load = false;
  3157. }
  3158. if (load && name.length() == 0) {
  3159. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3160. load = false;
  3161. }
  3162. if (load && type.length() == 0) {
  3163. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3164. load = false;
  3165. }
  3166. if (load && zone.length() == 0) {
  3167. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3168. load = false;
  3169. }
  3170. if (load && description.length() == 0) {
  3171. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3172. load = false;
  3173. }
  3174. if (load && level == 0) {
  3175. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3176. load = false;
  3177. }
  3178. if (load)
  3179. quest->RegisterQuest(name, type, zone, level, description);
  3180. return 0;
  3181. }
  3182. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3183. if (!lua_interface)
  3184. return 0;
  3185. Quest* quest = lua_interface->GetQuest(state);
  3186. if (quest) {
  3187. int8 level = lua_interface->GetInt16Value(state, 2);
  3188. quest->SetPrereqLevel(level);
  3189. }
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Quest* quest = lua_interface->GetQuest(state);
  3196. if (quest) {
  3197. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3198. quest->AddPrereqQuest(quest_id);
  3199. }
  3200. return 0;
  3201. }
  3202. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3203. if (!lua_interface)
  3204. return 0;
  3205. Quest* quest = lua_interface->GetQuest(state);
  3206. if (quest) {
  3207. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3208. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3209. if (quantity == 0)
  3210. quantity = 1;
  3211. Item* master_item = master_item_list.GetItem(item_id);
  3212. if (master_item) {
  3213. Item* item = new Item(master_item);
  3214. item->details.count = quantity;
  3215. quest->AddPrereqItem(item);
  3216. }
  3217. }
  3218. return 0;
  3219. }
  3220. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3221. if (!lua_interface)
  3222. return 0;
  3223. Spawn* player = lua_interface->GetSpawn(state);
  3224. if(!player || !player->IsPlayer()) {
  3225. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3226. return 0;
  3227. }
  3228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3229. if (quest_id > 0) {
  3230. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3231. return 1;
  3232. } else {
  3233. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3234. }
  3235. return 0;
  3236. }
  3237. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3238. if (!lua_interface)
  3239. return 0;
  3240. Quest* quest = lua_interface->GetQuest(state);
  3241. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3242. lua_interface->ResetFunctionStack(state);
  3243. if (quest && spawn_id > 0)
  3244. quest->SetQuestReturnNPC(spawn_id);
  3245. return 0;
  3246. }
  3247. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3248. if (!lua_interface)
  3249. return 0;
  3250. Spawn* spawn = lua_interface->GetSpawn(state);
  3251. int32 time = lua_interface->GetInt32Value(state, 2);
  3252. string function = lua_interface->GetStringValue(state, 3);
  3253. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3254. Spawn* player = lua_interface->GetSpawn(state, 5);
  3255. lua_interface->ResetFunctionStack(state);
  3256. if (!spawn) {
  3257. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3258. return 0;
  3259. }
  3260. if (time <= 0) {
  3261. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3262. return 0;
  3263. }
  3264. if (function.length() == 0) {
  3265. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3266. return 0;
  3267. }
  3268. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3269. if ( time < 10)
  3270. time = 10;
  3271. timer->timer = Timer::GetCurrentTime2() + time;
  3272. timer->function = function;
  3273. timer->spawn = spawn->GetID();
  3274. timer->player = player ? player->GetID() : 0;
  3275. if (max_count == 0)
  3276. max_count = 1;
  3277. timer->max_count = max_count;
  3278. timer->current_count = 0;
  3279. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3280. return 0;
  3281. }
  3282. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3283. if (!lua_interface)
  3284. return 0;
  3285. Spawn* spawn = lua_interface->GetSpawn(state);
  3286. string function = lua_interface->GetStringValue(state, 2);
  3287. lua_interface->ResetFunctionStack(state);
  3288. if (!spawn) {
  3289. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3290. return 0;
  3291. }
  3292. if(!spawn->GetZone()) {
  3293. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3294. return 0;
  3295. }
  3296. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3297. return 0;
  3298. }
  3299. int EQ2Emu_lua_GetQuest(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. lua_interface->ResetFunctionStack(state);
  3305. if (player && player->IsPlayer() && quest_id > 0) {
  3306. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3307. return 1;
  3308. }
  3309. return 0;
  3310. }
  3311. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3312. if (!lua_interface)
  3313. return 0;
  3314. Spawn* player = lua_interface->GetSpawn(state);
  3315. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3316. lua_interface->ResetFunctionStack(state);
  3317. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3318. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3319. if (quest)
  3320. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3321. return 1;
  3322. }
  3323. return 0;
  3324. }
  3325. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3326. if (!lua_interface)
  3327. return 0;
  3328. Spawn* player = lua_interface->GetSpawn(state);
  3329. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3330. lua_interface->ResetFunctionStack(state);
  3331. if (player && player->IsPlayer() && quest_id > 0) {
  3332. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3333. return 1;
  3334. }
  3335. return 0;
  3336. }
  3337. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3338. if (!lua_interface)
  3339. return 0;
  3340. Spawn* npc = lua_interface->GetSpawn(state);
  3341. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3342. lua_interface->ResetFunctionStack(state);
  3343. if (npc && !npc->IsPlayer() && quest_id > 0)
  3344. npc->AddProvidedQuest(quest_id);
  3345. return 0;
  3346. }
  3347. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3348. if (!lua_interface)
  3349. return 0;
  3350. Spawn* npc = lua_interface->GetSpawn(state);
  3351. Spawn* player = lua_interface->GetSpawn(state, 2);
  3352. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3353. bool forced = lua_interface->GetBooleanValue(state, 4);
  3354. lua_interface->ResetFunctionStack(state);
  3355. /* NPC is allowed to be null */
  3356. if (player && player->IsPlayer() && quest_id > 0) {
  3357. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3358. if (master_quest) {
  3359. Client* client = player->GetZone()->GetClientBySpawn(player);
  3360. if (!client) {
  3361. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3362. }
  3363. Quest* quest = new Quest(master_quest);
  3364. if (!quest) {
  3365. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3366. }
  3367. if (client && quest) {
  3368. if (npc)
  3369. quest->SetQuestGiver(npc->GetDatabaseID());
  3370. else
  3371. quest->SetQuestGiver(0);
  3372. client->AddPendingQuest(quest, forced);
  3373. }
  3374. }
  3375. else {
  3376. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3377. }
  3378. }
  3379. else {
  3380. 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);
  3381. }
  3382. return 0;
  3383. }
  3384. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3385. if (!lua_interface)
  3386. return 0;
  3387. Quest* quest = lua_interface->GetQuest(state);
  3388. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3389. lua_interface->ResetFunctionStack(state);
  3390. if (quest) {
  3391. quest->AddPrereqClass(class_id);
  3392. }
  3393. return 0;
  3394. }
  3395. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3396. if (!lua_interface)
  3397. return 0;
  3398. Quest* quest = lua_interface->GetQuest(state);
  3399. int8 race = lua_interface->GetInt8Value(state, 2);
  3400. lua_interface->ResetFunctionStack(state);
  3401. if (quest) {
  3402. quest->AddPrereqRace(race);
  3403. }
  3404. return 0;
  3405. }
  3406. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3407. if (!lua_interface)
  3408. return 0;
  3409. Quest* quest = lua_interface->GetQuest(state);
  3410. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3411. lua_interface->ResetFunctionStack(state);
  3412. if (quest) {
  3413. quest->AddPrereqModelType(model_type);
  3414. }
  3415. return 0;
  3416. }
  3417. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3418. if (!lua_interface)
  3419. return 0;
  3420. Quest* quest = lua_interface->GetQuest(state);
  3421. int8 level = lua_interface->GetInt8Value(state, 2);
  3422. lua_interface->ResetFunctionStack(state);
  3423. if (!quest) {
  3424. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3425. return 0;
  3426. }
  3427. quest->SetPrereqTSLevel(level);
  3428. return 0;
  3429. }
  3430. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3431. if (!lua_interface)
  3432. return 0;
  3433. Quest* quest = lua_interface->GetQuest(state);
  3434. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3435. lua_interface->ResetFunctionStack(state);
  3436. if (!quest) {
  3437. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3438. return 0;
  3439. }
  3440. quest->AddPrereqTradeskillClass(class_id);
  3441. return 0;
  3442. }
  3443. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3444. if (!lua_interface)
  3445. return 0;
  3446. Quest* quest = lua_interface->GetQuest(state);
  3447. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3448. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3449. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3450. lua_interface->ResetFunctionStack(state);
  3451. if (quest) {
  3452. quest->AddPrereqFaction(faction_id, min, max);
  3453. }
  3454. return 0;
  3455. }
  3456. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3457. if (!lua_interface)
  3458. return 0;
  3459. Quest* quest = lua_interface->GetQuest(state);
  3460. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3461. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3462. lua_interface->ResetFunctionStack(state);
  3463. if (quest) {
  3464. if (quantity == 0)
  3465. quantity = 1;
  3466. Item* master_item = master_item_list.GetItem(item_id);
  3467. if (master_item) {
  3468. Item* item = new Item(master_item);
  3469. item->details.count = quantity;
  3470. quest->AddSelectableRewardItem(item);
  3471. }
  3472. }
  3473. return 0;
  3474. }
  3475. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3476. if (!lua_interface)
  3477. return 0;
  3478. Quest* quest = lua_interface->GetQuest(state);
  3479. if (quest) {
  3480. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3481. vector<Item*>* items = quest->GetRewardItems();
  3482. if (items) {
  3483. vector<Item*>::iterator itr;
  3484. for (itr = items->begin(); itr != items->end(); itr++) {
  3485. if (*itr && (*itr)->details.item_id == item_id) {
  3486. lua_interface->SetBooleanValue(state, true);
  3487. return 1;
  3488. }
  3489. }
  3490. }
  3491. }
  3492. lua_interface->SetBooleanValue(state, false);
  3493. return 1;
  3494. }
  3495. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3496. if (!lua_interface)
  3497. return 0;
  3498. Quest* quest = lua_interface->GetQuest(state);
  3499. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3500. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3501. lua_interface->ResetFunctionStack(state);
  3502. if (quest) {
  3503. if (quantity == 0)
  3504. quantity = 1;
  3505. Item* master_item = master_item_list.GetItem(item_id);
  3506. if (master_item) {
  3507. Item* item = new Item(master_item);
  3508. item->details.count = quantity;
  3509. quest->AddRewardItem(item);
  3510. }
  3511. }
  3512. return 0;
  3513. }
  3514. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3515. if (!lua_interface)
  3516. return 0;
  3517. Quest* quest = lua_interface->GetQuest(state);
  3518. int32 copper = lua_interface->GetInt32Value(state, 2);
  3519. int32 silver = lua_interface->GetInt32Value(state, 3);
  3520. int32 gold = lua_interface->GetInt32Value(state, 4);
  3521. int32 plat = lua_interface->GetInt32Value(state, 5);
  3522. lua_interface->ResetFunctionStack(state);
  3523. if (quest) {
  3524. quest->AddRewardCoins(copper, silver, gold, plat);
  3525. }
  3526. return 0;
  3527. }
  3528. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3529. if (!lua_interface)
  3530. return 0;
  3531. Quest* quest = lua_interface->GetQuest(state);
  3532. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3533. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3534. lua_interface->ResetFunctionStack(state);
  3535. if (quest && faction_id > 0 && amount != 0)
  3536. quest->AddRewardFaction(faction_id, amount);
  3537. return 0;
  3538. }
  3539. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3540. if (!lua_interface)
  3541. return 0;
  3542. Quest* quest = lua_interface->GetQuest(state);
  3543. int32 status = lua_interface->GetInt32Value(state, 2);
  3544. lua_interface->ResetFunctionStack(state);
  3545. if (quest) {
  3546. quest->SetRewardStatus(status);
  3547. }
  3548. return 0;
  3549. }
  3550. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3551. if (!lua_interface)
  3552. return 0;
  3553. Quest* quest = lua_interface->GetQuest(state);
  3554. int32 status = lua_interface->GetInt32Value(state, 2);
  3555. lua_interface->ResetFunctionStack(state);
  3556. if (quest) {
  3557. quest->SetStatusTmpReward(status);
  3558. }
  3559. return 0;
  3560. }
  3561. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3562. if (!lua_interface)
  3563. return 0;
  3564. Quest* quest = lua_interface->GetQuest(state);
  3565. int64 coins = lua_interface->GetInt64Value(state, 2);
  3566. lua_interface->ResetFunctionStack(state);
  3567. if (quest) {
  3568. quest->SetCoinTmpReward(coins);
  3569. }
  3570. return 0;
  3571. }
  3572. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3573. if (!lua_interface)
  3574. return 0;
  3575. Quest* quest = lua_interface->GetQuest(state);
  3576. string comment = lua_interface->GetStringValue(state, 2);
  3577. lua_interface->ResetFunctionStack(state);
  3578. if (quest) {
  3579. quest->SetRewardComment(comment);
  3580. }
  3581. return 0;
  3582. }
  3583. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3584. if (!lua_interface)
  3585. return 0;
  3586. Quest* quest = lua_interface->GetQuest(state);
  3587. int32 exp = lua_interface->GetInt32Value(state, 2);
  3588. lua_interface->ResetFunctionStack(state);
  3589. if (quest) {
  3590. quest->SetRewardXP(exp);
  3591. }
  3592. return 0;
  3593. }
  3594. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3595. Quest* quest = lua_interface->GetQuest(state);
  3596. int32 step = lua_interface->GetInt32Value(state, 2);
  3597. string description = lua_interface->GetStringValue(state, 3);
  3598. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3599. float percentage = lua_interface->GetFloatValue(state, 5);
  3600. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3601. int16 icon = lua_interface->GetInt16Value(state, 7);
  3602. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3603. if (quest) {
  3604. const char* taskgroup = 0;
  3605. if (str_taskgroup.length() > 0)
  3606. taskgroup = str_taskgroup.c_str();
  3607. int32 id = 0;
  3608. vector<int32>* ids = 0;
  3609. int i = 0;
  3610. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3611. if (ids == 0)
  3612. ids = new vector<int32>;
  3613. ids->push_back(id);
  3614. i++;
  3615. }
  3616. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3617. if (quest_step && icon && quantity > 0)
  3618. quest_step->SetIcon(icon);
  3619. if (quest->GetPlayer()) {
  3620. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3621. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3622. }
  3623. }
  3624. lua_interface->ResetFunctionStack(state);
  3625. return 0;
  3626. }
  3627. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3628. {
  3629. if (!lua_interface)
  3630. return 0;
  3631. Quest* quest = lua_interface->GetQuest(state);
  3632. int32 step = lua_interface->GetInt32Value(state, 2);
  3633. string description = lua_interface->GetStringValue(state, 3);
  3634. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3635. float percentage = lua_interface->GetFloatValue(state, 5);
  3636. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3637. int16 icon = lua_interface->GetInt16Value(state, 7);
  3638. if (quest) {
  3639. const char* taskgroup = 0;
  3640. if (str_taskgroup.length() > 0)
  3641. taskgroup = str_taskgroup.c_str();
  3642. int32 id = 0;
  3643. vector<int32>* ids = 0;
  3644. int i = 0;
  3645. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3646. if (ids == 0)
  3647. ids = new vector<int32>;
  3648. ids->push_back(id);
  3649. i++;
  3650. }
  3651. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3652. if (quest_step && icon > 0 && quantity > 0)
  3653. quest_step->SetIcon(icon);
  3654. if (quest->GetPlayer()) {
  3655. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3656. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3657. }
  3658. safe_delete(ids);
  3659. }
  3660. lua_interface->ResetFunctionStack(state);
  3661. return 0;
  3662. }
  3663. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3664. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3665. }
  3666. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3667. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3668. }
  3669. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3670. if (!lua_interface)
  3671. return 0;
  3672. Quest* quest = lua_interface->GetQuest(state);
  3673. int32 step = lua_interface->GetInt32Value(state, 2);
  3674. string description = lua_interface->GetStringValue(state, 3);
  3675. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3676. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3677. int16 icon = lua_interface->GetInt16Value(state, 6);
  3678. if (quest) {
  3679. const char* taskgroup = 0;
  3680. if (str_taskgroup.length() > 0)
  3681. taskgroup = str_taskgroup.c_str();
  3682. int32 npc_id = 0;
  3683. vector<int32>* ids = 0;
  3684. int i = 0;
  3685. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3686. if (ids == 0)
  3687. ids = new vector<int32>;
  3688. ids->push_back(npc_id);
  3689. i++;
  3690. }
  3691. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3692. if (quest_step && icon > 0)
  3693. quest_step->SetIcon(icon);
  3694. if (quest->GetPlayer()) {
  3695. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3696. if(client)
  3697. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3698. }
  3699. safe_delete(ids);
  3700. }
  3701. lua_interface->ResetFunctionStack(state);
  3702. return 0;
  3703. }
  3704. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3705. if (!lua_interface)
  3706. return 0;
  3707. Quest* quest = lua_interface->GetQuest(state);
  3708. int32 step = lua_interface->GetInt32Value(state, 2);
  3709. string description = lua_interface->GetStringValue(state, 3);
  3710. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3711. float percentage = lua_interface->GetFloatValue(state, 5);
  3712. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3713. int16 icon = lua_interface->GetInt16Value(state, 7);
  3714. if (quest) {
  3715. const char* taskgroup = 0;
  3716. if (str_taskgroup.length() > 0)
  3717. taskgroup = str_taskgroup.c_str();
  3718. int32 item_id = 0;
  3719. vector<int32>* ids = 0;
  3720. int i = 0;
  3721. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3722. if (ids == 0)
  3723. ids = new vector<int32>;
  3724. ids->push_back(item_id);
  3725. i++;
  3726. }
  3727. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3728. if (quest_step && icon > 0 && quantity > 0)
  3729. quest_step->SetIcon(icon);
  3730. if (quest->GetPlayer()) {
  3731. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3732. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3733. }
  3734. safe_delete(ids);
  3735. }
  3736. lua_interface->ResetFunctionStack(state);
  3737. return 0;
  3738. }
  3739. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3740. if (!lua_interface)
  3741. return 0;
  3742. Quest* quest = lua_interface->GetQuest(state);
  3743. int32 step = lua_interface->GetInt32Value(state, 2);
  3744. string description = lua_interface->GetStringValue(state, 3);
  3745. float max_variation = lua_interface->GetFloatValue(state, 4);
  3746. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3747. int16 icon = lua_interface->GetInt16Value(state, 6);
  3748. if (quest) {
  3749. const char* taskgroup = 0;
  3750. if (str_taskgroup.length() > 0)
  3751. taskgroup = str_taskgroup.c_str();
  3752. vector<Location>* locations = 0;
  3753. int8 i = 7;
  3754. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3755. while (true) {
  3756. Location loc;
  3757. loc.x = lua_interface->GetFloatValue(state, i);
  3758. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3759. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3760. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3761. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3762. break;
  3763. if (locations == 0)
  3764. locations = new vector<Location>;
  3765. locations->push_back(loc);
  3766. i += 4;
  3767. }
  3768. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3769. if (quest_step && icon > 0)
  3770. quest_step->SetIcon(icon);
  3771. if (quest->GetPlayer()) {
  3772. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3773. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3774. }
  3775. }
  3776. lua_interface->ResetFunctionStack(state);
  3777. return 0;
  3778. }
  3779. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3780. if (!lua_interface)
  3781. return 0;
  3782. Quest* quest = lua_interface->GetQuest(state);
  3783. int32 step = lua_interface->GetInt32Value(state, 2);
  3784. string description = lua_interface->GetStringValue(state, 3);
  3785. float max_variation = lua_interface->GetFloatValue(state, 4);
  3786. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3787. int16 icon = lua_interface->GetInt16Value(state, 6);
  3788. if (quest) {
  3789. const char* taskgroup = 0;
  3790. if (str_taskgroup.length() > 0)
  3791. taskgroup = str_taskgroup.c_str();
  3792. vector<Location>* locations = 0;
  3793. int8 i = 7;
  3794. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3795. while (true) {
  3796. Location loc;
  3797. loc.x = lua_interface->GetFloatValue(state, i);
  3798. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3799. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3800. loc.zone_id = 0;
  3801. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3802. break;
  3803. if (locations == 0)
  3804. locations = new vector<Location>;
  3805. locations->push_back(loc);
  3806. i += 3;
  3807. }
  3808. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3809. if (quest_step && icon > 0)
  3810. quest_step->SetIcon(icon);
  3811. if (quest->GetPlayer()) {
  3812. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3813. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3814. }
  3815. }
  3816. lua_interface->ResetFunctionStack(state);
  3817. return 0;
  3818. }
  3819. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3820. if (!lua_interface)
  3821. return 0;
  3822. Quest* quest = lua_interface->GetQuest(state);
  3823. int32 step = lua_interface->GetInt32Value(state, 2);
  3824. string description = lua_interface->GetStringValue(state, 3);
  3825. float max_variation = lua_interface->GetFloatValue(state, 4);
  3826. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3827. int16 icon = lua_interface->GetInt16Value(state, 6);
  3828. if (quest) {
  3829. const char* taskgroup = 0;
  3830. if (str_taskgroup.length() > 0)
  3831. taskgroup = str_taskgroup.c_str();
  3832. vector<Location>* locations = 0;
  3833. int i = 7;
  3834. while (true) {
  3835. Location loc;
  3836. loc.x = lua_interface->GetFloatValue(state, i);
  3837. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3838. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3839. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3840. break;
  3841. if (locations == 0)
  3842. locations = new vector<Location>;
  3843. locations->push_back(loc);
  3844. i += 3;
  3845. }
  3846. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3847. if (quest_step && icon > 0)
  3848. quest_step->SetIcon(icon);
  3849. if (quest->GetPlayer()) {
  3850. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3851. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3852. }
  3853. }
  3854. lua_interface->ResetFunctionStack(state);
  3855. return 0;
  3856. }
  3857. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3858. Quest* quest = lua_interface->GetQuest(state);
  3859. int32 step = lua_interface->GetInt32Value(state, 2);
  3860. string description = lua_interface->GetStringValue(state, 3);
  3861. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3862. float percentage = lua_interface->GetFloatValue(state, 5);
  3863. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3864. int16 icon = lua_interface->GetInt16Value(state, 7);
  3865. if (quest) {
  3866. const char* taskgroup = 0;
  3867. if (str_taskgroup.length() > 0)
  3868. taskgroup = str_taskgroup.c_str();
  3869. int32 spell_id = 0;
  3870. vector<int32>* ids = 0;
  3871. int i = 0;
  3872. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3873. if (ids == 0)
  3874. ids = new vector<int32>;
  3875. ids->push_back(spell_id);
  3876. i++;
  3877. }
  3878. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3879. if (quest_step && icon > 0 && quantity > 0)
  3880. quest_step->SetIcon(icon);
  3881. if (quest->GetPlayer()) {
  3882. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3883. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3884. }
  3885. safe_delete(ids);
  3886. }
  3887. lua_interface->ResetFunctionStack(state);
  3888. return 0;
  3889. }
  3890. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3891. if (!lua_interface)
  3892. return 0;
  3893. Quest* quest = lua_interface->GetQuest(state);
  3894. int32 step = lua_interface->GetInt32Value(state, 2);
  3895. string description = lua_interface->GetStringValue(state, 3);
  3896. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3897. float percentage = lua_interface->GetFloatValue(state, 5);
  3898. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3899. int16 icon = lua_interface->GetInt16Value(state, 7);
  3900. if (quest) {
  3901. const char* taskgroup = 0;
  3902. if (str_taskgroup.length() > 0)
  3903. taskgroup = str_taskgroup.c_str();
  3904. int32 item_id = 0;
  3905. vector<int32>* ids = 0;
  3906. int i = 0;
  3907. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3908. if (ids == 0)
  3909. ids = new vector<int32>;
  3910. ids->push_back(item_id);
  3911. i++;
  3912. }
  3913. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3914. if (quest_step && icon > 0 && quantity > 0)
  3915. quest_step->SetIcon(icon);
  3916. if (quest->GetPlayer()) {
  3917. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3918. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3919. }
  3920. safe_delete(ids);
  3921. }
  3922. lua_interface->ResetFunctionStack(state);
  3923. return 0;
  3924. }
  3925. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3926. if (!lua_interface)
  3927. return 0;
  3928. Quest* quest = lua_interface->GetQuest(state);
  3929. int32 step = lua_interface->GetInt32Value(state, 2);
  3930. string description = lua_interface->GetStringValue(state, 3);
  3931. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3932. float percentage = lua_interface->GetFloatValue(state, 5);
  3933. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3934. int16 icon = lua_interface->GetInt16Value(state, 7);
  3935. if (quest) {
  3936. const char* taskgroup = 0;
  3937. if (str_taskgroup.length() > 0)
  3938. taskgroup = str_taskgroup.c_str();
  3939. int32 item_id = 0;
  3940. vector<int32>* ids = 0;
  3941. int i = 0;
  3942. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3943. if (ids == 0)
  3944. ids = new vector<int32>;
  3945. ids->push_back(item_id);
  3946. i++;
  3947. }
  3948. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3949. if (quest_step && icon > 0 && quantity > 0)
  3950. quest_step->SetIcon(icon);
  3951. if (quest->GetPlayer()) {
  3952. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3953. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3954. }
  3955. safe_delete(ids);
  3956. }
  3957. lua_interface->ResetFunctionStack(state);
  3958. return 0;
  3959. }
  3960. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3961. if (!lua_interface)
  3962. return 0;
  3963. Quest* quest = lua_interface->GetQuest(state);
  3964. string action = lua_interface->GetStringValue(state, 2);
  3965. lua_interface->ResetFunctionStack(state);
  3966. if (quest) {
  3967. if (action.length() > 0)
  3968. quest->SetCompleteAction(action);
  3969. }
  3970. return 0;
  3971. }
  3972. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3973. if (!lua_interface)
  3974. return 0;
  3975. Quest* quest = lua_interface->GetQuest(state);
  3976. int32 step = lua_interface->GetInt32Value(state, 2);
  3977. string action = lua_interface->GetStringValue(state, 3);
  3978. lua_interface->ResetFunctionStack(state);
  3979. if (quest) {
  3980. if (step > 0 && action.length() > 0)
  3981. quest->AddCompleteAction(step, action);
  3982. }
  3983. return 0;
  3984. }
  3985. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3986. if (!lua_interface)
  3987. return 0;
  3988. Quest* quest = lua_interface->GetQuest(state);
  3989. int32 step = lua_interface->GetInt32Value(state, 2);
  3990. string action = lua_interface->GetStringValue(state, 3);
  3991. lua_interface->ResetFunctionStack(state);
  3992. if (quest) {
  3993. if (step > 0 && action.length() > 0)
  3994. quest->AddProgressAction(step, action);
  3995. }
  3996. return 0;
  3997. }
  3998. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3999. if (!lua_interface)
  4000. return 0;
  4001. Quest* quest = lua_interface->GetQuest(state);
  4002. string description = lua_interface->GetStringValue(state, 2);
  4003. lua_interface->ResetFunctionStack(state);
  4004. if (quest && description.length() > 0)
  4005. quest->SetDescription(description);
  4006. return 0;
  4007. }
  4008. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4009. if (!lua_interface)
  4010. return 0;
  4011. Quest* quest = lua_interface->GetQuest(state);
  4012. string description = lua_interface->GetStringValue(state, 2);
  4013. lua_interface->ResetFunctionStack(state);
  4014. if (quest && description.length() > 0)
  4015. quest->SetCompletedDescription(description);
  4016. return 0;
  4017. }
  4018. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4019. if (!lua_interface)
  4020. return 0;
  4021. Quest* quest = lua_interface->GetQuest(state);
  4022. int32 step = lua_interface->GetInt32Value(state, 2);
  4023. string description = lua_interface->GetStringValue(state, 3);
  4024. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4025. lua_interface->ResetFunctionStack(state);
  4026. if (quest && step > 0 && description.length() > 0) {
  4027. quest->SetTaskGroupDescription(step, description, display_bullets);
  4028. /* if (quest->GetPlayer()) {
  4029. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4030. if (client)
  4031. client->SendQuestUpdateStep(quest, step, false);
  4032. }*/
  4033. }
  4034. return 0;
  4035. }
  4036. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4037. if (!lua_interface)
  4038. return 0;
  4039. Quest* quest = lua_interface->GetQuest(state);
  4040. int32 step = lua_interface->GetInt32Value(state, 2);
  4041. string description = lua_interface->GetStringValue(state, 3);
  4042. lua_interface->ResetFunctionStack(state);
  4043. if (quest && step > 0 && description.length() > 0) {
  4044. quest->SetStepDescription(step, description);
  4045. /*if (quest->GetPlayer()) {
  4046. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4047. if (client)
  4048. client->SendQuestUpdateStepImmediately(quest, step);
  4049. }*/
  4050. }
  4051. return 0;
  4052. }
  4053. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4054. Quest* quest = lua_interface->GetQuest(state);
  4055. string zone = lua_interface->GetStringValue(state, 2);
  4056. lua_interface->ResetFunctionStack(state);
  4057. if (quest && zone.length() > 0)
  4058. quest->SetZone(zone);
  4059. return 0;
  4060. }
  4061. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4062. if (!lua_interface)
  4063. return 0;
  4064. Quest* quest = lua_interface->GetQuest(state);
  4065. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4066. lua_interface->ResetFunctionStack(state);
  4067. if (quest && spawn) {
  4068. if (spawn->IsPlayer()) {
  4069. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4070. if (client)
  4071. {
  4072. client->AddPendingQuestAcceptReward(quest);
  4073. client->AddPendingQuestReward(quest);
  4074. }
  4075. }
  4076. }
  4077. return 0;
  4078. }
  4079. int EQ2Emu_lua_Harvest(lua_State* state) {
  4080. if (!lua_interface)
  4081. return 0;
  4082. Spawn* player = lua_interface->GetSpawn(state);
  4083. Spawn* node = lua_interface->GetSpawn(state, 2);
  4084. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4085. Client* client = player->GetZone()->GetClientBySpawn(player);
  4086. if (client) {
  4087. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4088. ((GroundSpawn*)node)->ProcessHarvest(client);
  4089. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4090. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4091. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4092. }
  4093. }
  4094. }
  4095. else if (player && player->IsPlayer()) {
  4096. Client* client = player->GetZone()->GetClientBySpawn(player);
  4097. if (client)
  4098. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4099. }
  4100. lua_interface->ResetFunctionStack(state);
  4101. return 0;
  4102. }
  4103. int EQ2Emu_lua_Bind(lua_State* state) {
  4104. if (!lua_interface)
  4105. return 0;
  4106. Spawn* spawn = lua_interface->GetSpawn(state);
  4107. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4108. float x = lua_interface->GetFloatValue(state, 3);
  4109. float y = lua_interface->GetFloatValue(state, 4);
  4110. float z = lua_interface->GetFloatValue(state, 5);
  4111. float h = lua_interface->GetFloatValue(state, 6);
  4112. lua_interface->ResetFunctionStack(state);
  4113. if (!spawn) {
  4114. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4115. return 0;
  4116. }
  4117. if (!spawn->IsPlayer()) {
  4118. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4119. return 0;
  4120. }
  4121. if (zone_id == 0) {
  4122. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4123. if (!client) {
  4124. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4125. return 0;
  4126. }
  4127. if (!client->Bind())
  4128. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4129. }
  4130. else {
  4131. Player* player = (Player*)spawn;
  4132. player->GetPlayerInfo()->SetBindZone(zone_id);
  4133. player->GetPlayerInfo()->SetBindX(x);
  4134. player->GetPlayerInfo()->SetBindY(y);
  4135. player->GetPlayerInfo()->SetBindZ(z);
  4136. player->GetPlayerInfo()->SetBindHeading(h);
  4137. }
  4138. return 0;
  4139. }
  4140. int EQ2Emu_lua_Gate(lua_State* state) {
  4141. if (!lua_interface)
  4142. return 0;
  4143. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4144. Spawn* spawn = lua_interface->GetSpawn(state);
  4145. lua_interface->ResetFunctionStack(state);
  4146. if (spawn) {
  4147. if (spawn->IsPlayer()) {
  4148. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4149. if (client) {
  4150. if (!client->Gate((spell != nullptr) ? true : false))
  4151. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4152. }
  4153. }
  4154. }
  4155. return 0;
  4156. }
  4157. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4158. if (!lua_interface)
  4159. return 0;
  4160. bool ret = false;
  4161. Spawn* spawn = lua_interface->GetSpawn(state);
  4162. lua_interface->ResetFunctionStack(state);
  4163. if (spawn) {
  4164. if (spawn->IsPlayer()) {
  4165. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4166. if (client)
  4167. ret = client->BindAllowed();
  4168. }
  4169. }
  4170. lua_interface->SetBooleanValue(state, ret);
  4171. return 1;
  4172. }
  4173. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4174. if (!lua_interface)
  4175. return 0;
  4176. bool ret = false;
  4177. Spawn* spawn = lua_interface->GetSpawn(state);
  4178. lua_interface->ResetFunctionStack(state);
  4179. if (spawn) {
  4180. if (spawn->IsPlayer()) {
  4181. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4182. ZoneServer* zone = lua_interface->GetZone(state);
  4183. if (client && zone){
  4184. ret = zone->GetCanGate();
  4185. }
  4186. }
  4187. }
  4188. lua_interface->SetBooleanValue(state, ret);
  4189. return 1;
  4190. }
  4191. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4192. Spawn* spawn = lua_interface->GetSpawn(state);
  4193. lua_interface->ResetFunctionStack(state);
  4194. if (spawn) {
  4195. lua_interface->SetBooleanValue(state, spawn->Alive());
  4196. return 1;
  4197. }
  4198. return 0;
  4199. }
  4200. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4201. if (!lua_interface)
  4202. return 0;
  4203. Spawn* spawn = lua_interface->GetSpawn(state);
  4204. lua_interface->ResetFunctionStack(state);
  4205. if (spawn && spawn->IsEntity()) {
  4206. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4207. return 1;
  4208. }
  4209. return 0;
  4210. }
  4211. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4212. Spawn* spawn = lua_interface->GetSpawn(state);
  4213. string message = lua_interface->GetStringValue(state, 2);
  4214. string color_str = lua_interface->GetStringValue(state, 3);
  4215. lua_interface->ResetFunctionStack(state);
  4216. int8 color = CHANNEL_NARRATIVE;
  4217. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4218. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4219. if (client) {
  4220. if (color_str.length() > 0) {
  4221. // leave for backwards compat, but all future should just use the number
  4222. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4223. color = CHANNEL_COLOR_RED;
  4224. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4225. color = CHANNEL_COLOR_YELLOW;
  4226. else
  4227. {
  4228. // use a number to specify the channel as per Commands/Commands.h defines
  4229. color = (int8)atoul(color_str.c_str());
  4230. }
  4231. }
  4232. client->SimpleMessage(color, message.c_str());
  4233. }
  4234. }
  4235. return 0;
  4236. }
  4237. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4238. Spawn* spawn = lua_interface->GetSpawn(state);
  4239. string message = lua_interface->GetStringValue(state, 2);
  4240. int8 red = lua_interface->GetInt8Value(state, 3);
  4241. int8 green = lua_interface->GetInt8Value(state, 4);
  4242. int8 blue = lua_interface->GetInt8Value(state, 5);
  4243. lua_interface->ResetFunctionStack(state);
  4244. if (!spawn) {
  4245. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4246. return 0;
  4247. }
  4248. int32 words = ::CountWordsInString(message.c_str());
  4249. if (words < 5)
  4250. words = 5;
  4251. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4252. if (client)
  4253. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4254. return 0;
  4255. }
  4256. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4257. Spawn* spawn = lua_interface->GetSpawn(state);
  4258. int8 param = lua_interface->GetInt8Value(state, 2);
  4259. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4260. int8 value = lua_interface->GetInt8Value(state, 4);
  4261. lua_interface->ResetFunctionStack(state);
  4262. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4263. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4264. if (client) {
  4265. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4266. switch (param) {
  4267. case 1: {
  4268. packet->setDataByName("parameter1", param_value);
  4269. break;
  4270. }
  4271. case 2: {
  4272. packet->setDataByName("parameter2", param_value);
  4273. break;
  4274. }
  4275. case 3: {
  4276. packet->setDataByName("parameter3", param_value);
  4277. break;
  4278. }
  4279. case 4: {
  4280. packet->setDataByName("parameter4", param_value);
  4281. break;
  4282. }
  4283. case 5: {
  4284. packet->setDataByName("parameter5", param_value);
  4285. break;
  4286. }
  4287. }
  4288. packet->setDataByName("value", value);
  4289. client->QueuePacket(packet->serialize());
  4290. safe_delete(packet);
  4291. }
  4292. }
  4293. return 0;
  4294. }
  4295. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4296. Spawn* spawn = lua_interface->GetSpawn(state);
  4297. lua_interface->ResetFunctionStack(state);
  4298. if (spawn && spawn->IsPlayer()) {
  4299. if (((Player*)spawn)->GetIsTracking())
  4300. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4301. else
  4302. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4303. }
  4304. return 0;
  4305. }
  4306. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4307. Spawn* player = lua_interface->GetSpawn(state);
  4308. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4309. string name = lua_interface->GetStringValue(state, 3);
  4310. float distance = lua_interface->GetFloatValue(state, 4);
  4311. string command = lua_interface->GetStringValue(state, 5);
  4312. string error_text = lua_interface->GetStringValue(state, 6);
  4313. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4314. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4315. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4316. lua_interface->ResetFunctionStack(state);
  4317. if (spawn) {
  4318. if (distance == 0)
  4319. distance = 10.0f;
  4320. if (command.length() == 0)
  4321. command = name;
  4322. if (command.length() < 1 && name.length() < 1)
  4323. {
  4324. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4325. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4326. spawn->RemovePrimaryCommands();
  4327. }
  4328. else
  4329. {
  4330. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4331. }
  4332. }
  4333. return 0;
  4334. }
  4335. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4336. if (!lua_interface)
  4337. return 0;
  4338. Spawn* player = lua_interface->GetSpawn(state);
  4339. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4340. int16 tier = lua_interface->GetInt16Value(state, 3);
  4341. lua_interface->ResetFunctionStack(state);
  4342. if (player && player->IsPlayer()) {
  4343. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4344. return 1;
  4345. }
  4346. return 0;
  4347. }
  4348. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4349. if (!lua_interface)
  4350. return 0;
  4351. Spawn* player = lua_interface->GetSpawn(state);
  4352. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4353. int16 tier = lua_interface->GetInt16Value(state, 3);
  4354. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4355. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4356. bool add_to_hotbar = true;
  4357. if (num_args > 4) {
  4358. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4359. }
  4360. lua_interface->ResetFunctionStack(state);
  4361. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4362. if (player && spell && player->IsPlayer()) {
  4363. Client* client = player->GetClient();
  4364. if (client) {
  4365. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4366. {
  4367. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4368. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4369. client->GetPlayer()->UnlockSpell(spell);
  4370. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4371. }
  4372. else
  4373. {
  4374. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4375. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4376. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4377. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4378. client->GetPlayer()->UnlockSpell(spell);
  4379. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4380. }
  4381. //if (client ) {
  4382. // ((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);
  4383. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4384. if (outapp)
  4385. client->QueuePacket(outapp);
  4386. }
  4387. }
  4388. return 0;
  4389. }
  4390. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4391. if (!lua_interface)
  4392. return 0;
  4393. Spawn* player = lua_interface->GetSpawn(state);
  4394. lua_interface->ResetFunctionStack(state);
  4395. if (player && player->IsPlayer()) {
  4396. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4397. return 1;
  4398. }
  4399. return 0;
  4400. }
  4401. int EQ2Emu_lua_Attack(lua_State* state) {
  4402. if (lua_interface) {
  4403. Spawn* npc = lua_interface->GetSpawn(state);
  4404. Spawn* player = lua_interface->GetSpawn(state, 2);
  4405. lua_interface->ResetFunctionStack(state);
  4406. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4407. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4408. }
  4409. return 0;
  4410. }
  4411. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4412. if (lua_interface) {
  4413. Spawn* target = lua_interface->GetSpawn(state);
  4414. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4415. lua_interface->ResetFunctionStack(state);
  4416. if (target && target->GetZone())
  4417. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4418. }
  4419. return 0;
  4420. }
  4421. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4422. Spawn* player;
  4423. if (lua_interface) {
  4424. player = lua_interface->GetSpawn(state);
  4425. lua_interface->ResetFunctionStack(state);
  4426. if (player && player->IsPlayer()) {
  4427. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4428. return 1;
  4429. }
  4430. }
  4431. return 0;
  4432. }
  4433. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4434. Spawn* player;
  4435. Client* client;
  4436. if (lua_interface) {
  4437. player = lua_interface->GetSpawn(state);
  4438. lua_interface->ResetFunctionStack(state);
  4439. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4440. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4441. client->HandInCollections();
  4442. }
  4443. return 0;
  4444. }
  4445. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4446. Spawn* widget;
  4447. if (lua_interface) {
  4448. widget = lua_interface->GetSpawn(state);
  4449. lua_interface->ResetFunctionStack(state);
  4450. if (widget && widget->IsWidget())
  4451. ((Widget*)widget)->HandleUse(nullptr, "");
  4452. }
  4453. return 0;
  4454. }
  4455. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4456. Spawn* spawn = 0;
  4457. int32 primary_list = 0;
  4458. int32 secondary_list = 0;
  4459. if (lua_interface) {
  4460. spawn = lua_interface->GetSpawn(state);
  4461. primary_list = lua_interface->GetInt32Value(state, 2);
  4462. secondary_list = lua_interface->GetInt32Value(state, 3);
  4463. lua_interface->ResetFunctionStack(state);
  4464. if (!spawn->IsNPC()) {
  4465. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4466. return 0;
  4467. }
  4468. NPC* npc = (NPC*)spawn;
  4469. npc->SetPrimarySpellList(primary_list);
  4470. npc->SetSecondarySpellList(secondary_list);
  4471. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4472. }
  4473. return 0;
  4474. }
  4475. int EQ2Emu_lua_GetPet(lua_State* state) {
  4476. if (!lua_interface)
  4477. return 0;
  4478. Spawn* spawn = lua_interface->GetSpawn(state);
  4479. lua_interface->ResetFunctionStack(state);
  4480. if (spawn) {
  4481. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4482. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4483. return 1;
  4484. }
  4485. }
  4486. return 0;
  4487. }
  4488. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4489. if (!lua_interface)
  4490. return 0;
  4491. Spawn* spawn = lua_interface->GetSpawn(state);
  4492. lua_interface->ResetFunctionStack(state);
  4493. if (spawn) {
  4494. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4495. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4496. return 1;
  4497. }
  4498. }
  4499. return 0;
  4500. }
  4501. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4502. if (!lua_interface)
  4503. return 0;
  4504. Spawn* spawn = lua_interface->GetSpawn(state);
  4505. lua_interface->ResetFunctionStack(state);
  4506. if (spawn) {
  4507. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4508. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4509. return 1;
  4510. }
  4511. }
  4512. return 0;
  4513. }
  4514. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4515. if (!lua_interface)
  4516. return 0;
  4517. Spawn* spawn = lua_interface->GetSpawn(state);
  4518. lua_interface->ResetFunctionStack(state);
  4519. if (spawn) {
  4520. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4521. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4522. return 1;
  4523. }
  4524. }
  4525. return 0;
  4526. }
  4527. int EQ2Emu_lua_Charm(lua_State* state) {
  4528. if (!lua_interface)
  4529. return 0;
  4530. Spawn* owner = lua_interface->GetSpawn(state);
  4531. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4532. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4533. lua_interface->ResetFunctionStack(state);
  4534. if (!luaspell) {
  4535. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4536. return 0;
  4537. }
  4538. if(luaspell->resisted) {
  4539. return 0;
  4540. }
  4541. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4542. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4543. pet->SetPet(true);
  4544. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4545. ((NPC*)pet)->SetOwner((Entity*)owner);
  4546. // If owner is player and player does not have a summoned pet set the players charsheet
  4547. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4548. Player* player = (Player*)owner;
  4549. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4550. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4551. player->GetInfoStruct()->set_pet_movement(2);
  4552. player->GetInfoStruct()->set_pet_behavior(3);
  4553. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4554. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4555. // Make sure the values get sent to the client
  4556. player->SetCharSheetChanged(true);
  4557. }
  4558. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4559. pet->SetSpawnScript("");
  4560. // Set faction to the same as the owner
  4561. pet->SetFactionID(owner->GetFactionID());
  4562. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4563. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4564. // Clear hate list
  4565. ((NPC*)pet)->Brain()->ClearHate();
  4566. // Set the brain to a pet brain
  4567. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4568. }
  4569. return 0;
  4570. }
  4571. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4572. if (!lua_interface)
  4573. return 0;
  4574. Spawn* spawn = lua_interface->GetSpawn(state);
  4575. lua_interface->ResetFunctionStack(state);
  4576. if (!spawn) {
  4577. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4578. return 0;
  4579. }
  4580. vector<Spawn*> groupMembers;
  4581. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4582. groupMembers = *spawn->GetSpawnGroup();
  4583. }
  4584. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4585. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4586. deque<GroupMemberInfo*>::iterator itr;
  4587. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4588. if (group)
  4589. {
  4590. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4591. deque<GroupMemberInfo*>* members = group->GetMembers();
  4592. GroupMemberInfo* info = 0;
  4593. for (itr = members->begin(); itr != members->end(); itr++) {
  4594. info = *itr;
  4595. if (info->client)
  4596. groupMembers.push_back(info->client->GetPlayer());
  4597. }
  4598. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4599. }
  4600. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4601. }
  4602. else
  4603. return 0;
  4604. lua_createtable(state, groupMembers.size(), 0);
  4605. int newTable = lua_gettop(state);
  4606. for (int32 i = 0; i < groupMembers.size(); i++) {
  4607. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4608. lua_rawseti(state, newTable, i + 1);
  4609. }
  4610. return 1;
  4611. }
  4612. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4613. if (!lua_interface)
  4614. return 0;
  4615. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4616. lua_interface->SetOptionWindowValue(state, option_window);
  4617. return 1;
  4618. }
  4619. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4620. if (!lua_interface)
  4621. return 0;
  4622. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4623. if (option_window) {
  4624. OptionWindowOption option_window_option;
  4625. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4626. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4627. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4628. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4629. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4630. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4631. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4632. option_window->push_back(option_window_option);
  4633. }
  4634. return 0;
  4635. }
  4636. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4637. if (!lua_interface)
  4638. return 0;
  4639. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4640. Spawn* player = lua_interface->GetSpawn(state, 2);
  4641. string window_title = lua_interface->GetStringValue(state, 3);
  4642. string cancel_command = lua_interface->GetStringValue(state, 4);
  4643. Client* client = player->GetZone()->GetClientBySpawn(player);
  4644. if (option_window && window_title.length() > 0 && client) {
  4645. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4646. if (!packet)
  4647. return 0;
  4648. packet->setDataByName("title_text", window_title.c_str());
  4649. if (cancel_command.length() > 0)
  4650. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4651. packet->setArrayLengthByName("num_selections", option_window->size());
  4652. vector<OptionWindowOption>::iterator itr;
  4653. int8 i = 0;
  4654. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4655. OptionWindowOption opt = *itr;
  4656. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4657. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4658. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4659. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4660. if (opt.optionCommand.length() > 0)
  4661. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4662. if (opt.optionConfirmTitle.length() > 0)
  4663. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4664. i++;
  4665. }
  4666. client->QueuePacket(packet->serialize());
  4667. safe_delete(option_window);
  4668. safe_delete(packet);
  4669. }
  4670. return 0;
  4671. }
  4672. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4673. if (!lua_interface)
  4674. return 0;
  4675. Spawn* spawn = lua_interface->GetSpawn(state);
  4676. if (spawn) {
  4677. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4678. return 1;
  4679. }
  4680. else
  4681. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4682. return 0;
  4683. }
  4684. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4685. if (!lua_interface)
  4686. return 0;
  4687. Spawn* spawn = lua_interface->GetSpawn(state);
  4688. if (spawn) {
  4689. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4690. return 1;
  4691. }
  4692. else
  4693. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4694. return 0;
  4695. }
  4696. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4697. if (!lua_interface)
  4698. return 0;
  4699. Spawn* spawn = lua_interface->GetSpawn(state);
  4700. if (spawn) {
  4701. int8 class_id = spawn->GetTradeskillClass();
  4702. // Need to add 42 for the offset in the array
  4703. class_id += 44;
  4704. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4705. return 1;
  4706. }
  4707. else
  4708. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4709. return 0;
  4710. }
  4711. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4712. if (!lua_interface)
  4713. return 0;
  4714. Spawn* spawn = lua_interface->GetSpawn(state);
  4715. int16 level = lua_interface->GetInt8Value(state, 2);
  4716. if (spawn) {
  4717. if (spawn->IsPlayer())
  4718. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4719. else
  4720. spawn->SetTSLevel(level);
  4721. }
  4722. else
  4723. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4724. return 0;
  4725. }
  4726. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4727. if (!lua_interface)
  4728. return 0;
  4729. Spawn* spawn = lua_interface->GetSpawn(state);
  4730. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4731. if (spawn) {
  4732. spawn->SetAttackable(attackable);
  4733. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4734. }
  4735. return 0;
  4736. }
  4737. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4738. // Check to see if we have a valid lua_interface
  4739. if (!lua_interface)
  4740. return 0;
  4741. // Get the spawn that is getting the pet
  4742. Spawn* spawn = lua_interface->GetSpawn(state);
  4743. // Get the DB ID of the pet
  4744. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4745. // The max level the pet can gain
  4746. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4747. // Get the spell that this command was called from
  4748. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4749. // Check to make sure the spawn pointer is valid
  4750. if (!spawn) {
  4751. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4752. return 0;
  4753. }
  4754. // Check to make sure the spawn is an entity
  4755. if (!spawn->IsEntity()) {
  4756. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4757. return 0;
  4758. }
  4759. // Check to make sure the spawn doesn't already have a pet of this type
  4760. if (((Entity*)spawn)->GetPet()) {
  4761. if (spawn->IsPlayer()) {
  4762. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4763. if (client)
  4764. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4765. }
  4766. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4767. return 0;
  4768. }
  4769. // Check to see if the DB ID for the pet is set
  4770. if (pet_id == 0) {
  4771. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4772. return 0;
  4773. }
  4774. // Check to see if the pointer to the spell is valid
  4775. if (!luaspell) {
  4776. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4777. return 0;
  4778. }
  4779. if(luaspell->resisted) {
  4780. return 0;
  4781. }
  4782. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4783. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4784. if (!pet) {
  4785. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4786. return 0;
  4787. }
  4788. // Check to make sure the pet is an npc
  4789. if (!pet->IsNPC()) {
  4790. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4791. return 0;
  4792. }
  4793. // Spawn the pet at the same location as the owner
  4794. pet->SetX(spawn->GetX());
  4795. pet->SetY(spawn->GetY());
  4796. pet->SetZ(spawn->GetZ());
  4797. pet->SetLocation(spawn->GetLocation());
  4798. pet->SetHeading(spawn->GetHeading());
  4799. spawn->GetZone()->AddSpawn(pet);
  4800. /*
  4801. const char* spawn_script = world.GetSpawnScript(pet_id);
  4802. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4803. spawn->SetSpawnScript(string(spawn_script));
  4804. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4805. }*/
  4806. // Get a random pet name
  4807. string random_pet_name;
  4808. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4809. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4810. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4811. // If player set various values for the char sheet (pet window)
  4812. if (spawn->IsPlayer()) {
  4813. Player* player = (Player*)spawn;
  4814. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4815. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4816. player->GetInfoStruct()->set_pet_movement(2);
  4817. player->GetInfoStruct()->set_pet_behavior(3);
  4818. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4819. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4820. // Make sure the values get sent to the client
  4821. player->SetCharSheetChanged(true);
  4822. }
  4823. // Set the pets name
  4824. pet->SetName(random_pet_name.c_str());
  4825. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4826. if (max_level > 0)
  4827. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4828. else
  4829. pet->SetLevel(spawn->GetLevel());
  4830. // Set the max level this pet can reach
  4831. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4832. // Set the faction of the pet to the same faction as the owner
  4833. pet->SetFactionID(spawn->GetFactionID());
  4834. // Set the spawn as a pet
  4835. pet->SetPet(true);
  4836. // Give a pointer of the owner to the pet
  4837. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4838. // Give a pointer of the pet to the owner
  4839. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4840. // Set the pet type
  4841. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4842. // Set the spell id used to create this pet
  4843. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4844. // Set the spell tier used to create this pet
  4845. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4846. // Set the pets spawn type to 6
  4847. pet->SetSpawnType(6);
  4848. // Set the pets brain
  4849. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4850. // Check to see if the pet has a subtitle
  4851. if (strlen(pet->GetSubTitle()) > 0) {
  4852. // Add the players name to the front of the sub title
  4853. string pet_subtitle;
  4854. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4855. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4856. // Set the pets subtitle to the new one
  4857. pet->SetSubTitle(pet_subtitle.c_str());
  4858. }
  4859. // Add the "Pet Options" entity command to the pet
  4860. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4861. // Set the pet as the return value for this function
  4862. lua_interface->SetSpawnValue(state, pet);
  4863. return 1;
  4864. }
  4865. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4866. if (!lua_interface)
  4867. return 0;
  4868. Spawn* spawn = lua_interface->GetSpawn(state);
  4869. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4870. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4871. if (!spawn) {
  4872. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4873. return 0;
  4874. }
  4875. if (!spawn->IsEntity()) {
  4876. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4877. return 0;
  4878. }
  4879. if (((Entity*)spawn)->GetDeityPet()) {
  4880. if (spawn->IsPlayer()) {
  4881. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4882. if (client)
  4883. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4884. }
  4885. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4886. return 0;
  4887. }
  4888. if (pet_id == 0) {
  4889. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4890. return 0;
  4891. }
  4892. if (!luaspell) {
  4893. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4894. return 0;
  4895. }
  4896. if(luaspell->resisted) {
  4897. return 0;
  4898. }
  4899. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4900. if (!pet) {
  4901. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4902. return 0;
  4903. }
  4904. if (!pet->IsNPC()) {
  4905. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4906. return 0;
  4907. }
  4908. pet->SetX(spawn->GetX());
  4909. pet->SetY(spawn->GetY());
  4910. pet->SetZ(spawn->GetZ());
  4911. pet->SetLocation(spawn->GetLocation());
  4912. pet->SetHeading(spawn->GetHeading());
  4913. spawn->GetZone()->AddSpawn(pet);
  4914. string random_pet_name;
  4915. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4916. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4917. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4918. pet->SetName(random_pet_name.c_str());
  4919. pet->SetLevel(spawn->GetLevel());
  4920. pet->SetFactionID(spawn->GetFactionID());
  4921. pet->SetPet(true);
  4922. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4923. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4924. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4925. pet->SetSpawnType(6);
  4926. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4927. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4928. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4929. if (strlen(pet->GetSubTitle()) > 0) {
  4930. string pet_subtitle;
  4931. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4932. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4933. pet->SetSubTitle(pet_subtitle.c_str());
  4934. }
  4935. // deity and cosmetic pets are not attackable
  4936. pet->SetAttackable(false);
  4937. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4938. lua_interface->SetSpawnValue(state, pet);
  4939. return 1;
  4940. }
  4941. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4942. if (!lua_interface)
  4943. return 0;
  4944. Spawn* spawn = lua_interface->GetSpawn(state);
  4945. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4946. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4947. if (!spawn) {
  4948. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4949. return 0;
  4950. }
  4951. if (!spawn->IsEntity()) {
  4952. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4953. return 0;
  4954. }
  4955. if (((Entity*)spawn)->GetCosmeticPet()) {
  4956. if (spawn->IsPlayer()) {
  4957. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4958. if (client)
  4959. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4960. }
  4961. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4962. return 0;
  4963. }
  4964. if (pet_id == 0) {
  4965. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4966. return 0;
  4967. }
  4968. if (!luaspell) {
  4969. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4970. return 0;
  4971. }
  4972. if(luaspell->resisted) {
  4973. return 0;
  4974. }
  4975. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4976. if (!pet) {
  4977. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4978. return 0;
  4979. }
  4980. if (!pet->IsNPC()) {
  4981. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4982. return 0;
  4983. }
  4984. pet->SetX(spawn->GetX());
  4985. pet->SetY(spawn->GetY());
  4986. pet->SetZ(spawn->GetZ());
  4987. pet->SetLocation(spawn->GetLocation());
  4988. pet->SetHeading(spawn->GetHeading());
  4989. spawn->GetZone()->AddSpawn(pet);
  4990. string random_pet_name;
  4991. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4992. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4993. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4994. pet->SetName(random_pet_name.c_str());
  4995. pet->SetLevel(spawn->GetLevel());
  4996. pet->SetFactionID(spawn->GetFactionID());
  4997. pet->SetPet(true);
  4998. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4999. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5000. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5001. pet->SetSpawnType(6);
  5002. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5003. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5004. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5005. if (strlen(pet->GetSubTitle()) > 0) {
  5006. string pet_subtitle;
  5007. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5008. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5009. pet->SetSubTitle(pet_subtitle.c_str());
  5010. }
  5011. pet->SetAttackable(false);
  5012. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5013. lua_interface->SetSpawnValue(state, pet);
  5014. return 1;
  5015. }
  5016. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5017. if (!lua_interface)
  5018. return 0;
  5019. Spawn* spawn = lua_interface->GetSpawn(state);
  5020. if (!spawn) {
  5021. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5022. return 0;
  5023. }
  5024. if (!spawn->IsPet()) {
  5025. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5026. return 0;
  5027. }
  5028. if (!((NPC*)spawn)->IsDismissing())
  5029. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5030. return 0;
  5031. }
  5032. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5033. if (!lua_interface)
  5034. return 0;
  5035. Quest* quest = lua_interface->GetQuest(state);
  5036. if (!quest) {
  5037. 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));
  5038. return 0;
  5039. }
  5040. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5041. if (feather_color > 0)
  5042. quest->SetFeatherColor(feather_color);
  5043. return 0;
  5044. }
  5045. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5046. if (!lua_interface)
  5047. return 0;
  5048. Spawn* spawn = lua_interface->GetSpawn(state);
  5049. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5050. if (!spawn) {
  5051. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5052. return 0;
  5053. }
  5054. if (!spawn2) {
  5055. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5056. return 0;
  5057. }
  5058. spawn->RemoveSpawnAccess(spawn2);
  5059. return 0;
  5060. }
  5061. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5062. if (!lua_interface)
  5063. return 0;
  5064. ZoneServer* zone = lua_interface->GetZone(state);
  5065. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5066. if (!zone) {
  5067. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5068. return 0;
  5069. }
  5070. if (location_id == 0) {
  5071. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5072. return 0;
  5073. }
  5074. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5075. if (!location) {
  5076. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5077. return 0;
  5078. }
  5079. Spawn* spawn = 0;
  5080. if (location->entities[0]) {
  5081. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5082. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5083. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5084. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5085. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5086. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5087. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5088. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5089. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5090. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5091. if(spawn && spawn->IsOmittedByDBFlag())
  5092. {
  5093. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5094. safe_delete(spawn);
  5095. spawn = 0;
  5096. return 0;
  5097. }
  5098. if (spawn) {
  5099. const char* script = 0;
  5100. for (int x = 0; x < 3; x++) {
  5101. switch (x) {
  5102. case 0:
  5103. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5104. break;
  5105. case 1:
  5106. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5107. break;
  5108. case 2:
  5109. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5110. break;
  5111. }
  5112. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5113. spawn->SetSpawnScript(string(script));
  5114. break;
  5115. }
  5116. }
  5117. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5118. lua_interface->SetSpawnValue(state, spawn);
  5119. return 1;
  5120. }
  5121. else {
  5122. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5123. safe_delete(spawn);
  5124. }
  5125. }
  5126. return 0;
  5127. }
  5128. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5129. if (!lua_interface)
  5130. return 0;
  5131. Spawn* caster = lua_interface->GetSpawn(state);
  5132. Spawn* target = lua_interface->GetSpawn(state, 2);
  5133. int32 id = lua_interface->GetInt32Value(state, 3);
  5134. string command = lua_interface->GetStringValue(state, 4);
  5135. if (!caster) {
  5136. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5137. return 0;
  5138. }
  5139. if (!target) {
  5140. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5141. return 0;
  5142. }
  5143. if (!caster->IsPlayer()) {
  5144. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5145. return 0;
  5146. }
  5147. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5148. if (!entity_command) {
  5149. 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());
  5150. return 0;
  5151. }
  5152. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5153. if (!client) {
  5154. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5155. return 0;
  5156. }
  5157. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. Spawn* spawn = lua_interface->GetSpawn(state);
  5164. if (!spawn) {
  5165. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5166. return 0;
  5167. }
  5168. if (!spawn->IsNPC()) {
  5169. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5170. return 0;
  5171. }
  5172. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5173. return 0;
  5174. }
  5175. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5176. if (!lua_interface)
  5177. return 0;
  5178. Spawn* spawn = lua_interface->GetSpawn(state);
  5179. int16 tick = lua_interface->GetInt16Value(state, 2);
  5180. if (!spawn) {
  5181. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5182. return 0;
  5183. }
  5184. if (!spawn->IsNPC()) {
  5185. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5186. return 0;
  5187. }
  5188. if (tick < 20) {
  5189. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5190. return 0;
  5191. }
  5192. ((NPC*)spawn)->Brain()->SetTick(tick);
  5193. return 0;
  5194. }
  5195. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5196. if (!lua_interface)
  5197. return 0;
  5198. Spawn* spawn = lua_interface->GetSpawn(state);
  5199. Spawn* target = lua_interface->GetSpawn(state, 2);
  5200. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5201. if (!spawn) {
  5202. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5203. return 0;
  5204. }
  5205. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5206. spawn->SetFollowTarget(target, follow_distance);
  5207. return 0;
  5208. }
  5209. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5210. if (!lua_interface)
  5211. return 0;
  5212. Spawn* spawn = lua_interface->GetSpawn(state);
  5213. if (!spawn) {
  5214. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5215. return 0;
  5216. }
  5217. Spawn* target = spawn->GetFollowTarget();
  5218. if (target) {
  5219. lua_interface->SetSpawnValue(state, target);
  5220. return 1;
  5221. }
  5222. return 0;
  5223. }
  5224. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5225. if (!lua_interface)
  5226. return 0;
  5227. Spawn* spawn = lua_interface->GetSpawn(state);
  5228. if (!spawn) {
  5229. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5230. return 0;
  5231. }
  5232. if (spawn->following)
  5233. spawn->following = false;
  5234. else
  5235. spawn->following = true;
  5236. return 0;
  5237. }
  5238. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5239. if (!lua_interface)
  5240. return 0;
  5241. Spawn* spawn = lua_interface->GetSpawn(state);
  5242. if (!spawn) {
  5243. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5244. return 0;
  5245. }
  5246. lua_interface->SetBooleanValue(state, spawn->following);
  5247. return 1;
  5248. }
  5249. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5250. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5251. // I will attempt to explain how this function works for future refrence
  5252. // Fist lets make sure lua_interface is valid, if not return out
  5253. if (!lua_interface)
  5254. return 0;
  5255. // Next we grab the first 2 params same as we usually would
  5256. Spawn* spawn = lua_interface->GetSpawn(state);
  5257. string var = lua_interface->GetStringValue(state, 2);
  5258. // 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
  5259. // 1 = Spawn
  5260. // 2 = Zone
  5261. // 3 = Item
  5262. // 4 = Quest
  5263. // 5 = String
  5264. // 6 = nil (null)
  5265. int8 dataType = 0;
  5266. // Define pointers for each potential type
  5267. Spawn* spawnVal = 0;
  5268. ZoneServer* zone = 0;
  5269. Item* item = 0;
  5270. Quest* quest = 0;
  5271. string val;
  5272. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5273. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5274. // options window are also light user data be we do not handle those.
  5275. // We check with lua_islightuserdata(lua_State*, index)
  5276. if (lua_islightuserdata(state, 3)) {
  5277. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5278. // and convert it to LUAUserData*
  5279. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5280. // Check to make sure the data we got is valid, if not give an error
  5281. if (!data || !data->IsCorrectlyInitialized()) {
  5282. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5283. }
  5284. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5285. else if (data->IsSpawn()) {
  5286. spawnVal = data->spawn;
  5287. dataType = 1;
  5288. }
  5289. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5290. else if (data->IsZone()) {
  5291. zone = data->zone;
  5292. dataType = 2;
  5293. }
  5294. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5295. else if (data->IsItem()) {
  5296. item = data->item;
  5297. dataType = 3;
  5298. }
  5299. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5300. else if (data->IsQuest()) {
  5301. quest = data->quest;
  5302. dataType = 4;
  5303. }
  5304. }
  5305. // Wasn't light user data, check if it is nil(null)
  5306. else if (lua_isnil(state, 3)) {
  5307. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5308. dataType = 6;
  5309. }
  5310. // Wasn't light user data or nil (null), must be a string
  5311. else {
  5312. // Set the string and dataType variable
  5313. val = lua_interface->GetStringValue(state, 3);
  5314. dataType = 5;
  5315. }
  5316. // We now have all the params, lets check to make sure they are valid
  5317. if (!spawn) {
  5318. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. if (var.length() == 0) {
  5322. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5323. return 0;
  5324. }
  5325. if (dataType == 0) {
  5326. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5327. return 0;
  5328. }
  5329. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5330. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5331. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5332. switch (dataType) {
  5333. case 1:
  5334. // 1 = Spawn
  5335. spawn->AddTempVariable(var, spawnVal);
  5336. break;
  5337. case 2:
  5338. // 2 = Zone
  5339. spawn->AddTempVariable(var, zone);
  5340. break;
  5341. case 3:
  5342. // 3 = Item
  5343. spawn->AddTempVariable(var, item);
  5344. break;
  5345. case 4:
  5346. // 4 = Quest
  5347. spawn->AddTempVariable(var, quest);
  5348. break;
  5349. case 5:
  5350. // 5 = String
  5351. spawn->AddTempVariable(var, val);
  5352. break;
  5353. case 6:
  5354. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5355. spawn->DeleteTempVariable(var);
  5356. break;
  5357. }
  5358. // And we are done so return out
  5359. return 0;
  5360. }
  5361. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5362. if (!lua_interface)
  5363. return 0;
  5364. Spawn* spawn = lua_interface->GetSpawn(state);
  5365. string var = lua_interface->GetStringValue(state, 2);
  5366. if (!spawn) {
  5367. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5368. return 0;
  5369. }
  5370. if (var.length() == 0) {
  5371. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5372. return 0;
  5373. }
  5374. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5375. int8 type = spawn->GetTempVariableType(var);
  5376. Spawn* spawn2 = 0;
  5377. ZoneServer* zone = 0;
  5378. Item* item = 0;
  5379. Quest* quest = 0;
  5380. // Set the lua function return value based on the type of data the variable contains
  5381. switch (type) {
  5382. case 1:
  5383. spawn2 = spawn->GetTempVariableSpawn(var);
  5384. if (!spawn2)
  5385. return 0;
  5386. lua_interface->SetSpawnValue(state, spawn2);
  5387. break;
  5388. case 2:
  5389. zone = spawn->GetTempVariableZone(var);
  5390. if (!zone)
  5391. return 0;
  5392. lua_interface->SetZoneValue(state, zone);
  5393. break;
  5394. case 3:
  5395. item = spawn->GetTempVariableItem(var);
  5396. if (!item)
  5397. return 0;
  5398. lua_interface->SetItemValue(state, item);
  5399. break;
  5400. case 4:
  5401. quest = spawn->GetTempVariableQuest(var);
  5402. if (!quest)
  5403. return 0;
  5404. lua_interface->SetQuestValue(state, quest);
  5405. break;
  5406. case 5:
  5407. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5408. break;
  5409. default:
  5410. // Not a valid type then the variable was not set so return out
  5411. return 0;
  5412. }
  5413. // Return value was set so return out
  5414. return 1;
  5415. }
  5416. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5417. {
  5418. if (!lua_interface)
  5419. return 0;
  5420. Quest* quest = lua_interface->GetQuest(state);
  5421. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5422. string description = lua_interface->GetStringValue(state, 3);
  5423. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5424. if (!quest) {
  5425. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5426. lua_interface->SetBooleanValue(state, false);
  5427. return 1;
  5428. }
  5429. if (!spawn) {
  5430. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5431. lua_interface->SetBooleanValue(state, false);
  5432. return 1;
  5433. }
  5434. if (!spawn->IsPlayer()) {
  5435. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5436. lua_interface->SetBooleanValue(state, false);
  5437. return 1;
  5438. }
  5439. if (item_id == 0) {
  5440. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5441. lua_interface->SetBooleanValue(state, false);
  5442. return 1;
  5443. }
  5444. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5445. if (!client) {
  5446. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5447. lua_interface->SetBooleanValue(state, false);
  5448. return 1;
  5449. }
  5450. Item* item = master_item_list.GetItem(item_id);
  5451. if (!item) {
  5452. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5453. lua_interface->SetBooleanValue(state, false);
  5454. return 1;
  5455. }
  5456. Item* firstItem = new Item(item);
  5457. quest->AddTmpRewardItem(firstItem);
  5458. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5459. bool itemsAddedSuccessfully = true;
  5460. if(num_args > 4)
  5461. {
  5462. for(int8 n=5;n<num_args+1;n++)
  5463. {
  5464. int32 new_item = lua_interface->GetInt32Value(state, n);
  5465. Item* tmpItem = master_item_list.GetItem(new_item);
  5466. if(tmpItem)
  5467. {
  5468. Item* newTmpItem = new Item(tmpItem);
  5469. quest->AddTmpRewardItem(newTmpItem);
  5470. }
  5471. else
  5472. itemsAddedSuccessfully = false;
  5473. }
  5474. }
  5475. client->AddPendingQuestAcceptReward(quest);
  5476. client->DisplayQuestComplete(quest, true, description);
  5477. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5478. return 1;
  5479. }
  5480. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5481. if (!lua_interface)
  5482. return 0;
  5483. Quest* quest = lua_interface->GetQuest(state);
  5484. if (!quest) {
  5485. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5486. return 0;
  5487. }
  5488. quest->SetRepeatable(true);
  5489. return 0;
  5490. }
  5491. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5492. if (!lua_interface)
  5493. return 0;
  5494. Spawn* spawn = lua_interface->GetSpawn(state);
  5495. if (!spawn) {
  5496. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5497. return 0;
  5498. }
  5499. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5500. string ret = classes.GetClassNameCase(base_class);
  5501. if (ret.length() > 0) {
  5502. lua_interface->SetStringValue(state, ret.c_str());
  5503. return 1;
  5504. }
  5505. return 0;
  5506. }
  5507. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5508. if (!lua_interface)
  5509. return 0;
  5510. Spawn* player = lua_interface->GetSpawn(state);
  5511. if (player && player->IsPlayer()) {
  5512. Client* client = player->GetClient();
  5513. if (client)
  5514. client->SendWaypoints();
  5515. }
  5516. return 0;
  5517. }
  5518. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5519. if (!lua_interface)
  5520. return 0;
  5521. Spawn* player = lua_interface->GetSpawn(state);
  5522. string name = lua_interface->GetStringValue(state, 2);
  5523. int32 type = lua_interface->GetInt32Value(state, 3);
  5524. if (type == 0)
  5525. type = 2;
  5526. if (name.length() > 0) {
  5527. if (player && player->IsPlayer()) {
  5528. Client* client = player->GetClient();
  5529. if (client)
  5530. client->AddWaypoint(name, type);
  5531. }
  5532. }
  5533. return 0;
  5534. }
  5535. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5536. if (!lua_interface)
  5537. return 0;
  5538. Spawn* player = lua_interface->GetSpawn(state);
  5539. string name = lua_interface->GetStringValue(state, 2);
  5540. if (name.length() > 0) {
  5541. if (player && player->IsPlayer()) {
  5542. Client* client = player->GetClient();
  5543. if (client)
  5544. client->RemoveWaypoint(name);
  5545. }
  5546. }
  5547. return 0;
  5548. }
  5549. int EQ2Emu_lua_AddWard(lua_State* state) {
  5550. if (!lua_interface)
  5551. return 0;
  5552. int32 damage = lua_interface->GetInt32Value(state);
  5553. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5554. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5555. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5556. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5557. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5558. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5559. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5560. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5561. if(!spell || spell->resisted) {
  5562. return 0;
  5563. }
  5564. bool ward_was_added = false;
  5565. ZoneServer* zone = spell->caster->GetZone();
  5566. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5567. for (int32 i = 0; i < spell->targets.size(); i++) {
  5568. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5569. if (!target)
  5570. continue;
  5571. if (target->IsEntity()) {
  5572. // If the ward is already active remove it
  5573. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5574. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5575. // Create new ward info
  5576. WardInfo* ward = new WardInfo;
  5577. ward->Spell = spell;
  5578. ward->BaseDamage = damage;
  5579. ward->DamageLeft = damage;
  5580. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5581. ward->keepWard = keepWard;
  5582. ward->WardType = wardType;
  5583. if (damageAbsorptionPercent > 100)
  5584. damageAbsorptionPercent = 100;
  5585. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5586. if (damageAbsorptionMaxHealthPercent > 100)
  5587. damageAbsorptionMaxHealthPercent = 100;
  5588. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5589. ward->RedirectDamagePercent = redirectDamagePercent;
  5590. ward->LastRedirectDamage = 0;
  5591. ward->LastAbsorbedDamage = 0;
  5592. ward->HitCount = 0;
  5593. spell->num_triggers = maxHitCount;
  5594. spell->had_triggers = true;
  5595. spell->cancel_after_all_triggers = false;
  5596. ward->MaxHitCount = maxHitCount;
  5597. if (wardType == WARD_TYPE_MAGICAL)
  5598. ward->DamageType = damageTypes;
  5599. // Add the ward to the entity
  5600. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5601. ward_was_added = true;
  5602. }
  5603. }
  5604. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5605. if (ward_was_added && spell->caster->IsPlayer()) {
  5606. spell->had_dmg_remaining = true;
  5607. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5608. }
  5609. return 0;
  5610. }
  5611. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5612. if (!lua_interface)
  5613. return 0;
  5614. int32 amount = lua_interface->GetInt32Value(state);
  5615. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5616. WardInfo* ward = 0;
  5617. if(!spell || spell->resisted) {
  5618. return 0;
  5619. }
  5620. ZoneServer* zone = spell->caster->GetZone();
  5621. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5622. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5623. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5624. ward = target->GetWard(spell->spell->GetSpellID());
  5625. if (target && ward) {
  5626. ward->DamageLeft += amount;
  5627. if (ward->DamageLeft > ward->BaseDamage)
  5628. ward->DamageLeft = ward->BaseDamage;
  5629. for (int32 i = 0; i < spell->targets.size(); i++) {
  5630. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5631. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5632. }
  5633. }
  5634. }
  5635. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5636. if (ward && spell->caster->IsPlayer())
  5637. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5638. return 0;
  5639. }
  5640. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5641. if (!lua_interface)
  5642. return 0;
  5643. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5644. if (!spell) {
  5645. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5646. return 0;
  5647. }
  5648. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5649. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5650. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5651. if (ward) {
  5652. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5653. return 1;
  5654. }
  5655. }
  5656. return 0;
  5657. }
  5658. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5659. if (!lua_interface)
  5660. return 0;
  5661. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5662. if (!spell) {
  5663. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5664. return 0;
  5665. }
  5666. string type = lua_interface->GetStringValue(state, 2);
  5667. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5668. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5669. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5670. if (ward) {
  5671. if (boost::iequals(type, "damageleft"))
  5672. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5673. else if (boost::iequals(type, "basedamage"))
  5674. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5675. else if (boost::iequals(type, "keepward"))
  5676. lua_interface->SetBooleanValue(state, ward->keepWard);
  5677. else if (boost::iequals(type, "wardtype"))
  5678. lua_interface->SetInt32Value(state, ward->WardType);
  5679. else if (boost::iequals(type, "dmgabsorptionpct"))
  5680. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5681. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5682. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5683. else if (boost::iequals(type, "redirectdamagepercent"))
  5684. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5685. else if (boost::iequals(type, "lastredirectdamage"))
  5686. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5687. else if (boost::iequals(type, "lastabsorbeddamage"))
  5688. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5689. else if (boost::iequals(type, "hitcount"))
  5690. lua_interface->SetInt32Value(state, ward->HitCount);
  5691. else if (boost::iequals(type, "maxhitcount"))
  5692. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5693. else
  5694. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5695. return 1;
  5696. }
  5697. }
  5698. return 0;
  5699. }
  5700. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5701. if (!lua_interface)
  5702. return 0;
  5703. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5704. if(!spell) {
  5705. return 0;
  5706. }
  5707. ZoneServer* zone = spell->caster->GetZone();
  5708. Spawn* target = 0;
  5709. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5710. for (int32 i = 0; i < spell->targets.size(); i++) {
  5711. target = zone->GetSpawnByID(spell->targets.at(i));
  5712. if (target && target->IsEntity()) {
  5713. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5714. }
  5715. }
  5716. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5717. return 0;
  5718. }
  5719. int EQ2Emu_lua_Interrupt(lua_State* state)
  5720. {
  5721. if (!lua_interface)
  5722. return 0;
  5723. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5724. Spawn* target = lua_interface->GetSpawn(state, 2);
  5725. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5726. if (!caster)
  5727. {
  5728. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5729. return 0;
  5730. }
  5731. if (!target)
  5732. {
  5733. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5734. return 0;
  5735. }
  5736. if (!spell) {
  5737. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5738. return 0;
  5739. }
  5740. if (!target->IsEntity() && !spell)
  5741. {
  5742. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5743. return 0;
  5744. }
  5745. if (!target && spell) {
  5746. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5747. for (int8 i = 0; i < spell->targets.size(); i++) {
  5748. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5749. if (!target || !target->IsEntity())
  5750. continue;
  5751. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5752. }
  5753. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5754. }
  5755. else
  5756. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5757. return 0;
  5758. }
  5759. int EQ2Emu_lua_Stealth(lua_State* state) {
  5760. if (!lua_interface)
  5761. return 0;
  5762. int8 type = lua_interface->GetInt8Value(state);
  5763. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5764. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5765. if (!spell) {
  5766. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5767. return 0;
  5768. }
  5769. ZoneServer* zone = spell->caster->GetZone();
  5770. if (spawn) {
  5771. if (spawn->IsEntity()) {
  5772. if (type == 1) {
  5773. ((Entity*)spawn)->AddStealthSpell(spell);
  5774. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5775. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5776. }
  5777. else if (type == 2) {
  5778. ((Entity*)spawn)->AddInvisSpell(spell);
  5779. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5780. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5781. }
  5782. return 0;
  5783. }
  5784. else {
  5785. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5786. return 0;
  5787. }
  5788. }
  5789. else {
  5790. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5791. for (int32 i = 0; i < spell->targets.size(); i++) {
  5792. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5793. if (!spawn || !spawn->IsEntity())
  5794. continue;
  5795. if (type == 1) {
  5796. ((Entity*)spawn)->AddStealthSpell(spell);
  5797. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5798. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5799. }
  5800. else if (type == 2) {
  5801. ((Entity*)spawn)->AddInvisSpell(spell);
  5802. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5803. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5804. }
  5805. else {
  5806. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5807. break;
  5808. }
  5809. }
  5810. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5811. }
  5812. return 0;
  5813. }
  5814. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5815. if (!lua_interface)
  5816. return 0;
  5817. Spawn* spawn = lua_interface->GetSpawn(state);
  5818. if (!spawn) {
  5819. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5820. return 0;
  5821. }
  5822. if (spawn->IsEntity()) {
  5823. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5824. return 1;
  5825. }
  5826. else
  5827. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5828. return 0;
  5829. }
  5830. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5831. if (!lua_interface)
  5832. return 0;
  5833. Spawn* spawn = lua_interface->GetSpawn(state);
  5834. if (!spawn) {
  5835. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5836. return 0;
  5837. }
  5838. if (spawn->IsEntity()) {
  5839. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5840. return 1;
  5841. }
  5842. else
  5843. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5844. return 0;
  5845. }
  5846. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5847. if (!lua_interface)
  5848. return 0;
  5849. Spawn* player = lua_interface->GetSpawn(state);
  5850. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5851. lua_interface->ResetFunctionStack(state);
  5852. if (!player->IsPlayer()) {
  5853. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5854. return 0;
  5855. }
  5856. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5857. return 1;
  5858. }
  5859. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5860. if (!lua_interface)
  5861. return 0;
  5862. Spawn* player = lua_interface->GetSpawn(state);
  5863. int8 slot = lua_interface->GetInt8Value(state, 2);
  5864. lua_interface->ResetFunctionStack(state);
  5865. if (!player) {
  5866. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5867. return 0;
  5868. }
  5869. if (!player->IsPlayer()) {
  5870. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5871. return 0;
  5872. }
  5873. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5874. if (!item) {
  5875. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5876. return 0;
  5877. }
  5878. lua_interface->SetItemValue(state, item);
  5879. return 1;
  5880. }
  5881. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5882. if (!lua_interface)
  5883. return 0;
  5884. Spawn* player = lua_interface->GetSpawn(state);
  5885. int32 id = lua_interface->GetInt32Value(state, 2);
  5886. lua_interface->ResetFunctionStack(state);
  5887. if (!player) {
  5888. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5889. return 0;
  5890. }
  5891. if (!player->IsPlayer()) {
  5892. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5893. return 0;
  5894. }
  5895. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5896. if (!item) {
  5897. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5898. return 0;
  5899. }
  5900. lua_interface->SetItemValue(state, item);
  5901. return 1;
  5902. }
  5903. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5904. if (!lua_interface)
  5905. return 0;
  5906. Spawn* spawn = lua_interface->GetSpawn(state);
  5907. int8 slot = lua_interface->GetInt8Value(state, 2);
  5908. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5909. lua_interface->ResetFunctionStack(state);
  5910. if (!spawn) {
  5911. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5912. return 0;
  5913. }
  5914. if (!spawn->IsEntity()) {
  5915. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5916. return 0;
  5917. }
  5918. Item* item = master_item_list.GetItem(item_id);
  5919. if (!item) {
  5920. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5921. return 0;
  5922. }
  5923. Item* copy = new Item(item);
  5924. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5925. if(result)
  5926. {
  5927. ((Entity*)spawn)->SetEquipment(copy, slot);
  5928. spawn->vis_changed = true;
  5929. if(spawn->IsPlayer())
  5930. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5931. }
  5932. else
  5933. {
  5934. safe_delete(copy);
  5935. }
  5936. lua_interface->SetBooleanValue(state, result);
  5937. return 1;
  5938. }
  5939. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5940. if (!lua_interface)
  5941. return 0;
  5942. Spawn* spawn = lua_interface->GetSpawn(state);
  5943. int8 slot = lua_interface->GetInt8Value(state, 2);
  5944. Item* item = lua_interface->GetItem(state, 3);
  5945. lua_interface->ResetFunctionStack(state);
  5946. if (!spawn) {
  5947. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5948. return 0;
  5949. }
  5950. if (!spawn->IsEntity()) {
  5951. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5952. return 0;
  5953. }
  5954. if (!item) {
  5955. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5956. return 0;
  5957. }
  5958. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5959. if(result)
  5960. {
  5961. ((Entity*)spawn)->SetEquipment(item, slot);
  5962. spawn->vis_changed = true;
  5963. if(spawn->IsPlayer())
  5964. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5965. }
  5966. lua_interface->SetBooleanValue(state, result);
  5967. return 1;
  5968. }
  5969. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5970. if (!lua_interface)
  5971. return 0;
  5972. Spawn* spawn = lua_interface->GetSpawn(state);
  5973. int8 slot = lua_interface->GetInt8Value(state, 2);
  5974. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5975. lua_interface->ResetFunctionStack(state);
  5976. if (!spawn) {
  5977. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5978. return 0;
  5979. }
  5980. if (!spawn->IsEntity()) {
  5981. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5982. return 0;
  5983. }
  5984. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5985. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5986. spawn->vis_changed = true;
  5987. if(spawn->IsPlayer())
  5988. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5989. lua_interface->SetBooleanValue(state, true);
  5990. return 1;
  5991. }
  5992. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5993. if (!lua_interface)
  5994. return 0;
  5995. Spawn* spawn = lua_interface->GetSpawn(state);
  5996. int8 slot = lua_interface->GetInt8Value(state, 2);
  5997. int16 type = lua_interface->GetInt16Value(state, 3);
  5998. int8 r = lua_interface->GetInt8Value(state, 4);
  5999. int8 g = lua_interface->GetInt8Value(state, 5);
  6000. int8 b = lua_interface->GetInt8Value(state, 6);
  6001. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6002. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6003. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6004. lua_interface->ResetFunctionStack(state);
  6005. if (!spawn) {
  6006. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. if (!spawn->IsEntity()) {
  6010. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6011. return 0;
  6012. }
  6013. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6014. spawn->vis_changed = true;
  6015. lua_interface->SetBooleanValue(state, true);
  6016. return 1;
  6017. }
  6018. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6019. if (!lua_interface)
  6020. return 0;
  6021. Spawn* player = lua_interface->GetSpawn(state);
  6022. int32 id = lua_interface->GetInt32Value(state, 2);
  6023. int8 count = lua_interface->GetInt8Value(state, 3);
  6024. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6025. lua_interface->ResetFunctionStack(state);
  6026. if (!player) {
  6027. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6028. return 0;
  6029. }
  6030. if (!player->IsPlayer()) {
  6031. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6032. return 0;
  6033. }
  6034. if (!count)
  6035. count = 1;
  6036. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6037. if (!item) {
  6038. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6039. return 0;
  6040. }
  6041. lua_interface->SetItemValue(state, item);
  6042. return 1;
  6043. }
  6044. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6045. if (!lua_interface)
  6046. return 0;
  6047. Spawn* spawn = lua_interface->GetSpawn(state);
  6048. int32 anim = lua_interface->GetInt32Value(state, 2);
  6049. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6050. int8 type = lua_interface->GetInt8Value(state, 4);
  6051. if (!spawn) {
  6052. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6053. return 0;
  6054. }
  6055. if (spawn2) {
  6056. if (spawn2->IsPlayer()) {
  6057. if (type != 1 && type != 2)
  6058. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6059. else
  6060. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6061. return 0;
  6062. }
  6063. else {
  6064. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6065. return 0;
  6066. }
  6067. }
  6068. else
  6069. spawn->GetZone()->PlayAnimation(spawn, anim);
  6070. return 0;
  6071. }
  6072. int EQ2Emu_lua_IsPet(lua_State* state) {
  6073. if (!lua_interface)
  6074. return 0;
  6075. Spawn* spawn = lua_interface->GetSpawn(state);
  6076. if (!spawn) {
  6077. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6078. return 0;
  6079. }
  6080. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6081. return 1;
  6082. }
  6083. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6084. if (!lua_interface)
  6085. return 0;
  6086. Spawn* spawn = lua_interface->GetSpawn(state);
  6087. if (!spawn) {
  6088. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6089. return 0;
  6090. }
  6091. if (!spawn->IsNPC()) {
  6092. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6093. return 0;
  6094. }
  6095. if (((NPC*)spawn)->GetOwner()) {
  6096. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6097. return 1;
  6098. }
  6099. return 0;
  6100. }
  6101. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6102. if (!lua_interface)
  6103. return 0;
  6104. Spawn* spawn = lua_interface->GetSpawn(state);
  6105. Spawn* target = lua_interface->GetSpawn(state, 2);
  6106. if (!spawn) {
  6107. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6108. return 0;
  6109. }
  6110. if (!spawn) {
  6111. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6112. return 0;
  6113. }
  6114. spawn->SetTarget(target);
  6115. return 0;
  6116. }
  6117. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6118. if (!lua_interface)
  6119. return 0;
  6120. Spawn* spawn = lua_interface->GetSpawn(state);
  6121. bool val = lua_interface->GetBooleanValue(state, 2);
  6122. if (!spawn) {
  6123. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6124. return 0;
  6125. }
  6126. if (!spawn->IsEntity()) {
  6127. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6128. return 0;
  6129. }
  6130. ((Entity*)spawn)->InCombat(val);
  6131. if (val) {
  6132. spawn->ClearRunningLocations();
  6133. spawn->CalculateRunningLocation(true);
  6134. }
  6135. return 0;
  6136. }
  6137. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6138. if (!lua_interface)
  6139. return 0;
  6140. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6141. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6142. if (!spawn1) {
  6143. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. if (!spawn2) {
  6147. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6148. return 0;
  6149. }
  6150. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6151. return 1;
  6152. }
  6153. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6154. if (!lua_interface)
  6155. return 0;
  6156. Spawn* spawn = lua_interface->GetSpawn(state);
  6157. if (!spawn) {
  6158. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6159. return 0;
  6160. }
  6161. if (!spawn->IsNPC()) {
  6162. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6163. return 0;
  6164. }
  6165. ((NPC*)spawn)->ClearRunback();
  6166. return 0;
  6167. }
  6168. int EQ2Emu_lua_Runback(lua_State* state) {
  6169. if (!lua_interface)
  6170. return 0;
  6171. Spawn* spawn = lua_interface->GetSpawn(state);
  6172. if (!spawn) {
  6173. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6174. return 0;
  6175. }
  6176. if (!spawn->IsNPC()) {
  6177. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6178. return 0;
  6179. }
  6180. ((NPC*)spawn)->Runback();
  6181. return 0;
  6182. }
  6183. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6184. if (!lua_interface)
  6185. return 0;
  6186. Spawn* spawn = lua_interface->GetSpawn(state);
  6187. if (!spawn) {
  6188. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6189. return 0;
  6190. }
  6191. if (!spawn->IsNPC()) {
  6192. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6193. return 0;
  6194. }
  6195. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6196. return 1;
  6197. }
  6198. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6199. if (!lua_interface)
  6200. return 0;
  6201. Spawn* spawn = lua_interface->GetSpawn(state);
  6202. if (!spawn) {
  6203. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6204. return 0;
  6205. }
  6206. if (!spawn->IsEntity()) {
  6207. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6208. return 0;
  6209. }
  6210. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6211. return 1;
  6212. }
  6213. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6214. if (!lua_interface)
  6215. return 0;
  6216. Spawn* spawn = lua_interface->GetSpawn(state);
  6217. if (!spawn) {
  6218. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6219. return 0;
  6220. }
  6221. if (!spawn->IsEntity()) {
  6222. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6223. return 0;
  6224. }
  6225. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6226. return 1;
  6227. }
  6228. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6229. if (!lua_interface)
  6230. return 0;
  6231. Spawn* spawn = lua_interface->GetSpawn(state);
  6232. if (!spawn) {
  6233. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6234. return 0;
  6235. }
  6236. if (!spawn->IsEntity()) {
  6237. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6241. return 1;
  6242. }
  6243. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6244. if (!lua_interface)
  6245. return 0;
  6246. Spawn* spawn = lua_interface->GetSpawn(state);
  6247. if (!spawn) {
  6248. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6249. return 0;
  6250. }
  6251. if (!spawn->IsEntity()) {
  6252. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6253. return 0;
  6254. }
  6255. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6256. return 1;
  6257. }
  6258. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6259. if (!lua_interface)
  6260. return 0;
  6261. Spawn* spawn = lua_interface->GetSpawn(state);
  6262. Spawn* target = lua_interface->GetSpawn(state, 2);
  6263. float distance = lua_interface->GetFloatValue(state, 3);
  6264. if (!spawn) {
  6265. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6266. return 0;
  6267. }
  6268. if (!target) {
  6269. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. if (!spawn->IsNPC()) {
  6273. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6274. return 0;
  6275. }
  6276. if (!target->IsEntity()) {
  6277. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6278. return 0;
  6279. }
  6280. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6281. return 1;
  6282. }
  6283. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6284. if (!lua_interface)
  6285. return 0;
  6286. Spawn* spawn = lua_interface->GetSpawn(state);
  6287. Spawn* target = lua_interface->GetSpawn(state, 2);
  6288. float distance = lua_interface->GetFloatValue(state, 3);
  6289. if (!spawn) {
  6290. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. if (!target) {
  6294. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6295. return 0;
  6296. }
  6297. if (!spawn->IsNPC()) {
  6298. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6299. return 0;
  6300. }
  6301. if (!target->IsEntity()) {
  6302. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6303. return 0;
  6304. }
  6305. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6306. return 0;
  6307. }
  6308. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6309. if (!lua_interface)
  6310. return 0;
  6311. Spawn* spawn = lua_interface->GetSpawn(state);
  6312. if (!spawn) {
  6313. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6314. return 0;
  6315. }
  6316. if (!spawn->IsNPC()) {
  6317. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6318. return 0;
  6319. }
  6320. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6321. return 1;
  6322. }
  6323. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6324. if (!lua_interface)
  6325. return 0;
  6326. Spawn* spawn = lua_interface->GetSpawn(state);
  6327. if (!spawn) {
  6328. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6329. return 0;
  6330. }
  6331. if (!spawn->IsNPC()) {
  6332. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6333. return 0;
  6334. }
  6335. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6336. return 1;
  6337. }
  6338. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6339. if (!lua_interface)
  6340. return 0;
  6341. Spawn* spawn = lua_interface->GetSpawn(state);
  6342. if (!spawn) {
  6343. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6344. return 0;
  6345. }
  6346. if (!spawn->IsNPC()) {
  6347. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6348. return 0;
  6349. }
  6350. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6351. if (hated) {
  6352. lua_interface->SetSpawnValue(state, hated);
  6353. return 1;
  6354. }
  6355. return 0;
  6356. }
  6357. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6358. if (!lua_interface)
  6359. return 0;
  6360. Spawn* spawn = lua_interface->GetSpawn(state);
  6361. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6362. if (!spawn) {
  6363. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6364. return 0;
  6365. }
  6366. if (!spawn->IsNPC()) {
  6367. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6368. return 0;
  6369. }
  6370. if (!hated) {
  6371. ((NPC*)spawn)->Brain()->ClearHate();
  6372. return 0;
  6373. }
  6374. else
  6375. {
  6376. if (!hated->IsEntity()) {
  6377. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6378. return 0;
  6379. }
  6380. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6381. return 0;
  6382. }
  6383. return 0;
  6384. }
  6385. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6386. if (!lua_interface)
  6387. return 0;
  6388. Spawn* spawn = lua_interface->GetSpawn(state);
  6389. if (!spawn) {
  6390. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6391. return 0;
  6392. }
  6393. if (!spawn->IsNPC()) {
  6394. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6395. return 0;
  6396. }
  6397. ((NPC*)spawn)->Brain()->ClearEncounter();
  6398. return 0;
  6399. }
  6400. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6401. if (!lua_interface)
  6402. return 0;
  6403. Spawn* spawn = lua_interface->GetSpawn(state);
  6404. if (!spawn) {
  6405. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6406. return 0;
  6407. }
  6408. if (!spawn->IsNPC()) {
  6409. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6410. return 0;
  6411. }
  6412. // Temp list to store hate list
  6413. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6414. if (encounterList->size() == 0) {
  6415. safe_delete(encounterList);
  6416. return 0;
  6417. }
  6418. lua_createtable(state, encounterList->size(), 0);
  6419. int newTable = lua_gettop(state);
  6420. for (int32 i = 0; i < encounterList->size(); i++) {
  6421. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6422. if (temp)
  6423. lua_interface->SetSpawnValue(state, temp);
  6424. lua_rawseti(state, newTable, i + 1);
  6425. }
  6426. safe_delete(encounterList);
  6427. return 1;
  6428. }
  6429. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6430. if (!lua_interface)
  6431. return 0;
  6432. Spawn* spawn = lua_interface->GetSpawn(state);
  6433. if (!spawn) {
  6434. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6435. return 0;
  6436. }
  6437. if (!spawn->IsNPC()) {
  6438. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6439. return 0;
  6440. }
  6441. // Temp list to store hate list
  6442. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6443. if (hateList->size() == 0) {
  6444. safe_delete(hateList);
  6445. return 0;
  6446. }
  6447. lua_createtable(state, hateList->size(), 0);
  6448. int newTable = lua_gettop(state);
  6449. for (int32 i = 0; i < hateList->size(); i++) {
  6450. lua_interface->SetSpawnValue(state, hateList->at(i));
  6451. lua_rawseti(state, newTable, i + 1);
  6452. }
  6453. safe_delete(hateList);
  6454. return 1;
  6455. }
  6456. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6457. if (!lua_interface)
  6458. return 0;
  6459. Spawn* spawn = lua_interface->GetSpawn(state);
  6460. if (!spawn) {
  6461. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6462. return 0;
  6463. }
  6464. if (spawn->IsPlayer()) {
  6465. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6466. lua_interface->SetBooleanValue(state, true);
  6467. else
  6468. lua_interface->SetBooleanValue(state, false);
  6469. return 1;
  6470. }
  6471. else {
  6472. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6473. return 1;
  6474. }
  6475. }
  6476. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6477. if (!lua_interface)
  6478. return 0;
  6479. Quest* quest = lua_interface->GetQuest(state);
  6480. if (!quest) {
  6481. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6482. return 0;
  6483. }
  6484. quest->SetCompletedFlag(true);
  6485. return 0;
  6486. }
  6487. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6488. if (!lua_interface)
  6489. return 0;
  6490. Spawn* spawn = lua_interface->GetSpawn(state);
  6491. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6492. int8 tier = lua_interface->GetInt8Value(state, 3);
  6493. if (!spawn) {
  6494. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6495. return 0;
  6496. }
  6497. if (!spawn->IsEntity()) {
  6498. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6499. return 0;
  6500. }
  6501. if (spellID == 0) {
  6502. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6503. return 0;
  6504. }
  6505. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6506. if (effect) {
  6507. if (tier > 0) {
  6508. // If a tier was passed chec to see if it is the same as the effect
  6509. if (tier == effect->tier)
  6510. lua_interface->SetBooleanValue(state, true);
  6511. else
  6512. lua_interface->SetBooleanValue(state, false);
  6513. return 1;
  6514. }
  6515. else {
  6516. // Have an effect but no tier was passed so return true
  6517. lua_interface->SetBooleanValue(state, true);
  6518. }
  6519. return 1;
  6520. }
  6521. // no effect so return false
  6522. lua_interface->SetBooleanValue(state, false);
  6523. return 1;
  6524. }
  6525. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6526. if (!lua_interface)
  6527. return 0;
  6528. Spawn* spawn = lua_interface->GetSpawn(state);
  6529. int32 id = lua_interface->GetInt32Value(state, 2);
  6530. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6531. Spawn* spawn2 = 0;
  6532. vector<Spawn*> list;
  6533. if (!spawn) {
  6534. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6535. return 0;
  6536. }
  6537. //If zone not provided, use spawn's zone
  6538. if (!zone)
  6539. zone = spawn->GetZone();
  6540. list = zone->GetSpawnsByID(id);
  6541. if (list.size() == 0) {
  6542. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6543. return 0;
  6544. }
  6545. vector<Spawn*>::iterator itr = list.begin();
  6546. for (int8 i = 0; i < list.size(); i++) {
  6547. spawn2 = itr[i];
  6548. if (spawn2)
  6549. spawn2->AddAllowAccessSpawn(spawn);
  6550. }
  6551. return 0;
  6552. }
  6553. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6554. if (!lua_interface)
  6555. return 0;
  6556. Spawn* spawn = lua_interface->GetSpawn(state);
  6557. int32 id = lua_interface->GetInt32Value(state, 2);
  6558. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6559. Spawn* spawn2 = 0;
  6560. if (!spawn) {
  6561. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6562. return 0;
  6563. }
  6564. //If zone not provided, use spawn's zone
  6565. if (!zone)
  6566. zone = spawn->GetZone();
  6567. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6568. vector<Spawn*>::iterator itr = list.begin();
  6569. if (list.size() == 0) {
  6570. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6571. return 0;
  6572. }
  6573. for (int8 i = 0; i < list.size(); i++) {
  6574. spawn2 = itr[i];
  6575. if (spawn2)
  6576. spawn2->RemoveSpawnAccess(spawn);
  6577. }
  6578. return 0;
  6579. }
  6580. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6581. if (!lua_interface)
  6582. return 0;
  6583. Quest* quest = lua_interface->GetQuest(state);
  6584. if (!quest) {
  6585. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6586. return 0;
  6587. }
  6588. quest->SetYellowName(true);
  6589. return 0;
  6590. }
  6591. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6592. if (!lua_interface)
  6593. return 0;
  6594. Spawn* spawn = lua_interface->GetSpawn(state);
  6595. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6596. if (!spawn) {
  6597. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6598. return 0;
  6599. }
  6600. if (!spawn->IsPlayer()) {
  6601. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6602. return 0;
  6603. }
  6604. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6605. return 1;
  6606. }
  6607. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6608. if (!lua_interface)
  6609. return 0;
  6610. Spawn* spawn = lua_interface->GetSpawn(state);
  6611. if (!spawn) {
  6612. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. if (!spawn->IsPlayer()) {
  6616. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6617. return 0;
  6618. }
  6619. ZoneServer* zone = spawn->GetZone();
  6620. if (!zone) {
  6621. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6622. return 0;
  6623. }
  6624. Instance_Type iType = zone->GetInstanceType();
  6625. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6626. iType == GROUP_LOCKOUT_INSTANCE ||
  6627. iType == RAID_LOCKOUT_INSTANCE ||
  6628. iType == SOLO_PERSIST_INSTANCE ||
  6629. iType == GROUP_PERSIST_INSTANCE ||
  6630. iType == RAID_PERSIST_INSTANCE) {
  6631. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6632. if (data) {
  6633. // Check to see if the timer has already been set, if it has return out.
  6634. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6635. return 0;
  6636. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6637. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6638. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6639. if (client) {
  6640. string time_msg = "";
  6641. int32 time = data->success_lockout_time;
  6642. int16 hour;
  6643. int8 min;
  6644. int8 sec;
  6645. hour = time / 3600;
  6646. time = time % 3600;
  6647. min = time / 60;
  6648. time = time % 60;
  6649. sec = time;
  6650. if (hour > 0) {
  6651. char temp[10];
  6652. sprintf(temp, " %i", hour);
  6653. time_msg.append(temp);
  6654. time_msg.append(" hour");
  6655. time_msg.append((hour > 1) ? "s" : "");
  6656. }
  6657. if (min > 0) {
  6658. char temp[5];
  6659. sprintf(temp, " %i", min);
  6660. time_msg.append(temp);
  6661. time_msg.append(" minute");
  6662. time_msg.append((min > 1) ? "s" : "");
  6663. }
  6664. // Only add seconds if minutes and hours are 0
  6665. if (hour == 0 && min == 0 && sec > 0) {
  6666. char temp[5];
  6667. sprintf(temp, " %i", sec);
  6668. time_msg.append(temp);
  6669. time_msg.append(" second");
  6670. time_msg.append((sec > 1) ? "s" : "");
  6671. }
  6672. 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());
  6673. }
  6674. }
  6675. else
  6676. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6677. }
  6678. else
  6679. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6680. return 0;
  6681. }
  6682. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6683. if (!lua_interface)
  6684. return 0;
  6685. Spawn* spawn = lua_interface->GetSpawn(state);
  6686. if (!spawn) {
  6687. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6688. return 0;
  6689. }
  6690. if (!spawn->IsPlayer()) {
  6691. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6692. return 0;
  6693. }
  6694. ZoneServer* zone = spawn->GetZone();
  6695. if (!zone) {
  6696. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6697. return 0;
  6698. }
  6699. Instance_Type iType = zone->GetInstanceType();
  6700. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6701. iType == GROUP_LOCKOUT_INSTANCE ||
  6702. iType == RAID_LOCKOUT_INSTANCE ||
  6703. iType == SOLO_PERSIST_INSTANCE ||
  6704. iType == GROUP_PERSIST_INSTANCE ||
  6705. iType == RAID_PERSIST_INSTANCE) {
  6706. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6707. if (data) {
  6708. // Check to see if the timer has already been set, if it has return out.
  6709. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6710. return 0;
  6711. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6712. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6713. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6714. if (client) {
  6715. string time_msg = "";
  6716. int32 time = data->failure_lockout_time;
  6717. int16 hour;
  6718. int8 min;
  6719. int8 sec;
  6720. hour = time / 3600;
  6721. time = time % 3600;
  6722. min = time / 60;
  6723. time = time % 60;
  6724. sec = time;
  6725. if (hour > 0) {
  6726. char temp[10];
  6727. sprintf(temp, " %i", hour);
  6728. time_msg.append(temp);
  6729. time_msg.append(" hour");
  6730. time_msg.append((hour > 1) ? "s" : "");
  6731. }
  6732. if (min > 0) {
  6733. char temp[5];
  6734. sprintf(temp, " %i", min);
  6735. time_msg.append(temp);
  6736. time_msg.append(" minute");
  6737. time_msg.append((min > 1) ? "s" : "");
  6738. }
  6739. // Only add seconds if minutes and hours are 0
  6740. if (hour == 0 && min == 0 && sec > 0) {
  6741. char temp[5];
  6742. sprintf(temp, " %i", sec);
  6743. time_msg.append(temp);
  6744. time_msg.append(" second");
  6745. time_msg.append((sec > 1) ? "s" : "");
  6746. }
  6747. 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());
  6748. }
  6749. }
  6750. else
  6751. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6752. }
  6753. else
  6754. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6755. return 0;
  6756. }
  6757. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6758. if (!lua_interface)
  6759. return 0;
  6760. Spawn* spawn = lua_interface->GetSpawn(state);
  6761. if (!spawn) {
  6762. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6763. return 0;
  6764. }
  6765. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6766. return 1;
  6767. }
  6768. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6769. if (!lua_interface)
  6770. return 0;
  6771. Spawn* player = lua_interface->GetSpawn(state);
  6772. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6773. if (!player) {
  6774. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6775. return 0;
  6776. }
  6777. if (!player->IsPlayer()) {
  6778. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6779. return 0;
  6780. }
  6781. if (!ground) {
  6782. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6783. return 0;
  6784. }
  6785. if (!ground->IsGroundSpawn()) {
  6786. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6787. return 0;
  6788. }
  6789. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6790. if (!groundspawn_entries) {
  6791. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6792. return 0;
  6793. }
  6794. Skill* skill = 0;
  6795. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6796. if (collection_skill == "Collecting")
  6797. skill = ((Player*)player)->GetSkillByName("Gathering");
  6798. else
  6799. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6800. if (!skill) {
  6801. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6802. return 0;
  6803. }
  6804. vector<GroundSpawnEntry*>::iterator itr;
  6805. GroundSpawnEntry* entry = 0;
  6806. bool can_harvest = false;
  6807. sint32 min_skill = -1;
  6808. int16 totalSkill = skill->current_val;
  6809. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6810. if(skillID != 0xFFFFFFFF)
  6811. {
  6812. ((Entity*)player)->MStats.lock();
  6813. totalSkill += ((Entity*)player)->stats[skillID];
  6814. ((Entity*)player)->MStats.unlock();
  6815. }
  6816. // first, iterate through groundspawn_entries, discard tables player cannot use
  6817. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6818. {
  6819. entry = *itr;
  6820. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6821. min_skill = entry->min_skill_level;
  6822. // if player lacks skill, skip table
  6823. if (entry->min_skill_level > totalSkill)
  6824. continue;
  6825. // if bonus, but player lacks level, skip table
  6826. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6827. continue;
  6828. can_harvest = true;
  6829. break;
  6830. }
  6831. lua_interface->SetBooleanValue(state, can_harvest);
  6832. // If false, send the message to the client
  6833. if (!can_harvest) {
  6834. Client* client = player->GetZone()->GetClientBySpawn(player);
  6835. if (client) {
  6836. string msg = "You do not have enough skill to ";
  6837. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6838. msg.append("gather");
  6839. else if (collection_skill == "Mining")
  6840. msg.append("mine");
  6841. else if (collection_skill == "Trapping")
  6842. msg.append("trap");
  6843. else if (collection_skill == "Foresting")
  6844. msg.append("forest");
  6845. else if (collection_skill == "Fishing")
  6846. msg.append("catch");
  6847. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6848. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6849. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6850. }
  6851. }
  6852. return 1;
  6853. }
  6854. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6855. if (!lua_interface)
  6856. return 0;
  6857. Spawn* player = lua_interface->GetSpawn(state);
  6858. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6859. if (!player) {
  6860. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6861. return 0;
  6862. }
  6863. if (!player->IsPlayer()) {
  6864. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6865. return 0;
  6866. }
  6867. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6868. lua_interface->SetBooleanValue(state, ret);
  6869. return 1;
  6870. }
  6871. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6872. // Check to see if we have a valid lua_interface
  6873. if (!lua_interface)
  6874. return 0;
  6875. // Get the spawn that is getting the pet
  6876. Spawn* spawn = lua_interface->GetSpawn(state);
  6877. Spawn* target = lua_interface->GetSpawn(state, 2);
  6878. // Get the DB ID of the pet
  6879. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6880. float x = lua_interface->GetFloatValue(state, 4);
  6881. float y = lua_interface->GetFloatValue(state, 5);
  6882. float z = lua_interface->GetFloatValue(state, 6);
  6883. // Get the spell that this command was called from
  6884. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6885. // Check to make sure the spawn pointer is valid
  6886. if (!spawn) {
  6887. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6888. return 0;
  6889. }
  6890. // Check to make sure the spawn is an entity
  6891. if (!spawn->IsEntity()) {
  6892. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6893. return 0;
  6894. }
  6895. if (!target) {
  6896. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6897. return 0;
  6898. }
  6899. if (!target->IsEntity()) {
  6900. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6901. return 0;
  6902. }
  6903. // Check to see if the DB ID for the pet is set
  6904. if (pet_id == 0) {
  6905. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6906. return 0;
  6907. }
  6908. // Check to see if the pointer to the spell is valid
  6909. if (!luaspell) {
  6910. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6911. return 0;
  6912. }
  6913. if(luaspell->resisted) {
  6914. return 0;
  6915. }
  6916. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6917. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6918. if (!pet) {
  6919. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6920. return 0;
  6921. }
  6922. // Check to make sure the pet is an npc
  6923. if (!pet->IsNPC()) {
  6924. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6925. return 0;
  6926. }
  6927. if (x == 0)
  6928. x = spawn->GetX();
  6929. if (y == 0)
  6930. y = spawn->GetY();
  6931. if (z == 0)
  6932. z = spawn->GetZ();
  6933. // Spawn the pet at the same location as the owner
  6934. pet->SetX(x);
  6935. pet->SetY(y);
  6936. pet->SetZ(z);
  6937. pet->SetLocation(spawn->GetLocation());
  6938. pet->SetHeading(spawn->GetHeading());
  6939. spawn->GetZone()->AddSpawn(pet);
  6940. /*
  6941. const char* spawn_script = world.GetSpawnScript(pet_id);
  6942. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6943. spawn->SetSpawnScript(string(spawn_script));
  6944. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6945. }*/
  6946. // Get a random pet name
  6947. string random_pet_name;
  6948. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6949. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6950. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6951. // Set the pets name
  6952. pet->SetName(random_pet_name.c_str());
  6953. // Set the level of the pet to the owners level
  6954. pet->SetLevel(spawn->GetLevel());
  6955. // Set the faction of the pet to the same faction as the owner
  6956. pet->SetFactionID(spawn->GetFactionID());
  6957. // Set the spawn as a pet
  6958. pet->SetPet(true);
  6959. // Give a pointer of the owner to the pet
  6960. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6961. // Set the pet type
  6962. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6963. // Set the spell id used to create this pet
  6964. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6965. // Set the spell tier used to create this pet
  6966. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6967. // Set the pets spawn type to 6
  6968. pet->SetSpawnType(6);
  6969. // Set the pets brain
  6970. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6971. // Check to see if the pet has a subtitle
  6972. if (strlen(pet->GetSubTitle()) > 0) {
  6973. // Add the players name to the front of the sub title
  6974. string pet_subtitle;
  6975. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6976. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6977. // Set the pets subtitle to the new one
  6978. pet->SetSubTitle(pet_subtitle.c_str());
  6979. }
  6980. // Set the pet as the return value for this function
  6981. lua_interface->SetSpawnValue(state, pet);
  6982. return 1;
  6983. }
  6984. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6985. if (!lua_interface)
  6986. return 0;
  6987. Spawn* spawn = lua_interface->GetSpawn(state);
  6988. Spawn* player = lua_interface->GetSpawn(state, 2);
  6989. float max_distance = lua_interface->GetFloatValue(state, 3);
  6990. string type = lua_interface->GetStringValue(state, 4);
  6991. if (!spawn || (spawn && spawn->IsPlayer())) {
  6992. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. if (!player || (player && !player->IsPlayer())) {
  6996. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6997. return 0;
  6998. }
  6999. Client* client = 0;
  7000. if (player->GetZone())
  7001. client = player->GetZone()->GetClientBySpawn(player);
  7002. if (!client) {
  7003. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7004. return 0;
  7005. }
  7006. //Set max_distance to default if not set or not proper value
  7007. if (max_distance <= 0)
  7008. max_distance = 500;
  7009. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7010. if (packet) {
  7011. float unknown2_3 = 0;
  7012. int8 placement_mode = 0;
  7013. if (type == "wall") {
  7014. placement_mode = 2;
  7015. unknown2_3 = 150;
  7016. }
  7017. else if (type == "ceiling")
  7018. placement_mode = 1;
  7019. packet->setDataByName("placement_mode", placement_mode);
  7020. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7021. packet->setDataByName("model_type", spawn->GetModelType());
  7022. packet->setDataByName("unknown", 1); //size
  7023. packet->setDataByName("unknown2", 1); //size 2
  7024. packet->setDataByName("unknown2", .5, 1); //size 3
  7025. packet->setDataByName("unknown2", 3, 2);
  7026. packet->setDataByName("unknown2", unknown2_3, 3);
  7027. packet->setDataByName("max_distance", max_distance);
  7028. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7029. client->QueuePacket(packet->serialize());
  7030. safe_delete(packet);
  7031. }
  7032. return 0;
  7033. }
  7034. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7035. if (!lua_interface)
  7036. return 0;
  7037. Item* item = lua_interface->GetItem(state);
  7038. if (!item) {
  7039. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7040. return 0;
  7041. }
  7042. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7043. return 1;
  7044. }
  7045. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7046. if (!lua_interface)
  7047. return 0;
  7048. Item* item = lua_interface->GetItem(state);
  7049. if (!item) {
  7050. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7051. return 0;
  7052. }
  7053. lua_interface->SetInt32Value(state, item->effect_type);
  7054. return 1;
  7055. }
  7056. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7057. if (!lua_interface)
  7058. return 0;
  7059. Spawn* spawn = lua_interface->GetSpawn(state);
  7060. if (!spawn) {
  7061. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7062. return 0;
  7063. }
  7064. if (spawn->GetZone())
  7065. spawn->GetZone()->AddTransportSpawn(spawn);
  7066. return 0;
  7067. }
  7068. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7069. if (!lua_interface)
  7070. return 0;
  7071. Spawn* spawn = lua_interface->GetSpawn(state);
  7072. if (!spawn) {
  7073. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7074. return 0;
  7075. }
  7076. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7077. return 1;
  7078. }
  7079. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7080. if (!lua_interface)
  7081. return 0;
  7082. Skill* skill = lua_interface->GetSkill(state);
  7083. if (!skill) {
  7084. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7085. return 0;
  7086. }
  7087. lua_interface->SetInt32Value(state, skill->current_val);
  7088. return 1;
  7089. }
  7090. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7091. if (!lua_interface)
  7092. return 0;
  7093. Skill* skill = lua_interface->GetSkill(state);
  7094. if (!skill) {
  7095. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7096. return 0;
  7097. }
  7098. lua_interface->SetInt32Value(state, skill->max_val);
  7099. return 1;
  7100. }
  7101. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7102. if (!lua_interface)
  7103. return 0;
  7104. Skill* skill = lua_interface->GetSkill(state);
  7105. if (!skill) {
  7106. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7107. return 0;
  7108. }
  7109. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7110. return 1;
  7111. }
  7112. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7113. if (!lua_interface)
  7114. return 0;
  7115. Skill* skill = lua_interface->GetSkill(state);
  7116. int16 value = lua_interface->GetInt16Value(state, 2);
  7117. if (!skill) {
  7118. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7119. return 0;
  7120. }
  7121. skill->max_val = value;
  7122. if (skill->max_val < skill->current_val)
  7123. skill->current_val = skill->max_val;
  7124. return 0;
  7125. }
  7126. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7127. if (!lua_interface)
  7128. return 0;
  7129. Skill* skill = lua_interface->GetSkill(state);
  7130. int16 value = lua_interface->GetInt16Value(state, 2);
  7131. if (!skill) {
  7132. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7133. return 0;
  7134. }
  7135. if (value > skill->max_val)
  7136. skill->current_val = skill->max_val;
  7137. else
  7138. skill->current_val = value;
  7139. return 0;
  7140. }
  7141. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7142. if (!lua_interface)
  7143. return 0;
  7144. Spawn* player = lua_interface->GetSpawn(state);
  7145. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7146. if (skill_id > 0 && player && player->IsPlayer()) {
  7147. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7148. return 1;
  7149. }
  7150. return 0;
  7151. }
  7152. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7153. if (!lua_interface)
  7154. return 0;
  7155. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7156. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7157. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7158. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7159. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7160. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7161. if (player_spawn && player_spawn->IsPlayer()) {
  7162. Player* player = (Player*)player_spawn;
  7163. bool added = false;
  7164. if (!player->skill_list.HasSkill(skill_id)) {
  7165. player->AddSkill(skill_id, current_val, max_val, true);
  7166. added = true;
  7167. }
  7168. 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
  7169. Client* client = player->GetClient();
  7170. if (client) {
  7171. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7172. if (packet)
  7173. client->QueuePacket(packet);
  7174. }
  7175. }
  7176. if (added) {
  7177. lua_interface->SetBooleanValue(state, true);
  7178. return 1;
  7179. }
  7180. }
  7181. else {
  7182. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7183. }
  7184. }
  7185. else {
  7186. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7187. }
  7188. lua_interface->SetBooleanValue(state, false);
  7189. return 1;
  7190. }
  7191. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7192. if (!lua_interface)
  7193. return 0;
  7194. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7195. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7196. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7197. if (skill_id > 0) {
  7198. if (player_spawn && player_spawn->IsPlayer()) {
  7199. Player* player = (Player*)player_spawn;
  7200. if (player->skill_list.HasSkill(skill_id)) {
  7201. player->RemovePlayerSkill(skill_id);
  7202. if (!more_to_remove) {
  7203. Client* client = player->GetClient();
  7204. if (client) {
  7205. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7206. if (packet)
  7207. client->QueuePacket(packet);
  7208. }
  7209. }
  7210. }
  7211. }
  7212. else {
  7213. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7214. }
  7215. }
  7216. else {
  7217. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7218. }
  7219. return 0;
  7220. }
  7221. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7222. if (!lua_interface)
  7223. return 0;
  7224. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7225. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7226. int16 amount = lua_interface->GetInt8Value(state, 3);
  7227. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7228. if (amount > 0 && skill_type < 100) {
  7229. if (player_spawn && player_spawn->IsPlayer()) {
  7230. Player* player = (Player*)player_spawn;
  7231. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7232. if (!more_to_increase) {
  7233. Client* client = player->GetClient();
  7234. if (client) {
  7235. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7236. if (packet)
  7237. client->QueuePacket(packet);
  7238. }
  7239. }
  7240. }
  7241. else {
  7242. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7243. }
  7244. }
  7245. else {
  7246. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7247. }
  7248. return 0;
  7249. }
  7250. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7251. if (!lua_interface)
  7252. return 0;
  7253. Spawn* spawn = lua_interface->GetSpawn(state);
  7254. string name = lua_interface->GetStringValue(state, 2);
  7255. if (!spawn) {
  7256. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7257. return 0;
  7258. }
  7259. if (!spawn->IsEntity()) {
  7260. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7261. return 0;
  7262. }
  7263. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7264. if (skill) {
  7265. lua_interface->SetSkillValue(state, skill);
  7266. return 1;
  7267. }
  7268. return 0;
  7269. }
  7270. int EQ2Emu_lua_AddProc(lua_State* state) {
  7271. if (!lua_interface)
  7272. return 0;
  7273. Spawn* spawn = lua_interface->GetSpawn(state);
  7274. int8 type = lua_interface->GetInt8Value(state, 2);
  7275. float chance = lua_interface->GetFloatValue(state, 3);
  7276. Item* item = lua_interface->GetItem(state, 4);
  7277. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7278. LuaSpell* spell = 0;
  7279. if (!spawn && (!spell || !use_all_spelltargets)) {
  7280. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7281. return 0;
  7282. }
  7283. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7284. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7285. return 0;
  7286. }
  7287. if (!item)
  7288. spell = lua_interface->GetCurrentSpell(state);
  7289. if (!item && !spell) {
  7290. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7291. return 0;
  7292. }
  7293. if(spell && spell->resisted) {
  7294. return 0;
  7295. }
  7296. if (spell && use_all_spelltargets) {
  7297. Spawn* target;
  7298. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7299. for (int8 i = 0; i < spell->targets.size(); i++) {
  7300. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7301. if (!target || !target->IsEntity())
  7302. continue;
  7303. ((Entity*)target)->AddProc(type, chance, item, spell);
  7304. }
  7305. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7306. }
  7307. else
  7308. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7309. return 0;
  7310. }
  7311. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7312. if (!lua_interface)
  7313. return 0;
  7314. Spawn* spawn = lua_interface->GetSpawn(state);
  7315. Item* item = lua_interface->GetItem(state, 2);
  7316. LuaSpell* spell = 0;
  7317. if (!spawn) {
  7318. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7319. return 0;
  7320. }
  7321. if (!spawn->IsEntity()) {
  7322. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7323. return 0;
  7324. }
  7325. if (!item)
  7326. spell = lua_interface->GetCurrentSpell(state);
  7327. if (!item && !spell) {
  7328. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7329. return 0;
  7330. }
  7331. if (spell) {
  7332. Spawn* target;
  7333. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7334. for (int8 i = 0; i < spell->targets.size(); i++) {
  7335. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7336. if (!target || !target->IsEntity())
  7337. continue;
  7338. ((Entity*)target)->RemoveProc(item, spell);
  7339. }
  7340. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7341. spell->caster->RemoveProc(item, spell);
  7342. }
  7343. else
  7344. ((Entity*)spawn)->RemoveProc(item, spell);
  7345. return 0;
  7346. }
  7347. int EQ2Emu_lua_Knockback(lua_State* state) {
  7348. if (!lua_interface)
  7349. return 0;
  7350. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7351. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7352. int32 duration = lua_interface->GetInt32Value(state, 3);
  7353. float vertical = lua_interface->GetFloatValue(state, 4);
  7354. float horizontal = lua_interface->GetFloatValue(state, 5);
  7355. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7356. if (!target_spawn) {
  7357. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7358. return 0;
  7359. }
  7360. if (!spawn) {
  7361. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7362. return 0;
  7363. }
  7364. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7365. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7366. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7367. if (packet) {
  7368. packet->setDataByName("target_x", target_spawn->GetX());
  7369. packet->setDataByName("target_y", target_spawn->GetY());
  7370. packet->setDataByName("target_z", target_spawn->GetZ());
  7371. packet->setDataByName("vertical_movement", vertical);
  7372. packet->setDataByName("horizontal_movement", horizontal);
  7373. if (use_heading)
  7374. packet->setDataByName("use_player_heading", 1);
  7375. client->QueuePacket(packet->serialize());
  7376. }
  7377. safe_delete(packet);
  7378. }
  7379. return 0;
  7380. }
  7381. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7382. if (!lua_interface)
  7383. return 0;
  7384. Spawn* spawn = lua_interface->GetSpawn(state);
  7385. if (!spawn) {
  7386. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7387. return 0;
  7388. }
  7389. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7390. return 1;
  7391. }
  7392. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7393. if (!lua_interface)
  7394. return 0;
  7395. Spawn* caster = lua_interface->GetSpawn(state);
  7396. Spawn* target = lua_interface->GetSpawn(state, 2);
  7397. string name = lua_interface->GetStringValue(state, 3);
  7398. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7399. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7400. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7401. string success_msg = lua_interface->GetStringValue(state, 7);
  7402. string effect_msg = lua_interface->GetStringValue(state, 8);
  7403. if (!caster) {
  7404. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7405. return 0;
  7406. }
  7407. if (!caster->IsEntity()) {
  7408. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7409. return 0;
  7410. }
  7411. if (!target) {
  7412. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7413. return 0;
  7414. }
  7415. if (!target->IsEntity()) {
  7416. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7417. return 0;
  7418. }
  7419. if (name.length() == 0) {
  7420. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7421. return 0;
  7422. }
  7423. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7424. return 0;
  7425. }
  7426. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7427. if (!lua_interface)
  7428. return 0;
  7429. string name = lua_interface->GetStringValue(state);
  7430. if (name.length() == 0) {
  7431. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7432. return 0;
  7433. }
  7434. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7435. if (!skill) {
  7436. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7437. return 0;
  7438. }
  7439. lua_interface->SetInt32Value(state, skill->skill_id);
  7440. return 1;
  7441. }
  7442. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7443. if (!lua_interface)
  7444. return 0;
  7445. Spawn* spawn = lua_interface->GetSpawn(state);
  7446. if (!spawn) {
  7447. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7448. return 0;
  7449. }
  7450. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7451. return 1;
  7452. }
  7453. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7454. if (!lua_interface)
  7455. return 0;
  7456. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7457. if (!luaspell) {
  7458. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7459. return 0;
  7460. }
  7461. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7462. return 1;
  7463. }
  7464. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7465. if (!lua_interface)
  7466. return 0;
  7467. Spawn* spawn = lua_interface->GetSpawn(state);
  7468. Spawn* target = lua_interface->GetSpawn(state, 2);
  7469. if (!spawn) {
  7470. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7471. return 0;
  7472. }
  7473. if (!spawn->IsEntity()) {
  7474. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7475. return 0;
  7476. }
  7477. if (!target) {
  7478. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7479. return 0;
  7480. }
  7481. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7482. return 1;
  7483. }
  7484. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7485. if (!lua_interface)
  7486. return 0;
  7487. Spawn* spawn = lua_interface->GetSpawn(state);
  7488. Spawn* target = lua_interface->GetSpawn(state, 2);
  7489. if (!spawn) {
  7490. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7491. return 0;
  7492. }
  7493. if (!spawn->IsEntity()) {
  7494. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7495. return 0;
  7496. }
  7497. if (!target) {
  7498. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7499. return 0;
  7500. }
  7501. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7502. return 1;
  7503. }
  7504. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7505. if (!lua_interface)
  7506. return 0;
  7507. Item* item = lua_interface->GetItem(state);
  7508. if (!item) {
  7509. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7510. return 0;
  7511. }
  7512. lua_interface->SetInt32Value(state, item->details.count);
  7513. return 1;
  7514. }
  7515. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7516. if (!lua_interface)
  7517. return 0;
  7518. Item* item = lua_interface->GetItem(state);
  7519. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7520. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7521. if (!item) {
  7522. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7523. return 0;
  7524. }
  7525. if (!owner) {
  7526. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7527. return 0;
  7528. }
  7529. if (!owner->IsPlayer()) {
  7530. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7531. return 0;
  7532. }
  7533. if (item->stack_count < new_count) {
  7534. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7535. return 0;
  7536. }
  7537. if (new_count > 0) {
  7538. item->details.count = new_count;
  7539. item->save_needed = true;
  7540. }
  7541. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7542. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7543. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7544. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7545. else
  7546. {
  7547. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7548. return 0;
  7549. }
  7550. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7551. if (!client)
  7552. return 0;
  7553. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7554. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7555. if (app)
  7556. client->QueuePacket(app);
  7557. return 0;
  7558. }
  7559. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7560. if (!lua_interface)
  7561. return 0;
  7562. int32 time = lua_interface->GetInt32Value(state);
  7563. string function = lua_interface->GetStringValue(state, 2);
  7564. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7565. Spawn* target = lua_interface->GetSpawn(state, 4);
  7566. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7567. if (time == 0) {
  7568. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7569. return 0;
  7570. }
  7571. if (function.length() == 0) {
  7572. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7573. return 0;
  7574. }
  7575. if (!spell) {
  7576. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7577. return 0;
  7578. }
  7579. SpellScriptTimer* timer = new SpellScriptTimer;
  7580. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7581. #ifdef WIN32
  7582. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7583. #else
  7584. bzero(timer, sizeof(SpellScriptTimer));
  7585. #endif*/
  7586. timer->caster = 0;
  7587. timer->deleteWhenDone = false;
  7588. timer->target = 0;
  7589. timer->time = Timer::GetCurrentTime2() + time;
  7590. timer->customFunction = function;
  7591. timer->spell = spell;
  7592. if (caster)
  7593. timer->caster = caster->GetID();
  7594. if (target)
  7595. timer->target = target->GetID();
  7596. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7597. return 0;
  7598. }
  7599. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7600. if (!lua_interface)
  7601. return 0;
  7602. float hp_perc = lua_interface->GetFloatValue(state);
  7603. float power_perc = lua_interface->GetFloatValue(state, 2);
  7604. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7605. Spawn* target = lua_interface->GetSpawn(state, 4);
  7606. string heal_name = lua_interface->GetStringValue(state, 5);
  7607. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7608. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7609. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7610. if (!spell) {
  7611. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7612. return 0;
  7613. }
  7614. Entity* caster = spell->caster;
  7615. if (!caster) {
  7616. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7617. return 0;
  7618. }
  7619. Client* client = 0;
  7620. PendingResurrection* rez = 0;
  7621. ZoneServer* zone = spell->caster->GetZone();
  7622. if (!target) {
  7623. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7624. if (spell->targets.size() > 0) {
  7625. vector<int32> spell_targets = spell->targets;
  7626. for (int8 i = 0; i < spell_targets.size(); i++) {
  7627. target = zone->GetSpawnByID(spell_targets.at(i));
  7628. if (!target)
  7629. continue;
  7630. if (!target->IsPlayer())
  7631. continue;
  7632. client = target->GetZone()->GetClientBySpawn(target);
  7633. if (!client)
  7634. continue;
  7635. rez = client->GetCurrentRez();
  7636. if (rez->active)
  7637. continue;
  7638. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7639. rez->active = true;
  7640. rez->caster = caster;
  7641. rez->expire_timer = new Timer;
  7642. int32 duration = spell->spell->GetSpellDuration();
  7643. rez->expire_timer->Start(duration * 100);
  7644. rez->hp_perc = hp_perc;
  7645. rez->mp_perc = power_perc;
  7646. rez->range = spell->spell->GetSpellData()->range;
  7647. rez->spell_name = spell->spell->GetName();
  7648. if (heal_name.length() > 0)
  7649. rez->heal_name = heal_name;
  7650. else
  7651. rez->heal_name = rez->spell_name;
  7652. rez->no_calcs = no_calcs;
  7653. rez->crit_mod = crit_mod;
  7654. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7655. if (send_window)
  7656. client->SendResurrectionWindow();
  7657. else {
  7658. target->GetZone()->ResurrectSpawn(target, client);
  7659. rez->should_delete = true;
  7660. }
  7661. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7662. }
  7663. }
  7664. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7665. }
  7666. else {
  7667. client = target->GetZone()->GetClientBySpawn(target);
  7668. if (!client)
  7669. return 0;
  7670. rez = client->GetCurrentRez();
  7671. if (rez->active)
  7672. return 0;
  7673. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7674. rez->active = true;
  7675. rez->caster = caster;
  7676. rez->expire_timer = new Timer;
  7677. int32 duration = spell->spell->GetSpellDuration();
  7678. rez->expire_timer->Start(duration * 100);
  7679. rez->hp_perc = hp_perc;
  7680. rez->mp_perc = power_perc;
  7681. rez->range = spell->spell->GetSpellData()->range;
  7682. rez->spell_name = spell->spell->GetName();
  7683. if (heal_name.length() > 0)
  7684. rez->heal_name = heal_name;
  7685. else
  7686. rez->heal_name = rez->spell_name;
  7687. rez->no_calcs = no_calcs;
  7688. rez->crit_mod = crit_mod;
  7689. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7690. if (send_window)
  7691. client->SendResurrectionWindow();
  7692. else {
  7693. target->GetZone()->ResurrectSpawn(target, client);
  7694. rez->should_delete = true;
  7695. }
  7696. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7697. }
  7698. return 0;
  7699. }
  7700. int EQ2Emu_lua_SetVision(lua_State* state) {
  7701. if (!lua_interface)
  7702. return 0;
  7703. Spawn* spawn = lua_interface->GetSpawn(state);
  7704. int8 vision = lua_interface->GetInt8Value(state, 2);
  7705. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7706. if (!spawn) {
  7707. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7708. return 0;
  7709. }
  7710. if (!spawn->IsEntity()) {
  7711. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7712. return 0;
  7713. }
  7714. if (spell && spell->targets.size() > 0) {
  7715. ZoneServer* zone = spell->caster->GetZone();
  7716. for (int8 i = 0; i < spell->targets.size(); i++) {
  7717. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7718. if (target && target->IsEntity()) {
  7719. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7720. if (target->IsPlayer())
  7721. ((Player*)target)->SetCharSheetChanged(true);
  7722. }
  7723. }
  7724. }
  7725. else {
  7726. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7727. if (spawn->IsPlayer())
  7728. ((Player*)spawn)->SetCharSheetChanged(true);
  7729. }
  7730. return 0;
  7731. }
  7732. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7733. if (!lua_interface)
  7734. return 0;
  7735. Spawn* spawn = lua_interface->GetSpawn(state);
  7736. float intensity = lua_interface->GetFloatValue(state, 2);
  7737. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7738. if (!spawn) {
  7739. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7740. return 0;
  7741. }
  7742. if (!spawn->IsEntity()) {
  7743. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7744. return 0;
  7745. }
  7746. if (spell && spell->targets.size() > 0) {
  7747. ZoneServer* zone = spell->caster->GetZone();
  7748. for (int8 i = 0; i < spell->targets.size(); i++) {
  7749. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7750. if (target && target->IsEntity()) {
  7751. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7752. if (target->IsPlayer())
  7753. ((Player*)target)->SetCharSheetChanged(true);
  7754. }
  7755. }
  7756. }
  7757. else {
  7758. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7759. if (spawn->IsPlayer())
  7760. ((Player*)spawn)->SetCharSheetChanged(true);
  7761. }
  7762. return 0;
  7763. }
  7764. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7765. if (!lua_interface)
  7766. return 0;
  7767. Spawn* spawn = lua_interface->GetSpawn(state);
  7768. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7769. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7770. if (!spawn) {
  7771. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7772. return 0;
  7773. }
  7774. if (!spawn->IsEntity()) {
  7775. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7776. return 0;
  7777. }
  7778. if (spell && spell->targets.size() > 0) {
  7779. ZoneServer* zone = spell->caster->GetZone();
  7780. for (int8 i = 0; i < spell->targets.size(); i++) {
  7781. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7782. if (target && target->IsEntity()) {
  7783. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7784. if (target->IsPlayer())
  7785. ((Player*)target)->SetCharSheetChanged(true);
  7786. }
  7787. }
  7788. }
  7789. else {
  7790. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7791. if (spawn->IsPlayer())
  7792. ((Player*)spawn)->SetCharSheetChanged(true);
  7793. }
  7794. return 0;
  7795. }
  7796. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7797. if (!lua_interface)
  7798. return 0;
  7799. Item* item = lua_interface->GetItem(state);
  7800. int8 type = lua_interface->GetInt32Value(state, 2);
  7801. if (!item) {
  7802. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7803. return 0;
  7804. }
  7805. if (type == 1)
  7806. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7807. else if (type == 2)
  7808. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7809. return 1;
  7810. }
  7811. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7812. if (!lua_interface)
  7813. return 0;
  7814. Spawn* target = lua_interface->GetSpawn(state);
  7815. float val = lua_interface->GetFloatValue(state, 2);
  7816. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7817. // Added from Gangrenous post
  7818. if (spell && spell->resisted)
  7819. return 0;
  7820. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7821. if (val > 1.0f)
  7822. val = 1.0f - (val / 100.0f);
  7823. if (spell && spell->spell && spell->targets.size() > 0) {
  7824. ZoneServer* zone = spell->caster->GetZone();
  7825. for (int32 i = 0; i != spell->targets.size(); i++) {
  7826. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7827. if (spawn && spawn->IsEntity()) {
  7828. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7829. if (spawn->IsPlayer())
  7830. ((Player*)spawn)->SetCharSheetChanged(true);
  7831. }
  7832. }
  7833. }
  7834. else {
  7835. if (target && target->IsEntity()) {
  7836. ((Entity*)target)->SetSpeedMultiplier(val);
  7837. if (target->IsPlayer())
  7838. ((Player*)target)->SetCharSheetChanged(true);
  7839. }
  7840. }
  7841. return 0;
  7842. }
  7843. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7844. if (!lua_interface)
  7845. return 0;
  7846. Spawn* spawn = lua_interface->GetSpawn(state);
  7847. int16 model = lua_interface->GetInt16Value(state, 2);
  7848. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7849. if (spell && spell->spell && spell->targets.size() > 0) {
  7850. ZoneServer* zone = spell->caster->GetZone();
  7851. for (int32 i = 0; i < spell->targets.size(); i++) {
  7852. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7853. if (target)
  7854. target->SetIllusionModel(model);
  7855. }
  7856. }
  7857. else {
  7858. if (!spawn) {
  7859. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7860. return 0;
  7861. }
  7862. spawn->SetIllusionModel(model);
  7863. }
  7864. return 0;
  7865. }
  7866. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7867. if (!lua_interface)
  7868. return 0;
  7869. Spawn* spawn = lua_interface->GetSpawn(state);
  7870. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7871. if (spell && spell->spell && spell->targets.size() > 0) {
  7872. ZoneServer* zone = spell->caster->GetZone();
  7873. for (int32 i = 0; i < spell->targets.size(); i++) {
  7874. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7875. if (target)
  7876. target->SetIllusionModel(0);
  7877. }
  7878. }
  7879. else {
  7880. if (!spawn) {
  7881. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7882. return 0;
  7883. }
  7884. spawn->SetIllusionModel(0);
  7885. }
  7886. return 0;
  7887. }
  7888. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7889. if (!lua_interface)
  7890. return 0;
  7891. Spawn* caster = lua_interface->GetSpawn(state);
  7892. Spawn* target = lua_interface->GetSpawn(state, 2);
  7893. float chance = lua_interface->GetFloatValue(state, 3);
  7894. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7895. if (!caster) {
  7896. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. if (!caster->IsEntity()) {
  7900. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7901. return 0;
  7902. }
  7903. if (!target) {
  7904. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7905. return 0;
  7906. }
  7907. if (!target->IsEntity()) {
  7908. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7909. return 0;
  7910. }
  7911. if (chance <= 0) {
  7912. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7913. return 0;
  7914. }
  7915. if (!spell) {
  7916. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7917. return 0;
  7918. }
  7919. if(spell->resisted) {
  7920. return 0;
  7921. }
  7922. if (((Entity*)caster)->GetThreatTransfer()) {
  7923. return 0;
  7924. }
  7925. ThreatTransfer* transfer = new ThreatTransfer;
  7926. transfer->Target = target->GetID();
  7927. transfer->Amount = chance;
  7928. transfer->Spell = spell;
  7929. ((Entity*)caster)->SetThreatTransfer(transfer);
  7930. return 0;
  7931. }
  7932. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7933. if (!lua_interface)
  7934. return 0;
  7935. Spawn* spawn = lua_interface->GetSpawn(state);
  7936. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7937. if (!spawn) {
  7938. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7939. return 0;
  7940. }
  7941. if (!spell) {
  7942. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7943. return 0;
  7944. }
  7945. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7946. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7947. if(transfer && transfer->Spell != spell) {
  7948. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  7949. return 0;
  7950. }
  7951. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  7952. }
  7953. return 0;
  7954. }
  7955. int EQ2Emu_lua_CureByType(lua_State* state) {
  7956. if (!lua_interface)
  7957. return 0;
  7958. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7959. int8 cure_count = lua_interface->GetInt8Value(state);
  7960. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7961. string cure_name = lua_interface->GetStringValue(state, 3);
  7962. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7963. Spawn* target = lua_interface->GetSpawn(state, 5);
  7964. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  7965. if(spell && spell->resisted) {
  7966. return 0;
  7967. }
  7968. if (target) {
  7969. if (!target->IsEntity()) {
  7970. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7971. return 0;
  7972. }
  7973. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  7974. std::string alternate_name = "item";
  7975. if(spell)
  7976. alternate_name = std::string(spell->spell->GetName());
  7977. if(!caster && spell)
  7978. caster = (Spawn*)spell->caster;
  7979. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  7980. }
  7981. }
  7982. else {
  7983. ZoneServer* zone = spell->caster->GetZone();
  7984. vector<int32> targets = spell->targets;
  7985. vector<Entity*> targets_to_cure;
  7986. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7987. for (int8 i = 0; i < targets.size(); i++) {
  7988. target = zone->GetSpawnByID(targets.at(i));
  7989. if (!target || !target->IsEntity())
  7990. continue;
  7991. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  7992. targets_to_cure.push_back((Entity*)target);
  7993. }
  7994. }
  7995. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7996. vector<Entity*>::iterator itr;
  7997. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  7998. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7999. }
  8000. }
  8001. return 0;
  8002. }
  8003. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8004. if (!lua_interface)
  8005. return 0;
  8006. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8007. if (!spell) {
  8008. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8009. return 0;
  8010. }
  8011. if(spell->resisted) {
  8012. return 0;
  8013. }
  8014. int8 cure_count = lua_interface->GetInt8Value(state);
  8015. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8016. string cure_name = lua_interface->GetStringValue(state, 3);
  8017. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8018. Spawn* target = lua_interface->GetSpawn(state, 5);
  8019. if (target) {
  8020. if (!target->IsEntity()) {
  8021. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8022. return 0;
  8023. }
  8024. if (((Entity*)target)->GetDetCount() > 0)
  8025. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8026. }
  8027. else {
  8028. ZoneServer* zone = spell->caster->GetZone();
  8029. vector<int32> targets = spell->targets;
  8030. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8031. for (int8 i = 0; i < targets.size(); i++) {
  8032. target = zone->GetSpawnByID(targets.at(i));
  8033. if (!target || !target->IsEntity())
  8034. continue;
  8035. if (((Entity*)target)->GetDetCount() > 0)
  8036. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8037. }
  8038. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8039. }
  8040. return 0;
  8041. }
  8042. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8043. if (!lua_interface)
  8044. return 0;
  8045. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8046. if (!spell) {
  8047. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8048. return 0;
  8049. }
  8050. if (!spell->caster) {
  8051. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8052. return 0;
  8053. }
  8054. if (!spell->caster->GetZone()) {
  8055. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8056. return 0;
  8057. }
  8058. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8059. return 0;
  8060. }
  8061. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8062. if (!lua_interface)
  8063. return 0;
  8064. Spawn* spawn = lua_interface->GetSpawn(state);
  8065. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8066. if (!spell) {
  8067. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8068. return 0;
  8069. }
  8070. if (spawn && spawn->IsEntity())
  8071. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8072. else {
  8073. ZoneServer* zone = spell->caster->GetZone();
  8074. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8075. for (int32 i = 0; i < spell->targets.size(); i++) {
  8076. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8077. if (!spawn || !spawn->IsEntity())
  8078. continue;
  8079. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8080. }
  8081. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8082. }
  8083. return 0;
  8084. }
  8085. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8086. if (!lua_interface)
  8087. return 0;
  8088. Spawn* spawn = lua_interface->GetSpawn(state);
  8089. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8090. if (!spell) {
  8091. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8092. return 0;
  8093. }
  8094. if (spawn && spawn->IsEntity())
  8095. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8096. else {
  8097. ZoneServer* zone = spell->caster->GetZone();
  8098. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8099. for (int32 i = 0; i < spell->targets.size(); i++) {
  8100. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8101. if (!spawn || !spawn->IsEntity())
  8102. continue;
  8103. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8104. }
  8105. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8106. }
  8107. return 0;
  8108. }
  8109. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8110. if (!lua_interface)
  8111. return 0;
  8112. Spawn* caster = lua_interface->GetSpawn(state);
  8113. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8114. if (!caster) {
  8115. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8116. return 0;
  8117. }
  8118. if (!caster->IsPlayer()) {
  8119. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8120. return 0;
  8121. }
  8122. Spawn* target = caster->GetTarget();
  8123. if (!target) {
  8124. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8125. return 0;
  8126. }
  8127. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8128. if (!client) {
  8129. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8130. return 0;
  8131. }
  8132. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8133. if (ho) {
  8134. ho->SetTarget(target->GetID());
  8135. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8136. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8137. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8138. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8139. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8140. deque<GroupMemberInfo*>::iterator itr;
  8141. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8142. if (group)
  8143. {
  8144. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8145. deque<GroupMemberInfo*>* members = group->GetMembers();
  8146. for (itr = members->begin(); itr != members->end(); itr++) {
  8147. if ((*itr)->client)
  8148. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8149. }
  8150. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8151. }
  8152. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8153. }
  8154. else
  8155. safe_delete(ho);
  8156. }
  8157. else {
  8158. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8159. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8160. }
  8161. else
  8162. safe_delete(ho);
  8163. }
  8164. }
  8165. return 0;
  8166. }
  8167. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8168. if (!lua_interface)
  8169. return 0;
  8170. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8171. if (!spell) {
  8172. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8173. return 0;
  8174. }
  8175. int16 triggerCount = lua_interface->GetInt16Value(state);
  8176. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8177. if (!triggerCount) {
  8178. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8179. return 0;
  8180. }
  8181. spell->num_triggers = triggerCount;
  8182. spell->had_triggers = true;
  8183. spell->cancel_after_all_triggers = cancel_after_triggers;
  8184. return 0;
  8185. }
  8186. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8187. if (!lua_interface)
  8188. return 0;
  8189. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8190. if (!spell) {
  8191. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8192. return 0;
  8193. }
  8194. lua_interface->SetInt32Value(state, spell->num_triggers);
  8195. return 1;
  8196. }
  8197. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8198. if (!lua_interface)
  8199. return 0;
  8200. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8201. if (!spell) {
  8202. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8203. return 0;
  8204. }
  8205. int16 remove_count = lua_interface->GetInt16Value(state);
  8206. if (!remove_count)
  8207. remove_count = 1;
  8208. if (remove_count >= spell->num_triggers) {
  8209. spell->num_triggers = 0;
  8210. if (spell->cancel_after_all_triggers)
  8211. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8212. }
  8213. else {
  8214. spell->num_triggers -= remove_count;
  8215. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8216. }
  8217. return 0;
  8218. }
  8219. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8220. if (!lua_interface)
  8221. return 0;
  8222. Spawn* spawn = lua_interface->GetSpawn(state);
  8223. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8224. if (!spawn) {
  8225. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8226. return 0;
  8227. }
  8228. if (!copy_spawn) {
  8229. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8230. return 0;
  8231. }
  8232. spawn->CopySpawnAppearance(copy_spawn);
  8233. return 0;
  8234. }
  8235. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8236. Spawn* spawn = lua_interface->GetSpawn(state);
  8237. int8 type = lua_interface->GetInt8Value(state, 2);
  8238. if (!spawn) {
  8239. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8240. return 0;
  8241. }
  8242. else if (!spawn->IsEntity()) {
  8243. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8244. return 0;
  8245. }
  8246. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8247. return 1;
  8248. }
  8249. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8250. if (!lua_interface)
  8251. return 0;
  8252. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8253. int8 type = lua_interface->GetInt8Value(state);
  8254. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8255. if (!spell) {
  8256. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8257. return 0;
  8258. }
  8259. if(spell->resisted) {
  8260. return 0;
  8261. }
  8262. if (spawn) {
  8263. if (!spawn->IsEntity()) {
  8264. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8265. return 0;
  8266. }
  8267. Entity* entity = ((Entity*)spawn);
  8268. entity->AddImmunity(spell, type);
  8269. }
  8270. else {
  8271. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8272. for (int8 i = 0; i < spell->targets.size(); i++) {
  8273. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8274. if (!spawn || !spawn->IsEntity())
  8275. continue;
  8276. Entity* entity = ((Entity*)spawn);
  8277. entity->AddImmunity(spell, type);
  8278. }
  8279. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8280. }
  8281. return 0;
  8282. }
  8283. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8284. if (!lua_interface)
  8285. return 0;
  8286. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8287. int8 type = lua_interface->GetInt8Value(state);
  8288. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8289. if (!spell) {
  8290. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8291. return 0;
  8292. }
  8293. if (spawn) {
  8294. if (!spawn->IsEntity()) {
  8295. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8296. return 0;
  8297. }
  8298. Entity* entity = ((Entity*)spawn);
  8299. entity->RemoveImmunity(spell, type);
  8300. }
  8301. else {
  8302. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8303. for (int8 i = 0; i < spell->targets.size(); i++) {
  8304. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8305. if (!spawn || !spawn->IsEntity())
  8306. continue;
  8307. Entity* entity = ((Entity*)spawn);
  8308. entity->RemoveImmunity(spell, type);
  8309. }
  8310. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8311. }
  8312. return 0;
  8313. }
  8314. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8315. if (!lua_interface)
  8316. return 0;
  8317. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8318. if (!spell) {
  8319. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8320. return 0;
  8321. }
  8322. if(spell->resisted) {
  8323. return 0;
  8324. }
  8325. float snare = lua_interface->GetFloatValue(state);
  8326. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8327. // convert the val to the speed multipler value (100 - val)
  8328. float val = 100.0 - snare;
  8329. val /= 100.0;
  8330. if (spawn) {
  8331. if (!spawn->IsEntity()) {
  8332. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8333. return 0;
  8334. }
  8335. ((Entity*)spawn)->SetSnareValue(spell, val);
  8336. }
  8337. else {
  8338. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8339. for (int8 i = 0; i < spell->targets.size(); i++) {
  8340. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8341. if (!spawn || !spawn->IsEntity())
  8342. continue;
  8343. ((Entity*)spawn)->SetSnareValue(spell, val);
  8344. }
  8345. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8346. }
  8347. return 0;
  8348. }
  8349. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8350. if (!lua_interface)
  8351. return 0;
  8352. Spawn* spawn = lua_interface->GetSpawn(state);
  8353. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8354. if (!spawn) {
  8355. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8356. return 0;
  8357. }
  8358. if (race_id == 0) {
  8359. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8360. return 0;
  8361. }
  8362. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8363. return 1;
  8364. }
  8365. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8366. if (!lua_interface)
  8367. return 0;
  8368. Spawn* spawn = lua_interface->GetSpawn(state);
  8369. if (!spawn) {
  8370. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8371. return 0;
  8372. }
  8373. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8374. return 1;
  8375. }
  8376. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8377. if (!lua_interface)
  8378. return 0;
  8379. Spawn* spawn = lua_interface->GetSpawn(state);
  8380. if (!spawn) {
  8381. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8382. return 0;
  8383. }
  8384. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8385. return 1;
  8386. }
  8387. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8388. if (!lua_interface)
  8389. return 0;
  8390. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8391. if (!spell) {
  8392. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8393. return 0;
  8394. }
  8395. lua_interface->SetStringValue(state, spell->spell->GetName());
  8396. return 1;
  8397. }
  8398. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8399. if (!lua_interface)
  8400. return 0;
  8401. Quest* quest = lua_interface->GetQuest(state);
  8402. if (!quest) {
  8403. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8404. return 0;
  8405. }
  8406. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8407. return 1;
  8408. }
  8409. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8410. if (!lua_interface)
  8411. return 0;
  8412. Quest* quest = lua_interface->GetQuest(state);
  8413. int32 flags = lua_interface->GetInt32Value(state, 2);
  8414. if (!quest) {
  8415. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8416. return 0;
  8417. }
  8418. quest->SetQuestFlags(flags);
  8419. return 0;
  8420. }
  8421. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8422. if (!lua_interface)
  8423. return 0;
  8424. Quest* quest = lua_interface->GetQuest(state);
  8425. Spawn* player = lua_interface->GetSpawn(state, 2);
  8426. int32 step = lua_interface->GetInt32Value(state, 3);
  8427. int32 duration = lua_interface->GetInt32Value(state, 4);
  8428. string action = lua_interface->GetStringValue(state, 5);
  8429. if (!quest) {
  8430. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8431. return 0;
  8432. }
  8433. if (!player) {
  8434. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8435. return 0;
  8436. }
  8437. if (!player->IsPlayer()) {
  8438. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8439. return 0;
  8440. }
  8441. if (step == 0) {
  8442. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8443. return 0;
  8444. }
  8445. if (duration == 0) {
  8446. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. if (action.length() == 0) {
  8450. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8451. return 0;
  8452. }
  8453. Client* client = player->GetZone()->GetClientBySpawn(player);
  8454. if (!client) {
  8455. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. quest->SetTimerStep(step);
  8459. quest->AddFailedAction(step, action);
  8460. quest->SetStepTimer(duration);
  8461. client->AddQuestTimer(quest->GetQuestID());
  8462. return 0;
  8463. }
  8464. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8465. if (!lua_interface)
  8466. return 0;
  8467. Quest* quest = lua_interface->GetQuest(state);
  8468. Spawn* player = lua_interface->GetSpawn(state, 2);
  8469. if (!quest) {
  8470. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8471. return 0;
  8472. }
  8473. if (!player) {
  8474. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8475. return 0;
  8476. }
  8477. if (!player->IsPlayer()) {
  8478. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8479. return 0;
  8480. }
  8481. Client* client = player->GetZone()->GetClientBySpawn(player);
  8482. if (!client) {
  8483. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8484. return 0;
  8485. }
  8486. quest->SetTimerStep(0);
  8487. quest->SetStepTimer(0);
  8488. client->RemoveQuestTimer(quest->GetQuestID());
  8489. return 0;
  8490. }
  8491. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8492. if (!lua_interface)
  8493. return 0;
  8494. Spawn* player = lua_interface->GetSpawn(state);
  8495. Quest* quest = lua_interface->GetQuest(state, 2);
  8496. int32 step = lua_interface->GetInt32Value(state, 3);
  8497. if (!player) {
  8498. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8499. return 0;
  8500. }
  8501. if (!player->IsPlayer()) {
  8502. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8503. return 0;
  8504. }
  8505. if (!quest) {
  8506. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8507. return 0;
  8508. }
  8509. if (step == 0) {
  8510. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8511. return 0;
  8512. }
  8513. Client* client = player->GetZone()->GetClientBySpawn(player);
  8514. if (!client) {
  8515. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8516. return 0;
  8517. }
  8518. if (quest->RemoveQuestStep(step, client)) {
  8519. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8520. client->GetCurrentZone()->SendQuestUpdates(client);
  8521. }
  8522. else
  8523. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8524. return 0;
  8525. }
  8526. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8527. if (!lua_interface)
  8528. return 0;
  8529. Quest* quest = lua_interface->GetQuest(state, 1);
  8530. int32 step = lua_interface->GetInt32Value(state, 2);
  8531. string desc = lua_interface->GetStringValue(state, 3);
  8532. string task_group = lua_interface->GetStringValue(state, 4);
  8533. if (!quest) {
  8534. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8535. return 0;
  8536. }
  8537. if (step == 0) {
  8538. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8539. return 0;
  8540. }
  8541. QuestStep* quest_step = quest->GetQuestStep(step);
  8542. if (!quest_step) {
  8543. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8544. return 0;
  8545. }
  8546. quest_step->SetStepProgress(0);
  8547. quest_step->SetTaskGroup(task_group);
  8548. quest_step->SetDescription(desc);
  8549. return 0;
  8550. }
  8551. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8552. if (!lua_interface)
  8553. return 0;
  8554. Quest* quest = lua_interface->GetQuest(state);
  8555. int32 step = lua_interface->GetInt32Value(state, 2);
  8556. string action = lua_interface->GetStringValue(state, 3);
  8557. if (!quest) {
  8558. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8559. return 0;
  8560. }
  8561. if (step == 0) {
  8562. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8563. return 0;
  8564. }
  8565. if (action.length() == 0) {
  8566. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8567. return 0;
  8568. }
  8569. quest->AddFailedAction(step, action);
  8570. return 0;
  8571. }
  8572. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8573. if (!lua_interface)
  8574. return 0;
  8575. Spawn* player = lua_interface->GetSpawn(state);
  8576. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8577. int32 step = lua_interface->GetInt32Value(state, 3);
  8578. if (!player) {
  8579. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8580. return 0;
  8581. }
  8582. if (!player->IsPlayer()) {
  8583. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8584. return 0;
  8585. }
  8586. if (quest_id == 0) {
  8587. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8588. return 0;
  8589. }
  8590. if (step == 0) {
  8591. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8592. return 0;
  8593. }
  8594. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8595. if (!quest) {
  8596. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8597. return 0;
  8598. }
  8599. quest->StepFailed(step);
  8600. return 0;
  8601. }
  8602. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8603. if (!lua_interface)
  8604. return 0;
  8605. Spawn* player = lua_interface->GetSpawn(state);
  8606. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8607. if (!player) {
  8608. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8609. return 0;
  8610. }
  8611. if (!player->IsPlayer()) {
  8612. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8613. return 0;
  8614. }
  8615. if (quest_id == 0) {
  8616. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8617. return 0;
  8618. }
  8619. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8620. if (!quest) {
  8621. lua_interface->SetInt32Value(state, 0);
  8622. return 1;
  8623. }
  8624. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8625. return 1;
  8626. }
  8627. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8628. if (!lua_interface)
  8629. return 0;
  8630. string name = lua_interface->GetStringValue(state);
  8631. string value = lua_interface->GetStringValue(state, 2);
  8632. string comment = lua_interface->GetStringValue(state, 3);
  8633. if (name.length() == 0) {
  8634. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8635. return 0;
  8636. }
  8637. if (value.length() == 0) {
  8638. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8639. return 0;
  8640. }
  8641. string varname = string("lua_").append(name);
  8642. Variable* var = variables.FindVariable(varname);
  8643. if (var)
  8644. var->SetValue(value.c_str());
  8645. else {
  8646. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8647. variables.AddVariable(var);
  8648. }
  8649. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8650. return 0;
  8651. }
  8652. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8653. if (!lua_interface)
  8654. return 0;
  8655. string name = lua_interface->GetStringValue(state);
  8656. if (name.length() == 0) {
  8657. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8658. return 0;
  8659. }
  8660. string varname = string("lua_").append(name);
  8661. Variable* var = variables.FindVariable(varname);
  8662. if (var)
  8663. lua_interface->SetStringValue(state, var->GetValue());
  8664. else
  8665. lua_interface->SetStringValue(state, "NULL");
  8666. return 1;
  8667. }
  8668. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8669. if (!lua_interface)
  8670. return 0;
  8671. Spawn* player = lua_interface->GetSpawn(state);
  8672. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8673. if (!player) {
  8674. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8675. return 0;
  8676. }
  8677. if (!player->IsPlayer()) {
  8678. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8679. return 0;
  8680. }
  8681. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8682. return 1;
  8683. }
  8684. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8685. if (!lua_interface)
  8686. return 0;
  8687. Spawn* player = lua_interface->GetSpawn(state);
  8688. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8689. if (!player) {
  8690. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8691. return 0;
  8692. }
  8693. if (!player->IsPlayer()) {
  8694. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8695. return 0;
  8696. }
  8697. Language* language = master_languages_list.GetLanguage(language_id);
  8698. if (language)
  8699. {
  8700. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8701. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8702. }
  8703. return 0;
  8704. }
  8705. int EQ2Emu_lua_IsNight(lua_State* state) {
  8706. if (!lua_interface)
  8707. return 0;
  8708. ZoneServer* zone = lua_interface->GetZone(state);
  8709. if (!zone) {
  8710. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8711. return 0;
  8712. }
  8713. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8714. return 1;
  8715. }
  8716. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8717. if (!lua_interface)
  8718. return 0;
  8719. Spawn* spawn = lua_interface->GetSpawn(state);
  8720. if (!spawn) {
  8721. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8722. return 0;
  8723. }
  8724. if (!spawn->IsWidget()) {
  8725. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8726. return 0;
  8727. }
  8728. ((Widget*)spawn)->SetMultiFloorLift(true);
  8729. if (spawn->GetZone())
  8730. spawn->GetZone()->AddTransportSpawn(spawn);
  8731. return 0;
  8732. }
  8733. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8734. if (!lua_interface)
  8735. return 0;
  8736. Spawn* player = lua_interface->GetSpawn(state);
  8737. int32 path = lua_interface->GetInt32Value(state, 2);
  8738. if (!player) {
  8739. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8740. return 0;
  8741. }
  8742. if (!player->IsPlayer()) {
  8743. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8744. return 0;
  8745. }
  8746. if (path == 0) {
  8747. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8748. return 0;
  8749. }
  8750. Client* client = player->GetZone()->GetClientBySpawn(player);
  8751. if (!client) {
  8752. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8753. return 0;
  8754. }
  8755. client->SendFlightAutoMount(path);
  8756. return 0;
  8757. }
  8758. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8759. if (!lua_interface)
  8760. return 0;
  8761. Spawn* player = lua_interface->GetSpawn(state);
  8762. if (!player) {
  8763. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8764. return 0;
  8765. }
  8766. if (!player->IsPlayer()) {
  8767. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8768. return 0;
  8769. }
  8770. Client* client = player->GetZone()->GetClientBySpawn(player);
  8771. if (!client) {
  8772. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8773. return 0;
  8774. }
  8775. client->EndAutoMount();
  8776. return 0;
  8777. }
  8778. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8779. if (!lua_interface)
  8780. return 0;
  8781. Spawn* player = lua_interface->GetSpawn(state);
  8782. if (!player) {
  8783. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8784. return 0;
  8785. }
  8786. if (!player->IsPlayer()) {
  8787. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8788. return 0;
  8789. }
  8790. Client* client = player->GetZone()->GetClientBySpawn(player);
  8791. if (!client) {
  8792. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8793. return 0;
  8794. }
  8795. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8796. return 1;
  8797. }
  8798. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8799. if (!lua_interface)
  8800. return 0;
  8801. Spawn* player = lua_interface->GetSpawn(state);
  8802. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8803. int32 value = lua_interface->GetInt32Value(state, 3);
  8804. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8805. if (!player) {
  8806. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8807. return 0;
  8808. }
  8809. if (!player->IsPlayer()) {
  8810. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8811. return 0;
  8812. }
  8813. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8814. return 0;
  8815. }
  8816. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8817. if (!lua_interface)
  8818. return 0;
  8819. Spawn* player = lua_interface->GetSpawn(state);
  8820. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8821. if (!player) {
  8822. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8823. return 0;
  8824. }
  8825. if (!player->IsPlayer()) {
  8826. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8827. return 0;
  8828. }
  8829. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8830. if (!hd)
  8831. return 0;
  8832. lua_interface->SetInt32Value(state, hd->Value);
  8833. lua_interface->SetInt32Value(state, hd->Value2);
  8834. return 2;
  8835. }
  8836. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8837. if (!lua_interface)
  8838. return 0;
  8839. Spawn* spawn = lua_interface->GetSpawn(state);
  8840. int32 grid = lua_interface->GetInt32Value(state, 2);
  8841. if (!spawn) {
  8842. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8843. return 0;
  8844. }
  8845. if (grid == 0) {
  8846. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8847. return 0;
  8848. }
  8849. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8850. return 0;
  8851. }
  8852. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8853. if (!lua_interface)
  8854. return 0;
  8855. Spawn* spawn = lua_interface->GetSpawn(state);
  8856. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8857. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8858. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8859. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8860. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8861. if (!spawn) {
  8862. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8863. return 0;
  8864. }
  8865. //Add this quest to the list of required quests for this spawn
  8866. spawn->SetRequiredHistory(event_id, value1, value2);
  8867. //If private spawn value set
  8868. if (private_spawn) {
  8869. //Set the spawn to be private when not granted access via history
  8870. spawn->AddAllowAccessSpawn(spawn);
  8871. spawn->SetPrivateQuestSpawn(true);
  8872. }
  8873. //This value will override vis_flags in the vis packet
  8874. if (flag_override > 0)
  8875. spawn->SetQuestsRequiredOverride(flag_override);
  8876. return 0;
  8877. }
  8878. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8879. if (!lua_interface)
  8880. return 0;
  8881. Spawn* player = lua_interface->GetSpawn(state);
  8882. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8883. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8884. if (!player) {
  8885. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8886. return 0;
  8887. }
  8888. if (!player->IsPlayer()) {
  8889. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8890. return 0;
  8891. }
  8892. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8893. return 1;
  8894. }
  8895. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8896. if (!lua_interface)
  8897. return 0;
  8898. Spawn* player = lua_interface->GetSpawn(state);
  8899. int8 level = lua_interface->GetInt8Value(state, 2);
  8900. if (!player) {
  8901. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8902. return 0;
  8903. }
  8904. if (!player->IsPlayer()) {
  8905. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8906. return 0;
  8907. }
  8908. if (level == 0) {
  8909. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8910. return 0;
  8911. }
  8912. Client* client = player->GetZone()->GetClientBySpawn(player);
  8913. if (!client) {
  8914. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8915. return 0;
  8916. }
  8917. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8918. return 0;
  8919. }
  8920. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8921. if (!lua_interface)
  8922. return 0;
  8923. Spawn* player = lua_interface->GetSpawn(state);
  8924. int32 amount = lua_interface->GetInt32Value(state, 2);
  8925. if (!player) {
  8926. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8927. return 0;
  8928. }
  8929. if (!player->IsPlayer()) {
  8930. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8931. return 0;
  8932. }
  8933. if (amount == 0) {
  8934. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8935. return 0;
  8936. }
  8937. ((Player*)player)->AddCoins(amount);
  8938. return 0;
  8939. }
  8940. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8941. if (!lua_interface)
  8942. return 0;
  8943. Spawn* player = lua_interface->GetSpawn(state);
  8944. int32 amount = lua_interface->GetInt32Value(state, 2);
  8945. if (!player) {
  8946. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8947. return 0;
  8948. }
  8949. if (!player->IsPlayer()) {
  8950. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8951. return 0;
  8952. }
  8953. if (amount == 0) {
  8954. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8955. return 0;
  8956. }
  8957. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8958. return 1;
  8959. }
  8960. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8961. if (!lua_interface)
  8962. return 0;
  8963. ZoneServer* zone = lua_interface->GetZone(state);
  8964. if (!zone) {
  8965. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8966. return 0;
  8967. }
  8968. vector<Entity*> players = zone->GetPlayers();
  8969. if (players.size() == 0)
  8970. return 0;
  8971. lua_createtable(state, players.size(), 0);
  8972. int newTable = lua_gettop(state);
  8973. for (int32 i = 0; i < players.size(); i++) {
  8974. lua_interface->SetSpawnValue(state, players.at(i));
  8975. lua_rawseti(state, newTable, i + 1);
  8976. }
  8977. return 1;
  8978. }
  8979. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8980. if (!lua_interface)
  8981. return 0;
  8982. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8983. if (!zone) {
  8984. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8985. return 0;
  8986. }
  8987. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8988. //Map of <placement_id, location_id>
  8989. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8990. map<int32, int32>::iterator itr;
  8991. vector<Spawn*> group;
  8992. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8993. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8994. if (!location) {
  8995. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8996. return 0;
  8997. }
  8998. Spawn* spawn = 0;
  8999. if (location->entities[0]) {
  9000. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9001. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9002. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9003. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9004. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9005. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9006. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9007. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9008. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9009. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9010. if(spawn && spawn->IsOmittedByDBFlag())
  9011. {
  9012. 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);
  9013. safe_delete(spawn);
  9014. continue;
  9015. }
  9016. if (spawn) {
  9017. const char* script = 0;
  9018. for (int x = 0; x < 3; x++) {
  9019. switch (x) {
  9020. case 0:
  9021. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9022. break;
  9023. case 1:
  9024. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9025. break;
  9026. case 2:
  9027. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9028. break;
  9029. }
  9030. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9031. spawn->SetSpawnScript(string(script));
  9032. break;
  9033. }
  9034. }
  9035. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9036. lua_interface->SetSpawnValue(state, spawn);
  9037. group.push_back(spawn);
  9038. }
  9039. else {
  9040. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9041. safe_delete(spawn);
  9042. }
  9043. }
  9044. }
  9045. if (!group.empty()) {
  9046. lua_createtable(state, group.size(), 0);
  9047. int newTable = lua_gettop(state);
  9048. for (int32 i = 0; i < group.size(); i++) {
  9049. lua_interface->SetSpawnValue(state, group[i]);
  9050. lua_rawseti(state, newTable, i + 1);
  9051. }
  9052. }
  9053. else
  9054. lua_pushnil(state);
  9055. return 1;
  9056. }
  9057. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9058. if (!lua_interface)
  9059. return 0;
  9060. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9061. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9062. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9063. if (!spawn) {
  9064. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9065. return 0;
  9066. }
  9067. if (anim_id == 0) {
  9068. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9069. return 0;
  9070. }
  9071. if (leeway == 0)
  9072. leeway = 5000;
  9073. spawn->SetSpawnAnim(anim_id);
  9074. spawn->SetSpawnAnimLeeway(leeway);
  9075. return 0;
  9076. }
  9077. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9078. if (!lua_interface)
  9079. return 0;
  9080. Spawn* player = lua_interface->GetSpawn(state);
  9081. if (!player) {
  9082. return 0;
  9083. }
  9084. Client* client = player->GetZone()->GetClientBySpawn(player);
  9085. if (!client) {
  9086. return 0;
  9087. }
  9088. lua_interface->SetInt32Value(state, client->GetVersion());
  9089. return 1;
  9090. }
  9091. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9092. if (!lua_interface)
  9093. return 0;
  9094. Item* item = lua_interface->GetItem(state);
  9095. if (!item) {
  9096. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9097. return 0;
  9098. }
  9099. lua_interface->SetInt32Value(state, item->details.item_id);
  9100. return 1;
  9101. }
  9102. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9103. if (!lua_interface)
  9104. return 0;
  9105. Spawn* spawn = lua_interface->GetSpawn(state);
  9106. if (!spawn) {
  9107. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9108. return 0;
  9109. }
  9110. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9111. return 1;
  9112. }
  9113. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9114. if (!lua_interface)
  9115. return 0;
  9116. Spawn* spawn = lua_interface->GetSpawn(state);
  9117. if (!spawn) {
  9118. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9119. return 0;
  9120. }
  9121. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9122. return 1;
  9123. }
  9124. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9125. if (!lua_interface)
  9126. return 0;
  9127. Spawn* spawn = lua_interface->GetSpawn(state);
  9128. if (!spawn) {
  9129. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9130. return 0;
  9131. }
  9132. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9133. return 1;
  9134. }
  9135. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9136. if (!lua_interface)
  9137. return 0;
  9138. Spawn* spawn = lua_interface->GetSpawn(state);
  9139. if (!spawn) {
  9140. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9141. return 0;
  9142. }
  9143. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9144. return 1;
  9145. }
  9146. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9147. if (!lua_interface)
  9148. return 0;
  9149. Spawn* spawn = lua_interface->GetSpawn(state);
  9150. float pct = lua_interface->GetFloatValue(state, 2);
  9151. if (!spawn) {
  9152. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9153. return 0;
  9154. }
  9155. if (pct == 0) {
  9156. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9157. return 0;
  9158. }
  9159. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9160. lua_interface->SetInt32Value(state, amount);
  9161. return 1;
  9162. }
  9163. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9164. if (!lua_interface)
  9165. return 0;
  9166. Spawn* spawn = lua_interface->GetSpawn(state);
  9167. float pct = lua_interface->GetFloatValue(state, 2);
  9168. if (!spawn) {
  9169. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9170. return 0;
  9171. }
  9172. if (pct == 0) {
  9173. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9174. return 0;
  9175. }
  9176. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9177. lua_interface->SetInt32Value(state, amount);
  9178. return 1;
  9179. }
  9180. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9181. if (!lua_interface)
  9182. return 0;
  9183. Spawn* spawn = lua_interface->GetSpawn(state);
  9184. if (!spawn) {
  9185. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9186. return 0;
  9187. }
  9188. if (!spawn->IsPlayer()) {
  9189. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9190. return 0;
  9191. }
  9192. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9193. return 1;
  9194. }
  9195. int EQ2Emu_lua_Evac(lua_State* state) {
  9196. if (!lua_interface)
  9197. return 0;
  9198. Spawn* target = lua_interface->GetSpawn(state);
  9199. if (target) {
  9200. float x = target->GetZone()->GetSafeX();
  9201. float y = target->GetZone()->GetSafeY();
  9202. float z = target->GetZone()->GetSafeZ();
  9203. float h = target->GetZone()->GetSafeHeading();
  9204. target->SetX(x);
  9205. target->SetY(y);
  9206. target->SetZ(z);
  9207. target->SetHeading(h);
  9208. target->SetSpawnOrigX(x);
  9209. target->SetSpawnOrigY(y);
  9210. target->SetSpawnOrigZ(z);
  9211. target->SetSpawnOrigHeading(h);
  9212. if (target->IsPlayer()) {
  9213. Client* client = target->GetZone()->GetClientBySpawn(target);
  9214. if (client) {
  9215. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9216. int numargs = lua_interface->GetNumberOfArgs(state);
  9217. if(numargs == 4) {
  9218. x = lua_interface->GetFloatValue(state,1);
  9219. y = lua_interface->GetFloatValue(state,2);
  9220. z = lua_interface->GetFloatValue(state,3);
  9221. h = lua_interface->GetFloatValue(state,4);
  9222. }
  9223. client->SetReloadingZone(true);
  9224. target->SetX(x);
  9225. target->SetY(y);
  9226. target->SetZ(z);
  9227. target->SetHeading(h);
  9228. target->SetSpawnOrigX(x);
  9229. target->SetSpawnOrigY(y);
  9230. target->SetSpawnOrigZ(z);
  9231. target->SetSpawnOrigHeading(h);
  9232. target->SetAppearancePosition(x,y,z);
  9233. client->SetZoningCoords(x,y,z,h);
  9234. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9235. if (packet)
  9236. {
  9237. packet->setDataByName("x", x);
  9238. packet->setDataByName("y", y);
  9239. packet->setDataByName("z", z);
  9240. client->QueuePacket(packet->serialize());
  9241. safe_delete(packet);
  9242. }
  9243. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9244. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9245. }
  9246. }
  9247. }
  9248. else {
  9249. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9250. if(!spell)
  9251. return 0;
  9252. ZoneServer* zone = spell->caster->GetZone();
  9253. float x = spell->caster->GetZone()->GetSafeX();
  9254. float y = spell->caster->GetZone()->GetSafeY();
  9255. float z = spell->caster->GetZone()->GetSafeZ();
  9256. float h = spell->caster->GetZone()->GetSafeHeading();
  9257. int numargs = lua_interface->GetNumberOfArgs(state);
  9258. if(numargs == 4) {
  9259. x = lua_interface->GetFloatValue(state,1);
  9260. y = lua_interface->GetFloatValue(state,2);
  9261. z = lua_interface->GetFloatValue(state,3);
  9262. h = lua_interface->GetFloatValue(state,4);
  9263. }
  9264. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9265. for (int32 i = 0; i < spell->targets.size(); i++) {
  9266. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9267. if (!target2)
  9268. continue;
  9269. if (target2->IsPlayer()) {
  9270. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9271. if (client) {
  9272. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9273. client->SetReloadingZone(true);
  9274. target2->SetX(x);
  9275. target2->SetY(y);
  9276. target2->SetZ(z);
  9277. target2->SetHeading(h);
  9278. target2->SetSpawnOrigX(x);
  9279. target2->SetSpawnOrigY(y);
  9280. target2->SetSpawnOrigZ(z);
  9281. target2->SetSpawnOrigHeading(h);
  9282. target2->SetAppearancePosition(x,y,z);
  9283. client->SetZoningCoords(x,y,z,h);
  9284. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9285. if (packet)
  9286. {
  9287. packet->setDataByName("x", x);
  9288. packet->setDataByName("y", y);
  9289. packet->setDataByName("z", z);
  9290. client->QueuePacket(packet->serialize());
  9291. safe_delete(packet);
  9292. }
  9293. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9294. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9295. }
  9296. }
  9297. }
  9298. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9299. }
  9300. return 0;
  9301. }
  9302. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9303. if (!lua_interface)
  9304. return 0;
  9305. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9306. if (!luaspell) {
  9307. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9308. return 0;
  9309. }
  9310. int8 tier = luaspell->spell->GetSpellTier();
  9311. lua_interface->SetInt32Value(state, tier);
  9312. return 1;
  9313. }
  9314. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9315. if (!lua_interface)
  9316. return 0;
  9317. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9318. if (!luaspell) {
  9319. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9320. return 0;
  9321. }
  9322. int32 spell_id = luaspell->spell->GetSpellID();
  9323. lua_interface->SetInt32Value(state, spell_id);
  9324. return 1;
  9325. }
  9326. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9327. if (!lua_interface)
  9328. return 0;
  9329. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9330. if (!spawn) {
  9331. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9332. return 0;
  9333. }
  9334. if (!spawn->IsPlayer()) {
  9335. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9336. return 0;
  9337. }
  9338. ZoneServer* zone = spawn->GetZone();
  9339. if (!zone) {
  9340. return 0;
  9341. }
  9342. Client* client = zone->GetClientBySpawn(spawn);
  9343. if (!client) {
  9344. return 0;
  9345. }
  9346. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9347. return 0;
  9348. }
  9349. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9350. if (!lua_interface)
  9351. return 0;
  9352. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9353. if (!spawn) {
  9354. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9355. return 0;
  9356. }
  9357. if (!spawn->IsPlayer()) {
  9358. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9359. return 0;
  9360. }
  9361. ZoneServer* zone = spawn->GetZone();
  9362. if (!zone) {
  9363. return 0;
  9364. }
  9365. Client* client = zone->GetClientBySpawn(spawn);
  9366. if (!client) {
  9367. return 0;
  9368. }
  9369. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9370. return 0;
  9371. }
  9372. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9373. if (!lua_interface)
  9374. return 0;
  9375. Spawn* caster = lua_interface->GetSpawn(state);
  9376. Spawn* target = lua_interface->GetSpawn(state, 2);
  9377. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9378. string spell_name = lua_interface->GetStringValue(state, 4);
  9379. if (!caster) {
  9380. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9381. return 0;
  9382. }
  9383. if (!caster->IsEntity()) {
  9384. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9385. return 0;
  9386. }
  9387. if (!target) {
  9388. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9389. return 0;
  9390. }
  9391. if (!target->IsEntity()) {
  9392. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9393. return 0;
  9394. }
  9395. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9396. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9397. return 0;
  9398. }
  9399. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9400. if (!lua_interface)
  9401. return 0;
  9402. Spawn* player = lua_interface->GetSpawn(state);
  9403. int32 amount = lua_interface->GetInt32Value(state, 2);
  9404. if (player && player->IsPlayer() && amount > 0) {
  9405. ((Player*)player)->AddXP(amount);
  9406. ((Player*)player)->SetCharSheetChanged(true);
  9407. Client* client = player->GetZone()->GetClientBySpawn(player);
  9408. if (client) {
  9409. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9410. }
  9411. }
  9412. return 0;
  9413. }
  9414. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9415. if (!lua_interface)
  9416. return 0;
  9417. Spawn* player = lua_interface->GetSpawn(state);
  9418. int8 type = lua_interface->GetInt8Value(state, 2);
  9419. string text = lua_interface->GetStringValue(state, 3);
  9420. Client* client = 0;
  9421. if (player && player->IsPlayer())
  9422. client = player->GetZone()->GetClientBySpawn(player);
  9423. if (!client || text.length() == 0) {
  9424. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9425. return 0;
  9426. }
  9427. client->SimpleMessage(type, text.c_str());
  9428. return 0;
  9429. }
  9430. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9431. if (!lua_interface)
  9432. return 0;
  9433. Spawn* player = lua_interface->GetSpawn(state);
  9434. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9435. Client* client = 0;
  9436. if (player && player->IsPlayer())
  9437. client = player->GetZone()->GetClientBySpawn(player);
  9438. if (!client || !spawn) {
  9439. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9440. return 0;
  9441. }
  9442. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9443. if (!items) {
  9444. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9445. return 0;
  9446. }
  9447. client->Loot(spawn->GetLootCoins(), items, spawn);
  9448. return 0;
  9449. }
  9450. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9451. if (!lua_interface)
  9452. return 0;
  9453. Spawn* spawnref = lua_interface->GetSpawn(state);
  9454. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9455. if (spawn_id > 0 && spawnref) {
  9456. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9457. if (spawns.size() == 0) {
  9458. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9459. return 0;
  9460. }
  9461. Spawn* spawn = 0;
  9462. int16 index = MakeRandomInt(0, spawns.size());
  9463. if (index >= spawns.size() || index < 0)
  9464. index = 0;
  9465. spawn = spawns[index];
  9466. lua_interface->SetSpawnValue(state, spawn);
  9467. return 1;
  9468. }
  9469. else {
  9470. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9471. }
  9472. return 0;
  9473. }
  9474. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9475. Spawn* player = lua_interface->GetSpawn(state);
  9476. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9477. string name = lua_interface->GetStringValue(state, 3);
  9478. float distance = lua_interface->GetFloatValue(state, 4);
  9479. string command = lua_interface->GetStringValue(state, 5);
  9480. string error_text = lua_interface->GetStringValue(state, 6);
  9481. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9482. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9483. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9484. if (distance == 0)
  9485. distance = 10.0f;
  9486. if (command.length() == 0)
  9487. command = name;
  9488. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9489. if (spawns.size() == 0) {
  9490. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9491. return 0;
  9492. }
  9493. Spawn* spawn = 0;
  9494. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9495. spawn = *itr;
  9496. if (spawn) {
  9497. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9498. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9499. }
  9500. }
  9501. }
  9502. return 0;
  9503. }
  9504. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9505. if (!lua_interface)
  9506. return 0;
  9507. Client* client = 0;
  9508. Spawn* player = lua_interface->GetSpawn(state);
  9509. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9510. if (player && player->IsPlayer() && player->GetZone())
  9511. client = player->GetZone()->GetClientBySpawn(player);
  9512. else{
  9513. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9514. return 0;
  9515. }
  9516. if (client) {
  9517. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9518. if (packet) {
  9519. packet->setDataByName("goal_num", goal_num);
  9520. client->QueuePacket(packet->serialize());
  9521. safe_delete(packet);
  9522. }
  9523. }
  9524. return 0;
  9525. }
  9526. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9527. if (!lua_interface)
  9528. return 0;
  9529. Client* client = 0;
  9530. Spawn* player = lua_interface->GetSpawn(state);
  9531. if (player && player->IsPlayer() && player->GetZone())
  9532. client = player->GetZone()->GetClientBySpawn(player);
  9533. else {
  9534. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9535. return 0;
  9536. }
  9537. if (client) {
  9538. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9539. }
  9540. return 0;
  9541. }
  9542. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9543. if (!lua_interface)
  9544. return 0;
  9545. Client* client = 0;
  9546. Spawn* player = lua_interface->GetSpawn(state);
  9547. float duration = lua_interface->GetFloatValue(state, 2);
  9548. string text = lua_interface->GetStringValue(state, 3);
  9549. string voice = lua_interface->GetStringValue(state, 4);
  9550. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9551. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9552. string signal = lua_interface->GetStringValue(state, 7);
  9553. string goal1 = lua_interface->GetStringValue(state, 8);
  9554. string task1 = lua_interface->GetStringValue(state, 9);
  9555. string goal2 = lua_interface->GetStringValue(state, 10);
  9556. string task2 = lua_interface->GetStringValue(state, 11);
  9557. string goal3 = lua_interface->GetStringValue(state, 12);
  9558. string task3 = lua_interface->GetStringValue(state, 13);
  9559. string goal4 = lua_interface->GetStringValue(state, 14);
  9560. string task4 = lua_interface->GetStringValue(state, 15);
  9561. if (!player) {
  9562. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9563. return 0;
  9564. }
  9565. if (!player->IsPlayer()) {
  9566. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9567. return 0;
  9568. }
  9569. else
  9570. client = ((Player*)player)->GetClient();
  9571. if (!client) {
  9572. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9573. return 0;
  9574. }
  9575. if (text.length() == 0) {
  9576. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9577. return 0;
  9578. }
  9579. if (duration >= 0 && duration < 2)
  9580. duration = 2;
  9581. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9582. if (packet) {
  9583. packet->setDataByName("open_seconds_max", duration);
  9584. packet->setDataByName("text", text.c_str());
  9585. packet->setDataByName("voice", voice.c_str());
  9586. int8 num_goals = 1;
  9587. if (task2.length() > 0)
  9588. num_goals++;
  9589. if (task3.length() > 0)
  9590. num_goals++;
  9591. if (task4.length() > 0)
  9592. num_goals++;
  9593. packet->setArrayLengthByName("num_goals", num_goals);
  9594. for (int8 i = 0; i < num_goals; i++) {
  9595. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9596. }
  9597. if (goal1.length() > 0)
  9598. packet->setArrayDataByName("goal_text", goal1.c_str());
  9599. if (goal2.length() > 0)
  9600. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9601. if (goal3.length() > 0)
  9602. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9603. if (goal4.length() > 0)
  9604. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9605. packet->setSubArrayDataByName("task_text", task1.c_str());
  9606. if (task2.length() > 0)
  9607. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9608. if (task3.length() > 0)
  9609. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9610. if (task4.length() > 0)
  9611. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9612. packet->setDataByName("complete_sound", "click");
  9613. packet->setDataByName("signal", signal.c_str());
  9614. packet->setDataByName("voice_key1", voice_key1);
  9615. packet->setDataByName("voice_key2", voice_key2);
  9616. client->QueuePacket(packet->serialize());
  9617. safe_delete(packet);
  9618. }
  9619. return 0;
  9620. }
  9621. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9622. if (!lua_interface)
  9623. return 0;
  9624. Client* client = 0;
  9625. Spawn* player = lua_interface->GetSpawn(state);
  9626. string window = lua_interface->GetStringValue(state, 2);
  9627. int8 show = lua_interface->GetInt8Value(state, 3);
  9628. if (!player) {
  9629. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9630. return 0;
  9631. }
  9632. if (!player->IsPlayer()) {
  9633. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9634. return 0;
  9635. }
  9636. else
  9637. client = ((Player*)player)->GetClient();
  9638. if (!client) {
  9639. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9640. return 0;
  9641. }
  9642. if (window.length() == 0) {
  9643. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9644. return 0;
  9645. }
  9646. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9647. if (packet) {
  9648. packet->setDataByName("window", window.c_str());
  9649. packet->setDataByName("show", show);
  9650. client->QueuePacket(packet->serialize());
  9651. safe_delete(packet);
  9652. }
  9653. return 0;
  9654. }
  9655. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9656. //See GameEvents.txt for options that can be used for this function
  9657. if (!lua_interface)
  9658. return 0;
  9659. Client* client = 0;
  9660. Spawn* player = lua_interface->GetSpawn(state);
  9661. string event_name = lua_interface->GetStringValue(state, 2);
  9662. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9663. if (!player || !player->IsPlayer()) {
  9664. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9665. return 0;
  9666. }
  9667. if (player->GetZone())
  9668. client = player->GetZone()->GetClientBySpawn(player);
  9669. if (!client) {
  9670. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9671. return 0;
  9672. }
  9673. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9674. if (packet) {
  9675. packet->setDataByName("event_name", event_name.c_str());
  9676. packet->setDataByName("enabled", enabled);
  9677. client->QueuePacket(packet->serialize());
  9678. safe_delete(packet);
  9679. }
  9680. return 0;
  9681. }
  9682. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9683. if (!lua_interface)
  9684. return 0;
  9685. Spawn* player = lua_interface->GetSpawn(state);
  9686. if (player && player->IsPlayer()) {
  9687. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9688. return 1;
  9689. }
  9690. return 0;
  9691. }
  9692. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9693. if (!lua_interface)
  9694. return 0;
  9695. Spawn* player = lua_interface->GetSpawn(state);
  9696. int8 step = lua_interface->GetInt8Value(state, 2);
  9697. if (player && player->IsPlayer() && step > 0) {
  9698. ((Player*)player)->SetTutorialStep(step);
  9699. }
  9700. return 0;
  9701. }
  9702. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9703. if (!lua_interface)
  9704. return 0;
  9705. Client* client = 0;
  9706. Spawn* player = lua_interface->GetSpawn(state);
  9707. string window = lua_interface->GetStringValue(state, 2);
  9708. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9709. if (!player) {
  9710. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9711. return 0;
  9712. }
  9713. if (!player->IsPlayer()) {
  9714. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9715. return 0;
  9716. }
  9717. else
  9718. client = ((Player*)player)->GetClient();
  9719. if (!client) {
  9720. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9721. return 0;
  9722. }
  9723. if (window.length() == 0) {
  9724. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9725. return 0;
  9726. }
  9727. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9728. if (packet) {
  9729. packet->setDataByName("window", window.c_str());
  9730. packet->setDataByName("flash_seconds", flash_seconds);
  9731. client->QueuePacket(packet->serialize());
  9732. safe_delete(packet);
  9733. }
  9734. return 0;
  9735. }
  9736. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9737. if (!lua_interface)
  9738. return 0;
  9739. Spawn* spawn = lua_interface->GetSpawn(state);
  9740. Spawn* target = lua_interface->GetSpawn(state, 2);
  9741. if (spawn && target)
  9742. return spawn->CheckLoS(target);
  9743. return 0;
  9744. }
  9745. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9746. if (!lua_interface)
  9747. return 0;
  9748. Spawn* spawn = lua_interface->GetSpawn(state);
  9749. float x = lua_interface->GetFloatValue(state, 2);
  9750. float y = lua_interface->GetFloatValue(state, 3);
  9751. float z = lua_interface->GetFloatValue(state, 4);
  9752. if (spawn)
  9753. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9754. return 0;
  9755. }
  9756. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9757. if (!lua_interface)
  9758. return 0;
  9759. ZoneServer* zone = lua_interface->GetZone(state);
  9760. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9761. if (zone)
  9762. zone->SetExpansionFlag(xpackFlag);
  9763. return 0;
  9764. }
  9765. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9766. if (!lua_interface)
  9767. return 0;
  9768. ZoneServer* zone = lua_interface->GetZone(state);
  9769. if (zone) {
  9770. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9771. return 1;
  9772. }
  9773. return 0;
  9774. }
  9775. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9776. if (!lua_interface)
  9777. return 0;
  9778. ZoneServer* zone = lua_interface->GetZone(state);
  9779. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9780. if (zone)
  9781. zone->SetHolidayFlag(holidayFlag);
  9782. return 0;
  9783. }
  9784. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9785. if (!lua_interface)
  9786. return 0;
  9787. ZoneServer* zone = lua_interface->GetZone(state);
  9788. if (zone) {
  9789. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9790. return 1;
  9791. }
  9792. return 0;
  9793. }
  9794. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  9795. if (!lua_interface)
  9796. return 0;
  9797. Spawn* player = lua_interface->GetSpawn(state);
  9798. ZoneServer* zone = player->GetZone();
  9799. bool canbind = lua_interface->GetInt32Value(state, 2);
  9800. if (zone)
  9801. zone->SetCanBind(canbind);
  9802. return 0;
  9803. }
  9804. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  9805. if (!lua_interface)
  9806. return 0;
  9807. Spawn* player = lua_interface->GetSpawn(state);
  9808. ZoneServer* zone = player->GetZone();
  9809. if (zone) {
  9810. lua_interface->SetInt32Value(state, zone->GetCanBind());
  9811. return 1;
  9812. }
  9813. return 0;
  9814. }
  9815. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  9816. if (!lua_interface)
  9817. return 0;
  9818. Spawn* player = lua_interface->GetSpawn(state);
  9819. ZoneServer* zone = player->GetZone();
  9820. bool cangate = lua_interface->GetInt32Value(state, 2);
  9821. if (zone)
  9822. zone->SetCanGate(cangate);
  9823. return 0;
  9824. }
  9825. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  9826. if (!lua_interface)
  9827. return 0;
  9828. Spawn* player = lua_interface->GetSpawn(state);
  9829. ZoneServer* zone = player->GetZone();
  9830. if (zone) {
  9831. lua_interface->SetInt32Value(state, zone->GetCanGate());
  9832. return 1;
  9833. }
  9834. return 0;
  9835. }
  9836. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9837. if (!lua_interface)
  9838. return 0;
  9839. Spawn* spawn = lua_interface->GetSpawn(state);
  9840. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9841. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9842. float distance = lua_interface->GetFloatValue(state, 4);
  9843. string in_range_function = lua_interface->GetStringValue(state, 5);
  9844. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9845. if (spawn && distance > 0 && in_range_function.length() > 0)
  9846. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9847. return 0;
  9848. }
  9849. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9850. if (!lua_interface)
  9851. return 0;
  9852. Spawn* spawn = lua_interface->GetSpawn(state);
  9853. Spawn* target = lua_interface->GetSpawn(state, 2);
  9854. if (spawn && target)
  9855. {
  9856. if (spawn->IsPlayer() && target->IsEntity())
  9857. {
  9858. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9859. return 1;
  9860. }
  9861. else if (spawn->IsEntity() && target->IsEntity())
  9862. {
  9863. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9864. return 1;
  9865. }
  9866. }
  9867. return 0;
  9868. }
  9869. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9870. if (!lua_interface)
  9871. return 0;
  9872. Spawn* spawn = lua_interface->GetSpawn(state);
  9873. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9874. if (spawn && spawn->IsEntity())
  9875. {
  9876. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9877. if (spawn->IsPlayer())
  9878. {
  9879. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9880. if (client)
  9881. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9882. }
  9883. }
  9884. return 0;
  9885. }
  9886. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9887. if (!lua_interface)
  9888. return 0;
  9889. Spawn* spawn = lua_interface->GetSpawn(state);
  9890. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9891. if (spawn && spawn->IsEntity())
  9892. {
  9893. ((Entity*)spawn)->SetSeeHideSpell(val);
  9894. if (spawn->IsPlayer())
  9895. {
  9896. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9897. if (client)
  9898. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9899. }
  9900. }
  9901. return 0;
  9902. }
  9903. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9904. {
  9905. if (!lua_interface)
  9906. return 0;
  9907. Spawn* player = lua_interface->GetSpawn(state);
  9908. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9909. string command = lua_interface->GetStringValue(state, 3);
  9910. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9911. lua_interface->ResetFunctionStack(state);
  9912. if (spawn && player && player->IsPlayer())
  9913. {
  9914. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9915. bool res = false;
  9916. if (cmd)
  9917. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9918. lua_interface->SetBooleanValue(state, res);
  9919. return 1;
  9920. }
  9921. return 0;
  9922. }
  9923. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9924. {
  9925. if (!lua_interface)
  9926. return 0;
  9927. Spawn* spawn = lua_interface->GetSpawn(state);
  9928. int32 charID = lua_interface->GetInt32Value(state, 2);
  9929. string command = lua_interface->GetStringValue(state, 3);
  9930. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9931. lua_interface->ResetFunctionStack(state);
  9932. if (spawn && charID)
  9933. {
  9934. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9935. bool res = false;
  9936. if (cmd)
  9937. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9938. lua_interface->SetBooleanValue(state, res);
  9939. return 1;
  9940. }
  9941. return 0;
  9942. }
  9943. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9944. {
  9945. if (!lua_interface)
  9946. return 0;
  9947. Spawn* spawn = lua_interface->GetSpawn(state);
  9948. string command = lua_interface->GetStringValue(state, 2);
  9949. lua_interface->ResetFunctionStack(state);
  9950. if (spawn && command.length() > 0)
  9951. spawn->RemovePrimaryEntityCommand(command.c_str());
  9952. return 0;
  9953. }
  9954. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9955. if (!lua_interface)
  9956. return 0;
  9957. Spawn* spawn = lua_interface->GetSpawn(state);
  9958. float distance = lua_interface->GetFloatValue(state, 2);
  9959. string command = lua_interface->GetStringValue(state, 3);
  9960. Spawn* player = lua_interface->GetSpawn(state, 4);
  9961. lua_interface->ResetFunctionStack(state);
  9962. if (spawn) {
  9963. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9964. }
  9965. return 0;
  9966. }
  9967. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9968. if (!lua_interface)
  9969. return 0;
  9970. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9971. Spawn* spawn = lua_interface->GetSpawn(state);
  9972. Spawn* player = lua_interface->GetSpawn(state, 2);
  9973. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9974. lua_interface->ResetFunctionStack(state);
  9975. if (spawn && player && transport_id && player->IsPlayer()) {
  9976. Client* client = 0;
  9977. if (player && player->IsPlayer())
  9978. client = player->GetZone()->GetClientBySpawn(player);
  9979. if (!client)
  9980. return 0;
  9981. vector<TransportDestination*> destinations;
  9982. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9983. if (destinations.size())
  9984. {
  9985. client->SetTemporaryTransportID(transport_id);
  9986. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9987. }
  9988. else
  9989. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9990. }
  9991. return 0;
  9992. }
  9993. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9994. if (!lua_interface)
  9995. return 0;
  9996. Spawn* player = lua_interface->GetSpawn(state);
  9997. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9998. lua_interface->ResetFunctionStack(state);
  9999. if (player && player->IsPlayer()) {
  10000. Client* client = 0;
  10001. if (player && player->IsPlayer())
  10002. client = player->GetZone()->GetClientBySpawn(player);
  10003. if (!client)
  10004. return 0;
  10005. client->SetTemporaryTransportID(transport_id);
  10006. }
  10007. return 0;
  10008. }
  10009. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10010. if (!lua_interface)
  10011. return 0;
  10012. Spawn* player = lua_interface->GetSpawn(state);
  10013. lua_interface->ResetFunctionStack(state);
  10014. if (player && player->IsPlayer()) {
  10015. Client* client = 0;
  10016. if (player && player->IsPlayer())
  10017. client = player->GetZone()->GetClientBySpawn(player);
  10018. if (!client)
  10019. return 0;
  10020. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10021. return 1;
  10022. }
  10023. return 0;
  10024. }
  10025. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10026. if (!lua_interface)
  10027. return 0;
  10028. Spawn* spawn = lua_interface->GetSpawn(state);
  10029. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10030. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10031. if (!spawn) {
  10032. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10033. return 0;
  10034. }
  10035. if (!spawn->IsEntity()) {
  10036. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10037. return 0;
  10038. }
  10039. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10040. {
  10041. 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);
  10042. return 0;
  10043. }
  10044. lua_interface->ResetFunctionStack(state);
  10045. if (spell && spell->targets.size() > 0) {
  10046. ZoneServer* zone = spell->caster->GetZone();
  10047. for (int8 i = 0; i < spell->targets.size(); i++) {
  10048. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10049. if (target && target->IsEntity()) {
  10050. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10051. if (target->IsPlayer())
  10052. ((Player*)target)->SetCharSheetChanged(true);
  10053. }
  10054. }
  10055. }
  10056. else {
  10057. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10058. if (spawn->IsPlayer())
  10059. ((Player*)spawn)->SetCharSheetChanged(true);
  10060. }
  10061. return 0;
  10062. }
  10063. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10064. if (!lua_interface)
  10065. return 0;
  10066. Spawn* spawn = lua_interface->GetSpawn(state);
  10067. lua_interface->ResetFunctionStack(state);
  10068. if (!spawn) {
  10069. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10070. return 0;
  10071. }
  10072. if (!spawn->IsEntity()) {
  10073. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10074. return 0;
  10075. }
  10076. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10077. return 1;
  10078. }
  10079. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10080. if (!lua_interface)
  10081. return 0;
  10082. int32 spell_id = lua_interface->GetInt32Value(state);
  10083. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10084. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10085. if (spell_id > 0) {
  10086. if (spell_tier == 0)
  10087. spell_tier = 1;
  10088. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10089. LuaSpell* lua_spell = 0;
  10090. if(custom_lua_script.size() > 0)
  10091. {
  10092. // attempt to load the custom script since it isn't already loaded
  10093. // we will re-obtain the lua_spell further below
  10094. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10095. {
  10096. 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());
  10097. lua_interface->LoadLuaSpell(custom_lua_script);
  10098. }
  10099. }
  10100. else
  10101. custom_lua_script = spell->GetSpellData()->lua_script;
  10102. if (!lua_spell && lua_interface)
  10103. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10104. if (!lua_spell)
  10105. {
  10106. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10107. return 0;
  10108. }
  10109. lua_spell->spell = new Spell(spell);
  10110. lua_interface->AddCustomSpell(lua_spell);
  10111. lua_interface->SetSpellValue(state, lua_spell);
  10112. return 1;
  10113. }
  10114. return 0;
  10115. }
  10116. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10117. if (!lua_interface)
  10118. return 0;
  10119. LuaSpell* spell = lua_interface->GetSpell(state);
  10120. string field = lua_interface->GetStringValue(state, 2);
  10121. if (!spell) {
  10122. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10123. return 0;
  10124. }
  10125. if (!spell->spell || !spell->spell->GetSpellData()) {
  10126. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10127. return 0;
  10128. }
  10129. boost::to_lower(field);
  10130. return spell->spell->GetSpellData(state, field);
  10131. }
  10132. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10133. if (!lua_interface)
  10134. return 0;
  10135. LuaSpell* spell = lua_interface->GetSpell(state);
  10136. string field = lua_interface->GetStringValue(state, 2);
  10137. int8 fieldArg = 3; // field value after the initial set
  10138. if (!spell) {
  10139. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10140. return 0;
  10141. }
  10142. if (!spell->spell || !spell->spell->GetSpellData()) {
  10143. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10144. return 0;
  10145. }
  10146. boost::to_lower(field);
  10147. bool valSet = false;
  10148. spell->spell->SetSpellData(state, field, fieldArg);
  10149. return valSet;
  10150. }
  10151. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10152. if (!lua_interface)
  10153. return 0;
  10154. LuaSpell* spell = lua_interface->GetSpell(state);
  10155. int8 idx = lua_interface->GetInt32Value(state, 2);
  10156. if (!spell) {
  10157. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10158. return 0;
  10159. }
  10160. if (!spell->spell || !spell->spell->GetSpellData()) {
  10161. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10162. return 0;
  10163. }
  10164. if (spell->spell->lua_data.size() <= idx)
  10165. {
  10166. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10167. return 0;
  10168. }
  10169. bool setVal = true;
  10170. LUAData* data = spell->spell->lua_data[idx];
  10171. switch (data->type)
  10172. {
  10173. case 0:
  10174. {
  10175. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10176. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10177. data->int_value = value;
  10178. data->int_value2 = value2;
  10179. break;
  10180. }
  10181. case 1:
  10182. {
  10183. float value = lua_interface->GetFloatValue(state, 3);
  10184. float value2 = lua_interface->GetFloatValue(state, 4);
  10185. data->float_value = value;
  10186. data->float_value2 = value2;
  10187. break;
  10188. }
  10189. case 2:
  10190. {
  10191. bool value = lua_interface->GetBooleanValue(state, 3);
  10192. data->bool_value = value;
  10193. break;
  10194. }
  10195. case 3:
  10196. {
  10197. string value = lua_interface->GetStringValue(state, 3);
  10198. string value2 = lua_interface->GetStringValue(state, 4);
  10199. data->string_value = value;
  10200. data->string_value2 = value2;
  10201. break;
  10202. }
  10203. default:
  10204. setVal = false;
  10205. }
  10206. return setVal;
  10207. }
  10208. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10209. if (!lua_interface)
  10210. return 0;
  10211. LuaSpell* spell = lua_interface->GetSpell(state);
  10212. int8 idx = lua_interface->GetInt32Value(state, 2);
  10213. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10214. if (!spell) {
  10215. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10216. return 0;
  10217. }
  10218. if (!spell->spell || !spell->spell->GetSpellData()) {
  10219. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10220. return 0;
  10221. }
  10222. if (spell->spell->lua_data.size() <= idx)
  10223. {
  10224. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10225. return 0;
  10226. }
  10227. bool setVal = true;
  10228. LUAData* data = spell->spell->lua_data[idx];
  10229. switch (data->type)
  10230. {
  10231. case 0:
  10232. {
  10233. if(!secondfield)
  10234. lua_interface->SetSInt32Value(state, data->int_value);
  10235. else
  10236. lua_interface->SetSInt32Value(state, data->int_value2);
  10237. break;
  10238. }
  10239. case 1:
  10240. {
  10241. if (!secondfield)
  10242. lua_interface->SetFloatValue(state, data->float_value);
  10243. else
  10244. lua_interface->SetFloatValue(state, data->float_value2);
  10245. break;
  10246. }
  10247. case 2:
  10248. {
  10249. lua_interface->SetBooleanValue(state, data->bool_value);
  10250. break;
  10251. }
  10252. case 3:
  10253. {
  10254. if (!secondfield)
  10255. lua_interface->SetStringValue(state, data->string_value.c_str());
  10256. else
  10257. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10258. break;
  10259. }
  10260. default:
  10261. setVal = false;
  10262. }
  10263. return setVal;
  10264. }
  10265. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10266. if (!lua_interface)
  10267. return 0;
  10268. LuaSpell* spell = lua_interface->GetSpell(state);
  10269. int8 idx = lua_interface->GetInt32Value(state, 2);
  10270. string field = lua_interface->GetStringValue(state, 3);
  10271. boost::to_lower(field);
  10272. if (!spell) {
  10273. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10274. return 0;
  10275. }
  10276. if (!spell->spell || !spell->spell->GetSpellData()) {
  10277. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10278. return 0;
  10279. }
  10280. if (spell->spell->effects.size() <= idx)
  10281. {
  10282. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10283. return 0;
  10284. }
  10285. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10286. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10287. if (field == "description")
  10288. effect->description = string(lua_interface->GetStringValue(state, 4));
  10289. else if (field == "bullet")
  10290. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10291. else if (field == "percentage")
  10292. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10293. else // no match
  10294. return 0;
  10295. return 1;
  10296. }
  10297. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10298. if (!lua_interface)
  10299. return 0;
  10300. LuaSpell* spell = lua_interface->GetSpell(state);
  10301. int8 idx = lua_interface->GetInt32Value(state, 2);
  10302. string field = lua_interface->GetStringValue(state, 3);
  10303. boost::to_lower(field);
  10304. if (!spell) {
  10305. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10306. return 0;
  10307. }
  10308. if (!spell->spell || !spell->spell->GetSpellData()) {
  10309. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10310. return 0;
  10311. }
  10312. if (spell->spell->effects.size() <= idx)
  10313. {
  10314. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10315. return 0;
  10316. }
  10317. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10318. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10319. if (field == "description")
  10320. lua_interface->SetStringValue(state, effect->description.c_str());
  10321. else if (field == "bullet")
  10322. lua_interface->SetInt32Value(state, effect->subbullet);
  10323. else if (field == "percentage")
  10324. lua_interface->SetInt32Value(state, effect->percentage);
  10325. else // no match
  10326. return 0;
  10327. return 1;
  10328. }
  10329. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10330. if (!lua_interface)
  10331. return 0;
  10332. LuaSpell* spell = lua_interface->GetSpell(state);
  10333. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10334. Spawn* target = lua_interface->GetSpawn(state, 3);
  10335. if (!target) {
  10336. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10337. return 0;
  10338. }
  10339. if (!target->IsEntity()) {
  10340. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10341. return 0;
  10342. }
  10343. if (!spell) {
  10344. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10345. return 0;
  10346. }
  10347. if (caster && !caster->IsEntity()) {
  10348. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10349. return 0;
  10350. }
  10351. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10352. return 0;
  10353. }
  10354. int EQ2Emu_lua_InWater(lua_State* state) {
  10355. if (!lua_interface)
  10356. return 0;
  10357. Spawn* spawn = lua_interface->GetSpawn(state);
  10358. lua_interface->ResetFunctionStack(state);
  10359. if (spawn) {
  10360. lua_interface->SetBooleanValue(state, spawn->InWater());
  10361. return 1;
  10362. }
  10363. return 0;
  10364. }
  10365. int EQ2Emu_lua_InLava(lua_State* state) {
  10366. if (!lua_interface)
  10367. return 0;
  10368. Spawn* spawn = lua_interface->GetSpawn(state);
  10369. lua_interface->ResetFunctionStack(state);
  10370. if (spawn) {
  10371. lua_interface->SetBooleanValue(state, spawn->InLava());
  10372. return 1;
  10373. }
  10374. return 0;
  10375. }
  10376. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10377. if (!lua_interface)
  10378. return 0;
  10379. Spawn* attacker = lua_interface->GetSpawn(state);
  10380. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10381. int8 type = lua_interface->GetInt8Value(state, 3);
  10382. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10383. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10384. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10385. string spell_name = lua_interface->GetStringValue(state, 7);
  10386. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10387. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10388. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10389. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10390. lua_interface->ResetFunctionStack(state);
  10391. if (!attacker) {
  10392. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10393. return 0;
  10394. }
  10395. if (!attacker->IsEntity()) {
  10396. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10397. return 0;
  10398. }
  10399. if (!victim) {
  10400. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10401. return 0;
  10402. }
  10403. if (!victim->IsEntity()) {
  10404. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10405. return 0;
  10406. }
  10407. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10408. return 0;
  10409. }
  10410. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10411. if (!lua_interface)
  10412. return 0;
  10413. Spawn* spawn = lua_interface->GetSpawn(state);
  10414. lua_interface->ResetFunctionStack(state);
  10415. if (spawn) {
  10416. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10417. return 1;
  10418. }
  10419. return 0;
  10420. }
  10421. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10422. if (!lua_interface)
  10423. return 0;
  10424. Spawn* spawn = lua_interface->GetSpawn(state);
  10425. bool invul = lua_interface->GetBooleanValue(state, 2);
  10426. lua_interface->ResetFunctionStack(state);
  10427. if (spawn) {
  10428. spawn->SetInvulnerable(invul);
  10429. }
  10430. return 0;
  10431. }
  10432. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10433. if (!lua_interface)
  10434. return 0;
  10435. string category = lua_interface->GetStringValue(state);
  10436. string name = lua_interface->GetStringValue(state, 2);
  10437. lua_interface->ResetFunctionStack(state);
  10438. Rule *ret = 0;
  10439. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10440. lua_interface->SetBooleanValue(state, ret->GetBool());
  10441. return 1;
  10442. }
  10443. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10444. return 0;
  10445. }
  10446. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10447. if (!lua_interface)
  10448. return 0;
  10449. string category = lua_interface->GetStringValue(state);
  10450. string name = lua_interface->GetStringValue(state, 2);
  10451. lua_interface->ResetFunctionStack(state);
  10452. Rule *ret = 0;
  10453. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10454. lua_interface->SetInt32Value(state, ret->GetInt32());
  10455. return 1;
  10456. }
  10457. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10458. return 0;
  10459. }
  10460. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10461. if (!lua_interface)
  10462. return 0;
  10463. string category = lua_interface->GetStringValue(state);
  10464. string name = lua_interface->GetStringValue(state, 2);
  10465. lua_interface->ResetFunctionStack(state);
  10466. Rule *ret = 0;
  10467. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10468. lua_interface->SetFloatValue(state, ret->GetFloat());
  10469. return 1;
  10470. }
  10471. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10472. return 0;
  10473. }
  10474. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10475. if (!lua_interface)
  10476. return 0;
  10477. Spawn* spawn = lua_interface->GetSpawn(state);
  10478. string type = lua_interface->GetStringValue(state, 2);
  10479. lua_interface->ResetFunctionStack(state);
  10480. if (spawn) {
  10481. int res = 1;
  10482. boost::to_lower(type);
  10483. if(type == "assigned_aa")
  10484. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10485. else if ( type == "unassigned_aa")
  10486. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10487. else if ( type == "assigned_tradeskill_aa")
  10488. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10489. else if ( type == "unassigned_tradeskill_aa")
  10490. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10491. else if ( type == "assigned_prestige_aa")
  10492. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10493. else if ( type == "unassigned_prestige_aa")
  10494. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10495. else if ( type == "assigned_tradeskill_prestige_aa")
  10496. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10497. else if ( type == "unassigned_tradeskill_prestige_aa")
  10498. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10499. else
  10500. res = 0;
  10501. return res;
  10502. }
  10503. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10504. return 0;
  10505. }
  10506. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10507. if (!lua_interface)
  10508. return 0;
  10509. Spawn* spawn = lua_interface->GetSpawn(state);
  10510. string type = lua_interface->GetStringValue(state, 2);
  10511. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10512. lua_interface->ResetFunctionStack(state);
  10513. if (spawn) {
  10514. boost::to_lower(type);
  10515. if(type == "assigned_aa")
  10516. spawn->SetAssignedAA((sint16)value);
  10517. else if ( type == "unassigned_aa")
  10518. spawn->SetUnassignedAA((sint16)value);
  10519. else if ( type == "assigned_tradeskill_aa")
  10520. spawn->SetTradeskillAA((sint16)value);
  10521. else if ( type == "unassigned_tradeskill_aa")
  10522. spawn->SetUnassignedTradeskillAA((sint16)value);
  10523. else if ( type == "assigned_prestige_aa")
  10524. spawn->SetPrestigeAA((sint16)value);
  10525. else if ( type == "unassigned_prestige_aa")
  10526. spawn->SetUnassignedPrestigeAA((sint16)value);
  10527. else if ( type == "assigned_tradeskill_prestige_aa")
  10528. spawn->SetTradeskillPrestigeAA((sint16)value);
  10529. else if ( type == "unassigned_tradeskill_prestige_aa")
  10530. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10531. if(spawn->IsPlayer())
  10532. ((Player*)spawn)->SetCharSheetChanged(true);
  10533. }
  10534. return 0;
  10535. }
  10536. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10537. if (!lua_interface)
  10538. return 0;
  10539. string titleName = lua_interface->GetStringValue(state);
  10540. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10541. lua_interface->ResetFunctionStack(state);
  10542. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10543. lua_interface->SetSInt32Value(state, index);
  10544. return 1;
  10545. }
  10546. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10547. if (!lua_interface)
  10548. return 0;
  10549. Spawn* spawn = lua_interface->GetSpawn(state);
  10550. string titleName = lua_interface->GetStringValue(state, 2);
  10551. lua_interface->ResetFunctionStack(state);
  10552. if(!spawn->IsPlayer())
  10553. {
  10554. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10555. lua_interface->SetSInt32Value(state, -1);
  10556. return 1;
  10557. }
  10558. Player* player = (Player*)spawn;
  10559. // check if player already has the title, don't need to add twice
  10560. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10561. if ( playerHasTitle)
  10562. {
  10563. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10564. return 1;
  10565. }
  10566. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10567. if(!title)
  10568. {
  10569. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10570. lua_interface->SetSInt32Value(state, -1);
  10571. return 1;
  10572. }
  10573. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10574. if(returnIdx < 0)
  10575. {
  10576. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10577. }
  10578. lua_interface->SetSInt32Value(state, returnIdx);
  10579. player->GetClient()->SendTitleUpdate();
  10580. return 1;
  10581. }
  10582. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10583. if (!lua_interface)
  10584. return 0;
  10585. Spawn* spawn = lua_interface->GetSpawn(state);
  10586. string titleName = lua_interface->GetStringValue(state, 2);
  10587. lua_interface->ResetFunctionStack(state);
  10588. if(!spawn->IsPlayer())
  10589. {
  10590. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10591. return 0;
  10592. }
  10593. Player* player = (Player*)spawn;
  10594. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10595. if(!title)
  10596. {
  10597. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10598. return 0;
  10599. }
  10600. if(title->GetPrefix())
  10601. {
  10602. 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());
  10603. return 0;
  10604. }
  10605. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10606. player->GetClient()->SendTitleUpdate();
  10607. return 1;
  10608. }
  10609. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10610. if (!lua_interface)
  10611. return 0;
  10612. Spawn* spawn = lua_interface->GetSpawn(state);
  10613. string titleName = lua_interface->GetStringValue(state, 2);
  10614. lua_interface->ResetFunctionStack(state);
  10615. if(!spawn->IsPlayer())
  10616. {
  10617. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10618. return 0;
  10619. }
  10620. Player* player = (Player*)spawn;
  10621. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10622. if(!title)
  10623. {
  10624. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10625. return 0;
  10626. }
  10627. if(!title->GetPrefix())
  10628. {
  10629. 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());
  10630. return 0;
  10631. }
  10632. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10633. player->GetClient()->SendTitleUpdate();
  10634. return 1;
  10635. }
  10636. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10637. if (!lua_interface)
  10638. return 0;
  10639. Spawn* spawn = lua_interface->GetSpawn(state);
  10640. lua_interface->ResetFunctionStack(state);
  10641. if(!spawn->IsPlayer())
  10642. {
  10643. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10644. return 0;
  10645. }
  10646. Player* player = (Player*)spawn;
  10647. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10648. player->GetClient()->SendTitleUpdate();
  10649. return 1;
  10650. }
  10651. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10652. if (!lua_interface)
  10653. return 0;
  10654. Spawn* spawn = lua_interface->GetSpawn(state);
  10655. lua_interface->ResetFunctionStack(state);
  10656. if(!spawn->IsPlayer())
  10657. {
  10658. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10659. return 0;
  10660. }
  10661. Player* player = (Player*)spawn;
  10662. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10663. player->GetClient()->SendTitleUpdate();
  10664. return 1;
  10665. }
  10666. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10667. if (!lua_interface)
  10668. return 0;
  10669. Spawn* spawn = lua_interface->GetSpawn(state);
  10670. string field = lua_interface->GetStringValue(state, 2);
  10671. lua_interface->ResetFunctionStack(state);
  10672. if(!spawn || !spawn->IsEntity())
  10673. {
  10674. 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));
  10675. return 0;
  10676. }
  10677. Entity* ent = (Entity*)spawn;
  10678. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10679. return 1;
  10680. }
  10681. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10682. if (!lua_interface)
  10683. return 0;
  10684. Spawn* spawn = lua_interface->GetSpawn(state);
  10685. string field = lua_interface->GetStringValue(state, 2);
  10686. lua_interface->ResetFunctionStack(state);
  10687. if(!spawn || !spawn->IsEntity())
  10688. {
  10689. 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));
  10690. return 0;
  10691. }
  10692. Entity* ent = (Entity*)spawn;
  10693. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10694. return 1;
  10695. }
  10696. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10697. if (!lua_interface)
  10698. return 0;
  10699. Spawn* spawn = lua_interface->GetSpawn(state);
  10700. string field = lua_interface->GetStringValue(state, 2);
  10701. lua_interface->ResetFunctionStack(state);
  10702. if(!spawn || !spawn->IsEntity())
  10703. {
  10704. 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));
  10705. return 0;
  10706. }
  10707. Entity* ent = (Entity*)spawn;
  10708. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10709. return 1;
  10710. }
  10711. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10712. if (!lua_interface)
  10713. return 0;
  10714. Spawn* spawn = lua_interface->GetSpawn(state);
  10715. string field = lua_interface->GetStringValue(state, 2);
  10716. lua_interface->ResetFunctionStack(state);
  10717. if(!spawn || !spawn->IsEntity())
  10718. {
  10719. 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));
  10720. return 0;
  10721. }
  10722. Entity* ent = (Entity*)spawn;
  10723. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10724. return 1;
  10725. }
  10726. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10727. if (!lua_interface)
  10728. return 0;
  10729. Spawn* spawn = lua_interface->GetSpawn(state);
  10730. string field = lua_interface->GetStringValue(state, 2);
  10731. string value = lua_interface->GetStringValue(state, 3);
  10732. lua_interface->ResetFunctionStack(state);
  10733. if(!spawn || !spawn->IsEntity())
  10734. {
  10735. 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));
  10736. return 0;
  10737. }
  10738. Entity* ent = (Entity*)spawn;
  10739. bool set_ = ent->SetInfoStructString(field, value);
  10740. lua_interface->SetBooleanValue(state, set_);
  10741. return 1;
  10742. }
  10743. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10744. if (!lua_interface)
  10745. return 0;
  10746. Spawn* spawn = lua_interface->GetSpawn(state);
  10747. string field = lua_interface->GetStringValue(state, 2);
  10748. int64 value = lua_interface->GetInt64Value(state, 3);
  10749. lua_interface->ResetFunctionStack(state);
  10750. if(!spawn || !spawn->IsEntity())
  10751. {
  10752. 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));
  10753. return 0;
  10754. }
  10755. Entity* ent = (Entity*)spawn;
  10756. bool set_ = ent->SetInfoStructUInt(field, value);
  10757. lua_interface->SetBooleanValue(state, set_);
  10758. return 1;
  10759. }
  10760. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10761. if (!lua_interface)
  10762. return 0;
  10763. Spawn* spawn = lua_interface->GetSpawn(state);
  10764. string field = lua_interface->GetStringValue(state, 2);
  10765. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10766. lua_interface->ResetFunctionStack(state);
  10767. if(!spawn || !spawn->IsEntity())
  10768. {
  10769. 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));
  10770. return 0;
  10771. }
  10772. Entity* ent = (Entity*)spawn;
  10773. bool set_ = ent->SetInfoStructSInt(field, value);
  10774. lua_interface->SetBooleanValue(state, set_);
  10775. return 1;
  10776. }
  10777. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10778. if (!lua_interface)
  10779. return 0;
  10780. Spawn* spawn = lua_interface->GetSpawn(state);
  10781. string field = lua_interface->GetStringValue(state, 2);
  10782. float value = lua_interface->GetFloatValue(state, 3);
  10783. lua_interface->ResetFunctionStack(state);
  10784. if(!spawn || !spawn->IsEntity())
  10785. {
  10786. 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));
  10787. return 0;
  10788. }
  10789. Entity* ent = (Entity*)spawn;
  10790. bool set_ = ent->SetInfoStructFloat(field, value);
  10791. lua_interface->SetBooleanValue(state, set_);
  10792. return 1;
  10793. }
  10794. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10795. if (!lua_interface)
  10796. return 0;
  10797. Spawn* spawn = lua_interface->GetSpawn(state);
  10798. bool value = lua_interface->GetBooleanValue(state, 2);
  10799. lua_interface->ResetFunctionStack(state);
  10800. if(!spawn || !spawn->IsPlayer())
  10801. {
  10802. 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));
  10803. return 0;
  10804. }
  10805. ((Player*)spawn)->SetCharSheetChanged(value);
  10806. return 0;
  10807. }
  10808. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10809. if (!lua_interface)
  10810. return 0;
  10811. Spawn* spawn = lua_interface->GetSpawn(state);
  10812. std::string fromName = lua_interface->GetStringValue(state, 2);
  10813. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10814. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10815. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10816. int32 copper = lua_interface->GetInt32Value(state, 6);
  10817. int32 silver = lua_interface->GetInt32Value(state, 7);
  10818. int32 gold = lua_interface->GetInt32Value(state, 8);
  10819. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10820. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10821. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10822. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10823. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10824. lua_interface->ResetFunctionStack(state);
  10825. if(!spawn || !spawn->IsPlayer())
  10826. {
  10827. 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));
  10828. lua_interface->SetBooleanValue(state, false);
  10829. return 1;
  10830. }
  10831. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10832. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10833. lua_interface->SetBooleanValue(state, true);
  10834. return 1;
  10835. }
  10836. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10837. if (!lua_interface)
  10838. return 0;
  10839. int32 char_id = lua_interface->GetInt32Value(state);
  10840. std::string fromName = lua_interface->GetStringValue(state, 2);
  10841. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10842. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10843. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10844. int32 copper = lua_interface->GetInt32Value(state, 6);
  10845. int32 silver = lua_interface->GetInt32Value(state, 7);
  10846. int32 gold = lua_interface->GetInt32Value(state, 8);
  10847. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10848. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10849. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10850. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10851. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10852. lua_interface->ResetFunctionStack(state);
  10853. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10854. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10855. lua_interface->SetBooleanValue(state, true);
  10856. return 1;
  10857. }
  10858. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10859. Spawn* widget;
  10860. if (lua_interface) {
  10861. widget = lua_interface->GetSpawn(state);
  10862. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10863. lua_interface->ResetFunctionStack(state);
  10864. if (widget && widget->IsWidget())
  10865. {
  10866. ((Widget*)widget)->OpenDoor();
  10867. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10868. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10869. }
  10870. else
  10871. 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));
  10872. }
  10873. return 0;
  10874. }
  10875. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10876. Spawn* widget;
  10877. if (lua_interface) {
  10878. widget = lua_interface->GetSpawn(state);
  10879. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10880. lua_interface->ResetFunctionStack(state);
  10881. if (widget && widget->IsWidget())
  10882. {
  10883. ((Widget*)widget)->CloseDoor();
  10884. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10885. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10886. }
  10887. else
  10888. 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));
  10889. }
  10890. return 0;
  10891. }
  10892. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10893. if (!lua_interface)
  10894. return 0;
  10895. Spawn* widget = lua_interface->GetSpawn(state);
  10896. lua_interface->ResetFunctionStack(state);
  10897. if (widget && widget->IsWidget())
  10898. {
  10899. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10900. return 1;
  10901. }
  10902. return 0;
  10903. }
  10904. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10905. if (!lua_interface)
  10906. return 0;
  10907. sint32 min = lua_interface->GetSInt32Value(state);
  10908. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10909. lua_interface->ResetFunctionStack(state);
  10910. sint32 result = MakeRandomInt(min, max);
  10911. lua_interface->SetSInt32Value(state, result);
  10912. return 1;
  10913. }
  10914. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10915. if (!lua_interface)
  10916. return 0;
  10917. float min = lua_interface->GetFloatValue(state);
  10918. float max = lua_interface->GetFloatValue(state, 2);
  10919. lua_interface->ResetFunctionStack(state);
  10920. float result = MakeRandomFloat(min, max);
  10921. lua_interface->SetFloatValue(state, result);
  10922. return 1;
  10923. }
  10924. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10925. if (!lua_interface)
  10926. return 0;
  10927. Spawn* spawn = lua_interface->GetSpawn(state);
  10928. int32 value = lua_interface->GetInt32Value(state, 2);
  10929. lua_interface->ResetFunctionStack(state);
  10930. if(!spawn)
  10931. {
  10932. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10933. lua_interface->SetBooleanValue(state, false);
  10934. return 1;
  10935. }
  10936. spawn->AddIconValue(value);
  10937. lua_interface->SetBooleanValue(state, true);
  10938. return 1;
  10939. }
  10940. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10941. if (!lua_interface)
  10942. return 0;
  10943. Spawn* spawn = lua_interface->GetSpawn(state);
  10944. int32 value = lua_interface->GetInt32Value(state, 2);
  10945. lua_interface->ResetFunctionStack(state);
  10946. if(!spawn)
  10947. {
  10948. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10949. lua_interface->SetBooleanValue(state, false);
  10950. return 1;
  10951. }
  10952. spawn->RemoveIconValue(value);
  10953. lua_interface->SetBooleanValue(state, true);
  10954. return 1;
  10955. }
  10956. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10957. Spawn* npc = lua_interface->GetSpawn(state);
  10958. lua_interface->ResetFunctionStack(state);
  10959. if (npc && npc->IsNPC()) {
  10960. NPC* shard = (NPC*)npc;
  10961. int32 shardid = shard->GetShardID();
  10962. lua_interface->SetInt32Value(state, shardid);
  10963. return 1;
  10964. }
  10965. lua_interface->SetInt32Value(state, 0);
  10966. return 1;
  10967. }
  10968. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10969. Spawn* npc = lua_interface->GetSpawn(state);
  10970. lua_interface->ResetFunctionStack(state);
  10971. if (npc && npc->IsNPC()) {
  10972. NPC* shard = (NPC*)npc;
  10973. int32 charid = shard->GetShardCharID();
  10974. lua_interface->SetInt32Value(state, charid);
  10975. return 1;
  10976. }
  10977. lua_interface->SetInt32Value(state, 0);
  10978. return 1;
  10979. }
  10980. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10981. Spawn* npc = lua_interface->GetSpawn(state);
  10982. lua_interface->ResetFunctionStack(state);
  10983. if (npc && npc->IsNPC()) {
  10984. NPC* shard = (NPC*)npc;
  10985. int64 timestamp = shard->GetShardCreatedTimestamp();
  10986. lua_interface->SetSInt64Value(state, timestamp);
  10987. return 1;
  10988. }
  10989. lua_interface->SetSInt64Value(state, 0);
  10990. return 1;
  10991. }
  10992. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10993. if (!lua_interface)
  10994. return 0;
  10995. int32 shardid = lua_interface->GetInt32Value(state);
  10996. lua_interface->ResetFunctionStack(state);
  10997. if(shardid < 1)
  10998. lua_interface->SetBooleanValue(state, false);
  10999. else
  11000. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11001. return 1;
  11002. }
  11003. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11004. if (!lua_interface)
  11005. return 0;
  11006. Spawn* spawn = lua_interface->GetSpawn(state);
  11007. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11008. if (spawn) {
  11009. spawn->PauseMovement(delay_in_ms);
  11010. }
  11011. lua_interface->ResetFunctionStack(state);
  11012. return 0;
  11013. }
  11014. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11015. if (!lua_interface)
  11016. return 0;
  11017. Spawn* spawn = lua_interface->GetSpawn(state);
  11018. if (spawn) {
  11019. spawn->StopMovement();
  11020. }
  11021. lua_interface->ResetFunctionStack(state);
  11022. return 0;
  11023. }
  11024. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11025. Player* player = (Player*)lua_interface->GetSpawn(state);
  11026. int8 level = lua_interface->GetInt8Value(state, 2);
  11027. lua_interface->ResetFunctionStack(state);
  11028. if (player && player->IsPlayer() && level > 0) {
  11029. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11030. return 1;
  11031. }
  11032. return 0;
  11033. }
  11034. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11035. Player* player = (Player*)lua_interface->GetSpawn(state);
  11036. int8 level = lua_interface->GetInt8Value(state, 2);
  11037. lua_interface->ResetFunctionStack(state);
  11038. if (player && player->IsPlayer() && level > 0) {
  11039. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11040. return 1;
  11041. }
  11042. return 0;
  11043. }
  11044. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11045. ZoneServer* zone = lua_interface->GetZone(state);
  11046. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11047. lua_interface->ResetFunctionStack(state);
  11048. if (zone) {
  11049. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11050. if (spawn) {
  11051. lua_interface->SetSpawnValue(state, spawn);
  11052. return 1;
  11053. }
  11054. }
  11055. return 0;
  11056. }
  11057. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11058. if (!lua_interface)
  11059. return 0;
  11060. Spawn* spawn = lua_interface->GetSpawn(state);
  11061. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11062. lua_interface->ResetFunctionStack(state);
  11063. bool res = false;
  11064. if(spawn && spawn->IsTransportSpawn())
  11065. {
  11066. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11067. spawn->SetRailID(rail_id);
  11068. res = true;
  11069. }
  11070. else if (!spawn) {
  11071. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11072. }
  11073. else if(!spawn->IsTransportSpawn()) {
  11074. 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());
  11075. }
  11076. lua_interface->SetBooleanValue(state, res);
  11077. return 1;
  11078. }
  11079. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11080. if (!lua_interface)
  11081. return 0;
  11082. ZoneServer* zone = lua_interface->GetZone(state);
  11083. lua_interface->ResetFunctionStack(state);
  11084. if (zone) {
  11085. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11086. return 1;
  11087. }
  11088. return 0;
  11089. }
  11090. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11091. if (!lua_interface)
  11092. return 0;
  11093. Spawn* spawn = lua_interface->GetSpawn(state);
  11094. lua_interface->ResetFunctionStack(state);
  11095. if (spawn) {
  11096. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11097. return 1;
  11098. }
  11099. return 0;
  11100. }
  11101. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11102. if (!lua_interface)
  11103. return 0;
  11104. Spawn* player = lua_interface->GetSpawn(state);
  11105. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11106. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11107. lua_interface->ResetFunctionStack(state);
  11108. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11109. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11110. }
  11111. else if(!zoneID) {
  11112. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11113. }
  11114. else
  11115. {
  11116. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11117. return 1;
  11118. }
  11119. return 0;
  11120. }
  11121. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11122. if (!lua_interface)
  11123. return 0;
  11124. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11125. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11126. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11127. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11128. lua_interface->ResetFunctionStack(state);
  11129. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11130. world.GetWorldTimeStruct()->year = newYear;
  11131. world.GetWorldTimeStruct()->month = newMonth;
  11132. world.GetWorldTimeStruct()->hour = newHour;
  11133. world.GetWorldTimeStruct()->minute = newMinute;
  11134. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11135. return 0;
  11136. }
  11137. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11138. if (!lua_interface)
  11139. return 0;
  11140. lua_interface->ResetFunctionStack(state);
  11141. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11142. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11143. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11144. return 1;
  11145. }
  11146. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11147. if (!lua_interface)
  11148. return 0;
  11149. lua_interface->ResetFunctionStack(state);
  11150. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11151. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11152. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11153. return 1;
  11154. }
  11155. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11156. if (!lua_interface)
  11157. return 0;
  11158. lua_interface->ResetFunctionStack(state);
  11159. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11160. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11161. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11162. return 1;
  11163. }
  11164. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11165. if (!lua_interface)
  11166. return 0;
  11167. lua_interface->ResetFunctionStack(state);
  11168. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11169. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11170. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11171. return 1;
  11172. }
  11173. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11174. if (!lua_interface)
  11175. return 0;
  11176. lua_interface->ResetFunctionStack(state);
  11177. world.SendTimeUpdate();
  11178. return 0;
  11179. }
  11180. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11181. bool update_result = false;
  11182. Faction* faction = 0;
  11183. Player* player = (Player*)lua_interface->GetSpawn(state);
  11184. Client* client = player->GetZone()->GetClientBySpawn(player);
  11185. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11186. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11187. lua_interface->ResetFunctionStack(state);
  11188. if (player && player->IsPlayer() && faction_id > 0) {
  11189. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11190. if(hasfaction == 0) {
  11191. //they do not have the faction. Lets get the default value and feed it in.
  11192. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11193. //add the default faction for the player.
  11194. player->SetFactionValue(faction_id, defaultfaction);
  11195. }
  11196. if(increase >= 0) {
  11197. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11198. faction = master_faction_list.GetFaction(faction_id);
  11199. if(faction && update_result)
  11200. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11201. else if(faction)
  11202. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11203. lua_interface->SetBooleanValue(state, true);
  11204. return 1;
  11205. }
  11206. if(increase < 0){
  11207. //change the negative to a positive, since thats how decreasefaction() likes it.
  11208. increase *= -1;
  11209. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11210. faction = master_faction_list.GetFaction(faction_id);
  11211. if(faction && update_result)
  11212. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11213. else if(faction)
  11214. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11215. lua_interface->SetBooleanValue(state, true);
  11216. return 1;
  11217. }
  11218. }
  11219. lua_interface->SetBooleanValue(state, false);
  11220. return 1;
  11221. }
  11222. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11223. bool hascoin = 0;
  11224. Player* player = (Player*)lua_interface->GetSpawn(state);
  11225. int32 coins = lua_interface->GetInt32Value(state, 2);
  11226. lua_interface->ResetFunctionStack(state);
  11227. if (player && player->IsPlayer()) {
  11228. hascoin = player->HasCoins(coins);
  11229. if(hascoin == 0) {
  11230. lua_interface->SetBooleanValue(state, false);
  11231. return 1;
  11232. }
  11233. if(hascoin == 1) {
  11234. lua_interface->SetBooleanValue(state, true);
  11235. return 1;
  11236. }
  11237. }
  11238. return 0;
  11239. }
  11240. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11241. int32 loot_tier = 0;
  11242. Spawn* spawn = lua_interface->GetSpawn(state);
  11243. lua_interface->ResetFunctionStack(state);
  11244. if (spawn) {
  11245. loot_tier = spawn->GetLootTier();
  11246. lua_interface->SetInt32Value(state, loot_tier);
  11247. return 1;
  11248. }
  11249. return 0;
  11250. }
  11251. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11252. if (!lua_interface)
  11253. return 0;
  11254. Spawn* spawn = lua_interface->GetSpawn(state);
  11255. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11256. lua_interface->ResetFunctionStack(state);
  11257. if (spawn) {
  11258. spawn->SetLootTier(loot_tier);
  11259. lua_interface->SetBooleanValue(state, true);
  11260. return 1;
  11261. }
  11262. lua_interface->SetBooleanValue(state, false);
  11263. return 1;
  11264. }
  11265. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11266. int32 loot_drop_type = 0;
  11267. Spawn* spawn = lua_interface->GetSpawn(state);
  11268. lua_interface->ResetFunctionStack(state);
  11269. if (spawn) {
  11270. loot_drop_type = spawn->GetLootDropType();
  11271. lua_interface->SetInt32Value(state, loot_drop_type);
  11272. return 1;
  11273. }
  11274. return 0;
  11275. }
  11276. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11277. if (!lua_interface)
  11278. return 0;
  11279. Spawn* spawn = lua_interface->GetSpawn(state);
  11280. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11281. lua_interface->ResetFunctionStack(state);
  11282. if (spawn) {
  11283. spawn->SetLootDropType(loot_drop_type);
  11284. lua_interface->SetBooleanValue(state, true);
  11285. return 1;
  11286. }
  11287. lua_interface->SetBooleanValue(state, false);
  11288. return 1;
  11289. }