LuaFunctions.cpp 396 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002
  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. int8 language = lua_interface->GetInt8Value(state, 9);
  943. int numargs = lua_interface->GetNumberOfArgs(state);
  944. int8 can_close = 1;
  945. if(numargs > 9)
  946. can_close = lua_interface->GetInt32Value(state, 10);
  947. lua_interface->ResetFunctionStack(state);
  948. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  949. Client* client = player->GetZone()->GetClientBySpawn(player);
  950. if (client) {
  951. if (spawn) {
  952. // Need to do this so the function works the same as it did before
  953. if (type == 1)
  954. type++;
  955. if (mp3.length() > 0)
  956. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  957. else
  958. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  959. }
  960. else {
  961. if (mp3.length() > 0)
  962. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  963. else
  964. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  965. }
  966. }
  967. }
  968. safe_delete(conversation);
  969. lua_interface->SetConversationValue(state, NULL);
  970. return 0;
  971. }
  972. int EQ2Emu_lua_StartConversation(lua_State* state) {
  973. if (!lua_interface)
  974. return 0;
  975. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  976. Spawn* source = lua_interface->GetSpawn(state, 2);
  977. Spawn* player = lua_interface->GetSpawn(state, 3);
  978. string text = lua_interface->GetStringValue(state, 4);
  979. string mp3 = lua_interface->GetStringValue(state, 5);
  980. int32 key1 = lua_interface->GetInt32Value(state, 6);
  981. int32 key2 = lua_interface->GetInt32Value(state, 7);
  982. int8 language = lua_interface->GetInt32Value(state, 8);
  983. int numargs = lua_interface->GetNumberOfArgs(state);
  984. int8 can_close = 1;
  985. if(numargs > 8)
  986. can_close = lua_interface->GetInt32Value(state, 9);
  987. lua_interface->ResetFunctionStack(state);
  988. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  989. Client* client = source->GetZone()->GetClientBySpawn(player);
  990. if (mp3.length() > 0)
  991. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  992. else
  993. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  994. safe_delete(conversation);
  995. lua_interface->SetConversationValue(state, NULL);
  996. }
  997. else
  998. 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);
  999. return 0;
  1000. }
  1001. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1002. if (!lua_interface)
  1003. return 0;
  1004. Spawn* spawn = lua_interface->GetSpawn(state);
  1005. float distance = lua_interface->GetFloatValue(state, 2);
  1006. string in_range_function = lua_interface->GetStringValue(state, 3);
  1007. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1008. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1009. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1010. return 0;
  1011. }
  1012. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1013. ZoneServer* zone = lua_interface->GetZone(state);
  1014. float x = lua_interface->GetFloatValue(state, 2);
  1015. float y = lua_interface->GetFloatValue(state, 3);
  1016. float z = lua_interface->GetFloatValue(state, 4);
  1017. float max_variation = lua_interface->GetFloatValue(state, 5);
  1018. string in_range_function = lua_interface->GetStringValue(state, 6);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1020. lua_interface->ResetFunctionStack(state);
  1021. if (zone && in_range_function.length() > 0)
  1022. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1023. return 0;
  1024. }
  1025. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1026. if (!lua_interface)
  1027. return 0;
  1028. Spawn* spawn = lua_interface->GetSpawn(state);
  1029. if (spawn && spawn->IsEntity()) {
  1030. int32 val = lua_interface->GetInt32Value(state, 2);
  1031. ((Entity*)spawn)->SetLootCoins(val);
  1032. }
  1033. lua_interface->ResetFunctionStack(state);
  1034. return 0;
  1035. }
  1036. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1037. if (!lua_interface)
  1038. return 0;
  1039. Spawn* spawn = lua_interface->GetSpawn(state);
  1040. lua_interface->ResetFunctionStack(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1043. return 1;
  1044. }
  1045. return 0;
  1046. }
  1047. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1048. if (!lua_interface)
  1049. return 0;
  1050. Spawn* spawn = lua_interface->GetSpawn(state);
  1051. float x = lua_interface->GetFloatValue(state, 2);
  1052. float y = lua_interface->GetFloatValue(state, 3);
  1053. float z = lua_interface->GetFloatValue(state, 4);
  1054. float speed = lua_interface->GetFloatValue(state, 5);
  1055. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1056. string function = lua_interface->GetStringValue(state, 7);
  1057. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1058. float heading = lua_interface->GetFloatValue(state, 8);
  1059. if (spawn) {
  1060. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1061. spawn->GetZone()->AddMovementNPC(spawn);
  1062. }
  1063. lua_interface->ResetFunctionStack(state);
  1064. return 0;
  1065. }
  1066. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1067. if (!lua_interface)
  1068. return 0;
  1069. Spawn* spawn = lua_interface->GetSpawn(state);
  1070. lua_interface->ResetFunctionStack(state);
  1071. if (spawn) {
  1072. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1073. return 1;
  1074. }
  1075. return 0;
  1076. }
  1077. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1078. if (!lua_interface)
  1079. return 0;
  1080. Spawn* spawn = lua_interface->GetSpawn(state);
  1081. lua_interface->ResetFunctionStack(state);
  1082. if (spawn && spawn->IsPlayer()) {
  1083. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1084. return 1;
  1085. }
  1086. lua_interface->SetInt32Value(state, 0);
  1087. return 1;
  1088. }
  1089. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. Spawn* target = lua_interface->GetSpawn(state, 2);
  1094. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1095. bool reset_action_state = true;
  1096. if(num_args > 2)
  1097. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1098. if (spawn && target) {
  1099. if (spawn->IsEntity())
  1100. // ((Entity*)spawn)->FaceTarget(target);
  1101. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1102. }
  1103. lua_interface->ResetFunctionStack(state);
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* spawn = lua_interface->GetSpawn(state);
  1110. float x = lua_interface->GetFloatValue(state, 2);
  1111. float y = lua_interface->GetFloatValue(state, 3);
  1112. float z = lua_interface->GetFloatValue(state, 4);
  1113. float speed = lua_interface->GetFloatValue(state, 5);
  1114. string lua_function = lua_interface->GetStringValue(state, 6);
  1115. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1116. if (spawn) {
  1117. if (speed == 0)
  1118. speed = spawn->GetSpeed();
  1119. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1120. }
  1121. lua_interface->ResetFunctionStack(state);
  1122. return 0;
  1123. }
  1124. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1125. if (!lua_interface)
  1126. return 0;
  1127. Spawn* spawn = lua_interface->GetSpawn(state);
  1128. lua_interface->ResetFunctionStack(state);
  1129. if (spawn) {
  1130. spawn->ClearRunningLocations();
  1131. }
  1132. return 0;
  1133. }
  1134. int EQ2Emu_lua_Say(lua_State* state) {
  1135. if (!lua_interface)
  1136. return 0;
  1137. Spawn* spawn = lua_interface->GetSpawn(state);
  1138. string message = lua_interface->GetStringValue(state, 2);
  1139. Spawn* player = lua_interface->GetSpawn(state, 3);
  1140. int32 language = lua_interface->GetInt32Value(state, 4);
  1141. if (spawn && message.length() > 0) {
  1142. Client* client = 0;
  1143. if (player && player->IsPlayer())
  1144. client = spawn->GetZone()->GetClientBySpawn(player);
  1145. if (client)
  1146. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1147. else
  1148. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1149. }
  1150. lua_interface->ResetFunctionStack(state);
  1151. return 0;
  1152. }
  1153. int EQ2Emu_lua_Shout(lua_State* state) {
  1154. if (!lua_interface)
  1155. return 0;
  1156. Spawn* spawn = lua_interface->GetSpawn(state);
  1157. string message = lua_interface->GetStringValue(state, 2);
  1158. Spawn* player = lua_interface->GetSpawn(state, 3);
  1159. float dist = lua_interface->GetFloatValue(state, 4);
  1160. if (spawn && message.length() > 0) {
  1161. Client* client = 0;
  1162. if (player && player->IsPlayer())
  1163. client = spawn->GetZone()->GetClientBySpawn(player);
  1164. if (client)
  1165. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1166. else
  1167. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1168. }
  1169. lua_interface->ResetFunctionStack(state);
  1170. return 0;
  1171. }
  1172. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1173. if (!lua_interface)
  1174. return 0;
  1175. Spawn* spawn = lua_interface->GetSpawn(state);
  1176. string message = lua_interface->GetStringValue(state, 2);
  1177. Spawn* player = lua_interface->GetSpawn(state, 3);
  1178. if (spawn && message.length() > 0) {
  1179. Client* client = 0;
  1180. if (player && player->IsPlayer())
  1181. client = spawn->GetZone()->GetClientBySpawn(player);
  1182. if (client)
  1183. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1184. else
  1185. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1186. }
  1187. lua_interface->ResetFunctionStack(state);
  1188. return 0;
  1189. }
  1190. int EQ2Emu_lua_Emote(lua_State* state) {
  1191. if (!lua_interface)
  1192. return 0;
  1193. Spawn* spawn = lua_interface->GetSpawn(state);
  1194. string message = lua_interface->GetStringValue(state, 2);
  1195. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1196. Spawn* player = lua_interface->GetSpawn(state, 4);
  1197. char* to = 0;
  1198. if (spawn2)
  1199. to = spawn2->GetName();
  1200. if (spawn && message.length() > 0) {
  1201. Client* client = 0;
  1202. if (player && player->IsPlayer())
  1203. client = spawn->GetZone()->GetClientBySpawn(player);
  1204. if (client)
  1205. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1206. else
  1207. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1208. }
  1209. lua_interface->ResetFunctionStack(state);
  1210. return 0;
  1211. }
  1212. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1213. if (!lua_interface)
  1214. return 0;
  1215. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1216. if(!luaspell || luaspell->resisted) {
  1217. return 0;
  1218. }
  1219. Spawn* caster = luaspell->caster;
  1220. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1221. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1222. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1223. Spawn* target = lua_interface->GetSpawn(state, 4);
  1224. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1225. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1226. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1227. lua_interface->ResetFunctionStack(state);
  1228. boost::to_lower(heal_type);
  1229. if (caster && caster->IsEntity()) {
  1230. bool success = false;
  1231. luaspell->resisted = false;
  1232. if (target) {
  1233. float distance = caster->GetDistance(target, true);
  1234. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1235. success = true;
  1236. }
  1237. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1238. Spawn* target = 0;
  1239. ZoneServer* zone = luaspell->caster->GetZone();
  1240. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1241. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1242. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1243. float distance = caster->GetDistance(target, true);
  1244. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1245. }
  1246. }
  1247. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1248. success = true;
  1249. }
  1250. if (success) {
  1251. if (caster->GetZone())
  1252. caster->GetZone()->TriggerCharSheetTimer();
  1253. }
  1254. }
  1255. return 0;
  1256. }
  1257. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1258. if (!lua_interface)
  1259. return 0;
  1260. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1261. if(!luaspell || luaspell->resisted) {
  1262. return 0;
  1263. }
  1264. Spawn* caster = luaspell->caster;
  1265. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1266. float percentage = lua_interface->GetFloatValue(state, 2);
  1267. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1268. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1269. Spawn* target = lua_interface->GetSpawn(state, 5);
  1270. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1271. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1272. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1273. lua_interface->ResetFunctionStack(state);
  1274. boost::to_lower(heal_type);
  1275. int32 min_heal = 0, max_heal = 0;
  1276. if (caster && caster->IsEntity() && target) {
  1277. if(percentage <= 0.0f)
  1278. {
  1279. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1280. return 0;
  1281. }
  1282. if(heal_type == "power")
  1283. {
  1284. if(current_value)
  1285. {
  1286. if(caster_value)
  1287. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1288. else
  1289. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1290. }
  1291. else
  1292. {
  1293. if(caster_value)
  1294. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1295. else
  1296. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1297. }
  1298. }
  1299. else
  1300. {
  1301. if(current_value)
  1302. {
  1303. if(caster_value)
  1304. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1305. else
  1306. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1307. }
  1308. else
  1309. {
  1310. if(caster_value)
  1311. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1312. else
  1313. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1314. }
  1315. }
  1316. bool success = false;
  1317. luaspell->resisted = false;
  1318. if (target) {
  1319. float distance = caster->GetDistance(target, true);
  1320. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1321. success = true;
  1322. }
  1323. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1324. Spawn* target = 0;
  1325. ZoneServer* zone = luaspell->caster->GetZone();
  1326. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1327. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1328. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1329. float distance = caster->GetDistance(target, true);
  1330. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1331. }
  1332. }
  1333. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1334. success = true;
  1335. }
  1336. if (success) {
  1337. if (caster->GetZone())
  1338. caster->GetZone()->TriggerCharSheetTimer();
  1339. }
  1340. }
  1341. return 0;
  1342. }
  1343. int EQ2Emu_lua_AddItem(lua_State* state) {
  1344. if (!lua_interface)
  1345. return 0;
  1346. Spawn* spawn = lua_interface->GetSpawn(state);
  1347. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1348. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1349. lua_interface->ResetFunctionStack(state);
  1350. // default of 1 quantity to add
  1351. if (quantity == 0)
  1352. quantity = 1;
  1353. if (spawn && spawn->IsPlayer()) {
  1354. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1355. if (client && item_id > 0) {
  1356. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1357. return 1;
  1358. }
  1359. }
  1360. lua_interface->SetBooleanValue(state, false);
  1361. return 1;
  1362. }
  1363. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1364. if (!lua_interface)
  1365. return 0;
  1366. Spawn* spawn = lua_interface->GetSpawn(state);
  1367. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1368. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1369. string location = lua_interface->GetStringValue(state, 4);
  1370. int16 item_count = lua_interface->GetInt16Value(state,5);
  1371. //devn00b: if we dont have a count, assume 1 item.
  1372. if(!item_count) {
  1373. item_count = 1;
  1374. }
  1375. lua_interface->ResetFunctionStack(state);
  1376. if (spawn && spawn->IsPlayer()) {
  1377. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1378. if (client && item_id > 0) {
  1379. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1380. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1381. else
  1382. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1383. if (send_messages) {
  1384. Item* item = master_item_list.GetItem(item_id);
  1385. if (item) {
  1386. if(item_count > 1) {
  1387. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1388. string popup_text1 = "You receive "+ item_count;
  1389. string popup_text2 = " " + item->name;
  1390. string popup_text = popup_text1 + popup_text2;
  1391. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1392. // return 1;
  1393. } else {
  1394. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1395. string popup_text = "You receive " + item->name;
  1396. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1397. }
  1398. }
  1399. }
  1400. return 1;
  1401. }
  1402. }
  1403. lua_interface->SetBooleanValue(state, false);
  1404. return 1;
  1405. }
  1406. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1407. Spawn* spawn = lua_interface->GetSpawn(state);
  1408. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1409. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1410. lua_interface->ResetFunctionStack(state);
  1411. // default of 1 to remove
  1412. if (quantity == 0)
  1413. quantity = 1;
  1414. Client* client;
  1415. Item* item;
  1416. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1417. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1418. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1419. if (client->RemoveItem(item, quantity)) {
  1420. lua_interface->SetBooleanValue(state, true);
  1421. return 1;
  1422. }
  1423. }
  1424. }
  1425. }
  1426. lua_interface->SetBooleanValue(state, false);
  1427. return 1;
  1428. }
  1429. int EQ2Emu_lua_HasItem(lua_State* state) {
  1430. Spawn* player = lua_interface->GetSpawn(state);
  1431. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1432. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1433. lua_interface->ResetFunctionStack(state);
  1434. if (player && player->IsPlayer()) {
  1435. bool hasItem = false;
  1436. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1437. if (!hasItem)
  1438. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1439. lua_interface->SetBooleanValue(state, hasItem);
  1440. return 1;
  1441. }
  1442. lua_interface->SetBooleanValue(state, false);
  1443. return 1;
  1444. }
  1445. int EQ2Emu_lua_Spawn(lua_State* state) {
  1446. if (!lua_interface)
  1447. return 0;
  1448. ZoneServer* zone = lua_interface->GetZone(state);
  1449. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1450. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1451. float x = lua_interface->GetFloatValue(state, 4);
  1452. float y = lua_interface->GetFloatValue(state, 5);
  1453. float z = lua_interface->GetFloatValue(state, 6);
  1454. float heading = lua_interface->GetFloatValue(state, 7);
  1455. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1456. Spawn* spawn = zone->GetSpawn(spawn_id);
  1457. if (!spawn)
  1458. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1459. else {
  1460. spawn->SetX(x);
  1461. spawn->SetZ(z);
  1462. spawn->SetY(y,true,true);
  1463. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1464. spawn->SetHeading(heading);
  1465. if (restricted_npc)
  1466. spawn->AddAllowAccessSpawn(spawn);
  1467. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1468. bool scriptActive = false;
  1469. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1470. scriptActive = true;
  1471. spawn->SetSpawnScript(string(spawn_script));
  1472. }
  1473. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1474. zone->AddSpawn(spawn);
  1475. if (scriptActive) {
  1476. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1477. }
  1478. lua_interface->ResetFunctionStack(state);
  1479. lua_interface->SetSpawnValue(state, spawn);
  1480. return 1;
  1481. }
  1482. }
  1483. else {
  1484. string output = "Invalid paramaters to LUA Spawn command: \n";
  1485. if (!zone)
  1486. output = output.append("\t").append("Missing zone reference. \n");
  1487. if (spawn_id == 0)
  1488. output = output.append("\t").append("Missing spawn_id.");
  1489. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1490. }
  1491. lua_interface->ResetFunctionStack(state);
  1492. return 0;
  1493. }
  1494. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1495. if (!lua_interface)
  1496. return 0;
  1497. ZoneServer* zone = lua_interface->GetZone(state);
  1498. lua_interface->ResetFunctionStack(state);
  1499. if (zone) {
  1500. lua_interface->SetStringValue(state, zone->GetZoneName());
  1501. return 1;
  1502. }
  1503. return 0;
  1504. }
  1505. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1506. if (!lua_interface)
  1507. return 0;
  1508. ZoneServer* zone = lua_interface->GetZone(state);
  1509. lua_interface->ResetFunctionStack(state);
  1510. if (zone) {
  1511. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1512. return 1;
  1513. }
  1514. return 0;
  1515. }
  1516. int EQ2Emu_lua_GetZone(lua_State* state) {
  1517. if (!lua_interface)
  1518. return 0;
  1519. int32 zone_id = lua_interface->GetInt32Value(state);
  1520. ZoneServer* zone = 0;
  1521. if (zone_id > 0)
  1522. zone = zone_list.Get(zone_id);
  1523. else {
  1524. string zone_name = lua_interface->GetStringValue(state);
  1525. if (zone_name.length() > 0) {
  1526. zone = zone_list.Get(zone_name.c_str());
  1527. }
  1528. else {
  1529. Spawn* spawn = lua_interface->GetSpawn(state);
  1530. if (spawn)
  1531. zone = spawn->GetZone();
  1532. }
  1533. }
  1534. lua_interface->ResetFunctionStack(state);
  1535. if (zone) {
  1536. lua_interface->SetZoneValue(state, zone);
  1537. return 1;
  1538. }
  1539. return 0;
  1540. }
  1541. int EQ2Emu_lua_AddHate(lua_State* state) {
  1542. Spawn* entity = lua_interface->GetSpawn(state);
  1543. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1544. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1545. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1546. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1547. if(!luaspell || luaspell->resisted) {
  1548. return 0;
  1549. }
  1550. if (entity && entity->IsEntity() && amount != 0) {
  1551. if (luaspell) {
  1552. ZoneServer* zone = luaspell->caster->GetZone();
  1553. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1554. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1555. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1556. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1557. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1558. if (send_packet)
  1559. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1560. }
  1561. }
  1562. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1563. }
  1564. else if (npc && npc->IsNPC() && npc->GetZone())
  1565. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1566. }
  1567. lua_interface->ResetFunctionStack(state);
  1568. return 0;
  1569. }
  1570. int EQ2Emu_lua_Zone(lua_State* state) {
  1571. if (!lua_interface)
  1572. return 0;
  1573. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1574. ZoneServer* zone = lua_interface->GetZone(state);
  1575. Spawn* player = lua_interface->GetSpawn(state, 2);
  1576. Client* client = 0;
  1577. if (player && player->IsPlayer())
  1578. client = player->GetZone()->GetClientBySpawn(player);
  1579. float x = lua_interface->GetFloatValue(state, 3);
  1580. float y = lua_interface->GetFloatValue(state, 4);
  1581. float z = lua_interface->GetFloatValue(state, 5);
  1582. float heading = lua_interface->GetFloatValue(state, 6);
  1583. if (zone && client) {
  1584. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1585. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1586. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1587. {
  1588. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1589. return 0;
  1590. }
  1591. if (x != 0 || y != 0 || z != 0) {
  1592. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1593. player->SetX(x);
  1594. player->SetY(y);
  1595. player->SetZ(z);
  1596. player->SetHeading(heading);
  1597. client->Zone(zone->GetZoneName(), false);
  1598. }
  1599. else
  1600. client->Zone(zone->GetZoneName());
  1601. }
  1602. else
  1603. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1604. lua_interface->ResetFunctionStack(state);
  1605. return 0;
  1606. }
  1607. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1608. if (!lua_interface)
  1609. return 0;
  1610. Spawn* spawn = lua_interface->GetSpawn(state);
  1611. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1612. if (spawn && spawn2)
  1613. spawn->AddAllowAccessSpawn(spawn2);
  1614. lua_interface->ResetFunctionStack(state);
  1615. return 0;
  1616. }
  1617. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1618. if (!lua_interface)
  1619. return 0;
  1620. Spawn* target = lua_interface->GetSpawn(state);
  1621. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1622. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1623. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1624. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1625. lua_interface->ResetFunctionStack(state);
  1626. if (!target) {
  1627. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1628. return 0;
  1629. }
  1630. if (!target->IsEntity()) {
  1631. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1632. return 0;
  1633. }
  1634. if (spell_id <= 0) {
  1635. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1636. return 0;
  1637. }
  1638. if (caster && !caster->IsEntity()) {
  1639. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1640. return 0;
  1641. }
  1642. if (spell_tier == 0)
  1643. spell_tier = 1;
  1644. if (!caster)
  1645. caster = target;
  1646. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1647. return 0;
  1648. }
  1649. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1650. if (!lua_interface)
  1651. return 0;
  1652. Spawn* target = lua_interface->GetSpawn(state);
  1653. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1654. if(!luaspell || luaspell->resisted) {
  1655. return 0;
  1656. }
  1657. Spawn* caster = luaspell->caster;
  1658. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1659. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1660. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1661. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1662. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1663. //lua_interface->ResetFunctionStack(state);
  1664. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1665. vector<int16> faction_req;
  1666. vector<int16> race_req;
  1667. int32 class_req = 0;
  1668. int32 i = 0;
  1669. int8 f = 0;
  1670. int8 r = 0;
  1671. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1672. if (class_id < 100) {
  1673. class_req += pow(2.0, double(class_id - 1));
  1674. }
  1675. else if (class_id > 100 && class_id < 1000) {
  1676. race_req.push_back(class_id);
  1677. r++;
  1678. }
  1679. else {
  1680. faction_req.push_back(class_id);
  1681. f++;
  1682. }
  1683. i++;
  1684. }
  1685. lua_interface->ResetFunctionStack(state);
  1686. if (caster && caster->IsEntity()) {
  1687. bool race_match = false;
  1688. bool success = false;
  1689. luaspell->resisted = false;
  1690. if (luaspell->targets.size() > 0) {
  1691. ZoneServer* zone = luaspell->caster->GetZone();
  1692. Spawn* target = 0;
  1693. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1694. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1695. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1696. if (race_req.size() > 0) {
  1697. for (int8 i = 0; i < race_req.size(); i++) {
  1698. if(race_req[i] == target->GetRace() ||
  1699. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1700. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1701. race_match = true;
  1702. }
  1703. }
  1704. }
  1705. else
  1706. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1707. if (race_match == true) {
  1708. float distance = caster->GetDistance(target, true);
  1709. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1710. }
  1711. }
  1712. }
  1713. success = true;
  1714. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1715. }
  1716. else if (target) {
  1717. //check class and race/faction here
  1718. if (race_req.size() > 0) {
  1719. for (int8 i = 0; i < race_req.size(); i++) {
  1720. if(race_req[i] == target->GetRace() ||
  1721. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1722. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1723. race_match = true;
  1724. }
  1725. }
  1726. }
  1727. else
  1728. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1729. if (race_match == true) {
  1730. float distance = caster->GetDistance(target, true);
  1731. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1732. success = true;
  1733. }
  1734. }
  1735. if (success) {
  1736. Spell* spell = luaspell->spell;
  1737. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1738. ((Player*)caster)->InCombat(true);
  1739. if (caster->GetZone())
  1740. caster->GetZone()->TriggerCharSheetTimer();
  1741. }
  1742. }
  1743. }
  1744. return 0;
  1745. }
  1746. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1747. if (!lua_interface)
  1748. return 0;
  1749. Spawn* spawn = lua_interface->GetSpawn(state);
  1750. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1751. lua_interface->ResetFunctionStack(state);
  1752. if (spawn && value != 0) {
  1753. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1754. spawn->SetPower(spawn->GetTotalPower());
  1755. else
  1756. spawn->SetPower(spawn->GetPower() + value);
  1757. }
  1758. return 0;
  1759. }
  1760. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1761. if (!lua_interface)
  1762. return 0;
  1763. Spawn* spawn = lua_interface->GetSpawn(state);
  1764. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1765. lua_interface->ResetFunctionStack(state);
  1766. if (spawn && value != 0) {
  1767. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1768. spawn->SetHP(spawn->GetTotalHP());
  1769. else
  1770. spawn->SetHP(spawn->GetHP() + value);
  1771. }
  1772. return 0;
  1773. }
  1774. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1775. if (!lua_interface)
  1776. return 0;
  1777. Spawn* spawn = lua_interface->GetSpawn(state);
  1778. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1779. lua_interface->ResetFunctionStack(state);
  1780. if (spawn && value != 0) {
  1781. spawn->SetPower(spawn->GetPower() + value);
  1782. if (value > spawn->GetTotalHPBase())
  1783. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1784. }
  1785. return 0;
  1786. }
  1787. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1788. if (!lua_interface)
  1789. return 0;
  1790. Spawn* spawn = lua_interface->GetSpawn(state);
  1791. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1792. lua_interface->ResetFunctionStack(state);
  1793. if (spawn && value != 0) {
  1794. spawn->SetHP(spawn->GetHP() + value);
  1795. if (value > spawn->GetTotalHPBase())
  1796. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1797. }
  1798. return 0;
  1799. }
  1800. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1801. if (!lua_interface)
  1802. return 0;
  1803. Spawn* spawn = lua_interface->GetSpawn(state);
  1804. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1805. lua_interface->ResetFunctionStack(state);
  1806. if (spawn) {
  1807. spawn->SetHP(value);
  1808. if (value > spawn->GetTotalHPBase())
  1809. spawn->SetTotalHP(value);
  1810. }
  1811. return 0;
  1812. }
  1813. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1814. if (!lua_interface)
  1815. return 0;
  1816. Spawn* spawn = lua_interface->GetSpawn(state);
  1817. float value = lua_interface->GetFloatValue(state, 2);
  1818. lua_interface->ResetFunctionStack(state);
  1819. if (spawn && spawn->IsEntity() && value > 0)
  1820. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1821. if (spawn->IsPlayer())
  1822. ((Player*)spawn)->SetCharSheetChanged(true);
  1823. return 0;
  1824. }
  1825. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1826. if (!lua_interface)
  1827. return 0;
  1828. Spawn* spawn = lua_interface->GetSpawn(state);
  1829. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1830. lua_interface->ResetFunctionStack(state);
  1831. if (spawn && spawn->IsEntity() && value > 0)
  1832. ((Entity*)spawn)->SetTotalHPBase(value);
  1833. return 0;
  1834. }
  1835. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1836. if (!lua_interface)
  1837. return 0;
  1838. Spawn* spawn = lua_interface->GetSpawn(state);
  1839. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1840. lua_interface->ResetFunctionStack(state);
  1841. if (spawn && value > 0) {
  1842. spawn->SetPower(value);
  1843. if (value > spawn->GetTotalPowerBase())
  1844. spawn->SetTotalPower(value);
  1845. }
  1846. return 0;
  1847. }
  1848. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1849. if (!lua_interface)
  1850. return 0;
  1851. Spawn* spawn = lua_interface->GetSpawn(state);
  1852. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1853. lua_interface->ResetFunctionStack(state);
  1854. if (spawn && spawn->IsEntity() && value > 0)
  1855. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1856. return 0;
  1857. }
  1858. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1859. if (!lua_interface)
  1860. return 0;
  1861. Spawn* spawn = lua_interface->GetSpawn(state);
  1862. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1863. lua_interface->ResetFunctionStack(state);
  1864. if (spawn && spawn->IsEntity() && value > 0)
  1865. ((Entity*)spawn)->SetTotalPowerBase(value);
  1866. return 0;
  1867. }
  1868. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1869. if (!lua_interface)
  1870. return 0;
  1871. Spawn* spawn = lua_interface->GetSpawn(state);
  1872. float x = lua_interface->GetFloatValue(state, 2);
  1873. float y = lua_interface->GetFloatValue(state, 3);
  1874. float z = lua_interface->GetFloatValue(state, 4);
  1875. float heading = lua_interface->GetFloatValue(state, 5);
  1876. lua_interface->ResetFunctionStack(state);
  1877. if (spawn) {
  1878. spawn->SetX(x);
  1879. spawn->SetY(y);
  1880. spawn->SetZ(z);
  1881. if (heading != 0)
  1882. spawn->SetHeading(heading);
  1883. spawn->SetSpawnOrigX(spawn->GetX());
  1884. spawn->SetSpawnOrigY(spawn->GetY());
  1885. spawn->SetSpawnOrigZ(spawn->GetZ());
  1886. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1887. if (spawn->IsPlayer()) {
  1888. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1889. if (client) {
  1890. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1891. client->QueuePacket(packet);
  1892. }
  1893. }
  1894. }
  1895. return 0;
  1896. }
  1897. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1898. if (!lua_interface)
  1899. return 0;
  1900. Spawn* spawn = lua_interface->GetSpawn(state);
  1901. float value = lua_interface->GetFloatValue(state, 2);
  1902. lua_interface->ResetFunctionStack(state);
  1903. if (spawn) {
  1904. spawn->SetHeading(value);
  1905. if (spawn->IsPlayer()) {
  1906. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1907. if (client) {
  1908. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1909. client->QueuePacket(packet);
  1910. }
  1911. }
  1912. }
  1913. return 0;
  1914. }
  1915. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1916. if (!lua_interface)
  1917. return 0;
  1918. Spawn* spawn = lua_interface->GetSpawn(state);
  1919. int16 value = lua_interface->GetInt16Value(state, 2);
  1920. lua_interface->ResetFunctionStack(state);
  1921. if (spawn)
  1922. spawn->SetModelType(value);
  1923. return 0;
  1924. }
  1925. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1926. if (!lua_interface)
  1927. return 0;
  1928. Spawn* spawn = lua_interface->GetSpawn(state);
  1929. int8 value = lua_interface->GetInt8Value(state, 2);
  1930. lua_interface->ResetFunctionStack(state);
  1931. if (spawn) {
  1932. if (spawn->IsPlayer())
  1933. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1934. else
  1935. spawn->SetAdventureClass(value);
  1936. }
  1937. return 0;
  1938. }
  1939. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1940. if (!lua_interface)
  1941. return 0;
  1942. Spawn* spawn = lua_interface->GetSpawn(state);
  1943. int8 value = lua_interface->GetInt8Value(state, 2);
  1944. lua_interface->ResetFunctionStack(state);
  1945. if (spawn) {
  1946. spawn->SetTradeskillClass(value);
  1947. if (spawn->IsEntity()) {
  1948. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1949. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1950. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1951. }
  1952. if (spawn->IsPlayer())
  1953. ((Player*)spawn)->SetCharSheetChanged(true);
  1954. }
  1955. return 0;
  1956. }
  1957. int EQ2Emu_lua_SetMount(lua_State* state) {
  1958. if (!lua_interface)
  1959. return 0;
  1960. Spawn* spawn = lua_interface->GetSpawn(state);
  1961. int16 value = lua_interface->GetInt16Value(state, 2);
  1962. if (spawn && spawn->IsEntity()) {
  1963. ((Entity*)spawn)->SetMount(value);
  1964. EQ2_Color color;
  1965. color.red = 255;
  1966. color.green = 255;
  1967. color.blue = 255;
  1968. ((Entity*)spawn)->SetMountColor(&color);
  1969. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1970. }
  1971. return 0;
  1972. }
  1973. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1974. if (!lua_interface)
  1975. return 0;
  1976. Spawn* spawn = lua_interface->GetSpawn(state);
  1977. EQ2_Color mount_color;
  1978. EQ2_Color saddle_color;
  1979. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1980. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1981. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1982. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1983. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1984. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1985. if (spawn && spawn->IsEntity()) {
  1986. ((Entity*)spawn)->SetMountColor(&mount_color);
  1987. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1988. }
  1989. return 0;
  1990. }
  1991. int EQ2Emu_lua_GetMount(lua_State* state) {
  1992. if (!lua_interface)
  1993. return 0;
  1994. Spawn* spawn = lua_interface->GetSpawn(state);
  1995. if (spawn && spawn->IsEntity()) {
  1996. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1997. return 1;
  1998. }
  1999. return 0;
  2000. }
  2001. int EQ2Emu_lua_GetRace(lua_State* state) {
  2002. if (!lua_interface)
  2003. return 0;
  2004. Spawn* spawn = lua_interface->GetSpawn(state);
  2005. if (spawn)
  2006. {
  2007. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2008. lua_interface->SetInt32Value(state, spawn->GetRace());
  2009. return 1;
  2010. }
  2011. return 0;
  2012. }
  2013. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2014. if (!lua_interface)
  2015. return 0;
  2016. Spawn* spawn = lua_interface->GetSpawn(state);
  2017. if (spawn) {
  2018. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2019. return 1;
  2020. }
  2021. return 0;
  2022. }
  2023. int EQ2Emu_lua_GetClass(lua_State* state) {
  2024. Spawn* spawn = lua_interface->GetSpawn(state);
  2025. if (spawn) {
  2026. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2027. return 1;
  2028. }
  2029. return 0;
  2030. }
  2031. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2032. Spawn* spawn = lua_interface->GetSpawn(state);
  2033. if (spawn) {
  2034. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2035. return 1;
  2036. }
  2037. return 0;
  2038. }
  2039. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2040. if (!lua_interface)
  2041. return 0;
  2042. Spawn* spawn = lua_interface->GetSpawn(state);
  2043. float value = lua_interface->GetFloatValue(state, 2);
  2044. lua_interface->ResetFunctionStack(state);
  2045. if (spawn) {
  2046. spawn->SetSpeed(value);
  2047. if(spawn->IsEntity())
  2048. ((Entity*)spawn)->SetSpeed(value);
  2049. if (spawn->IsPlayer()) {
  2050. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2051. if (client) {
  2052. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2053. if (packet) {
  2054. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2055. packet->setDataByName("speed", value);
  2056. packet->setDataByName("size", 0.51);
  2057. EQ2Packet* app = packet->serialize();
  2058. client->QueuePacket(app);
  2059. safe_delete(packet);
  2060. }
  2061. }
  2062. }
  2063. }
  2064. return 0;
  2065. }
  2066. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2067. if (!lua_interface)
  2068. return 0;
  2069. Spawn* spawn = lua_interface->GetSpawn(state);
  2070. const int16 type = lua_interface->GetInt16Value(state, 2);
  2071. const float value = lua_interface->GetFloatValue(state, 3);
  2072. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2073. if(!luaspell || luaspell->resisted) {
  2074. return 0;
  2075. }
  2076. int64 class_req = 0;
  2077. int32 class_id = 0;
  2078. vector<int16> faction_req;
  2079. vector<int16> race_req;
  2080. int32 i = 0;
  2081. int8 f = 0;
  2082. int8 r = 0;
  2083. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2084. if (class_id < 100) {
  2085. class_req += pow(2.0, double(class_id - 1));
  2086. }
  2087. else if (class_id > 100 && class_id < 1000) {
  2088. race_req.push_back(class_id);
  2089. r++;
  2090. }
  2091. else {
  2092. faction_req.push_back(class_id);
  2093. f++;
  2094. }
  2095. i++;
  2096. }
  2097. if (value != 0 && type >= 0) {
  2098. if (luaspell && luaspell->spell && luaspell->caster) {
  2099. ZoneServer* zone = luaspell->caster->GetZone();
  2100. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2101. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2102. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2103. if (target) {
  2104. if (target->IsPlayer()) {
  2105. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2106. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2107. if (((Player*)target)->GetGroupMemberInfo())
  2108. ((Player*)target)->UpdateGroupMemberInfo();
  2109. ((Player*)target)->SetCharSheetChanged(true);
  2110. }
  2111. else if (target->IsNPC())
  2112. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2113. else
  2114. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2115. }
  2116. }
  2117. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2118. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2119. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2120. }
  2121. else if (spawn && spawn->IsEntity()) {
  2122. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2123. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2124. if (spawn->IsPlayer())
  2125. ((Player*)spawn)->SetCharSheetChanged(true);
  2126. }
  2127. else
  2128. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2129. }
  2130. else
  2131. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2132. return 0;
  2133. }
  2134. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2135. if (!lua_interface)
  2136. return 0;
  2137. Spawn* spawn = lua_interface->GetSpawn(state);
  2138. int16 type = lua_interface->GetInt16Value(state, 2);
  2139. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2140. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2141. if (!spawn) {
  2142. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2143. return 0;
  2144. }
  2145. if (!spawn->IsEntity()) {
  2146. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2147. return 0;
  2148. }
  2149. if (value == 0) {
  2150. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2151. return 0;
  2152. }
  2153. if (!luaspell || !luaspell->spell) {
  2154. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2155. return 0;
  2156. }
  2157. if(luaspell->resisted) {
  2158. return 0;
  2159. }
  2160. int32 class_req = 0;
  2161. vector<int16> faction_req;
  2162. vector<int16> race_req;
  2163. int32 class_id = 0;
  2164. int32 i = 0;
  2165. int8 f = 0;
  2166. int8 r = 0;
  2167. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2168. if (class_id < 100) {
  2169. class_req += pow(2.0, double(class_id - 1));
  2170. }
  2171. else if (class_id > 100 && class_id < 1000) {
  2172. race_req.push_back(class_id);
  2173. r++;
  2174. }
  2175. else {
  2176. faction_req.push_back(class_id);
  2177. f++;
  2178. }
  2179. i++;
  2180. }
  2181. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2182. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2183. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2184. if (spawn->IsPlayer())
  2185. ((Player*)spawn)->SetCharSheetChanged(true);
  2186. return 0;
  2187. }
  2188. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2189. if (!lua_interface)
  2190. return 0;
  2191. Spawn* spawn = lua_interface->GetSpawn(state);
  2192. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2193. if (!spawn) {
  2194. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2195. return 0;
  2196. }
  2197. if (!spawn->IsEntity()) {
  2198. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2199. return 0;
  2200. }
  2201. if (!luaspell || !luaspell->spell) {
  2202. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2203. return 0;
  2204. }
  2205. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2206. if (spawn->IsPlayer())
  2207. ((Player*)spawn)->SetCharSheetChanged(true);
  2208. return 0;
  2209. }
  2210. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2211. if (!lua_interface)
  2212. return 0;
  2213. Spawn* spawn = lua_interface->GetSpawn(state);
  2214. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2215. if (luaspell && luaspell->spell) {
  2216. ZoneServer* zone = luaspell->caster->GetZone();
  2217. Spawn* target = 0;
  2218. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2219. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2220. target = zone->GetSpawnByID(luaspell->targets[i]);
  2221. if (target && target->IsEntity()) {
  2222. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2223. if (target->IsPlayer())
  2224. ((Player*)target)->SetCharSheetChanged(true);
  2225. }
  2226. }
  2227. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2228. }
  2229. else if (spawn && spawn->IsEntity()) {
  2230. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2231. if (spawn->IsPlayer())
  2232. ((Player*)spawn)->SetCharSheetChanged(true);
  2233. }
  2234. return 0;
  2235. }
  2236. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2237. if (!lua_interface)
  2238. return 0;
  2239. Spawn* spawn = lua_interface->GetSpawn(state);
  2240. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2241. float value = lua_interface->GetFloatValue(state, 3);
  2242. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2243. if (value != 0) {
  2244. int32 spell_id = 0;
  2245. if (luaspell && luaspell->spell && luaspell->caster) {
  2246. if(luaspell->resisted) {
  2247. return 0;
  2248. }
  2249. spell_id = luaspell->spell->GetSpellID();
  2250. ZoneServer* zone = luaspell->caster->GetZone();
  2251. Spawn* target = 0;
  2252. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2253. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2254. target = zone->GetSpawnByID(luaspell->targets[i]);
  2255. if (target && target->Alive()) {
  2256. if (target->IsPlayer()) {
  2257. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2258. Client* client = target->GetZone()->GetClientBySpawn(target);
  2259. if (client) {
  2260. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2261. if (packet)
  2262. client->QueuePacket(packet);
  2263. }
  2264. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2265. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2266. }
  2267. else if (target->IsNPC()) {
  2268. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2269. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2270. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2271. }
  2272. else
  2273. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2274. }
  2275. }
  2276. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2277. }
  2278. else if (spawn) {
  2279. if (spawn->IsPlayer()) {
  2280. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2281. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2282. if (client) {
  2283. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2284. if (packet)
  2285. client->QueuePacket(packet);
  2286. }
  2287. }
  2288. else if (spawn->IsNPC())
  2289. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2290. else
  2291. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2292. }
  2293. }
  2294. else
  2295. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2296. return 0;
  2297. }
  2298. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2299. if (!lua_interface)
  2300. return 0;
  2301. Spawn* spawn = lua_interface->GetSpawn(state);
  2302. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2303. if (spawn && spawn->IsPlayer()) {
  2304. int32 spell_id = 0;
  2305. if (luaspell && luaspell->spell) {
  2306. if(luaspell->resisted) {
  2307. return 0;
  2308. }
  2309. spell_id = luaspell->spell->GetSpellID();
  2310. ZoneServer* zone = luaspell->caster->GetZone();
  2311. Spawn* target = 0;
  2312. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2313. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2314. target = zone->GetSpawnByID(luaspell->targets[i]);
  2315. if (target) {
  2316. if (target->IsPlayer()) {
  2317. ((Player*)target)->RemoveSkillBonus(spell_id);
  2318. Client* client = target->GetZone()->GetClientBySpawn(target);
  2319. if (client) {
  2320. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2321. if (packet)
  2322. client->QueuePacket(packet);
  2323. }
  2324. }
  2325. else if (target->IsNPC())
  2326. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2327. else
  2328. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2329. }
  2330. }
  2331. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2332. }
  2333. else if (spawn) {
  2334. if (spawn->IsPlayer()) {
  2335. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2336. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2337. if (client) {
  2338. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2339. if (packet)
  2340. client->QueuePacket(packet);
  2341. }
  2342. }
  2343. else if (spawn->IsNPC())
  2344. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2345. else
  2346. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2347. }
  2348. }
  2349. return 0;
  2350. }
  2351. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2352. if (!lua_interface)
  2353. return 0;
  2354. Spawn* spawn = lua_interface->GetSpawn(state);
  2355. int8 type = lua_interface->GetInt32Value(state, 2);
  2356. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2357. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2358. if(luaspell && luaspell->resisted) {
  2359. return 0;
  2360. }
  2361. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2362. ZoneServer* zone = luaspell->caster->GetZone();
  2363. Spawn* target = 0;
  2364. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2365. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2366. target = zone->GetSpawnByID(luaspell->targets[i]);
  2367. if (target && target->IsEntity()) {
  2368. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2369. ((Entity*)target)->AddMezSpell(luaspell);
  2370. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2371. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2372. if (target->IsNPC())
  2373. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2374. }
  2375. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2376. ((Entity*)target)->AddStifleSpell(luaspell);
  2377. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2378. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2379. if (target->IsNPC())
  2380. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2381. }
  2382. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2383. ((Entity*)target)->AddDazeSpell(luaspell);
  2384. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2385. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2386. if (target->IsNPC())
  2387. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2388. }
  2389. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2390. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2391. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2392. ((Entity*)target)->AddStunSpell(luaspell);
  2393. if (target->IsNPC())
  2394. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2395. }
  2396. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2397. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2398. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2399. ((Entity*)target)->AddRootSpell(luaspell);
  2400. if (target->IsNPC())
  2401. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2402. }
  2403. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2404. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2405. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2406. ((Entity*)target)->AddFearSpell(luaspell);
  2407. if (target->IsNPC())
  2408. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2409. }
  2410. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2411. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2412. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2413. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2414. }
  2415. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2416. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2417. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2418. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2419. }
  2420. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2421. ((Entity*)target)->AddSnareSpell(luaspell);
  2422. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2423. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2424. if (target->IsNPC())
  2425. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2426. }
  2427. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2428. ((Entity*)target)->AddFlightSpell(luaspell);
  2429. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2430. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2431. }
  2432. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2433. ((Entity*)target)->AddGlideSpell(luaspell);
  2434. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2435. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2436. }
  2437. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2438. ((Entity*)target)->AddSafefallSpell(luaspell);
  2439. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2440. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2441. }
  2442. else
  2443. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2444. }
  2445. else
  2446. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2447. }
  2448. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2449. }
  2450. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2451. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2452. ((Entity*)spawn)->AddMezSpell(luaspell);
  2453. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2454. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2455. }
  2456. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2457. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2458. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2459. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2460. }
  2461. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2462. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2463. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2464. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2465. }
  2466. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2467. ((Entity*)spawn)->AddStunSpell(luaspell);
  2468. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2469. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2470. }
  2471. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2472. ((Entity*)spawn)->AddRootSpell(luaspell);
  2473. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2474. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2475. }
  2476. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2477. ((Entity*)spawn)->AddFearSpell(luaspell);
  2478. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2479. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2480. }
  2481. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2482. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2483. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2484. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2485. }
  2486. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2487. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2488. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2489. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2490. }
  2491. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2492. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2493. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2494. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2495. }
  2496. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2497. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2498. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2499. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2500. }
  2501. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2502. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2503. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2504. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2505. }
  2506. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2507. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2508. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2509. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2510. }
  2511. else
  2512. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2513. }
  2514. else
  2515. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2516. return 0;
  2517. }
  2518. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2519. if (!lua_interface)
  2520. return 0;
  2521. Spawn* spawn = lua_interface->GetSpawn(state);
  2522. int8 type = lua_interface->GetInt8Value(state, 2);
  2523. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2524. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2525. if (spawn && spawn->IsEntity()) {
  2526. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2527. ZoneServer* zone = luaspell->caster->GetZone();
  2528. Spawn* target = 0;
  2529. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2530. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2531. target = zone->GetSpawnByID(luaspell->targets[i]);
  2532. if (target) {
  2533. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2534. ((Entity*)target)->RemoveMezSpell(luaspell);
  2535. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2536. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2537. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2538. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2539. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2540. ((Entity*)target)->RemoveStunSpell(luaspell);
  2541. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2542. ((Entity*)target)->RemoveRootSpell(luaspell);
  2543. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2544. ((Entity*)target)->RemoveFearSpell(luaspell);
  2545. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2546. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2547. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2548. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2549. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2550. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2551. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2552. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2553. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2554. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2555. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2556. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2557. else
  2558. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2559. }
  2560. }
  2561. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2562. }
  2563. else if (only_remove_spawn) {
  2564. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2565. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2566. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2567. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2568. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2569. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2570. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2571. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2572. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2573. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2574. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2575. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2576. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2577. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2579. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2581. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2583. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2585. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2587. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2588. else
  2589. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2590. }
  2591. }
  2592. return 0;
  2593. }
  2594. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2595. if (!lua_interface)
  2596. return 0;
  2597. Spawn* spawn = lua_interface->GetSpawn(state);
  2598. int8 type = lua_interface->GetInt8Value(state, 2);
  2599. bool hasEffect = false;
  2600. if (!spawn)
  2601. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2602. else if (!spawn->IsEntity())
  2603. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2604. else if (type < CONTROL_MAX_EFFECTS)
  2605. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2606. else
  2607. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2608. lua_interface->SetBooleanValue(state, hasEffect);
  2609. return 1;
  2610. }
  2611. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2612. if (!lua_interface)
  2613. return 0;
  2614. Spawn* spawn = lua_interface->GetSpawn(state);
  2615. float distance = 0.0f;
  2616. if (!spawn)
  2617. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2618. else if (!spawn->IsNPC())
  2619. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2620. else
  2621. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2622. lua_interface->SetFloatValue(state, distance);
  2623. return 1;
  2624. }
  2625. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2626. if (!lua_interface)
  2627. return 0;
  2628. Spawn* spawn = lua_interface->GetSpawn(state);
  2629. float distance = 0.0f;
  2630. if (!spawn)
  2631. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2632. else if (!spawn->IsNPC())
  2633. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2634. else
  2635. distance = ((NPC*)spawn)->GetAggroRadius();
  2636. lua_interface->SetFloatValue(state, distance);
  2637. return 1;
  2638. }
  2639. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2640. if (!lua_interface)
  2641. return 0;
  2642. Spawn* spawn = lua_interface->GetSpawn(state);
  2643. float distance = lua_interface->GetFloatValue(state, 2);
  2644. bool override = lua_interface->GetBooleanValue(state, 3);
  2645. bool result = false;
  2646. lua_interface->ResetFunctionStack(state);
  2647. if (!spawn)
  2648. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2649. else if (!spawn->IsNPC())
  2650. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2651. else
  2652. {
  2653. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2654. result = true;
  2655. }
  2656. lua_interface->SetBooleanValue(state, result);
  2657. return 1;
  2658. }
  2659. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2660. if (!lua_interface)
  2661. return 0;
  2662. Spawn* spawn = lua_interface->GetSpawn(state);
  2663. int16 value = lua_interface->GetInt16Value(state, 2);
  2664. if (spawn && spawn->IsEntity()) {
  2665. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2666. if (spawn->IsPlayer())
  2667. ((Player*)spawn)->SetCharSheetChanged(true);
  2668. }
  2669. return 0;
  2670. }
  2671. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2672. if (!lua_interface)
  2673. return 0;
  2674. Spawn* spawn = lua_interface->GetSpawn(state);
  2675. int16 value = lua_interface->GetInt16Value(state, 2);
  2676. if (spawn && spawn->IsEntity()) {
  2677. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2678. if (spawn->IsPlayer())
  2679. ((Player*)spawn)->SetCharSheetChanged(true);
  2680. }
  2681. return 0;
  2682. }
  2683. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2684. if (!lua_interface)
  2685. return 0;
  2686. Spawn* spawn = lua_interface->GetSpawn(state);
  2687. int16 value = lua_interface->GetInt16Value(state, 2);
  2688. if (spawn && spawn->IsEntity()) {
  2689. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2690. if (spawn->IsPlayer())
  2691. ((Player*)spawn)->SetCharSheetChanged(true);
  2692. }
  2693. return 0;
  2694. }
  2695. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2696. if (!lua_interface)
  2697. return 0;
  2698. Spawn* spawn = lua_interface->GetSpawn(state);
  2699. int16 value = lua_interface->GetInt16Value(state, 2);
  2700. if (spawn && spawn->IsEntity()) {
  2701. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2702. if (spawn->IsPlayer())
  2703. ((Player*)spawn)->SetCharSheetChanged(true);
  2704. }
  2705. return 0;
  2706. }
  2707. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2708. if (!lua_interface)
  2709. return 0;
  2710. Spawn* spawn = lua_interface->GetSpawn(state);
  2711. int16 value = lua_interface->GetInt16Value(state, 2);
  2712. if (spawn && spawn->IsEntity()) {
  2713. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2714. if (spawn->IsPlayer())
  2715. ((Player*)spawn)->SetCharSheetChanged(true);
  2716. }
  2717. return 0;
  2718. }
  2719. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2720. if (!lua_interface)
  2721. return 0;
  2722. Spawn* spawn = lua_interface->GetSpawn(state);
  2723. int8 value = lua_interface->GetInt8Value(state, 2);
  2724. if (spawn && spawn->IsEntity()) {
  2725. ((Entity*)spawn)->SetDeity(value);
  2726. if (spawn->IsPlayer())
  2727. ((Player*)spawn)->SetCharSheetChanged(true);
  2728. }
  2729. lua_interface->ResetFunctionStack(state);
  2730. return 0;
  2731. }
  2732. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2733. if (!lua_interface)
  2734. return 0;
  2735. Spawn* spawn = lua_interface->GetSpawn(state);
  2736. if (spawn && spawn->IsEntity()) {
  2737. int8 deity = ((Entity*)spawn)->GetDeity();
  2738. lua_interface->SetInt32Value(state, deity);
  2739. return 1;
  2740. }
  2741. return 0;
  2742. }
  2743. int EQ2Emu_lua_SetInt(lua_State* state) {
  2744. if (!lua_interface)
  2745. return 0;
  2746. Spawn* spawn = lua_interface->GetSpawn(state);
  2747. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2748. if (spawn && spawn->IsEntity()) {
  2749. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2750. if (spawn->IsPlayer())
  2751. ((Player*)spawn)->SetCharSheetChanged(true);
  2752. }
  2753. return 0;
  2754. }
  2755. int EQ2Emu_lua_SetWis(lua_State* state) {
  2756. if (!lua_interface)
  2757. return 0;
  2758. Spawn* spawn = lua_interface->GetSpawn(state);
  2759. float value = lua_interface->GetFloatValue(state, 2);
  2760. if (spawn && spawn->IsEntity()) {
  2761. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2762. if (spawn->IsPlayer())
  2763. ((Player*)spawn)->SetCharSheetChanged(true);
  2764. }
  2765. return 0;
  2766. }
  2767. int EQ2Emu_lua_SetSta(lua_State* state) {
  2768. if (!lua_interface)
  2769. return 0;
  2770. Spawn* spawn = lua_interface->GetSpawn(state);
  2771. float value = lua_interface->GetFloatValue(state, 2);
  2772. if (spawn && spawn->IsEntity()) {
  2773. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2774. if (spawn->IsPlayer())
  2775. ((Player*)spawn)->SetCharSheetChanged(true);
  2776. }
  2777. return 0;
  2778. }
  2779. int EQ2Emu_lua_SetStr(lua_State* state) {
  2780. if (!lua_interface)
  2781. return 0;
  2782. Spawn* spawn = lua_interface->GetSpawn(state);
  2783. float value = lua_interface->GetFloatValue(state, 2);
  2784. if (spawn && spawn->IsEntity()) {
  2785. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2786. if (spawn->IsPlayer())
  2787. ((Player*)spawn)->SetCharSheetChanged(true);
  2788. }
  2789. return 0;
  2790. }
  2791. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2792. if (!lua_interface)
  2793. return 0;
  2794. Spawn* spawn = lua_interface->GetSpawn(state);
  2795. float value = lua_interface->GetFloatValue(state, 2);
  2796. if (spawn && spawn->IsEntity()) {
  2797. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2798. if (spawn->IsPlayer())
  2799. ((Player*)spawn)->SetCharSheetChanged(true);
  2800. }
  2801. return 0;
  2802. }
  2803. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2804. if (!lua_interface)
  2805. return 0;
  2806. Spawn* spawn = lua_interface->GetSpawn(state);
  2807. if (spawn) {
  2808. lua_interface->SetInt32Value(state, spawn->GetHP());
  2809. return 1;
  2810. }
  2811. return 0;
  2812. }
  2813. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2814. if (!lua_interface)
  2815. return 0;
  2816. Spawn* spawn = lua_interface->GetSpawn(state);
  2817. if (spawn) {
  2818. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2819. return 1;
  2820. }
  2821. return 0;
  2822. }
  2823. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2824. if (!lua_interface)
  2825. return 0;
  2826. Spawn* spawn = lua_interface->GetSpawn(state);
  2827. if (spawn) {
  2828. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2829. return 1;
  2830. }
  2831. return 0;
  2832. }
  2833. int EQ2Emu_lua_GetName(lua_State* state) {
  2834. if (!lua_interface)
  2835. return 0;
  2836. Spawn* spawn = lua_interface->GetSpawn(state);
  2837. if (spawn) {
  2838. lua_interface->SetStringValue(state, spawn->GetName());
  2839. return 1;
  2840. }
  2841. return 0;
  2842. }
  2843. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2844. Spawn* spawn = lua_interface->GetSpawn(state);
  2845. if (spawn) {
  2846. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2847. return 1;
  2848. }
  2849. return 0;
  2850. }
  2851. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2852. if (!lua_interface)
  2853. return 0;
  2854. Spawn* spawn = lua_interface->GetSpawn(state);
  2855. if (spawn) {
  2856. lua_interface->SetInt32Value(state, spawn->GetPower());
  2857. return 1;
  2858. }
  2859. return 0;
  2860. }
  2861. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2862. if (!lua_interface)
  2863. return 0;
  2864. Spawn* spawn = lua_interface->GetSpawn(state);
  2865. if (spawn) {
  2866. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2867. return 1;
  2868. }
  2869. return 0;
  2870. }
  2871. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2872. if (!lua_interface)
  2873. return 0;
  2874. Spawn* spawn = lua_interface->GetSpawn(state);
  2875. if (spawn) {
  2876. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2877. return 1;
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Spawn* spawn = lua_interface->GetSpawn(state);
  2885. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2886. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2887. if (spawn && spawn2) {
  2888. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2889. lua_interface->SetFloatValue(state, distance);
  2890. return 1;
  2891. }
  2892. return 0;
  2893. }
  2894. int EQ2Emu_lua_GetX(lua_State* state) {
  2895. if (!lua_interface)
  2896. return 0;
  2897. Spawn* spawn = lua_interface->GetSpawn(state);
  2898. if (spawn) {
  2899. lua_interface->SetFloatValue(state, spawn->GetX());
  2900. return 1;
  2901. }
  2902. return 0;
  2903. }
  2904. int EQ2Emu_lua_GetY(lua_State* state) {
  2905. if (!lua_interface)
  2906. return 0;
  2907. Spawn* spawn = lua_interface->GetSpawn(state);
  2908. if (spawn) {
  2909. lua_interface->SetFloatValue(state, spawn->GetY());
  2910. return 1;
  2911. }
  2912. return 0;
  2913. }
  2914. int EQ2Emu_lua_GetZ(lua_State* state) {
  2915. if (!lua_interface)
  2916. return 0;
  2917. Spawn* spawn = lua_interface->GetSpawn(state);
  2918. if (spawn) {
  2919. lua_interface->SetFloatValue(state, spawn->GetZ());
  2920. return 1;
  2921. }
  2922. return 0;
  2923. }
  2924. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2925. if (!lua_interface)
  2926. return 0;
  2927. Spawn* spawn = lua_interface->GetSpawn(state);
  2928. if (spawn) {
  2929. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2930. return 1;
  2931. }
  2932. return 0;
  2933. }
  2934. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2935. if (!lua_interface)
  2936. return 0;
  2937. Spawn* spawn = lua_interface->GetSpawn(state);
  2938. if (spawn) {
  2939. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2940. return 1;
  2941. }
  2942. return 0;
  2943. }
  2944. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2945. if (!lua_interface)
  2946. return 0;
  2947. Spawn* spawn = lua_interface->GetSpawn(state);
  2948. if (spawn) {
  2949. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2950. return 1;
  2951. }
  2952. return 0;
  2953. }
  2954. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2955. if (!lua_interface)
  2956. return 0;
  2957. Spawn* spawn = lua_interface->GetSpawn(state);
  2958. if (spawn && spawn->IsEntity()) {
  2959. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2960. return 1;
  2961. }
  2962. return 0;
  2963. }
  2964. int EQ2Emu_lua_GetInt(lua_State* state) {
  2965. if (!lua_interface)
  2966. return 0;
  2967. Spawn* spawn = lua_interface->GetSpawn(state);
  2968. if (spawn && spawn->IsEntity()) {
  2969. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2970. return 1;
  2971. }
  2972. return 0;
  2973. }
  2974. int EQ2Emu_lua_GetWis(lua_State* state) {
  2975. if (!lua_interface)
  2976. return 0;
  2977. Spawn* spawn = lua_interface->GetSpawn(state);
  2978. if (spawn && spawn->IsEntity()) {
  2979. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2980. return 1;
  2981. }
  2982. return 0;
  2983. }
  2984. int EQ2Emu_lua_GetSta(lua_State* state) {
  2985. if (!lua_interface)
  2986. return 0;
  2987. Spawn* spawn = lua_interface->GetSpawn(state);
  2988. if (spawn && spawn->IsEntity()) {
  2989. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2990. return 1;
  2991. }
  2992. return 0;
  2993. }
  2994. int EQ2Emu_lua_GetStr(lua_State* state) {
  2995. if (!lua_interface)
  2996. return 0;
  2997. Spawn* spawn = lua_interface->GetSpawn(state);
  2998. if (spawn && spawn->IsEntity()) {
  2999. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3000. return 1;
  3001. }
  3002. return 0;
  3003. }
  3004. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3005. if (!lua_interface)
  3006. return 0;
  3007. Spawn* spawn = lua_interface->GetSpawn(state);
  3008. if (spawn && spawn->IsEntity()) {
  3009. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3010. return 1;
  3011. }
  3012. return 0;
  3013. }
  3014. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3015. if (!lua_interface)
  3016. return 0;
  3017. Spawn* spawn = lua_interface->GetSpawn(state);
  3018. if (spawn && spawn->IsEntity()) {
  3019. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3020. return 1;
  3021. }
  3022. return 0;
  3023. }
  3024. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3025. if (!lua_interface)
  3026. return 0;
  3027. Spawn* spawn = lua_interface->GetSpawn(state);
  3028. if (spawn && spawn->IsEntity()) {
  3029. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3030. return 1;
  3031. }
  3032. return 0;
  3033. }
  3034. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3035. if (!lua_interface)
  3036. return 0;
  3037. Spawn* spawn = lua_interface->GetSpawn(state);
  3038. if (spawn && spawn->IsEntity()) {
  3039. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3040. return 1;
  3041. }
  3042. return 0;
  3043. }
  3044. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3045. if (!lua_interface)
  3046. return 0;
  3047. Spawn* spawn = lua_interface->GetSpawn(state);
  3048. if (spawn && spawn->IsEntity()) {
  3049. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3050. return 1;
  3051. }
  3052. return 0;
  3053. }
  3054. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3055. if (!lua_interface)
  3056. return 0;
  3057. Spawn* spawn = lua_interface->GetSpawn(state);
  3058. if (spawn && spawn->IsEntity()) {
  3059. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3060. return 1;
  3061. }
  3062. return 0;
  3063. }
  3064. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3065. if (!lua_interface)
  3066. return 0;
  3067. Spawn* player = lua_interface->GetSpawn(state);
  3068. if (!player || !player->IsPlayer()) {
  3069. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3070. return 0;
  3071. }
  3072. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3073. if (quest_id <= 0) {
  3074. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3075. return 0;
  3076. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3077. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3078. return 0;
  3079. }
  3080. int32 step = lua_interface->GetInt32Value(state, 3);
  3081. if (step > 0) {
  3082. Client* client = player->GetZone()->GetClientBySpawn(player);
  3083. if (client)
  3084. client->AddPendingQuestUpdate(quest_id, step);
  3085. } else {
  3086. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3091. Spawn* player = lua_interface->GetSpawn(state);
  3092. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3093. int32 step = lua_interface->GetInt32Value(state, 3);
  3094. int32 progress = lua_interface->GetInt32Value(state, 4);
  3095. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3096. Client* client = player->GetZone()->GetClientBySpawn(player);
  3097. if (client)
  3098. client->AddPendingQuestUpdate(quest_id, step, progress);
  3099. }
  3100. return 0;
  3101. }
  3102. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3103. if (!lua_interface)
  3104. return 0;
  3105. Spawn* player = lua_interface->GetSpawn(state);
  3106. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3107. if (player && player->IsPlayer() && quest_id > 0) {
  3108. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3109. return 1;
  3110. }
  3111. return 0;
  3112. }
  3113. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3114. if (!lua_interface)
  3115. return 0;
  3116. Spawn* player = lua_interface->GetSpawn(state);
  3117. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3118. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3119. if (player && player->IsPlayer() && quest_id > 0) {
  3120. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3121. return 1;
  3122. }
  3123. return 0;
  3124. }
  3125. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3126. if (!lua_interface)
  3127. return 0;
  3128. Spawn* player = lua_interface->GetSpawn(state);
  3129. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3130. if (player && player->IsPlayer() && quest_id > 0) {
  3131. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3132. return 1;
  3133. }
  3134. return 0;
  3135. }
  3136. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3137. if (!lua_interface)
  3138. return 0;
  3139. Quest* quest = lua_interface->GetQuest(state);
  3140. string name = lua_interface->GetStringValue(state, 2);
  3141. string type = lua_interface->GetStringValue(state, 3);
  3142. string zone = lua_interface->GetStringValue(state, 4);
  3143. int16 level = lua_interface->GetInt16Value(state, 5);
  3144. string description = lua_interface->GetStringValue(state, 6);
  3145. bool load = true;
  3146. if (!quest) {
  3147. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3148. load = false;
  3149. }
  3150. if (load && name.length() == 0) {
  3151. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3152. load = false;
  3153. }
  3154. if (load && type.length() == 0) {
  3155. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3156. load = false;
  3157. }
  3158. if (load && zone.length() == 0) {
  3159. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3160. load = false;
  3161. }
  3162. if (load && description.length() == 0) {
  3163. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3164. load = false;
  3165. }
  3166. if (load && level == 0) {
  3167. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3168. load = false;
  3169. }
  3170. if (load)
  3171. quest->RegisterQuest(name, type, zone, level, description);
  3172. return 0;
  3173. }
  3174. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3175. if (!lua_interface)
  3176. return 0;
  3177. Quest* quest = lua_interface->GetQuest(state);
  3178. if (quest) {
  3179. int8 level = lua_interface->GetInt16Value(state, 2);
  3180. quest->SetPrereqLevel(level);
  3181. }
  3182. return 0;
  3183. }
  3184. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3185. if (!lua_interface)
  3186. return 0;
  3187. Quest* quest = lua_interface->GetQuest(state);
  3188. if (quest) {
  3189. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3190. quest->AddPrereqQuest(quest_id);
  3191. }
  3192. return 0;
  3193. }
  3194. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3195. if (!lua_interface)
  3196. return 0;
  3197. Quest* quest = lua_interface->GetQuest(state);
  3198. if (quest) {
  3199. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3200. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3201. if (quantity == 0)
  3202. quantity = 1;
  3203. Item* master_item = master_item_list.GetItem(item_id);
  3204. if (master_item) {
  3205. Item* item = new Item(master_item);
  3206. item->details.count = quantity;
  3207. quest->AddPrereqItem(item);
  3208. }
  3209. }
  3210. return 0;
  3211. }
  3212. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3213. if (!lua_interface)
  3214. return 0;
  3215. Spawn* player = lua_interface->GetSpawn(state);
  3216. if(!player || !player->IsPlayer()) {
  3217. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3218. return 0;
  3219. }
  3220. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3221. if (quest_id > 0) {
  3222. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3223. return 1;
  3224. } else {
  3225. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3226. }
  3227. return 0;
  3228. }
  3229. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3230. if (!lua_interface)
  3231. return 0;
  3232. Quest* quest = lua_interface->GetQuest(state);
  3233. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3234. lua_interface->ResetFunctionStack(state);
  3235. if (quest && spawn_id > 0)
  3236. quest->SetQuestReturnNPC(spawn_id);
  3237. return 0;
  3238. }
  3239. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3240. if (!lua_interface)
  3241. return 0;
  3242. Spawn* spawn = lua_interface->GetSpawn(state);
  3243. int32 time = lua_interface->GetInt32Value(state, 2);
  3244. string function = lua_interface->GetStringValue(state, 3);
  3245. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3246. Spawn* player = lua_interface->GetSpawn(state, 5);
  3247. lua_interface->ResetFunctionStack(state);
  3248. if (!spawn) {
  3249. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3250. return 0;
  3251. }
  3252. if (time <= 0) {
  3253. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3254. return 0;
  3255. }
  3256. if (function.length() == 0) {
  3257. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3258. return 0;
  3259. }
  3260. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3261. if ( time < 10)
  3262. time = 10;
  3263. timer->timer = Timer::GetCurrentTime2() + time;
  3264. timer->function = function;
  3265. timer->spawn = spawn->GetID();
  3266. timer->player = player ? player->GetID() : 0;
  3267. if (max_count == 0)
  3268. max_count = 1;
  3269. timer->max_count = max_count;
  3270. timer->current_count = 0;
  3271. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3272. return 0;
  3273. }
  3274. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3275. if (!lua_interface)
  3276. return 0;
  3277. Spawn* spawn = lua_interface->GetSpawn(state);
  3278. string function = lua_interface->GetStringValue(state, 2);
  3279. lua_interface->ResetFunctionStack(state);
  3280. if (!spawn) {
  3281. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3282. return 0;
  3283. }
  3284. if(!spawn->GetZone()) {
  3285. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3286. return 0;
  3287. }
  3288. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3289. return 0;
  3290. }
  3291. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3292. if (!lua_interface)
  3293. return 0;
  3294. Spawn* player = lua_interface->GetSpawn(state);
  3295. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3296. lua_interface->ResetFunctionStack(state);
  3297. if (player && player->IsPlayer() && quest_id > 0) {
  3298. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3299. return 1;
  3300. }
  3301. return 0;
  3302. }
  3303. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3304. if (!lua_interface)
  3305. return 0;
  3306. Spawn* player = lua_interface->GetSpawn(state);
  3307. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3308. lua_interface->ResetFunctionStack(state);
  3309. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3310. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3311. if (quest)
  3312. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3313. return 1;
  3314. }
  3315. return 0;
  3316. }
  3317. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3318. if (!lua_interface)
  3319. return 0;
  3320. Spawn* player = lua_interface->GetSpawn(state);
  3321. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3322. lua_interface->ResetFunctionStack(state);
  3323. if (player && player->IsPlayer() && quest_id > 0) {
  3324. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3325. return 1;
  3326. }
  3327. return 0;
  3328. }
  3329. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3330. if (!lua_interface)
  3331. return 0;
  3332. Spawn* npc = lua_interface->GetSpawn(state);
  3333. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3334. lua_interface->ResetFunctionStack(state);
  3335. if (npc && !npc->IsPlayer() && quest_id > 0)
  3336. npc->AddProvidedQuest(quest_id);
  3337. return 0;
  3338. }
  3339. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3340. if (!lua_interface)
  3341. return 0;
  3342. Spawn* npc = lua_interface->GetSpawn(state);
  3343. Spawn* player = lua_interface->GetSpawn(state, 2);
  3344. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3345. bool forced = lua_interface->GetBooleanValue(state, 4);
  3346. lua_interface->ResetFunctionStack(state);
  3347. /* NPC is allowed to be null */
  3348. if (player && player->IsPlayer() && quest_id > 0) {
  3349. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3350. if (master_quest) {
  3351. Client* client = player->GetZone()->GetClientBySpawn(player);
  3352. if (!client) {
  3353. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3354. }
  3355. Quest* quest = new Quest(master_quest);
  3356. if (!quest) {
  3357. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3358. }
  3359. if (client && quest) {
  3360. if (npc)
  3361. quest->SetQuestGiver(npc->GetDatabaseID());
  3362. else
  3363. quest->SetQuestGiver(0);
  3364. client->AddPendingQuest(quest, forced);
  3365. }
  3366. }
  3367. else {
  3368. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3369. }
  3370. }
  3371. else {
  3372. 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);
  3373. }
  3374. return 0;
  3375. }
  3376. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3377. if (!lua_interface)
  3378. return 0;
  3379. Quest* quest = lua_interface->GetQuest(state);
  3380. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3381. lua_interface->ResetFunctionStack(state);
  3382. if (quest) {
  3383. quest->AddPrereqClass(class_id);
  3384. }
  3385. return 0;
  3386. }
  3387. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3388. if (!lua_interface)
  3389. return 0;
  3390. Quest* quest = lua_interface->GetQuest(state);
  3391. int8 race = lua_interface->GetInt8Value(state, 2);
  3392. lua_interface->ResetFunctionStack(state);
  3393. if (quest) {
  3394. quest->AddPrereqRace(race);
  3395. }
  3396. return 0;
  3397. }
  3398. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3399. if (!lua_interface)
  3400. return 0;
  3401. Quest* quest = lua_interface->GetQuest(state);
  3402. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3403. lua_interface->ResetFunctionStack(state);
  3404. if (quest) {
  3405. quest->AddPrereqModelType(model_type);
  3406. }
  3407. return 0;
  3408. }
  3409. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3410. if (!lua_interface)
  3411. return 0;
  3412. Quest* quest = lua_interface->GetQuest(state);
  3413. int8 level = lua_interface->GetInt8Value(state, 2);
  3414. lua_interface->ResetFunctionStack(state);
  3415. if (!quest) {
  3416. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3417. return 0;
  3418. }
  3419. quest->SetPrereqTSLevel(level);
  3420. return 0;
  3421. }
  3422. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3423. if (!lua_interface)
  3424. return 0;
  3425. Quest* quest = lua_interface->GetQuest(state);
  3426. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3427. lua_interface->ResetFunctionStack(state);
  3428. if (!quest) {
  3429. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3430. return 0;
  3431. }
  3432. quest->AddPrereqTradeskillClass(class_id);
  3433. return 0;
  3434. }
  3435. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3436. if (!lua_interface)
  3437. return 0;
  3438. Quest* quest = lua_interface->GetQuest(state);
  3439. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3440. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3441. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3442. lua_interface->ResetFunctionStack(state);
  3443. if (quest) {
  3444. quest->AddPrereqFaction(faction_id, min, max);
  3445. }
  3446. return 0;
  3447. }
  3448. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3449. if (!lua_interface)
  3450. return 0;
  3451. Quest* quest = lua_interface->GetQuest(state);
  3452. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3453. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3454. lua_interface->ResetFunctionStack(state);
  3455. if (quest) {
  3456. if (quantity == 0)
  3457. quantity = 1;
  3458. Item* master_item = master_item_list.GetItem(item_id);
  3459. if (master_item) {
  3460. Item* item = new Item(master_item);
  3461. item->details.count = quantity;
  3462. quest->AddSelectableRewardItem(item);
  3463. }
  3464. }
  3465. return 0;
  3466. }
  3467. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3468. if (!lua_interface)
  3469. return 0;
  3470. Quest* quest = lua_interface->GetQuest(state);
  3471. if (quest) {
  3472. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3473. vector<Item*>* items = quest->GetRewardItems();
  3474. if (items) {
  3475. vector<Item*>::iterator itr;
  3476. for (itr = items->begin(); itr != items->end(); itr++) {
  3477. if (*itr && (*itr)->details.item_id == item_id) {
  3478. lua_interface->SetBooleanValue(state, true);
  3479. return 1;
  3480. }
  3481. }
  3482. }
  3483. }
  3484. lua_interface->SetBooleanValue(state, false);
  3485. return 1;
  3486. }
  3487. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3488. if (!lua_interface)
  3489. return 0;
  3490. Quest* quest = lua_interface->GetQuest(state);
  3491. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3492. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3493. lua_interface->ResetFunctionStack(state);
  3494. if (quest) {
  3495. if (quantity == 0)
  3496. quantity = 1;
  3497. Item* master_item = master_item_list.GetItem(item_id);
  3498. if (master_item) {
  3499. Item* item = new Item(master_item);
  3500. item->details.count = quantity;
  3501. quest->AddRewardItem(item);
  3502. }
  3503. }
  3504. return 0;
  3505. }
  3506. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3507. if (!lua_interface)
  3508. return 0;
  3509. Quest* quest = lua_interface->GetQuest(state);
  3510. int32 copper = lua_interface->GetInt32Value(state, 2);
  3511. int32 silver = lua_interface->GetInt32Value(state, 3);
  3512. int32 gold = lua_interface->GetInt32Value(state, 4);
  3513. int32 plat = lua_interface->GetInt32Value(state, 5);
  3514. lua_interface->ResetFunctionStack(state);
  3515. if (quest) {
  3516. quest->AddRewardCoins(copper, silver, gold, plat);
  3517. }
  3518. return 0;
  3519. }
  3520. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3521. if (!lua_interface)
  3522. return 0;
  3523. Quest* quest = lua_interface->GetQuest(state);
  3524. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3525. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3526. lua_interface->ResetFunctionStack(state);
  3527. if (quest && faction_id > 0 && amount != 0)
  3528. quest->AddRewardFaction(faction_id, amount);
  3529. return 0;
  3530. }
  3531. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3532. if (!lua_interface)
  3533. return 0;
  3534. Quest* quest = lua_interface->GetQuest(state);
  3535. int32 status = lua_interface->GetInt32Value(state, 2);
  3536. lua_interface->ResetFunctionStack(state);
  3537. if (quest) {
  3538. quest->SetRewardStatus(status);
  3539. }
  3540. return 0;
  3541. }
  3542. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3543. if (!lua_interface)
  3544. return 0;
  3545. Quest* quest = lua_interface->GetQuest(state);
  3546. int32 status = lua_interface->GetInt32Value(state, 2);
  3547. lua_interface->ResetFunctionStack(state);
  3548. if (quest) {
  3549. quest->SetStatusTmpReward(status);
  3550. }
  3551. return 0;
  3552. }
  3553. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3554. if (!lua_interface)
  3555. return 0;
  3556. Quest* quest = lua_interface->GetQuest(state);
  3557. int64 coins = lua_interface->GetInt64Value(state, 2);
  3558. lua_interface->ResetFunctionStack(state);
  3559. if (quest) {
  3560. quest->SetCoinTmpReward(coins);
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3565. if (!lua_interface)
  3566. return 0;
  3567. Quest* quest = lua_interface->GetQuest(state);
  3568. string comment = lua_interface->GetStringValue(state, 2);
  3569. lua_interface->ResetFunctionStack(state);
  3570. if (quest) {
  3571. quest->SetRewardComment(comment);
  3572. }
  3573. return 0;
  3574. }
  3575. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3576. if (!lua_interface)
  3577. return 0;
  3578. Quest* quest = lua_interface->GetQuest(state);
  3579. int32 exp = lua_interface->GetInt32Value(state, 2);
  3580. lua_interface->ResetFunctionStack(state);
  3581. if (quest) {
  3582. quest->SetRewardXP(exp);
  3583. }
  3584. return 0;
  3585. }
  3586. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3587. Quest* quest = lua_interface->GetQuest(state);
  3588. int32 step = lua_interface->GetInt32Value(state, 2);
  3589. string description = lua_interface->GetStringValue(state, 3);
  3590. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3591. float percentage = lua_interface->GetFloatValue(state, 5);
  3592. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3593. int16 icon = lua_interface->GetInt16Value(state, 7);
  3594. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3595. if (quest) {
  3596. const char* taskgroup = 0;
  3597. if (str_taskgroup.length() > 0)
  3598. taskgroup = str_taskgroup.c_str();
  3599. int32 id = 0;
  3600. vector<int32>* ids = 0;
  3601. int i = 0;
  3602. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3603. if (ids == 0)
  3604. ids = new vector<int32>;
  3605. ids->push_back(id);
  3606. i++;
  3607. }
  3608. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3609. if (quest_step && icon && quantity > 0)
  3610. quest_step->SetIcon(icon);
  3611. if (quest->GetPlayer()) {
  3612. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3613. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3614. }
  3615. }
  3616. lua_interface->ResetFunctionStack(state);
  3617. return 0;
  3618. }
  3619. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3620. {
  3621. if (!lua_interface)
  3622. return 0;
  3623. Quest* quest = lua_interface->GetQuest(state);
  3624. int32 step = lua_interface->GetInt32Value(state, 2);
  3625. string description = lua_interface->GetStringValue(state, 3);
  3626. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3627. float percentage = lua_interface->GetFloatValue(state, 5);
  3628. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3629. int16 icon = lua_interface->GetInt16Value(state, 7);
  3630. if (quest) {
  3631. const char* taskgroup = 0;
  3632. if (str_taskgroup.length() > 0)
  3633. taskgroup = str_taskgroup.c_str();
  3634. int32 id = 0;
  3635. vector<int32>* ids = 0;
  3636. int i = 0;
  3637. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3638. if (ids == 0)
  3639. ids = new vector<int32>;
  3640. ids->push_back(id);
  3641. i++;
  3642. }
  3643. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3644. if (quest_step && icon > 0 && quantity > 0)
  3645. quest_step->SetIcon(icon);
  3646. if (quest->GetPlayer()) {
  3647. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3648. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3649. }
  3650. safe_delete(ids);
  3651. }
  3652. lua_interface->ResetFunctionStack(state);
  3653. return 0;
  3654. }
  3655. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3656. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3657. }
  3658. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3659. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3660. }
  3661. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3662. if (!lua_interface)
  3663. return 0;
  3664. Quest* quest = lua_interface->GetQuest(state);
  3665. int32 step = lua_interface->GetInt32Value(state, 2);
  3666. string description = lua_interface->GetStringValue(state, 3);
  3667. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3668. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3669. int16 icon = lua_interface->GetInt16Value(state, 6);
  3670. if (quest) {
  3671. const char* taskgroup = 0;
  3672. if (str_taskgroup.length() > 0)
  3673. taskgroup = str_taskgroup.c_str();
  3674. int32 npc_id = 0;
  3675. vector<int32>* ids = 0;
  3676. int i = 0;
  3677. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3678. if (ids == 0)
  3679. ids = new vector<int32>;
  3680. ids->push_back(npc_id);
  3681. i++;
  3682. }
  3683. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3684. if (quest_step && icon > 0)
  3685. quest_step->SetIcon(icon);
  3686. if (quest->GetPlayer()) {
  3687. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3688. if(client)
  3689. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3690. }
  3691. safe_delete(ids);
  3692. }
  3693. lua_interface->ResetFunctionStack(state);
  3694. return 0;
  3695. }
  3696. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3697. if (!lua_interface)
  3698. return 0;
  3699. Quest* quest = lua_interface->GetQuest(state);
  3700. int32 step = lua_interface->GetInt32Value(state, 2);
  3701. string description = lua_interface->GetStringValue(state, 3);
  3702. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3703. float percentage = lua_interface->GetFloatValue(state, 5);
  3704. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3705. int16 icon = lua_interface->GetInt16Value(state, 7);
  3706. if (quest) {
  3707. const char* taskgroup = 0;
  3708. if (str_taskgroup.length() > 0)
  3709. taskgroup = str_taskgroup.c_str();
  3710. int32 item_id = 0;
  3711. vector<int32>* ids = 0;
  3712. int i = 0;
  3713. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3714. if (ids == 0)
  3715. ids = new vector<int32>;
  3716. ids->push_back(item_id);
  3717. i++;
  3718. }
  3719. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3720. if (quest_step && icon > 0 && quantity > 0)
  3721. quest_step->SetIcon(icon);
  3722. if (quest->GetPlayer()) {
  3723. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3724. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3725. }
  3726. safe_delete(ids);
  3727. }
  3728. lua_interface->ResetFunctionStack(state);
  3729. return 0;
  3730. }
  3731. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3732. if (!lua_interface)
  3733. return 0;
  3734. Quest* quest = lua_interface->GetQuest(state);
  3735. int32 step = lua_interface->GetInt32Value(state, 2);
  3736. string description = lua_interface->GetStringValue(state, 3);
  3737. float max_variation = lua_interface->GetFloatValue(state, 4);
  3738. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3739. int16 icon = lua_interface->GetInt16Value(state, 6);
  3740. if (quest) {
  3741. const char* taskgroup = 0;
  3742. if (str_taskgroup.length() > 0)
  3743. taskgroup = str_taskgroup.c_str();
  3744. vector<Location>* locations = 0;
  3745. int8 i = 7;
  3746. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3747. while (true) {
  3748. Location loc;
  3749. loc.x = lua_interface->GetFloatValue(state, i);
  3750. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3751. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3752. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3753. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3754. break;
  3755. if (locations == 0)
  3756. locations = new vector<Location>;
  3757. locations->push_back(loc);
  3758. i += 4;
  3759. }
  3760. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3761. if (quest_step && icon > 0)
  3762. quest_step->SetIcon(icon);
  3763. if (quest->GetPlayer()) {
  3764. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3765. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3766. }
  3767. }
  3768. lua_interface->ResetFunctionStack(state);
  3769. return 0;
  3770. }
  3771. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3772. if (!lua_interface)
  3773. return 0;
  3774. Quest* quest = lua_interface->GetQuest(state);
  3775. int32 step = lua_interface->GetInt32Value(state, 2);
  3776. string description = lua_interface->GetStringValue(state, 3);
  3777. float max_variation = lua_interface->GetFloatValue(state, 4);
  3778. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3779. int16 icon = lua_interface->GetInt16Value(state, 6);
  3780. if (quest) {
  3781. const char* taskgroup = 0;
  3782. if (str_taskgroup.length() > 0)
  3783. taskgroup = str_taskgroup.c_str();
  3784. vector<Location>* locations = 0;
  3785. int8 i = 7;
  3786. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3787. while (true) {
  3788. Location loc;
  3789. loc.x = lua_interface->GetFloatValue(state, i);
  3790. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3791. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3792. loc.zone_id = 0;
  3793. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3794. break;
  3795. if (locations == 0)
  3796. locations = new vector<Location>;
  3797. locations->push_back(loc);
  3798. i += 3;
  3799. }
  3800. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3801. if (quest_step && icon > 0)
  3802. quest_step->SetIcon(icon);
  3803. if (quest->GetPlayer()) {
  3804. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3805. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3806. }
  3807. }
  3808. lua_interface->ResetFunctionStack(state);
  3809. return 0;
  3810. }
  3811. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3812. if (!lua_interface)
  3813. return 0;
  3814. Quest* quest = lua_interface->GetQuest(state);
  3815. int32 step = lua_interface->GetInt32Value(state, 2);
  3816. string description = lua_interface->GetStringValue(state, 3);
  3817. float max_variation = lua_interface->GetFloatValue(state, 4);
  3818. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3819. int16 icon = lua_interface->GetInt16Value(state, 6);
  3820. if (quest) {
  3821. const char* taskgroup = 0;
  3822. if (str_taskgroup.length() > 0)
  3823. taskgroup = str_taskgroup.c_str();
  3824. vector<Location>* locations = 0;
  3825. int i = 7;
  3826. while (true) {
  3827. Location loc;
  3828. loc.x = lua_interface->GetFloatValue(state, i);
  3829. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3830. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3831. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3832. break;
  3833. if (locations == 0)
  3834. locations = new vector<Location>;
  3835. locations->push_back(loc);
  3836. i += 3;
  3837. }
  3838. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3839. if (quest_step && icon > 0)
  3840. quest_step->SetIcon(icon);
  3841. if (quest->GetPlayer()) {
  3842. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3843. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3844. }
  3845. }
  3846. lua_interface->ResetFunctionStack(state);
  3847. return 0;
  3848. }
  3849. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3850. Quest* quest = lua_interface->GetQuest(state);
  3851. int32 step = lua_interface->GetInt32Value(state, 2);
  3852. string description = lua_interface->GetStringValue(state, 3);
  3853. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3854. float percentage = lua_interface->GetFloatValue(state, 5);
  3855. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3856. int16 icon = lua_interface->GetInt16Value(state, 7);
  3857. if (quest) {
  3858. const char* taskgroup = 0;
  3859. if (str_taskgroup.length() > 0)
  3860. taskgroup = str_taskgroup.c_str();
  3861. int32 spell_id = 0;
  3862. vector<int32>* ids = 0;
  3863. int i = 0;
  3864. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3865. if (ids == 0)
  3866. ids = new vector<int32>;
  3867. ids->push_back(spell_id);
  3868. i++;
  3869. }
  3870. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3871. if (quest_step && icon > 0 && quantity > 0)
  3872. quest_step->SetIcon(icon);
  3873. if (quest->GetPlayer()) {
  3874. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3875. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3876. }
  3877. safe_delete(ids);
  3878. }
  3879. lua_interface->ResetFunctionStack(state);
  3880. return 0;
  3881. }
  3882. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3883. if (!lua_interface)
  3884. return 0;
  3885. Quest* quest = lua_interface->GetQuest(state);
  3886. int32 step = lua_interface->GetInt32Value(state, 2);
  3887. string description = lua_interface->GetStringValue(state, 3);
  3888. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3889. float percentage = lua_interface->GetFloatValue(state, 5);
  3890. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3891. int16 icon = lua_interface->GetInt16Value(state, 7);
  3892. if (quest) {
  3893. const char* taskgroup = 0;
  3894. if (str_taskgroup.length() > 0)
  3895. taskgroup = str_taskgroup.c_str();
  3896. int32 item_id = 0;
  3897. vector<int32>* ids = 0;
  3898. int i = 0;
  3899. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3900. if (ids == 0)
  3901. ids = new vector<int32>;
  3902. ids->push_back(item_id);
  3903. i++;
  3904. }
  3905. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3906. if (quest_step && icon > 0 && quantity > 0)
  3907. quest_step->SetIcon(icon);
  3908. if (quest->GetPlayer()) {
  3909. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3910. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3911. }
  3912. safe_delete(ids);
  3913. }
  3914. lua_interface->ResetFunctionStack(state);
  3915. return 0;
  3916. }
  3917. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3918. if (!lua_interface)
  3919. return 0;
  3920. Quest* quest = lua_interface->GetQuest(state);
  3921. int32 step = lua_interface->GetInt32Value(state, 2);
  3922. string description = lua_interface->GetStringValue(state, 3);
  3923. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3924. float percentage = lua_interface->GetFloatValue(state, 5);
  3925. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3926. int16 icon = lua_interface->GetInt16Value(state, 7);
  3927. if (quest) {
  3928. const char* taskgroup = 0;
  3929. if (str_taskgroup.length() > 0)
  3930. taskgroup = str_taskgroup.c_str();
  3931. int32 item_id = 0;
  3932. vector<int32>* ids = 0;
  3933. int i = 0;
  3934. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3935. if (ids == 0)
  3936. ids = new vector<int32>;
  3937. ids->push_back(item_id);
  3938. i++;
  3939. }
  3940. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3941. if (quest_step && icon > 0 && quantity > 0)
  3942. quest_step->SetIcon(icon);
  3943. if (quest->GetPlayer()) {
  3944. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3945. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3946. }
  3947. safe_delete(ids);
  3948. }
  3949. lua_interface->ResetFunctionStack(state);
  3950. return 0;
  3951. }
  3952. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3953. if (!lua_interface)
  3954. return 0;
  3955. Quest* quest = lua_interface->GetQuest(state);
  3956. string action = lua_interface->GetStringValue(state, 2);
  3957. lua_interface->ResetFunctionStack(state);
  3958. if (quest) {
  3959. if (action.length() > 0)
  3960. quest->SetCompleteAction(action);
  3961. }
  3962. return 0;
  3963. }
  3964. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3965. if (!lua_interface)
  3966. return 0;
  3967. Quest* quest = lua_interface->GetQuest(state);
  3968. int32 step = lua_interface->GetInt32Value(state, 2);
  3969. string action = lua_interface->GetStringValue(state, 3);
  3970. lua_interface->ResetFunctionStack(state);
  3971. if (quest) {
  3972. if (step > 0 && action.length() > 0)
  3973. quest->AddCompleteAction(step, action);
  3974. }
  3975. return 0;
  3976. }
  3977. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3978. if (!lua_interface)
  3979. return 0;
  3980. Quest* quest = lua_interface->GetQuest(state);
  3981. int32 step = lua_interface->GetInt32Value(state, 2);
  3982. string action = lua_interface->GetStringValue(state, 3);
  3983. lua_interface->ResetFunctionStack(state);
  3984. if (quest) {
  3985. if (step > 0 && action.length() > 0)
  3986. quest->AddProgressAction(step, action);
  3987. }
  3988. return 0;
  3989. }
  3990. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3991. if (!lua_interface)
  3992. return 0;
  3993. Quest* quest = lua_interface->GetQuest(state);
  3994. string description = lua_interface->GetStringValue(state, 2);
  3995. lua_interface->ResetFunctionStack(state);
  3996. if (quest && description.length() > 0)
  3997. quest->SetDescription(description);
  3998. return 0;
  3999. }
  4000. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4001. if (!lua_interface)
  4002. return 0;
  4003. Quest* quest = lua_interface->GetQuest(state);
  4004. string description = lua_interface->GetStringValue(state, 2);
  4005. lua_interface->ResetFunctionStack(state);
  4006. if (quest && description.length() > 0)
  4007. quest->SetCompletedDescription(description);
  4008. return 0;
  4009. }
  4010. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4011. if (!lua_interface)
  4012. return 0;
  4013. Quest* quest = lua_interface->GetQuest(state);
  4014. int32 step = lua_interface->GetInt32Value(state, 2);
  4015. string description = lua_interface->GetStringValue(state, 3);
  4016. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4017. lua_interface->ResetFunctionStack(state);
  4018. if (quest && step > 0 && description.length() > 0) {
  4019. quest->SetTaskGroupDescription(step, description, display_bullets);
  4020. /* if (quest->GetPlayer()) {
  4021. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4022. if (client)
  4023. client->SendQuestUpdateStep(quest, step, false);
  4024. }*/
  4025. }
  4026. return 0;
  4027. }
  4028. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4029. if (!lua_interface)
  4030. return 0;
  4031. Quest* quest = lua_interface->GetQuest(state);
  4032. int32 step = lua_interface->GetInt32Value(state, 2);
  4033. string description = lua_interface->GetStringValue(state, 3);
  4034. lua_interface->ResetFunctionStack(state);
  4035. if (quest && step > 0 && description.length() > 0) {
  4036. quest->SetStepDescription(step, description);
  4037. /*if (quest->GetPlayer()) {
  4038. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4039. if (client)
  4040. client->SendQuestUpdateStepImmediately(quest, step);
  4041. }*/
  4042. }
  4043. return 0;
  4044. }
  4045. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4046. Quest* quest = lua_interface->GetQuest(state);
  4047. string zone = lua_interface->GetStringValue(state, 2);
  4048. lua_interface->ResetFunctionStack(state);
  4049. if (quest && zone.length() > 0)
  4050. quest->SetZone(zone);
  4051. return 0;
  4052. }
  4053. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4054. if (!lua_interface)
  4055. return 0;
  4056. Quest* quest = lua_interface->GetQuest(state);
  4057. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4058. lua_interface->ResetFunctionStack(state);
  4059. if (quest && spawn) {
  4060. if (spawn->IsPlayer()) {
  4061. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4062. if (client)
  4063. {
  4064. client->AddPendingQuestAcceptReward(quest);
  4065. client->AddPendingQuestReward(quest);
  4066. }
  4067. }
  4068. }
  4069. return 0;
  4070. }
  4071. int EQ2Emu_lua_Harvest(lua_State* state) {
  4072. if (!lua_interface)
  4073. return 0;
  4074. Spawn* player = lua_interface->GetSpawn(state);
  4075. Spawn* node = lua_interface->GetSpawn(state, 2);
  4076. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4077. Client* client = player->GetZone()->GetClientBySpawn(player);
  4078. if (client) {
  4079. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4080. ((GroundSpawn*)node)->ProcessHarvest(client);
  4081. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4082. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4083. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4084. }
  4085. }
  4086. }
  4087. else if (player && player->IsPlayer()) {
  4088. Client* client = player->GetZone()->GetClientBySpawn(player);
  4089. if (client)
  4090. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4091. }
  4092. lua_interface->ResetFunctionStack(state);
  4093. return 0;
  4094. }
  4095. int EQ2Emu_lua_Bind(lua_State* state) {
  4096. if (!lua_interface)
  4097. return 0;
  4098. Spawn* spawn = lua_interface->GetSpawn(state);
  4099. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4100. float x = lua_interface->GetFloatValue(state, 3);
  4101. float y = lua_interface->GetFloatValue(state, 4);
  4102. float z = lua_interface->GetFloatValue(state, 5);
  4103. float h = lua_interface->GetFloatValue(state, 6);
  4104. lua_interface->ResetFunctionStack(state);
  4105. if (!spawn) {
  4106. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4107. return 0;
  4108. }
  4109. if (!spawn->IsPlayer()) {
  4110. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4111. return 0;
  4112. }
  4113. if (zone_id == 0) {
  4114. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4115. if (!client) {
  4116. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4117. return 0;
  4118. }
  4119. if (!client->Bind())
  4120. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4121. }
  4122. else {
  4123. Player* player = (Player*)spawn;
  4124. player->GetPlayerInfo()->SetBindZone(zone_id);
  4125. player->GetPlayerInfo()->SetBindX(x);
  4126. player->GetPlayerInfo()->SetBindY(y);
  4127. player->GetPlayerInfo()->SetBindZ(z);
  4128. player->GetPlayerInfo()->SetBindHeading(h);
  4129. }
  4130. return 0;
  4131. }
  4132. int EQ2Emu_lua_Gate(lua_State* state) {
  4133. if (!lua_interface)
  4134. return 0;
  4135. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4136. Spawn* spawn = lua_interface->GetSpawn(state);
  4137. lua_interface->ResetFunctionStack(state);
  4138. if (spawn) {
  4139. if (spawn->IsPlayer()) {
  4140. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4141. if (client) {
  4142. if (!client->Gate((spell != nullptr) ? true : false))
  4143. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4144. }
  4145. }
  4146. }
  4147. return 0;
  4148. }
  4149. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4150. if (!lua_interface)
  4151. return 0;
  4152. bool ret = false;
  4153. Spawn* spawn = lua_interface->GetSpawn(state);
  4154. lua_interface->ResetFunctionStack(state);
  4155. if (spawn) {
  4156. if (spawn->IsPlayer()) {
  4157. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4158. if (client)
  4159. ret = client->BindAllowed();
  4160. }
  4161. }
  4162. lua_interface->SetBooleanValue(state, ret);
  4163. return 1;
  4164. }
  4165. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4166. if (!lua_interface)
  4167. return 0;
  4168. bool ret = false;
  4169. Spawn* spawn = lua_interface->GetSpawn(state);
  4170. lua_interface->ResetFunctionStack(state);
  4171. if (spawn) {
  4172. if (spawn->IsPlayer()) {
  4173. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4174. ZoneServer* zone = lua_interface->GetZone(state);
  4175. if (client && zone){
  4176. ret = zone->GetCanGate();
  4177. }
  4178. }
  4179. }
  4180. lua_interface->SetBooleanValue(state, ret);
  4181. return 1;
  4182. }
  4183. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4184. Spawn* spawn = lua_interface->GetSpawn(state);
  4185. lua_interface->ResetFunctionStack(state);
  4186. if (spawn) {
  4187. lua_interface->SetBooleanValue(state, spawn->Alive());
  4188. return 1;
  4189. }
  4190. return 0;
  4191. }
  4192. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4193. if (!lua_interface)
  4194. return 0;
  4195. Spawn* spawn = lua_interface->GetSpawn(state);
  4196. lua_interface->ResetFunctionStack(state);
  4197. if (spawn && spawn->IsEntity()) {
  4198. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4199. return 1;
  4200. }
  4201. return 0;
  4202. }
  4203. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4204. Spawn* spawn = lua_interface->GetSpawn(state);
  4205. string message = lua_interface->GetStringValue(state, 2);
  4206. string color_str = lua_interface->GetStringValue(state, 3);
  4207. lua_interface->ResetFunctionStack(state);
  4208. int8 color = CHANNEL_NARRATIVE;
  4209. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4210. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4211. if (client) {
  4212. if (color_str.length() > 0) {
  4213. // leave for backwards compat, but all future should just use the number
  4214. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4215. color = CHANNEL_COLOR_RED;
  4216. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4217. color = CHANNEL_COLOR_YELLOW;
  4218. else
  4219. {
  4220. // use a number to specify the channel as per Commands/Commands.h defines
  4221. color = (int8)atoul(color_str.c_str());
  4222. }
  4223. }
  4224. client->SimpleMessage(color, message.c_str());
  4225. }
  4226. }
  4227. return 0;
  4228. }
  4229. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4230. Spawn* spawn = lua_interface->GetSpawn(state);
  4231. string message = lua_interface->GetStringValue(state, 2);
  4232. int8 red = lua_interface->GetInt8Value(state, 3);
  4233. int8 green = lua_interface->GetInt8Value(state, 4);
  4234. int8 blue = lua_interface->GetInt8Value(state, 5);
  4235. lua_interface->ResetFunctionStack(state);
  4236. if (!spawn) {
  4237. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4238. return 0;
  4239. }
  4240. int32 words = ::CountWordsInString(message.c_str());
  4241. if (words < 5)
  4242. words = 5;
  4243. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4244. if (client)
  4245. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4246. return 0;
  4247. }
  4248. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4249. Spawn* spawn = lua_interface->GetSpawn(state);
  4250. int8 param = lua_interface->GetInt8Value(state, 2);
  4251. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4252. int8 value = lua_interface->GetInt8Value(state, 4);
  4253. lua_interface->ResetFunctionStack(state);
  4254. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4255. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4256. if (client) {
  4257. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4258. switch (param) {
  4259. case 1: {
  4260. packet->setDataByName("parameter1", param_value);
  4261. break;
  4262. }
  4263. case 2: {
  4264. packet->setDataByName("parameter2", param_value);
  4265. break;
  4266. }
  4267. case 3: {
  4268. packet->setDataByName("parameter3", param_value);
  4269. break;
  4270. }
  4271. case 4: {
  4272. packet->setDataByName("parameter4", param_value);
  4273. break;
  4274. }
  4275. case 5: {
  4276. packet->setDataByName("parameter5", param_value);
  4277. break;
  4278. }
  4279. }
  4280. packet->setDataByName("value", value);
  4281. client->QueuePacket(packet->serialize());
  4282. safe_delete(packet);
  4283. }
  4284. }
  4285. return 0;
  4286. }
  4287. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4288. Spawn* spawn = lua_interface->GetSpawn(state);
  4289. lua_interface->ResetFunctionStack(state);
  4290. if (spawn && spawn->IsPlayer()) {
  4291. if (((Player*)spawn)->GetIsTracking())
  4292. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4293. else
  4294. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4295. }
  4296. return 0;
  4297. }
  4298. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4299. Spawn* player = lua_interface->GetSpawn(state);
  4300. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4301. string name = lua_interface->GetStringValue(state, 3);
  4302. float distance = lua_interface->GetFloatValue(state, 4);
  4303. string command = lua_interface->GetStringValue(state, 5);
  4304. string error_text = lua_interface->GetStringValue(state, 6);
  4305. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4306. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4307. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4308. lua_interface->ResetFunctionStack(state);
  4309. if (spawn) {
  4310. if (distance == 0)
  4311. distance = 10.0f;
  4312. if (command.length() == 0)
  4313. command = name;
  4314. if (command.length() < 1 && name.length() < 1)
  4315. {
  4316. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4317. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4318. spawn->RemovePrimaryCommands();
  4319. }
  4320. else
  4321. {
  4322. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4323. }
  4324. }
  4325. return 0;
  4326. }
  4327. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4328. if (!lua_interface)
  4329. return 0;
  4330. Spawn* player = lua_interface->GetSpawn(state);
  4331. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4332. int16 tier = lua_interface->GetInt16Value(state, 3);
  4333. lua_interface->ResetFunctionStack(state);
  4334. if (player && player->IsPlayer()) {
  4335. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4336. return 1;
  4337. }
  4338. return 0;
  4339. }
  4340. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4341. if (!lua_interface)
  4342. return 0;
  4343. Spawn* player = lua_interface->GetSpawn(state);
  4344. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4345. int16 tier = lua_interface->GetInt16Value(state, 3);
  4346. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4347. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4348. bool add_to_hotbar = true;
  4349. if (num_args > 4) {
  4350. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4351. }
  4352. lua_interface->ResetFunctionStack(state);
  4353. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4354. if (player && spell && player->IsPlayer()) {
  4355. Client* client = player->GetClient();
  4356. if (client) {
  4357. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4358. {
  4359. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4360. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4361. client->GetPlayer()->UnlockSpell(spell);
  4362. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4363. }
  4364. else
  4365. {
  4366. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4367. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4368. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4369. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4370. client->GetPlayer()->UnlockSpell(spell);
  4371. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4372. }
  4373. //if (client ) {
  4374. // ((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);
  4375. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4376. if (outapp)
  4377. client->QueuePacket(outapp);
  4378. }
  4379. }
  4380. return 0;
  4381. }
  4382. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4383. if (!lua_interface)
  4384. return 0;
  4385. Spawn* player = lua_interface->GetSpawn(state);
  4386. lua_interface->ResetFunctionStack(state);
  4387. if (player && player->IsPlayer()) {
  4388. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4389. return 1;
  4390. }
  4391. return 0;
  4392. }
  4393. int EQ2Emu_lua_Attack(lua_State* state) {
  4394. if (lua_interface) {
  4395. Spawn* npc = lua_interface->GetSpawn(state);
  4396. Spawn* player = lua_interface->GetSpawn(state, 2);
  4397. lua_interface->ResetFunctionStack(state);
  4398. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4399. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4400. }
  4401. return 0;
  4402. }
  4403. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4404. if (lua_interface) {
  4405. Spawn* target = lua_interface->GetSpawn(state);
  4406. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4407. lua_interface->ResetFunctionStack(state);
  4408. if (target && target->GetZone())
  4409. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4410. }
  4411. return 0;
  4412. }
  4413. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4414. Spawn* player;
  4415. if (lua_interface) {
  4416. player = lua_interface->GetSpawn(state);
  4417. lua_interface->ResetFunctionStack(state);
  4418. if (player && player->IsPlayer()) {
  4419. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4420. return 1;
  4421. }
  4422. }
  4423. return 0;
  4424. }
  4425. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4426. Spawn* player;
  4427. Client* client;
  4428. if (lua_interface) {
  4429. player = lua_interface->GetSpawn(state);
  4430. lua_interface->ResetFunctionStack(state);
  4431. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4432. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4433. client->HandInCollections();
  4434. }
  4435. return 0;
  4436. }
  4437. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4438. Spawn* widget;
  4439. if (lua_interface) {
  4440. widget = lua_interface->GetSpawn(state);
  4441. lua_interface->ResetFunctionStack(state);
  4442. if (widget && widget->IsWidget())
  4443. ((Widget*)widget)->HandleUse(nullptr, "");
  4444. }
  4445. return 0;
  4446. }
  4447. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4448. Spawn* spawn = 0;
  4449. int32 primary_list = 0;
  4450. int32 secondary_list = 0;
  4451. if (lua_interface) {
  4452. spawn = lua_interface->GetSpawn(state);
  4453. primary_list = lua_interface->GetInt32Value(state, 2);
  4454. secondary_list = lua_interface->GetInt32Value(state, 3);
  4455. lua_interface->ResetFunctionStack(state);
  4456. if (!spawn->IsNPC()) {
  4457. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4458. return 0;
  4459. }
  4460. NPC* npc = (NPC*)spawn;
  4461. npc->SetPrimarySpellList(primary_list);
  4462. npc->SetSecondarySpellList(secondary_list);
  4463. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4464. }
  4465. return 0;
  4466. }
  4467. int EQ2Emu_lua_GetPet(lua_State* state) {
  4468. if (!lua_interface)
  4469. return 0;
  4470. Spawn* spawn = lua_interface->GetSpawn(state);
  4471. lua_interface->ResetFunctionStack(state);
  4472. if (spawn) {
  4473. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4474. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4475. return 1;
  4476. }
  4477. }
  4478. return 0;
  4479. }
  4480. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4481. if (!lua_interface)
  4482. return 0;
  4483. Spawn* spawn = lua_interface->GetSpawn(state);
  4484. lua_interface->ResetFunctionStack(state);
  4485. if (spawn) {
  4486. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4487. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4488. return 1;
  4489. }
  4490. }
  4491. return 0;
  4492. }
  4493. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4494. if (!lua_interface)
  4495. return 0;
  4496. Spawn* spawn = lua_interface->GetSpawn(state);
  4497. lua_interface->ResetFunctionStack(state);
  4498. if (spawn) {
  4499. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4500. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4501. return 1;
  4502. }
  4503. }
  4504. return 0;
  4505. }
  4506. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4507. if (!lua_interface)
  4508. return 0;
  4509. Spawn* spawn = lua_interface->GetSpawn(state);
  4510. lua_interface->ResetFunctionStack(state);
  4511. if (spawn) {
  4512. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4513. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4514. return 1;
  4515. }
  4516. }
  4517. return 0;
  4518. }
  4519. int EQ2Emu_lua_Charm(lua_State* state) {
  4520. if (!lua_interface)
  4521. return 0;
  4522. Spawn* owner = lua_interface->GetSpawn(state);
  4523. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4524. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4525. lua_interface->ResetFunctionStack(state);
  4526. if (!luaspell) {
  4527. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4528. return 0;
  4529. }
  4530. if(luaspell->resisted) {
  4531. return 0;
  4532. }
  4533. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4534. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4535. pet->SetPet(true);
  4536. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4537. ((NPC*)pet)->SetOwner((Entity*)owner);
  4538. // If owner is player and player does not have a summoned pet set the players charsheet
  4539. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4540. Player* player = (Player*)owner;
  4541. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4542. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4543. player->GetInfoStruct()->set_pet_movement(2);
  4544. player->GetInfoStruct()->set_pet_behavior(3);
  4545. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4546. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4547. // Make sure the values get sent to the client
  4548. player->SetCharSheetChanged(true);
  4549. }
  4550. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4551. pet->SetSpawnScript("");
  4552. // Set faction to the same as the owner
  4553. pet->SetFactionID(owner->GetFactionID());
  4554. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4555. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4556. // Clear hate list
  4557. ((NPC*)pet)->Brain()->ClearHate();
  4558. // Set the brain to a pet brain
  4559. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4560. }
  4561. return 0;
  4562. }
  4563. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4564. if (!lua_interface)
  4565. return 0;
  4566. Spawn* spawn = lua_interface->GetSpawn(state);
  4567. lua_interface->ResetFunctionStack(state);
  4568. if (!spawn) {
  4569. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4570. return 0;
  4571. }
  4572. vector<Spawn*> groupMembers;
  4573. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4574. groupMembers = *spawn->GetSpawnGroup();
  4575. }
  4576. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4577. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4578. deque<GroupMemberInfo*>::iterator itr;
  4579. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4580. if (group)
  4581. {
  4582. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4583. deque<GroupMemberInfo*>* members = group->GetMembers();
  4584. GroupMemberInfo* info = 0;
  4585. for (itr = members->begin(); itr != members->end(); itr++) {
  4586. info = *itr;
  4587. if (info->client)
  4588. groupMembers.push_back(info->client->GetPlayer());
  4589. }
  4590. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4591. }
  4592. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4593. }
  4594. else
  4595. return 0;
  4596. lua_createtable(state, groupMembers.size(), 0);
  4597. int newTable = lua_gettop(state);
  4598. for (int32 i = 0; i < groupMembers.size(); i++) {
  4599. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4600. lua_rawseti(state, newTable, i + 1);
  4601. }
  4602. return 1;
  4603. }
  4604. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4605. if (!lua_interface)
  4606. return 0;
  4607. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4608. lua_interface->SetOptionWindowValue(state, option_window);
  4609. return 1;
  4610. }
  4611. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4612. if (!lua_interface)
  4613. return 0;
  4614. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4615. if (option_window) {
  4616. OptionWindowOption option_window_option;
  4617. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4618. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4619. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4620. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4621. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4622. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4623. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4624. option_window->push_back(option_window_option);
  4625. }
  4626. return 0;
  4627. }
  4628. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4629. if (!lua_interface)
  4630. return 0;
  4631. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4632. Spawn* player = lua_interface->GetSpawn(state, 2);
  4633. string window_title = lua_interface->GetStringValue(state, 3);
  4634. string cancel_command = lua_interface->GetStringValue(state, 4);
  4635. Client* client = player->GetZone()->GetClientBySpawn(player);
  4636. if (option_window && window_title.length() > 0 && client) {
  4637. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4638. if (!packet)
  4639. return 0;
  4640. packet->setDataByName("title_text", window_title.c_str());
  4641. if (cancel_command.length() > 0)
  4642. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4643. packet->setArrayLengthByName("num_selections", option_window->size());
  4644. vector<OptionWindowOption>::iterator itr;
  4645. int8 i = 0;
  4646. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4647. OptionWindowOption opt = *itr;
  4648. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4649. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4650. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4651. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4652. if (opt.optionCommand.length() > 0)
  4653. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4654. if (opt.optionConfirmTitle.length() > 0)
  4655. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4656. i++;
  4657. }
  4658. client->QueuePacket(packet->serialize());
  4659. safe_delete(option_window);
  4660. safe_delete(packet);
  4661. }
  4662. return 0;
  4663. }
  4664. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4665. if (!lua_interface)
  4666. return 0;
  4667. Spawn* spawn = lua_interface->GetSpawn(state);
  4668. if (spawn) {
  4669. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4670. return 1;
  4671. }
  4672. else
  4673. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4674. return 0;
  4675. }
  4676. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4677. if (!lua_interface)
  4678. return 0;
  4679. Spawn* spawn = lua_interface->GetSpawn(state);
  4680. if (spawn) {
  4681. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4682. return 1;
  4683. }
  4684. else
  4685. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4686. return 0;
  4687. }
  4688. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4689. if (!lua_interface)
  4690. return 0;
  4691. Spawn* spawn = lua_interface->GetSpawn(state);
  4692. if (spawn) {
  4693. int8 class_id = spawn->GetTradeskillClass();
  4694. // Need to add 42 for the offset in the array
  4695. class_id += 44;
  4696. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4697. return 1;
  4698. }
  4699. else
  4700. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4701. return 0;
  4702. }
  4703. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4704. if (!lua_interface)
  4705. return 0;
  4706. Spawn* spawn = lua_interface->GetSpawn(state);
  4707. int16 level = lua_interface->GetInt8Value(state, 2);
  4708. if (spawn) {
  4709. if (spawn->IsPlayer())
  4710. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4711. else
  4712. spawn->SetTSLevel(level);
  4713. }
  4714. else
  4715. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4716. return 0;
  4717. }
  4718. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4719. if (!lua_interface)
  4720. return 0;
  4721. Spawn* spawn = lua_interface->GetSpawn(state);
  4722. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4723. if (spawn) {
  4724. spawn->SetAttackable(attackable);
  4725. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4726. }
  4727. return 0;
  4728. }
  4729. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4730. // Check to see if we have a valid lua_interface
  4731. if (!lua_interface)
  4732. return 0;
  4733. // Get the spawn that is getting the pet
  4734. Spawn* spawn = lua_interface->GetSpawn(state);
  4735. // Get the DB ID of the pet
  4736. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4737. // The max level the pet can gain
  4738. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4739. // Get the spell that this command was called from
  4740. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4741. // Check to make sure the spawn pointer is valid
  4742. if (!spawn) {
  4743. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4744. return 0;
  4745. }
  4746. // Check to make sure the spawn is an entity
  4747. if (!spawn->IsEntity()) {
  4748. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4749. return 0;
  4750. }
  4751. // Check to make sure the spawn doesn't already have a pet of this type
  4752. if (((Entity*)spawn)->GetPet()) {
  4753. if (spawn->IsPlayer()) {
  4754. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4755. if (client)
  4756. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4757. }
  4758. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4759. return 0;
  4760. }
  4761. // Check to see if the DB ID for the pet is set
  4762. if (pet_id == 0) {
  4763. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4764. return 0;
  4765. }
  4766. // Check to see if the pointer to the spell is valid
  4767. if (!luaspell) {
  4768. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4769. return 0;
  4770. }
  4771. if(luaspell->resisted) {
  4772. return 0;
  4773. }
  4774. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4775. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4776. if (!pet) {
  4777. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4778. return 0;
  4779. }
  4780. // Check to make sure the pet is an npc
  4781. if (!pet->IsNPC()) {
  4782. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4783. return 0;
  4784. }
  4785. // Spawn the pet at the same location as the owner
  4786. pet->SetX(spawn->GetX());
  4787. pet->SetY(spawn->GetY());
  4788. pet->SetZ(spawn->GetZ());
  4789. pet->SetLocation(spawn->GetLocation());
  4790. pet->SetHeading(spawn->GetHeading());
  4791. spawn->GetZone()->AddSpawn(pet);
  4792. /*
  4793. const char* spawn_script = world.GetSpawnScript(pet_id);
  4794. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4795. spawn->SetSpawnScript(string(spawn_script));
  4796. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4797. }*/
  4798. // Get a random pet name
  4799. string random_pet_name;
  4800. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4801. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4802. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4803. // If player set various values for the char sheet (pet window)
  4804. if (spawn->IsPlayer()) {
  4805. Player* player = (Player*)spawn;
  4806. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4807. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4808. player->GetInfoStruct()->set_pet_movement(2);
  4809. player->GetInfoStruct()->set_pet_behavior(3);
  4810. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4811. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4812. // Make sure the values get sent to the client
  4813. player->SetCharSheetChanged(true);
  4814. }
  4815. // Set the pets name
  4816. pet->SetName(random_pet_name.c_str());
  4817. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4818. if (max_level > 0)
  4819. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4820. else
  4821. pet->SetLevel(spawn->GetLevel());
  4822. // Set the max level this pet can reach
  4823. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4824. // Set the faction of the pet to the same faction as the owner
  4825. pet->SetFactionID(spawn->GetFactionID());
  4826. // Set the spawn as a pet
  4827. pet->SetPet(true);
  4828. // Give a pointer of the owner to the pet
  4829. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4830. // Give a pointer of the pet to the owner
  4831. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4832. // Set the pet type
  4833. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4834. // Set the spell id used to create this pet
  4835. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4836. // Set the spell tier used to create this pet
  4837. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4838. // Set the pets spawn type to 6
  4839. pet->SetSpawnType(6);
  4840. // Set the pets brain
  4841. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4842. // Check to see if the pet has a subtitle
  4843. if (strlen(pet->GetSubTitle()) > 0) {
  4844. // Add the players name to the front of the sub title
  4845. string pet_subtitle;
  4846. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4847. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4848. // Set the pets subtitle to the new one
  4849. pet->SetSubTitle(pet_subtitle.c_str());
  4850. }
  4851. // Add the "Pet Options" entity command to the pet
  4852. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4853. // Set the pet as the return value for this function
  4854. lua_interface->SetSpawnValue(state, pet);
  4855. return 1;
  4856. }
  4857. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4858. if (!lua_interface)
  4859. return 0;
  4860. Spawn* spawn = lua_interface->GetSpawn(state);
  4861. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4862. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4863. if (!spawn) {
  4864. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4865. return 0;
  4866. }
  4867. if (!spawn->IsEntity()) {
  4868. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4869. return 0;
  4870. }
  4871. if (((Entity*)spawn)->GetDeityPet()) {
  4872. if (spawn->IsPlayer()) {
  4873. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4874. if (client)
  4875. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4876. }
  4877. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4878. return 0;
  4879. }
  4880. if (pet_id == 0) {
  4881. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4882. return 0;
  4883. }
  4884. if (!luaspell) {
  4885. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4886. return 0;
  4887. }
  4888. if(luaspell->resisted) {
  4889. return 0;
  4890. }
  4891. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4892. if (!pet) {
  4893. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4894. return 0;
  4895. }
  4896. if (!pet->IsNPC()) {
  4897. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4898. return 0;
  4899. }
  4900. pet->SetX(spawn->GetX());
  4901. pet->SetY(spawn->GetY());
  4902. pet->SetZ(spawn->GetZ());
  4903. pet->SetLocation(spawn->GetLocation());
  4904. pet->SetHeading(spawn->GetHeading());
  4905. spawn->GetZone()->AddSpawn(pet);
  4906. string random_pet_name;
  4907. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4908. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4909. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4910. pet->SetName(random_pet_name.c_str());
  4911. pet->SetLevel(spawn->GetLevel());
  4912. pet->SetFactionID(spawn->GetFactionID());
  4913. pet->SetPet(true);
  4914. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4915. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4916. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4917. pet->SetSpawnType(6);
  4918. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4919. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4920. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4921. if (strlen(pet->GetSubTitle()) > 0) {
  4922. string pet_subtitle;
  4923. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4924. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4925. pet->SetSubTitle(pet_subtitle.c_str());
  4926. }
  4927. // deity and cosmetic pets are not attackable
  4928. pet->SetAttackable(false);
  4929. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4930. lua_interface->SetSpawnValue(state, pet);
  4931. return 1;
  4932. }
  4933. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4934. if (!lua_interface)
  4935. return 0;
  4936. Spawn* spawn = lua_interface->GetSpawn(state);
  4937. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4938. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4939. if (!spawn) {
  4940. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4941. return 0;
  4942. }
  4943. if (!spawn->IsEntity()) {
  4944. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4945. return 0;
  4946. }
  4947. if (((Entity*)spawn)->GetCosmeticPet()) {
  4948. if (spawn->IsPlayer()) {
  4949. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4950. if (client)
  4951. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4952. }
  4953. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4954. return 0;
  4955. }
  4956. if (pet_id == 0) {
  4957. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4958. return 0;
  4959. }
  4960. if (!luaspell) {
  4961. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4962. return 0;
  4963. }
  4964. if(luaspell->resisted) {
  4965. return 0;
  4966. }
  4967. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4968. if (!pet) {
  4969. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4970. return 0;
  4971. }
  4972. if (!pet->IsNPC()) {
  4973. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4974. return 0;
  4975. }
  4976. pet->SetX(spawn->GetX());
  4977. pet->SetY(spawn->GetY());
  4978. pet->SetZ(spawn->GetZ());
  4979. pet->SetLocation(spawn->GetLocation());
  4980. pet->SetHeading(spawn->GetHeading());
  4981. spawn->GetZone()->AddSpawn(pet);
  4982. string random_pet_name;
  4983. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4984. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4985. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4986. pet->SetName(random_pet_name.c_str());
  4987. pet->SetLevel(spawn->GetLevel());
  4988. pet->SetFactionID(spawn->GetFactionID());
  4989. pet->SetPet(true);
  4990. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4991. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4992. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4993. pet->SetSpawnType(6);
  4994. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4995. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4996. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4997. if (strlen(pet->GetSubTitle()) > 0) {
  4998. string pet_subtitle;
  4999. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5000. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5001. pet->SetSubTitle(pet_subtitle.c_str());
  5002. }
  5003. pet->SetAttackable(false);
  5004. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5005. lua_interface->SetSpawnValue(state, pet);
  5006. return 1;
  5007. }
  5008. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5009. if (!lua_interface)
  5010. return 0;
  5011. Spawn* spawn = lua_interface->GetSpawn(state);
  5012. if (!spawn) {
  5013. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5014. return 0;
  5015. }
  5016. if (!spawn->IsPet()) {
  5017. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5018. return 0;
  5019. }
  5020. if (!((NPC*)spawn)->IsDismissing())
  5021. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5022. return 0;
  5023. }
  5024. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5025. if (!lua_interface)
  5026. return 0;
  5027. Quest* quest = lua_interface->GetQuest(state);
  5028. if (!quest) {
  5029. 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));
  5030. return 0;
  5031. }
  5032. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5033. if (feather_color > 0)
  5034. quest->SetFeatherColor(feather_color);
  5035. return 0;
  5036. }
  5037. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5038. if (!lua_interface)
  5039. return 0;
  5040. Spawn* spawn = lua_interface->GetSpawn(state);
  5041. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5042. if (!spawn) {
  5043. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5044. return 0;
  5045. }
  5046. if (!spawn2) {
  5047. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5048. return 0;
  5049. }
  5050. spawn->RemoveSpawnAccess(spawn2);
  5051. return 0;
  5052. }
  5053. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5054. if (!lua_interface)
  5055. return 0;
  5056. ZoneServer* zone = lua_interface->GetZone(state);
  5057. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5058. if (!zone) {
  5059. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5060. return 0;
  5061. }
  5062. if (location_id == 0) {
  5063. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5064. return 0;
  5065. }
  5066. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5067. if (!location) {
  5068. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5069. return 0;
  5070. }
  5071. Spawn* spawn = 0;
  5072. if (location->entities[0]) {
  5073. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5074. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5075. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5076. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5077. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5078. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5079. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5080. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5081. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5082. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5083. if(spawn && spawn->IsOmittedByDBFlag())
  5084. {
  5085. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5086. safe_delete(spawn);
  5087. spawn = 0;
  5088. return 0;
  5089. }
  5090. if (spawn) {
  5091. const char* script = 0;
  5092. for (int x = 0; x < 3; x++) {
  5093. switch (x) {
  5094. case 0:
  5095. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5096. break;
  5097. case 1:
  5098. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5099. break;
  5100. case 2:
  5101. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5102. break;
  5103. }
  5104. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5105. spawn->SetSpawnScript(string(script));
  5106. break;
  5107. }
  5108. }
  5109. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5110. lua_interface->SetSpawnValue(state, spawn);
  5111. return 1;
  5112. }
  5113. else {
  5114. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5115. safe_delete(spawn);
  5116. }
  5117. }
  5118. return 0;
  5119. }
  5120. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5121. if (!lua_interface)
  5122. return 0;
  5123. Spawn* caster = lua_interface->GetSpawn(state);
  5124. Spawn* target = lua_interface->GetSpawn(state, 2);
  5125. int32 id = lua_interface->GetInt32Value(state, 3);
  5126. string command = lua_interface->GetStringValue(state, 4);
  5127. if (!caster) {
  5128. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5129. return 0;
  5130. }
  5131. if (!target) {
  5132. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5133. return 0;
  5134. }
  5135. if (!caster->IsPlayer()) {
  5136. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5137. return 0;
  5138. }
  5139. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5140. if (!entity_command) {
  5141. 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());
  5142. return 0;
  5143. }
  5144. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5145. if (!client) {
  5146. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5147. return 0;
  5148. }
  5149. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5150. return 0;
  5151. }
  5152. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5153. if (!lua_interface)
  5154. return 0;
  5155. Spawn* spawn = lua_interface->GetSpawn(state);
  5156. if (!spawn) {
  5157. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5158. return 0;
  5159. }
  5160. if (!spawn->IsNPC()) {
  5161. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5162. return 0;
  5163. }
  5164. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5165. return 0;
  5166. }
  5167. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5168. if (!lua_interface)
  5169. return 0;
  5170. Spawn* spawn = lua_interface->GetSpawn(state);
  5171. int16 tick = lua_interface->GetInt16Value(state, 2);
  5172. if (!spawn) {
  5173. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5174. return 0;
  5175. }
  5176. if (!spawn->IsNPC()) {
  5177. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5178. return 0;
  5179. }
  5180. if (tick < 20) {
  5181. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5182. return 0;
  5183. }
  5184. ((NPC*)spawn)->Brain()->SetTick(tick);
  5185. return 0;
  5186. }
  5187. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5188. if (!lua_interface)
  5189. return 0;
  5190. Spawn* spawn = lua_interface->GetSpawn(state);
  5191. Spawn* target = lua_interface->GetSpawn(state, 2);
  5192. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5193. if (!spawn) {
  5194. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5195. return 0;
  5196. }
  5197. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5198. spawn->SetFollowTarget(target, follow_distance);
  5199. return 0;
  5200. }
  5201. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5202. if (!lua_interface)
  5203. return 0;
  5204. Spawn* spawn = lua_interface->GetSpawn(state);
  5205. if (!spawn) {
  5206. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5207. return 0;
  5208. }
  5209. Spawn* target = spawn->GetFollowTarget();
  5210. if (target) {
  5211. lua_interface->SetSpawnValue(state, target);
  5212. return 1;
  5213. }
  5214. return 0;
  5215. }
  5216. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5217. if (!lua_interface)
  5218. return 0;
  5219. Spawn* spawn = lua_interface->GetSpawn(state);
  5220. if (!spawn) {
  5221. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5222. return 0;
  5223. }
  5224. if (spawn->following)
  5225. spawn->following = false;
  5226. else
  5227. spawn->following = true;
  5228. return 0;
  5229. }
  5230. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5231. if (!lua_interface)
  5232. return 0;
  5233. Spawn* spawn = lua_interface->GetSpawn(state);
  5234. if (!spawn) {
  5235. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5236. return 0;
  5237. }
  5238. lua_interface->SetBooleanValue(state, spawn->following);
  5239. return 1;
  5240. }
  5241. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5242. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5243. // I will attempt to explain how this function works for future refrence
  5244. // Fist lets make sure lua_interface is valid, if not return out
  5245. if (!lua_interface)
  5246. return 0;
  5247. // Next we grab the first 2 params same as we usually would
  5248. Spawn* spawn = lua_interface->GetSpawn(state);
  5249. string var = lua_interface->GetStringValue(state, 2);
  5250. // 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
  5251. // 1 = Spawn
  5252. // 2 = Zone
  5253. // 3 = Item
  5254. // 4 = Quest
  5255. // 5 = String
  5256. // 6 = nil (null)
  5257. int8 dataType = 0;
  5258. // Define pointers for each potential type
  5259. Spawn* spawnVal = 0;
  5260. ZoneServer* zone = 0;
  5261. Item* item = 0;
  5262. Quest* quest = 0;
  5263. string val;
  5264. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5265. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5266. // options window are also light user data be we do not handle those.
  5267. // We check with lua_islightuserdata(lua_State*, index)
  5268. if (lua_islightuserdata(state, 3)) {
  5269. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5270. // and convert it to LUAUserData*
  5271. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5272. // Check to make sure the data we got is valid, if not give an error
  5273. if (!data || !data->IsCorrectlyInitialized()) {
  5274. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5275. }
  5276. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5277. else if (data->IsSpawn()) {
  5278. spawnVal = data->spawn;
  5279. dataType = 1;
  5280. }
  5281. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5282. else if (data->IsZone()) {
  5283. zone = data->zone;
  5284. dataType = 2;
  5285. }
  5286. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5287. else if (data->IsItem()) {
  5288. item = data->item;
  5289. dataType = 3;
  5290. }
  5291. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5292. else if (data->IsQuest()) {
  5293. quest = data->quest;
  5294. dataType = 4;
  5295. }
  5296. }
  5297. // Wasn't light user data, check if it is nil(null)
  5298. else if (lua_isnil(state, 3)) {
  5299. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5300. dataType = 6;
  5301. }
  5302. // Wasn't light user data or nil (null), must be a string
  5303. else {
  5304. // Set the string and dataType variable
  5305. val = lua_interface->GetStringValue(state, 3);
  5306. dataType = 5;
  5307. }
  5308. // We now have all the params, lets check to make sure they are valid
  5309. if (!spawn) {
  5310. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5311. return 0;
  5312. }
  5313. if (var.length() == 0) {
  5314. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5315. return 0;
  5316. }
  5317. if (dataType == 0) {
  5318. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5322. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5323. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5324. switch (dataType) {
  5325. case 1:
  5326. // 1 = Spawn
  5327. spawn->AddTempVariable(var, spawnVal);
  5328. break;
  5329. case 2:
  5330. // 2 = Zone
  5331. spawn->AddTempVariable(var, zone);
  5332. break;
  5333. case 3:
  5334. // 3 = Item
  5335. spawn->AddTempVariable(var, item);
  5336. break;
  5337. case 4:
  5338. // 4 = Quest
  5339. spawn->AddTempVariable(var, quest);
  5340. break;
  5341. case 5:
  5342. // 5 = String
  5343. spawn->AddTempVariable(var, val);
  5344. break;
  5345. case 6:
  5346. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5347. spawn->DeleteTempVariable(var);
  5348. break;
  5349. }
  5350. // And we are done so return out
  5351. return 0;
  5352. }
  5353. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5354. if (!lua_interface)
  5355. return 0;
  5356. Spawn* spawn = lua_interface->GetSpawn(state);
  5357. string var = lua_interface->GetStringValue(state, 2);
  5358. if (!spawn) {
  5359. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5360. return 0;
  5361. }
  5362. if (var.length() == 0) {
  5363. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5364. return 0;
  5365. }
  5366. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5367. int8 type = spawn->GetTempVariableType(var);
  5368. Spawn* spawn2 = 0;
  5369. ZoneServer* zone = 0;
  5370. Item* item = 0;
  5371. Quest* quest = 0;
  5372. // Set the lua function return value based on the type of data the variable contains
  5373. switch (type) {
  5374. case 1:
  5375. spawn2 = spawn->GetTempVariableSpawn(var);
  5376. if (!spawn2)
  5377. return 0;
  5378. lua_interface->SetSpawnValue(state, spawn2);
  5379. break;
  5380. case 2:
  5381. zone = spawn->GetTempVariableZone(var);
  5382. if (!zone)
  5383. return 0;
  5384. lua_interface->SetZoneValue(state, zone);
  5385. break;
  5386. case 3:
  5387. item = spawn->GetTempVariableItem(var);
  5388. if (!item)
  5389. return 0;
  5390. lua_interface->SetItemValue(state, item);
  5391. break;
  5392. case 4:
  5393. quest = spawn->GetTempVariableQuest(var);
  5394. if (!quest)
  5395. return 0;
  5396. lua_interface->SetQuestValue(state, quest);
  5397. break;
  5398. case 5:
  5399. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5400. break;
  5401. default:
  5402. // Not a valid type then the variable was not set so return out
  5403. return 0;
  5404. }
  5405. // Return value was set so return out
  5406. return 1;
  5407. }
  5408. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5409. {
  5410. if (!lua_interface)
  5411. return 0;
  5412. Quest* quest = lua_interface->GetQuest(state);
  5413. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5414. string description = lua_interface->GetStringValue(state, 3);
  5415. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5416. if (!quest) {
  5417. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5418. lua_interface->SetBooleanValue(state, false);
  5419. return 1;
  5420. }
  5421. if (!spawn) {
  5422. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5423. lua_interface->SetBooleanValue(state, false);
  5424. return 1;
  5425. }
  5426. if (!spawn->IsPlayer()) {
  5427. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5428. lua_interface->SetBooleanValue(state, false);
  5429. return 1;
  5430. }
  5431. if (item_id == 0) {
  5432. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5433. lua_interface->SetBooleanValue(state, false);
  5434. return 1;
  5435. }
  5436. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5437. if (!client) {
  5438. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5439. lua_interface->SetBooleanValue(state, false);
  5440. return 1;
  5441. }
  5442. Item* item = master_item_list.GetItem(item_id);
  5443. if (!item) {
  5444. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5445. lua_interface->SetBooleanValue(state, false);
  5446. return 1;
  5447. }
  5448. Item* firstItem = new Item(item);
  5449. quest->AddTmpRewardItem(firstItem);
  5450. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5451. bool itemsAddedSuccessfully = true;
  5452. if(num_args > 4)
  5453. {
  5454. for(int8 n=5;n<num_args+1;n++)
  5455. {
  5456. int32 new_item = lua_interface->GetInt32Value(state, n);
  5457. Item* tmpItem = master_item_list.GetItem(new_item);
  5458. if(tmpItem)
  5459. {
  5460. Item* newTmpItem = new Item(tmpItem);
  5461. quest->AddTmpRewardItem(newTmpItem);
  5462. }
  5463. else
  5464. itemsAddedSuccessfully = false;
  5465. }
  5466. }
  5467. client->AddPendingQuestAcceptReward(quest);
  5468. client->DisplayQuestComplete(quest, true, description);
  5469. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5470. return 1;
  5471. }
  5472. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5473. if (!lua_interface)
  5474. return 0;
  5475. Quest* quest = lua_interface->GetQuest(state);
  5476. if (!quest) {
  5477. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5478. return 0;
  5479. }
  5480. quest->SetRepeatable(true);
  5481. return 0;
  5482. }
  5483. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5484. if (!lua_interface)
  5485. return 0;
  5486. Spawn* spawn = lua_interface->GetSpawn(state);
  5487. if (!spawn) {
  5488. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5492. string ret = classes.GetClassNameCase(base_class);
  5493. if (ret.length() > 0) {
  5494. lua_interface->SetStringValue(state, ret.c_str());
  5495. return 1;
  5496. }
  5497. return 0;
  5498. }
  5499. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5500. if (!lua_interface)
  5501. return 0;
  5502. Spawn* player = lua_interface->GetSpawn(state);
  5503. if (player && player->IsPlayer()) {
  5504. Client* client = player->GetClient();
  5505. if (client)
  5506. client->SendWaypoints();
  5507. }
  5508. return 0;
  5509. }
  5510. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5511. if (!lua_interface)
  5512. return 0;
  5513. Spawn* player = lua_interface->GetSpawn(state);
  5514. string name = lua_interface->GetStringValue(state, 2);
  5515. int32 type = lua_interface->GetInt32Value(state, 3);
  5516. if (type == 0)
  5517. type = 2;
  5518. if (name.length() > 0) {
  5519. if (player && player->IsPlayer()) {
  5520. Client* client = player->GetClient();
  5521. if (client)
  5522. client->AddWaypoint(name, type);
  5523. }
  5524. }
  5525. return 0;
  5526. }
  5527. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5528. if (!lua_interface)
  5529. return 0;
  5530. Spawn* player = lua_interface->GetSpawn(state);
  5531. string name = lua_interface->GetStringValue(state, 2);
  5532. if (name.length() > 0) {
  5533. if (player && player->IsPlayer()) {
  5534. Client* client = player->GetClient();
  5535. if (client)
  5536. client->RemoveWaypoint(name);
  5537. }
  5538. }
  5539. return 0;
  5540. }
  5541. int EQ2Emu_lua_AddWard(lua_State* state) {
  5542. if (!lua_interface)
  5543. return 0;
  5544. int32 damage = lua_interface->GetInt32Value(state);
  5545. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5546. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5547. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5548. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5549. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5550. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5551. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5552. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5553. if(!spell || spell->resisted) {
  5554. return 0;
  5555. }
  5556. bool ward_was_added = false;
  5557. ZoneServer* zone = spell->caster->GetZone();
  5558. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5559. for (int32 i = 0; i < spell->targets.size(); i++) {
  5560. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5561. if (!target)
  5562. continue;
  5563. if (target->IsEntity()) {
  5564. // If the ward is already active remove it
  5565. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5566. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5567. // Create new ward info
  5568. WardInfo* ward = new WardInfo;
  5569. ward->Spell = spell;
  5570. ward->BaseDamage = damage;
  5571. ward->DamageLeft = damage;
  5572. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5573. ward->keepWard = keepWard;
  5574. ward->WardType = wardType;
  5575. if (damageAbsorptionPercent > 100)
  5576. damageAbsorptionPercent = 100;
  5577. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5578. if (damageAbsorptionMaxHealthPercent > 100)
  5579. damageAbsorptionMaxHealthPercent = 100;
  5580. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5581. ward->RedirectDamagePercent = redirectDamagePercent;
  5582. ward->LastRedirectDamage = 0;
  5583. ward->LastAbsorbedDamage = 0;
  5584. ward->HitCount = 0;
  5585. spell->num_triggers = maxHitCount;
  5586. spell->had_triggers = true;
  5587. spell->cancel_after_all_triggers = false;
  5588. ward->MaxHitCount = maxHitCount;
  5589. if (wardType == WARD_TYPE_MAGICAL)
  5590. ward->DamageType = damageTypes;
  5591. // Add the ward to the entity
  5592. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5593. ward_was_added = true;
  5594. }
  5595. }
  5596. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5597. if (ward_was_added && spell->caster->IsPlayer()) {
  5598. spell->had_dmg_remaining = true;
  5599. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5600. }
  5601. return 0;
  5602. }
  5603. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5604. if (!lua_interface)
  5605. return 0;
  5606. int32 amount = lua_interface->GetInt32Value(state);
  5607. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5608. WardInfo* ward = 0;
  5609. if(!spell || spell->resisted) {
  5610. return 0;
  5611. }
  5612. ZoneServer* zone = spell->caster->GetZone();
  5613. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5614. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5615. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5616. ward = target->GetWard(spell->spell->GetSpellID());
  5617. if (target && ward) {
  5618. ward->DamageLeft += amount;
  5619. if (ward->DamageLeft > ward->BaseDamage)
  5620. ward->DamageLeft = ward->BaseDamage;
  5621. for (int32 i = 0; i < spell->targets.size(); i++) {
  5622. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5623. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5624. }
  5625. }
  5626. }
  5627. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5628. if (ward && spell->caster->IsPlayer())
  5629. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5630. return 0;
  5631. }
  5632. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5633. if (!lua_interface)
  5634. return 0;
  5635. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5636. if (!spell) {
  5637. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5638. return 0;
  5639. }
  5640. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5641. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5642. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5643. if (ward) {
  5644. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5645. return 1;
  5646. }
  5647. }
  5648. return 0;
  5649. }
  5650. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5651. if (!lua_interface)
  5652. return 0;
  5653. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5654. if (!spell) {
  5655. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5656. return 0;
  5657. }
  5658. string type = lua_interface->GetStringValue(state, 2);
  5659. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5660. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5661. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5662. if (ward) {
  5663. if (boost::iequals(type, "damageleft"))
  5664. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5665. else if (boost::iequals(type, "basedamage"))
  5666. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5667. else if (boost::iequals(type, "keepward"))
  5668. lua_interface->SetBooleanValue(state, ward->keepWard);
  5669. else if (boost::iequals(type, "wardtype"))
  5670. lua_interface->SetInt32Value(state, ward->WardType);
  5671. else if (boost::iequals(type, "dmgabsorptionpct"))
  5672. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5673. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5674. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5675. else if (boost::iequals(type, "redirectdamagepercent"))
  5676. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5677. else if (boost::iequals(type, "lastredirectdamage"))
  5678. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5679. else if (boost::iequals(type, "lastabsorbeddamage"))
  5680. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5681. else if (boost::iequals(type, "hitcount"))
  5682. lua_interface->SetInt32Value(state, ward->HitCount);
  5683. else if (boost::iequals(type, "maxhitcount"))
  5684. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5685. else
  5686. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5687. return 1;
  5688. }
  5689. }
  5690. return 0;
  5691. }
  5692. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5693. if (!lua_interface)
  5694. return 0;
  5695. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5696. if(!spell) {
  5697. return 0;
  5698. }
  5699. ZoneServer* zone = spell->caster->GetZone();
  5700. Spawn* target = 0;
  5701. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5702. for (int32 i = 0; i < spell->targets.size(); i++) {
  5703. target = zone->GetSpawnByID(spell->targets.at(i));
  5704. if (target && target->IsEntity()) {
  5705. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5706. }
  5707. }
  5708. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5709. return 0;
  5710. }
  5711. int EQ2Emu_lua_Interrupt(lua_State* state)
  5712. {
  5713. if (!lua_interface)
  5714. return 0;
  5715. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5716. Spawn* target = lua_interface->GetSpawn(state, 2);
  5717. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5718. if (!caster)
  5719. {
  5720. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5721. return 0;
  5722. }
  5723. if (!target)
  5724. {
  5725. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5726. return 0;
  5727. }
  5728. if (!spell) {
  5729. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5730. return 0;
  5731. }
  5732. if (!target->IsEntity() && !spell)
  5733. {
  5734. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5735. return 0;
  5736. }
  5737. if (!target && spell) {
  5738. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5739. for (int8 i = 0; i < spell->targets.size(); i++) {
  5740. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5741. if (!target || !target->IsEntity())
  5742. continue;
  5743. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5744. }
  5745. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5746. }
  5747. else
  5748. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5749. return 0;
  5750. }
  5751. int EQ2Emu_lua_Stealth(lua_State* state) {
  5752. if (!lua_interface)
  5753. return 0;
  5754. int8 type = lua_interface->GetInt8Value(state);
  5755. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5756. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5757. if (!spell) {
  5758. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5759. return 0;
  5760. }
  5761. ZoneServer* zone = spell->caster->GetZone();
  5762. if (spawn) {
  5763. if (spawn->IsEntity()) {
  5764. if (type == 1) {
  5765. ((Entity*)spawn)->AddStealthSpell(spell);
  5766. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5767. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5768. }
  5769. else if (type == 2) {
  5770. ((Entity*)spawn)->AddInvisSpell(spell);
  5771. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5772. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5773. }
  5774. return 0;
  5775. }
  5776. else {
  5777. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. }
  5781. else {
  5782. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5783. for (int32 i = 0; i < spell->targets.size(); i++) {
  5784. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5785. if (!spawn || !spawn->IsEntity())
  5786. continue;
  5787. if (type == 1) {
  5788. ((Entity*)spawn)->AddStealthSpell(spell);
  5789. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5790. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5791. }
  5792. else if (type == 2) {
  5793. ((Entity*)spawn)->AddInvisSpell(spell);
  5794. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5795. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5796. }
  5797. else {
  5798. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5799. break;
  5800. }
  5801. }
  5802. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5803. }
  5804. return 0;
  5805. }
  5806. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5807. if (!lua_interface)
  5808. return 0;
  5809. Spawn* spawn = lua_interface->GetSpawn(state);
  5810. if (!spawn) {
  5811. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5812. return 0;
  5813. }
  5814. if (spawn->IsEntity()) {
  5815. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5816. return 1;
  5817. }
  5818. else
  5819. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5820. return 0;
  5821. }
  5822. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5823. if (!lua_interface)
  5824. return 0;
  5825. Spawn* spawn = lua_interface->GetSpawn(state);
  5826. if (!spawn) {
  5827. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5828. return 0;
  5829. }
  5830. if (spawn->IsEntity()) {
  5831. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5832. return 1;
  5833. }
  5834. else
  5835. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5836. return 0;
  5837. }
  5838. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5839. if (!lua_interface)
  5840. return 0;
  5841. Spawn* player = lua_interface->GetSpawn(state);
  5842. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5843. lua_interface->ResetFunctionStack(state);
  5844. if (!player->IsPlayer()) {
  5845. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5846. return 0;
  5847. }
  5848. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5849. return 1;
  5850. }
  5851. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5852. if (!lua_interface)
  5853. return 0;
  5854. Spawn* player = lua_interface->GetSpawn(state);
  5855. int8 slot = lua_interface->GetInt8Value(state, 2);
  5856. lua_interface->ResetFunctionStack(state);
  5857. if (!player) {
  5858. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5859. return 0;
  5860. }
  5861. if (!player->IsPlayer()) {
  5862. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5866. if (!item) {
  5867. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5868. return 0;
  5869. }
  5870. lua_interface->SetItemValue(state, item);
  5871. return 1;
  5872. }
  5873. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5874. if (!lua_interface)
  5875. return 0;
  5876. Spawn* player = lua_interface->GetSpawn(state);
  5877. int32 id = lua_interface->GetInt32Value(state, 2);
  5878. lua_interface->ResetFunctionStack(state);
  5879. if (!player) {
  5880. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5881. return 0;
  5882. }
  5883. if (!player->IsPlayer()) {
  5884. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5885. return 0;
  5886. }
  5887. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5888. if (!item) {
  5889. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5890. return 0;
  5891. }
  5892. lua_interface->SetItemValue(state, item);
  5893. return 1;
  5894. }
  5895. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5896. if (!lua_interface)
  5897. return 0;
  5898. Spawn* spawn = lua_interface->GetSpawn(state);
  5899. int8 slot = lua_interface->GetInt8Value(state, 2);
  5900. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5901. lua_interface->ResetFunctionStack(state);
  5902. if (!spawn) {
  5903. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5904. return 0;
  5905. }
  5906. if (!spawn->IsEntity()) {
  5907. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5908. return 0;
  5909. }
  5910. Item* item = master_item_list.GetItem(item_id);
  5911. if (!item) {
  5912. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5913. return 0;
  5914. }
  5915. Item* copy = new Item(item);
  5916. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5917. if(result)
  5918. {
  5919. ((Entity*)spawn)->SetEquipment(copy, slot);
  5920. spawn->vis_changed = true;
  5921. if(spawn->IsPlayer())
  5922. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5923. }
  5924. else
  5925. {
  5926. safe_delete(copy);
  5927. }
  5928. lua_interface->SetBooleanValue(state, result);
  5929. return 1;
  5930. }
  5931. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5932. if (!lua_interface)
  5933. return 0;
  5934. Spawn* spawn = lua_interface->GetSpawn(state);
  5935. int8 slot = lua_interface->GetInt8Value(state, 2);
  5936. Item* item = lua_interface->GetItem(state, 3);
  5937. lua_interface->ResetFunctionStack(state);
  5938. if (!spawn) {
  5939. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5940. return 0;
  5941. }
  5942. if (!spawn->IsEntity()) {
  5943. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5944. return 0;
  5945. }
  5946. if (!item) {
  5947. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5948. return 0;
  5949. }
  5950. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5951. if(result)
  5952. {
  5953. ((Entity*)spawn)->SetEquipment(item, slot);
  5954. spawn->vis_changed = true;
  5955. if(spawn->IsPlayer())
  5956. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5957. }
  5958. lua_interface->SetBooleanValue(state, result);
  5959. return 1;
  5960. }
  5961. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5962. if (!lua_interface)
  5963. return 0;
  5964. Spawn* spawn = lua_interface->GetSpawn(state);
  5965. int8 slot = lua_interface->GetInt8Value(state, 2);
  5966. 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
  5967. lua_interface->ResetFunctionStack(state);
  5968. if (!spawn) {
  5969. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5970. return 0;
  5971. }
  5972. if (!spawn->IsEntity()) {
  5973. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5974. return 0;
  5975. }
  5976. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5977. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5978. spawn->vis_changed = true;
  5979. if(spawn->IsPlayer())
  5980. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5981. lua_interface->SetBooleanValue(state, true);
  5982. return 1;
  5983. }
  5984. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5985. if (!lua_interface)
  5986. return 0;
  5987. Spawn* spawn = lua_interface->GetSpawn(state);
  5988. int8 slot = lua_interface->GetInt8Value(state, 2);
  5989. int16 type = lua_interface->GetInt16Value(state, 3);
  5990. int8 r = lua_interface->GetInt8Value(state, 4);
  5991. int8 g = lua_interface->GetInt8Value(state, 5);
  5992. int8 b = lua_interface->GetInt8Value(state, 6);
  5993. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5994. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5995. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5996. lua_interface->ResetFunctionStack(state);
  5997. if (!spawn) {
  5998. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. if (!spawn->IsEntity()) {
  6002. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6003. return 0;
  6004. }
  6005. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6006. spawn->vis_changed = true;
  6007. lua_interface->SetBooleanValue(state, true);
  6008. return 1;
  6009. }
  6010. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6011. if (!lua_interface)
  6012. return 0;
  6013. Spawn* player = lua_interface->GetSpawn(state);
  6014. int32 id = lua_interface->GetInt32Value(state, 2);
  6015. int8 count = lua_interface->GetInt8Value(state, 3);
  6016. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6017. lua_interface->ResetFunctionStack(state);
  6018. if (!player) {
  6019. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6020. return 0;
  6021. }
  6022. if (!player->IsPlayer()) {
  6023. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6024. return 0;
  6025. }
  6026. if (!count)
  6027. count = 1;
  6028. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6029. if (!item) {
  6030. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6031. return 0;
  6032. }
  6033. lua_interface->SetItemValue(state, item);
  6034. return 1;
  6035. }
  6036. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6037. if (!lua_interface)
  6038. return 0;
  6039. Spawn* spawn = lua_interface->GetSpawn(state);
  6040. int32 anim = lua_interface->GetInt32Value(state, 2);
  6041. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6042. int8 type = lua_interface->GetInt8Value(state, 4);
  6043. if (!spawn) {
  6044. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6045. return 0;
  6046. }
  6047. if (spawn2) {
  6048. if (spawn2->IsPlayer()) {
  6049. if (type != 1 && type != 2)
  6050. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6051. else
  6052. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6053. return 0;
  6054. }
  6055. else {
  6056. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6057. return 0;
  6058. }
  6059. }
  6060. else
  6061. spawn->GetZone()->PlayAnimation(spawn, anim);
  6062. return 0;
  6063. }
  6064. int EQ2Emu_lua_IsPet(lua_State* state) {
  6065. if (!lua_interface)
  6066. return 0;
  6067. Spawn* spawn = lua_interface->GetSpawn(state);
  6068. if (!spawn) {
  6069. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6070. return 0;
  6071. }
  6072. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6073. return 1;
  6074. }
  6075. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6076. if (!lua_interface)
  6077. return 0;
  6078. Spawn* spawn = lua_interface->GetSpawn(state);
  6079. if (!spawn) {
  6080. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6081. return 0;
  6082. }
  6083. if (!spawn->IsNPC()) {
  6084. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6085. return 0;
  6086. }
  6087. if (((NPC*)spawn)->GetOwner()) {
  6088. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6089. return 1;
  6090. }
  6091. return 0;
  6092. }
  6093. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6094. if (!lua_interface)
  6095. return 0;
  6096. Spawn* spawn = lua_interface->GetSpawn(state);
  6097. Spawn* target = lua_interface->GetSpawn(state, 2);
  6098. if (!spawn) {
  6099. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6100. return 0;
  6101. }
  6102. if (!spawn) {
  6103. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6104. return 0;
  6105. }
  6106. spawn->SetTarget(target);
  6107. return 0;
  6108. }
  6109. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6110. if (!lua_interface)
  6111. return 0;
  6112. Spawn* spawn = lua_interface->GetSpawn(state);
  6113. bool val = lua_interface->GetBooleanValue(state, 2);
  6114. if (!spawn) {
  6115. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6116. return 0;
  6117. }
  6118. if (!spawn->IsEntity()) {
  6119. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6120. return 0;
  6121. }
  6122. ((Entity*)spawn)->InCombat(val);
  6123. if (val) {
  6124. spawn->ClearRunningLocations();
  6125. spawn->CalculateRunningLocation(true);
  6126. }
  6127. return 0;
  6128. }
  6129. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6130. if (!lua_interface)
  6131. return 0;
  6132. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6133. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6134. if (!spawn1) {
  6135. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. if (!spawn2) {
  6139. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6140. return 0;
  6141. }
  6142. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6143. return 1;
  6144. }
  6145. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6146. if (!lua_interface)
  6147. return 0;
  6148. Spawn* spawn = lua_interface->GetSpawn(state);
  6149. if (!spawn) {
  6150. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6151. return 0;
  6152. }
  6153. if (!spawn->IsNPC()) {
  6154. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6155. return 0;
  6156. }
  6157. ((NPC*)spawn)->ClearRunback();
  6158. return 0;
  6159. }
  6160. int EQ2Emu_lua_Runback(lua_State* state) {
  6161. if (!lua_interface)
  6162. return 0;
  6163. Spawn* spawn = lua_interface->GetSpawn(state);
  6164. if (!spawn) {
  6165. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. if (!spawn->IsNPC()) {
  6169. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6170. return 0;
  6171. }
  6172. ((NPC*)spawn)->Runback();
  6173. return 0;
  6174. }
  6175. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6176. if (!lua_interface)
  6177. return 0;
  6178. Spawn* spawn = lua_interface->GetSpawn(state);
  6179. if (!spawn) {
  6180. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6181. return 0;
  6182. }
  6183. if (!spawn->IsNPC()) {
  6184. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6185. return 0;
  6186. }
  6187. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6188. return 1;
  6189. }
  6190. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6191. if (!lua_interface)
  6192. return 0;
  6193. Spawn* spawn = lua_interface->GetSpawn(state);
  6194. if (!spawn) {
  6195. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6196. return 0;
  6197. }
  6198. if (!spawn->IsEntity()) {
  6199. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6200. return 0;
  6201. }
  6202. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6203. return 1;
  6204. }
  6205. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6206. if (!lua_interface)
  6207. return 0;
  6208. Spawn* spawn = lua_interface->GetSpawn(state);
  6209. if (!spawn) {
  6210. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6211. return 0;
  6212. }
  6213. if (!spawn->IsEntity()) {
  6214. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6215. return 0;
  6216. }
  6217. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6218. return 1;
  6219. }
  6220. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6221. if (!lua_interface)
  6222. return 0;
  6223. Spawn* spawn = lua_interface->GetSpawn(state);
  6224. if (!spawn) {
  6225. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. if (!spawn->IsEntity()) {
  6229. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6230. return 0;
  6231. }
  6232. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6233. return 1;
  6234. }
  6235. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6236. if (!lua_interface)
  6237. return 0;
  6238. Spawn* spawn = lua_interface->GetSpawn(state);
  6239. if (!spawn) {
  6240. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6241. return 0;
  6242. }
  6243. if (!spawn->IsEntity()) {
  6244. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6245. return 0;
  6246. }
  6247. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6248. return 1;
  6249. }
  6250. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6251. if (!lua_interface)
  6252. return 0;
  6253. Spawn* spawn = lua_interface->GetSpawn(state);
  6254. Spawn* target = lua_interface->GetSpawn(state, 2);
  6255. float distance = lua_interface->GetFloatValue(state, 3);
  6256. if (!spawn) {
  6257. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6258. return 0;
  6259. }
  6260. if (!target) {
  6261. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6262. return 0;
  6263. }
  6264. if (!spawn->IsNPC()) {
  6265. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6266. return 0;
  6267. }
  6268. if (!target->IsEntity()) {
  6269. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6273. return 1;
  6274. }
  6275. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6276. if (!lua_interface)
  6277. return 0;
  6278. Spawn* spawn = lua_interface->GetSpawn(state);
  6279. Spawn* target = lua_interface->GetSpawn(state, 2);
  6280. float distance = lua_interface->GetFloatValue(state, 3);
  6281. if (!spawn) {
  6282. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6283. return 0;
  6284. }
  6285. if (!target) {
  6286. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6287. return 0;
  6288. }
  6289. if (!spawn->IsNPC()) {
  6290. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. if (!target->IsEntity()) {
  6294. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6295. return 0;
  6296. }
  6297. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6298. return 0;
  6299. }
  6300. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6301. if (!lua_interface)
  6302. return 0;
  6303. Spawn* spawn = lua_interface->GetSpawn(state);
  6304. if (!spawn) {
  6305. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6306. return 0;
  6307. }
  6308. if (!spawn->IsNPC()) {
  6309. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6310. return 0;
  6311. }
  6312. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6313. return 1;
  6314. }
  6315. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6316. if (!lua_interface)
  6317. return 0;
  6318. Spawn* spawn = lua_interface->GetSpawn(state);
  6319. if (!spawn) {
  6320. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6321. return 0;
  6322. }
  6323. if (!spawn->IsNPC()) {
  6324. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6325. return 0;
  6326. }
  6327. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6328. return 1;
  6329. }
  6330. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6331. if (!lua_interface)
  6332. return 0;
  6333. Spawn* spawn = lua_interface->GetSpawn(state);
  6334. if (!spawn) {
  6335. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6336. return 0;
  6337. }
  6338. if (!spawn->IsNPC()) {
  6339. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6340. return 0;
  6341. }
  6342. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6343. if (hated) {
  6344. lua_interface->SetSpawnValue(state, hated);
  6345. return 1;
  6346. }
  6347. return 0;
  6348. }
  6349. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6350. if (!lua_interface)
  6351. return 0;
  6352. Spawn* spawn = lua_interface->GetSpawn(state);
  6353. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6354. if (!spawn) {
  6355. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6356. return 0;
  6357. }
  6358. if (!spawn->IsNPC()) {
  6359. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6360. return 0;
  6361. }
  6362. if (!hated) {
  6363. ((NPC*)spawn)->Brain()->ClearHate();
  6364. return 0;
  6365. }
  6366. else
  6367. {
  6368. if (!hated->IsEntity()) {
  6369. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6370. return 0;
  6371. }
  6372. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6373. return 0;
  6374. }
  6375. return 0;
  6376. }
  6377. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6378. if (!lua_interface)
  6379. return 0;
  6380. Spawn* spawn = lua_interface->GetSpawn(state);
  6381. if (!spawn) {
  6382. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6383. return 0;
  6384. }
  6385. if (!spawn->IsNPC()) {
  6386. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6387. return 0;
  6388. }
  6389. ((NPC*)spawn)->Brain()->ClearEncounter();
  6390. return 0;
  6391. }
  6392. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6393. if (!lua_interface)
  6394. return 0;
  6395. Spawn* spawn = lua_interface->GetSpawn(state);
  6396. if (!spawn) {
  6397. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6398. return 0;
  6399. }
  6400. if (!spawn->IsNPC()) {
  6401. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6402. return 0;
  6403. }
  6404. // Temp list to store hate list
  6405. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6406. if (encounterList->size() == 0) {
  6407. safe_delete(encounterList);
  6408. return 0;
  6409. }
  6410. lua_createtable(state, encounterList->size(), 0);
  6411. int newTable = lua_gettop(state);
  6412. for (int32 i = 0; i < encounterList->size(); i++) {
  6413. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6414. if (temp)
  6415. lua_interface->SetSpawnValue(state, temp);
  6416. lua_rawseti(state, newTable, i + 1);
  6417. }
  6418. safe_delete(encounterList);
  6419. return 1;
  6420. }
  6421. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6422. if (!lua_interface)
  6423. return 0;
  6424. Spawn* spawn = lua_interface->GetSpawn(state);
  6425. if (!spawn) {
  6426. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6427. return 0;
  6428. }
  6429. if (!spawn->IsNPC()) {
  6430. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6431. return 0;
  6432. }
  6433. // Temp list to store hate list
  6434. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6435. if (hateList->size() == 0) {
  6436. safe_delete(hateList);
  6437. return 0;
  6438. }
  6439. lua_createtable(state, hateList->size(), 0);
  6440. int newTable = lua_gettop(state);
  6441. for (int32 i = 0; i < hateList->size(); i++) {
  6442. lua_interface->SetSpawnValue(state, hateList->at(i));
  6443. lua_rawseti(state, newTable, i + 1);
  6444. }
  6445. safe_delete(hateList);
  6446. return 1;
  6447. }
  6448. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6449. if (!lua_interface)
  6450. return 0;
  6451. Spawn* spawn = lua_interface->GetSpawn(state);
  6452. if (!spawn) {
  6453. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6454. return 0;
  6455. }
  6456. if (spawn->IsPlayer()) {
  6457. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6458. lua_interface->SetBooleanValue(state, true);
  6459. else
  6460. lua_interface->SetBooleanValue(state, false);
  6461. return 1;
  6462. }
  6463. else {
  6464. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6465. return 1;
  6466. }
  6467. }
  6468. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6469. if (!lua_interface)
  6470. return 0;
  6471. Quest* quest = lua_interface->GetQuest(state);
  6472. if (!quest) {
  6473. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6474. return 0;
  6475. }
  6476. quest->SetCompletedFlag(true);
  6477. return 0;
  6478. }
  6479. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6480. if (!lua_interface)
  6481. return 0;
  6482. Spawn* spawn = lua_interface->GetSpawn(state);
  6483. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6484. int8 tier = lua_interface->GetInt8Value(state, 3);
  6485. if (!spawn) {
  6486. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6487. return 0;
  6488. }
  6489. if (!spawn->IsEntity()) {
  6490. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. if (spellID == 0) {
  6494. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6495. return 0;
  6496. }
  6497. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6498. if (effect) {
  6499. if (tier > 0) {
  6500. // If a tier was passed chec to see if it is the same as the effect
  6501. if (tier == effect->tier)
  6502. lua_interface->SetBooleanValue(state, true);
  6503. else
  6504. lua_interface->SetBooleanValue(state, false);
  6505. return 1;
  6506. }
  6507. else {
  6508. // Have an effect but no tier was passed so return true
  6509. lua_interface->SetBooleanValue(state, true);
  6510. }
  6511. return 1;
  6512. }
  6513. // no effect so return false
  6514. lua_interface->SetBooleanValue(state, false);
  6515. return 1;
  6516. }
  6517. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6518. if (!lua_interface)
  6519. return 0;
  6520. Spawn* spawn = lua_interface->GetSpawn(state);
  6521. int32 id = lua_interface->GetInt32Value(state, 2);
  6522. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6523. Spawn* spawn2 = 0;
  6524. vector<Spawn*> list;
  6525. if (!spawn) {
  6526. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6527. return 0;
  6528. }
  6529. //If zone not provided, use spawn's zone
  6530. if (!zone)
  6531. zone = spawn->GetZone();
  6532. list = zone->GetSpawnsByID(id);
  6533. if (list.size() == 0) {
  6534. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6535. return 0;
  6536. }
  6537. vector<Spawn*>::iterator itr = list.begin();
  6538. for (int8 i = 0; i < list.size(); i++) {
  6539. spawn2 = itr[i];
  6540. if (spawn2)
  6541. spawn2->AddAllowAccessSpawn(spawn);
  6542. }
  6543. return 0;
  6544. }
  6545. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6546. if (!lua_interface)
  6547. return 0;
  6548. Spawn* spawn = lua_interface->GetSpawn(state);
  6549. int32 id = lua_interface->GetInt32Value(state, 2);
  6550. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6551. Spawn* spawn2 = 0;
  6552. if (!spawn) {
  6553. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. //If zone not provided, use spawn's zone
  6557. if (!zone)
  6558. zone = spawn->GetZone();
  6559. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6560. vector<Spawn*>::iterator itr = list.begin();
  6561. if (list.size() == 0) {
  6562. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6563. return 0;
  6564. }
  6565. for (int8 i = 0; i < list.size(); i++) {
  6566. spawn2 = itr[i];
  6567. if (spawn2)
  6568. spawn2->RemoveSpawnAccess(spawn);
  6569. }
  6570. return 0;
  6571. }
  6572. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6573. if (!lua_interface)
  6574. return 0;
  6575. Quest* quest = lua_interface->GetQuest(state);
  6576. if (!quest) {
  6577. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6578. return 0;
  6579. }
  6580. quest->SetYellowName(true);
  6581. return 0;
  6582. }
  6583. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6584. if (!lua_interface)
  6585. return 0;
  6586. Spawn* spawn = lua_interface->GetSpawn(state);
  6587. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6588. if (!spawn) {
  6589. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6590. return 0;
  6591. }
  6592. if (!spawn->IsPlayer()) {
  6593. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6594. return 0;
  6595. }
  6596. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6597. return 1;
  6598. }
  6599. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6600. if (!lua_interface)
  6601. return 0;
  6602. Spawn* spawn = lua_interface->GetSpawn(state);
  6603. if (!spawn) {
  6604. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6605. return 0;
  6606. }
  6607. if (!spawn->IsPlayer()) {
  6608. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6609. return 0;
  6610. }
  6611. ZoneServer* zone = spawn->GetZone();
  6612. if (!zone) {
  6613. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6614. return 0;
  6615. }
  6616. Instance_Type iType = zone->GetInstanceType();
  6617. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6618. iType == GROUP_LOCKOUT_INSTANCE ||
  6619. iType == RAID_LOCKOUT_INSTANCE ||
  6620. iType == SOLO_PERSIST_INSTANCE ||
  6621. iType == GROUP_PERSIST_INSTANCE ||
  6622. iType == RAID_PERSIST_INSTANCE) {
  6623. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6624. if (data) {
  6625. // Check to see if the timer has already been set, if it has return out.
  6626. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6627. return 0;
  6628. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6629. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6630. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6631. if (client) {
  6632. string time_msg = "";
  6633. int32 time = data->success_lockout_time;
  6634. int16 hour;
  6635. int8 min;
  6636. int8 sec;
  6637. hour = time / 3600;
  6638. time = time % 3600;
  6639. min = time / 60;
  6640. time = time % 60;
  6641. sec = time;
  6642. if (hour > 0) {
  6643. char temp[10];
  6644. sprintf(temp, " %i", hour);
  6645. time_msg.append(temp);
  6646. time_msg.append(" hour");
  6647. time_msg.append((hour > 1) ? "s" : "");
  6648. }
  6649. if (min > 0) {
  6650. char temp[5];
  6651. sprintf(temp, " %i", min);
  6652. time_msg.append(temp);
  6653. time_msg.append(" minute");
  6654. time_msg.append((min > 1) ? "s" : "");
  6655. }
  6656. // Only add seconds if minutes and hours are 0
  6657. if (hour == 0 && min == 0 && sec > 0) {
  6658. char temp[5];
  6659. sprintf(temp, " %i", sec);
  6660. time_msg.append(temp);
  6661. time_msg.append(" second");
  6662. time_msg.append((sec > 1) ? "s" : "");
  6663. }
  6664. 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());
  6665. }
  6666. }
  6667. else
  6668. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6669. }
  6670. else
  6671. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6672. return 0;
  6673. }
  6674. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6675. if (!lua_interface)
  6676. return 0;
  6677. Spawn* spawn = lua_interface->GetSpawn(state);
  6678. if (!spawn) {
  6679. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6680. return 0;
  6681. }
  6682. if (!spawn->IsPlayer()) {
  6683. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6684. return 0;
  6685. }
  6686. ZoneServer* zone = spawn->GetZone();
  6687. if (!zone) {
  6688. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6689. return 0;
  6690. }
  6691. Instance_Type iType = zone->GetInstanceType();
  6692. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6693. iType == GROUP_LOCKOUT_INSTANCE ||
  6694. iType == RAID_LOCKOUT_INSTANCE ||
  6695. iType == SOLO_PERSIST_INSTANCE ||
  6696. iType == GROUP_PERSIST_INSTANCE ||
  6697. iType == RAID_PERSIST_INSTANCE) {
  6698. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6699. if (data) {
  6700. // Check to see if the timer has already been set, if it has return out.
  6701. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6702. return 0;
  6703. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6704. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6705. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6706. if (client) {
  6707. string time_msg = "";
  6708. int32 time = data->failure_lockout_time;
  6709. int16 hour;
  6710. int8 min;
  6711. int8 sec;
  6712. hour = time / 3600;
  6713. time = time % 3600;
  6714. min = time / 60;
  6715. time = time % 60;
  6716. sec = time;
  6717. if (hour > 0) {
  6718. char temp[10];
  6719. sprintf(temp, " %i", hour);
  6720. time_msg.append(temp);
  6721. time_msg.append(" hour");
  6722. time_msg.append((hour > 1) ? "s" : "");
  6723. }
  6724. if (min > 0) {
  6725. char temp[5];
  6726. sprintf(temp, " %i", min);
  6727. time_msg.append(temp);
  6728. time_msg.append(" minute");
  6729. time_msg.append((min > 1) ? "s" : "");
  6730. }
  6731. // Only add seconds if minutes and hours are 0
  6732. if (hour == 0 && min == 0 && sec > 0) {
  6733. char temp[5];
  6734. sprintf(temp, " %i", sec);
  6735. time_msg.append(temp);
  6736. time_msg.append(" second");
  6737. time_msg.append((sec > 1) ? "s" : "");
  6738. }
  6739. 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());
  6740. }
  6741. }
  6742. else
  6743. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6744. }
  6745. else
  6746. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6747. return 0;
  6748. }
  6749. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6750. if (!lua_interface)
  6751. return 0;
  6752. Spawn* spawn = lua_interface->GetSpawn(state);
  6753. if (!spawn) {
  6754. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6755. return 0;
  6756. }
  6757. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6758. return 1;
  6759. }
  6760. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6761. if (!lua_interface)
  6762. return 0;
  6763. Spawn* player = lua_interface->GetSpawn(state);
  6764. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6765. if (!player) {
  6766. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6767. return 0;
  6768. }
  6769. if (!player->IsPlayer()) {
  6770. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6771. return 0;
  6772. }
  6773. if (!ground) {
  6774. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6775. return 0;
  6776. }
  6777. if (!ground->IsGroundSpawn()) {
  6778. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6779. return 0;
  6780. }
  6781. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6782. if (!groundspawn_entries) {
  6783. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6784. return 0;
  6785. }
  6786. Skill* skill = 0;
  6787. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6788. if (collection_skill == "Collecting")
  6789. skill = ((Player*)player)->GetSkillByName("Gathering");
  6790. else
  6791. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6792. if (!skill) {
  6793. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6794. return 0;
  6795. }
  6796. vector<GroundSpawnEntry*>::iterator itr;
  6797. GroundSpawnEntry* entry = 0;
  6798. bool can_harvest = false;
  6799. sint32 min_skill = -1;
  6800. int16 totalSkill = skill->current_val;
  6801. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6802. if(skillID != 0xFFFFFFFF)
  6803. {
  6804. ((Entity*)player)->MStats.lock();
  6805. totalSkill += ((Entity*)player)->stats[skillID];
  6806. ((Entity*)player)->MStats.unlock();
  6807. }
  6808. // first, iterate through groundspawn_entries, discard tables player cannot use
  6809. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6810. {
  6811. entry = *itr;
  6812. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6813. min_skill = entry->min_skill_level;
  6814. // if player lacks skill, skip table
  6815. if (entry->min_skill_level > totalSkill)
  6816. continue;
  6817. // if bonus, but player lacks level, skip table
  6818. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6819. continue;
  6820. can_harvest = true;
  6821. break;
  6822. }
  6823. lua_interface->SetBooleanValue(state, can_harvest);
  6824. // If false, send the message to the client
  6825. if (!can_harvest) {
  6826. Client* client = player->GetZone()->GetClientBySpawn(player);
  6827. if (client) {
  6828. string msg = "You do not have enough skill to ";
  6829. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6830. msg.append("gather");
  6831. else if (collection_skill == "Mining")
  6832. msg.append("mine");
  6833. else if (collection_skill == "Trapping")
  6834. msg.append("trap");
  6835. else if (collection_skill == "Foresting")
  6836. msg.append("forest");
  6837. else if (collection_skill == "Fishing")
  6838. msg.append("catch");
  6839. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6840. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6841. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6842. }
  6843. }
  6844. return 1;
  6845. }
  6846. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6847. if (!lua_interface)
  6848. return 0;
  6849. Spawn* player = lua_interface->GetSpawn(state);
  6850. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6851. if (!player) {
  6852. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6853. return 0;
  6854. }
  6855. if (!player->IsPlayer()) {
  6856. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6857. return 0;
  6858. }
  6859. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6860. lua_interface->SetBooleanValue(state, ret);
  6861. return 1;
  6862. }
  6863. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6864. // Check to see if we have a valid lua_interface
  6865. if (!lua_interface)
  6866. return 0;
  6867. // Get the spawn that is getting the pet
  6868. Spawn* spawn = lua_interface->GetSpawn(state);
  6869. Spawn* target = lua_interface->GetSpawn(state, 2);
  6870. // Get the DB ID of the pet
  6871. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6872. float x = lua_interface->GetFloatValue(state, 4);
  6873. float y = lua_interface->GetFloatValue(state, 5);
  6874. float z = lua_interface->GetFloatValue(state, 6);
  6875. // Get the spell that this command was called from
  6876. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6877. // Check to make sure the spawn pointer is valid
  6878. if (!spawn) {
  6879. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6880. return 0;
  6881. }
  6882. // Check to make sure the spawn is an entity
  6883. if (!spawn->IsEntity()) {
  6884. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6885. return 0;
  6886. }
  6887. if (!target) {
  6888. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6889. return 0;
  6890. }
  6891. if (!target->IsEntity()) {
  6892. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6893. return 0;
  6894. }
  6895. // Check to see if the DB ID for the pet is set
  6896. if (pet_id == 0) {
  6897. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6898. return 0;
  6899. }
  6900. // Check to see if the pointer to the spell is valid
  6901. if (!luaspell) {
  6902. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6903. return 0;
  6904. }
  6905. if(luaspell->resisted) {
  6906. return 0;
  6907. }
  6908. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6909. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6910. if (!pet) {
  6911. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6912. return 0;
  6913. }
  6914. // Check to make sure the pet is an npc
  6915. if (!pet->IsNPC()) {
  6916. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6917. return 0;
  6918. }
  6919. if (x == 0)
  6920. x = spawn->GetX();
  6921. if (y == 0)
  6922. y = spawn->GetY();
  6923. if (z == 0)
  6924. z = spawn->GetZ();
  6925. // Spawn the pet at the same location as the owner
  6926. pet->SetX(x);
  6927. pet->SetY(y);
  6928. pet->SetZ(z);
  6929. pet->SetLocation(spawn->GetLocation());
  6930. pet->SetHeading(spawn->GetHeading());
  6931. spawn->GetZone()->AddSpawn(pet);
  6932. /*
  6933. const char* spawn_script = world.GetSpawnScript(pet_id);
  6934. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6935. spawn->SetSpawnScript(string(spawn_script));
  6936. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6937. }*/
  6938. // Get a random pet name
  6939. string random_pet_name;
  6940. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6941. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6942. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6943. // Set the pets name
  6944. pet->SetName(random_pet_name.c_str());
  6945. // Set the level of the pet to the owners level
  6946. pet->SetLevel(spawn->GetLevel());
  6947. // Set the faction of the pet to the same faction as the owner
  6948. pet->SetFactionID(spawn->GetFactionID());
  6949. // Set the spawn as a pet
  6950. pet->SetPet(true);
  6951. // Give a pointer of the owner to the pet
  6952. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6953. // Set the pet type
  6954. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6955. // Set the spell id used to create this pet
  6956. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6957. // Set the spell tier used to create this pet
  6958. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6959. // Set the pets spawn type to 6
  6960. pet->SetSpawnType(6);
  6961. // Set the pets brain
  6962. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6963. // Check to see if the pet has a subtitle
  6964. if (strlen(pet->GetSubTitle()) > 0) {
  6965. // Add the players name to the front of the sub title
  6966. string pet_subtitle;
  6967. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6968. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6969. // Set the pets subtitle to the new one
  6970. pet->SetSubTitle(pet_subtitle.c_str());
  6971. }
  6972. // Set the pet as the return value for this function
  6973. lua_interface->SetSpawnValue(state, pet);
  6974. return 1;
  6975. }
  6976. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6977. if (!lua_interface)
  6978. return 0;
  6979. Spawn* spawn = lua_interface->GetSpawn(state);
  6980. Spawn* player = lua_interface->GetSpawn(state, 2);
  6981. float max_distance = lua_interface->GetFloatValue(state, 3);
  6982. string type = lua_interface->GetStringValue(state, 4);
  6983. if (!spawn || (spawn && spawn->IsPlayer())) {
  6984. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6985. return 0;
  6986. }
  6987. if (!player || (player && !player->IsPlayer())) {
  6988. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6989. return 0;
  6990. }
  6991. Client* client = 0;
  6992. if (player->GetZone())
  6993. client = player->GetZone()->GetClientBySpawn(player);
  6994. if (!client) {
  6995. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6996. return 0;
  6997. }
  6998. //Set max_distance to default if not set or not proper value
  6999. if (max_distance <= 0)
  7000. max_distance = 500;
  7001. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7002. if (packet) {
  7003. float unknown2_3 = 0;
  7004. int8 placement_mode = 0;
  7005. if (type == "wall") {
  7006. placement_mode = 2;
  7007. unknown2_3 = 150;
  7008. }
  7009. else if (type == "ceiling")
  7010. placement_mode = 1;
  7011. packet->setDataByName("placement_mode", placement_mode);
  7012. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7013. packet->setDataByName("model_type", spawn->GetModelType());
  7014. packet->setDataByName("unknown", 1); //size
  7015. packet->setDataByName("unknown2", 1); //size 2
  7016. packet->setDataByName("unknown2", .5, 1); //size 3
  7017. packet->setDataByName("unknown2", 3, 2);
  7018. packet->setDataByName("unknown2", unknown2_3, 3);
  7019. packet->setDataByName("max_distance", max_distance);
  7020. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7021. client->QueuePacket(packet->serialize());
  7022. safe_delete(packet);
  7023. }
  7024. return 0;
  7025. }
  7026. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7027. if (!lua_interface)
  7028. return 0;
  7029. Item* item = lua_interface->GetItem(state);
  7030. if (!item) {
  7031. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7032. return 0;
  7033. }
  7034. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7035. return 1;
  7036. }
  7037. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7038. if (!lua_interface)
  7039. return 0;
  7040. Item* item = lua_interface->GetItem(state);
  7041. if (!item) {
  7042. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7043. return 0;
  7044. }
  7045. lua_interface->SetInt32Value(state, item->effect_type);
  7046. return 1;
  7047. }
  7048. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7049. if (!lua_interface)
  7050. return 0;
  7051. Spawn* spawn = lua_interface->GetSpawn(state);
  7052. if (!spawn) {
  7053. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7054. return 0;
  7055. }
  7056. if (spawn->GetZone())
  7057. spawn->GetZone()->AddTransportSpawn(spawn);
  7058. return 0;
  7059. }
  7060. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7061. if (!lua_interface)
  7062. return 0;
  7063. Spawn* spawn = lua_interface->GetSpawn(state);
  7064. if (!spawn) {
  7065. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7066. return 0;
  7067. }
  7068. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7069. return 1;
  7070. }
  7071. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7072. if (!lua_interface)
  7073. return 0;
  7074. Skill* skill = lua_interface->GetSkill(state);
  7075. if (!skill) {
  7076. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7077. return 0;
  7078. }
  7079. lua_interface->SetInt32Value(state, skill->current_val);
  7080. return 1;
  7081. }
  7082. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7083. if (!lua_interface)
  7084. return 0;
  7085. Skill* skill = lua_interface->GetSkill(state);
  7086. if (!skill) {
  7087. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7088. return 0;
  7089. }
  7090. lua_interface->SetInt32Value(state, skill->max_val);
  7091. return 1;
  7092. }
  7093. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7094. if (!lua_interface)
  7095. return 0;
  7096. Skill* skill = lua_interface->GetSkill(state);
  7097. if (!skill) {
  7098. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7099. return 0;
  7100. }
  7101. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7102. return 1;
  7103. }
  7104. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7105. if (!lua_interface)
  7106. return 0;
  7107. Skill* skill = lua_interface->GetSkill(state);
  7108. int16 value = lua_interface->GetInt16Value(state, 2);
  7109. if (!skill) {
  7110. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7111. return 0;
  7112. }
  7113. skill->max_val = value;
  7114. if (skill->max_val < skill->current_val)
  7115. skill->current_val = skill->max_val;
  7116. return 0;
  7117. }
  7118. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7119. if (!lua_interface)
  7120. return 0;
  7121. Skill* skill = lua_interface->GetSkill(state);
  7122. int16 value = lua_interface->GetInt16Value(state, 2);
  7123. if (!skill) {
  7124. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7125. return 0;
  7126. }
  7127. if (value > skill->max_val)
  7128. skill->current_val = skill->max_val;
  7129. else
  7130. skill->current_val = value;
  7131. return 0;
  7132. }
  7133. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7134. if (!lua_interface)
  7135. return 0;
  7136. Spawn* player = lua_interface->GetSpawn(state);
  7137. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7138. if (skill_id > 0 && player && player->IsPlayer()) {
  7139. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7140. return 1;
  7141. }
  7142. return 0;
  7143. }
  7144. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7145. if (!lua_interface)
  7146. return 0;
  7147. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7148. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7149. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7150. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7151. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7152. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7153. if (player_spawn && player_spawn->IsPlayer()) {
  7154. Player* player = (Player*)player_spawn;
  7155. bool added = false;
  7156. if (!player->skill_list.HasSkill(skill_id)) {
  7157. player->AddSkill(skill_id, current_val, max_val, true);
  7158. added = true;
  7159. }
  7160. 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
  7161. Client* client = player->GetClient();
  7162. if (client) {
  7163. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7164. if (packet)
  7165. client->QueuePacket(packet);
  7166. }
  7167. }
  7168. if (added) {
  7169. lua_interface->SetBooleanValue(state, true);
  7170. return 1;
  7171. }
  7172. }
  7173. else {
  7174. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7175. }
  7176. }
  7177. else {
  7178. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7179. }
  7180. lua_interface->SetBooleanValue(state, false);
  7181. return 1;
  7182. }
  7183. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7184. if (!lua_interface)
  7185. return 0;
  7186. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7187. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7188. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7189. if (skill_id > 0) {
  7190. if (player_spawn && player_spawn->IsPlayer()) {
  7191. Player* player = (Player*)player_spawn;
  7192. if (player->skill_list.HasSkill(skill_id)) {
  7193. player->RemovePlayerSkill(skill_id);
  7194. if (!more_to_remove) {
  7195. Client* client = player->GetClient();
  7196. if (client) {
  7197. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7198. if (packet)
  7199. client->QueuePacket(packet);
  7200. }
  7201. }
  7202. }
  7203. }
  7204. else {
  7205. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7206. }
  7207. }
  7208. else {
  7209. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7210. }
  7211. return 0;
  7212. }
  7213. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7214. if (!lua_interface)
  7215. return 0;
  7216. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7217. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7218. int16 amount = lua_interface->GetInt8Value(state, 3);
  7219. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7220. if (amount > 0 && skill_type < 100) {
  7221. if (player_spawn && player_spawn->IsPlayer()) {
  7222. Player* player = (Player*)player_spawn;
  7223. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7224. if (!more_to_increase) {
  7225. Client* client = player->GetClient();
  7226. if (client) {
  7227. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7228. if (packet)
  7229. client->QueuePacket(packet);
  7230. }
  7231. }
  7232. }
  7233. else {
  7234. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7235. }
  7236. }
  7237. else {
  7238. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7239. }
  7240. return 0;
  7241. }
  7242. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7243. if (!lua_interface)
  7244. return 0;
  7245. Spawn* spawn = lua_interface->GetSpawn(state);
  7246. string name = lua_interface->GetStringValue(state, 2);
  7247. if (!spawn) {
  7248. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. if (!spawn->IsEntity()) {
  7252. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7253. return 0;
  7254. }
  7255. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7256. if (skill) {
  7257. lua_interface->SetSkillValue(state, skill);
  7258. return 1;
  7259. }
  7260. return 0;
  7261. }
  7262. int EQ2Emu_lua_AddProc(lua_State* state) {
  7263. if (!lua_interface)
  7264. return 0;
  7265. Spawn* spawn = lua_interface->GetSpawn(state);
  7266. int8 type = lua_interface->GetInt8Value(state, 2);
  7267. float chance = lua_interface->GetFloatValue(state, 3);
  7268. Item* item = lua_interface->GetItem(state, 4);
  7269. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7270. LuaSpell* spell = 0;
  7271. if (!spawn && (!spell || !use_all_spelltargets)) {
  7272. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7273. return 0;
  7274. }
  7275. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7276. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7277. return 0;
  7278. }
  7279. if (!item)
  7280. spell = lua_interface->GetCurrentSpell(state);
  7281. if (!item && !spell) {
  7282. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7283. return 0;
  7284. }
  7285. if(spell && spell->resisted) {
  7286. return 0;
  7287. }
  7288. if (spell && use_all_spelltargets) {
  7289. Spawn* target;
  7290. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7291. for (int8 i = 0; i < spell->targets.size(); i++) {
  7292. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7293. if (!target || !target->IsEntity())
  7294. continue;
  7295. ((Entity*)target)->AddProc(type, chance, item, spell);
  7296. }
  7297. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7298. }
  7299. else
  7300. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7301. return 0;
  7302. }
  7303. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7304. if (!lua_interface)
  7305. return 0;
  7306. Spawn* spawn = lua_interface->GetSpawn(state);
  7307. Item* item = lua_interface->GetItem(state, 2);
  7308. LuaSpell* spell = 0;
  7309. if (!spawn) {
  7310. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7311. return 0;
  7312. }
  7313. if (!spawn->IsEntity()) {
  7314. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. if (!item)
  7318. spell = lua_interface->GetCurrentSpell(state);
  7319. if (!item && !spell) {
  7320. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7321. return 0;
  7322. }
  7323. if (spell) {
  7324. Spawn* target;
  7325. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7326. for (int8 i = 0; i < spell->targets.size(); i++) {
  7327. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7328. if (!target || !target->IsEntity())
  7329. continue;
  7330. ((Entity*)target)->RemoveProc(item, spell);
  7331. }
  7332. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7333. spell->caster->RemoveProc(item, spell);
  7334. }
  7335. else
  7336. ((Entity*)spawn)->RemoveProc(item, spell);
  7337. return 0;
  7338. }
  7339. int EQ2Emu_lua_Knockback(lua_State* state) {
  7340. if (!lua_interface)
  7341. return 0;
  7342. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7343. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7344. int32 duration = lua_interface->GetInt32Value(state, 3);
  7345. float vertical = lua_interface->GetFloatValue(state, 4);
  7346. float horizontal = lua_interface->GetFloatValue(state, 5);
  7347. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7348. if (!target_spawn) {
  7349. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7350. return 0;
  7351. }
  7352. if (!spawn) {
  7353. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7354. return 0;
  7355. }
  7356. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7357. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7358. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7359. if (packet) {
  7360. packet->setDataByName("target_x", target_spawn->GetX());
  7361. packet->setDataByName("target_y", target_spawn->GetY());
  7362. packet->setDataByName("target_z", target_spawn->GetZ());
  7363. packet->setDataByName("vertical_movement", vertical);
  7364. packet->setDataByName("horizontal_movement", horizontal);
  7365. if (use_heading)
  7366. packet->setDataByName("use_player_heading", 1);
  7367. client->QueuePacket(packet->serialize());
  7368. }
  7369. safe_delete(packet);
  7370. }
  7371. return 0;
  7372. }
  7373. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7374. if (!lua_interface)
  7375. return 0;
  7376. Spawn* spawn = lua_interface->GetSpawn(state);
  7377. if (!spawn) {
  7378. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7379. return 0;
  7380. }
  7381. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7382. return 1;
  7383. }
  7384. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7385. if (!lua_interface)
  7386. return 0;
  7387. Spawn* caster = lua_interface->GetSpawn(state);
  7388. Spawn* target = lua_interface->GetSpawn(state, 2);
  7389. string name = lua_interface->GetStringValue(state, 3);
  7390. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7391. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7392. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7393. string success_msg = lua_interface->GetStringValue(state, 7);
  7394. string effect_msg = lua_interface->GetStringValue(state, 8);
  7395. if (!caster) {
  7396. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7397. return 0;
  7398. }
  7399. if (!caster->IsEntity()) {
  7400. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7401. return 0;
  7402. }
  7403. if (!target) {
  7404. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7405. return 0;
  7406. }
  7407. if (!target->IsEntity()) {
  7408. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7409. return 0;
  7410. }
  7411. if (name.length() == 0) {
  7412. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7413. return 0;
  7414. }
  7415. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7416. return 0;
  7417. }
  7418. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7419. if (!lua_interface)
  7420. return 0;
  7421. string name = lua_interface->GetStringValue(state);
  7422. if (name.length() == 0) {
  7423. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7424. return 0;
  7425. }
  7426. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7427. if (!skill) {
  7428. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7429. return 0;
  7430. }
  7431. lua_interface->SetInt32Value(state, skill->skill_id);
  7432. return 1;
  7433. }
  7434. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7435. if (!lua_interface)
  7436. return 0;
  7437. Spawn* spawn = lua_interface->GetSpawn(state);
  7438. if (!spawn) {
  7439. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7440. return 0;
  7441. }
  7442. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7443. return 1;
  7444. }
  7445. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7446. if (!lua_interface)
  7447. return 0;
  7448. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7449. if (!luaspell) {
  7450. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7451. return 0;
  7452. }
  7453. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7454. return 1;
  7455. }
  7456. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7457. if (!lua_interface)
  7458. return 0;
  7459. Spawn* spawn = lua_interface->GetSpawn(state);
  7460. Spawn* target = lua_interface->GetSpawn(state, 2);
  7461. if (!spawn) {
  7462. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7463. return 0;
  7464. }
  7465. if (!spawn->IsEntity()) {
  7466. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7467. return 0;
  7468. }
  7469. if (!target) {
  7470. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7471. return 0;
  7472. }
  7473. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7474. return 1;
  7475. }
  7476. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7477. if (!lua_interface)
  7478. return 0;
  7479. Spawn* spawn = lua_interface->GetSpawn(state);
  7480. Spawn* target = lua_interface->GetSpawn(state, 2);
  7481. if (!spawn) {
  7482. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7483. return 0;
  7484. }
  7485. if (!spawn->IsEntity()) {
  7486. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. if (!target) {
  7490. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7491. return 0;
  7492. }
  7493. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7494. return 1;
  7495. }
  7496. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7497. if (!lua_interface)
  7498. return 0;
  7499. Item* item = lua_interface->GetItem(state);
  7500. if (!item) {
  7501. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7502. return 0;
  7503. }
  7504. lua_interface->SetInt32Value(state, item->details.count);
  7505. return 1;
  7506. }
  7507. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7508. if (!lua_interface)
  7509. return 0;
  7510. Item* item = lua_interface->GetItem(state);
  7511. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7512. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7513. if (!item) {
  7514. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7515. return 0;
  7516. }
  7517. if (!owner) {
  7518. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7519. return 0;
  7520. }
  7521. if (!owner->IsPlayer()) {
  7522. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7523. return 0;
  7524. }
  7525. if (item->stack_count < new_count) {
  7526. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7527. return 0;
  7528. }
  7529. if (new_count > 0) {
  7530. item->details.count = new_count;
  7531. item->save_needed = true;
  7532. }
  7533. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7534. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7535. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7536. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7537. else
  7538. {
  7539. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7540. return 0;
  7541. }
  7542. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7543. if (!client)
  7544. return 0;
  7545. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7546. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7547. if (app)
  7548. client->QueuePacket(app);
  7549. return 0;
  7550. }
  7551. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7552. if (!lua_interface)
  7553. return 0;
  7554. int32 time = lua_interface->GetInt32Value(state);
  7555. string function = lua_interface->GetStringValue(state, 2);
  7556. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7557. Spawn* target = lua_interface->GetSpawn(state, 4);
  7558. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7559. if (time == 0) {
  7560. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7561. return 0;
  7562. }
  7563. if (function.length() == 0) {
  7564. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7565. return 0;
  7566. }
  7567. if (!spell) {
  7568. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7569. return 0;
  7570. }
  7571. SpellScriptTimer* timer = new SpellScriptTimer;
  7572. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7573. #ifdef WIN32
  7574. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7575. #else
  7576. bzero(timer, sizeof(SpellScriptTimer));
  7577. #endif*/
  7578. timer->caster = 0;
  7579. timer->deleteWhenDone = false;
  7580. timer->target = 0;
  7581. timer->time = Timer::GetCurrentTime2() + time;
  7582. timer->customFunction = function;
  7583. timer->spell = spell;
  7584. if (caster)
  7585. timer->caster = caster->GetID();
  7586. if (target)
  7587. timer->target = target->GetID();
  7588. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7589. return 0;
  7590. }
  7591. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7592. if (!lua_interface)
  7593. return 0;
  7594. float hp_perc = lua_interface->GetFloatValue(state);
  7595. float power_perc = lua_interface->GetFloatValue(state, 2);
  7596. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7597. Spawn* target = lua_interface->GetSpawn(state, 4);
  7598. string heal_name = lua_interface->GetStringValue(state, 5);
  7599. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7600. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7601. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7602. if (!spell) {
  7603. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7604. return 0;
  7605. }
  7606. Entity* caster = spell->caster;
  7607. if (!caster) {
  7608. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7609. return 0;
  7610. }
  7611. Client* client = 0;
  7612. PendingResurrection* rez = 0;
  7613. ZoneServer* zone = spell->caster->GetZone();
  7614. if (!target) {
  7615. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7616. if (spell->targets.size() > 0) {
  7617. vector<int32> spell_targets = spell->targets;
  7618. for (int8 i = 0; i < spell_targets.size(); i++) {
  7619. target = zone->GetSpawnByID(spell_targets.at(i));
  7620. if (!target)
  7621. continue;
  7622. if (!target->IsPlayer())
  7623. continue;
  7624. client = target->GetZone()->GetClientBySpawn(target);
  7625. if (!client)
  7626. continue;
  7627. rez = client->GetCurrentRez();
  7628. if (rez->active)
  7629. continue;
  7630. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7631. rez->active = true;
  7632. rez->caster = caster;
  7633. rez->expire_timer = new Timer;
  7634. int32 duration = spell->spell->GetSpellDuration();
  7635. rez->expire_timer->Start(duration * 100);
  7636. rez->hp_perc = hp_perc;
  7637. rez->mp_perc = power_perc;
  7638. rez->range = spell->spell->GetSpellData()->range;
  7639. rez->spell_name = spell->spell->GetName();
  7640. if (heal_name.length() > 0)
  7641. rez->heal_name = heal_name;
  7642. else
  7643. rez->heal_name = rez->spell_name;
  7644. rez->no_calcs = no_calcs;
  7645. rez->crit_mod = crit_mod;
  7646. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7647. if (send_window)
  7648. client->SendResurrectionWindow();
  7649. else {
  7650. target->GetZone()->ResurrectSpawn(target, client);
  7651. rez->should_delete = true;
  7652. }
  7653. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7654. }
  7655. }
  7656. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7657. }
  7658. else {
  7659. client = target->GetZone()->GetClientBySpawn(target);
  7660. if (!client)
  7661. return 0;
  7662. rez = client->GetCurrentRez();
  7663. if (rez->active)
  7664. return 0;
  7665. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7666. rez->active = true;
  7667. rez->caster = caster;
  7668. rez->expire_timer = new Timer;
  7669. int32 duration = spell->spell->GetSpellDuration();
  7670. rez->expire_timer->Start(duration * 100);
  7671. rez->hp_perc = hp_perc;
  7672. rez->mp_perc = power_perc;
  7673. rez->range = spell->spell->GetSpellData()->range;
  7674. rez->spell_name = spell->spell->GetName();
  7675. if (heal_name.length() > 0)
  7676. rez->heal_name = heal_name;
  7677. else
  7678. rez->heal_name = rez->spell_name;
  7679. rez->no_calcs = no_calcs;
  7680. rez->crit_mod = crit_mod;
  7681. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7682. if (send_window)
  7683. client->SendResurrectionWindow();
  7684. else {
  7685. target->GetZone()->ResurrectSpawn(target, client);
  7686. rez->should_delete = true;
  7687. }
  7688. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7689. }
  7690. return 0;
  7691. }
  7692. int EQ2Emu_lua_SetVision(lua_State* state) {
  7693. if (!lua_interface)
  7694. return 0;
  7695. Spawn* spawn = lua_interface->GetSpawn(state);
  7696. int8 vision = lua_interface->GetInt8Value(state, 2);
  7697. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7698. if (!spawn) {
  7699. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7700. return 0;
  7701. }
  7702. if (!spawn->IsEntity()) {
  7703. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7704. return 0;
  7705. }
  7706. if (spell && spell->targets.size() > 0) {
  7707. ZoneServer* zone = spell->caster->GetZone();
  7708. for (int8 i = 0; i < spell->targets.size(); i++) {
  7709. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7710. if (target && target->IsEntity()) {
  7711. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7712. if (target->IsPlayer())
  7713. ((Player*)target)->SetCharSheetChanged(true);
  7714. }
  7715. }
  7716. }
  7717. else {
  7718. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7719. if (spawn->IsPlayer())
  7720. ((Player*)spawn)->SetCharSheetChanged(true);
  7721. }
  7722. return 0;
  7723. }
  7724. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7725. if (!lua_interface)
  7726. return 0;
  7727. Spawn* spawn = lua_interface->GetSpawn(state);
  7728. float intensity = lua_interface->GetFloatValue(state, 2);
  7729. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7730. if (!spawn) {
  7731. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7732. return 0;
  7733. }
  7734. if (!spawn->IsEntity()) {
  7735. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7736. return 0;
  7737. }
  7738. if (spell && spell->targets.size() > 0) {
  7739. ZoneServer* zone = spell->caster->GetZone();
  7740. for (int8 i = 0; i < spell->targets.size(); i++) {
  7741. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7742. if (target && target->IsEntity()) {
  7743. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7744. if (target->IsPlayer())
  7745. ((Player*)target)->SetCharSheetChanged(true);
  7746. }
  7747. }
  7748. }
  7749. else {
  7750. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7751. if (spawn->IsPlayer())
  7752. ((Player*)spawn)->SetCharSheetChanged(true);
  7753. }
  7754. return 0;
  7755. }
  7756. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7757. if (!lua_interface)
  7758. return 0;
  7759. Spawn* spawn = lua_interface->GetSpawn(state);
  7760. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7761. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7762. if (!spawn) {
  7763. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7764. return 0;
  7765. }
  7766. if (!spawn->IsEntity()) {
  7767. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7768. return 0;
  7769. }
  7770. if (spell && spell->targets.size() > 0) {
  7771. ZoneServer* zone = spell->caster->GetZone();
  7772. for (int8 i = 0; i < spell->targets.size(); i++) {
  7773. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7774. if (target && target->IsEntity()) {
  7775. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7776. if (target->IsPlayer())
  7777. ((Player*)target)->SetCharSheetChanged(true);
  7778. }
  7779. }
  7780. }
  7781. else {
  7782. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7783. if (spawn->IsPlayer())
  7784. ((Player*)spawn)->SetCharSheetChanged(true);
  7785. }
  7786. return 0;
  7787. }
  7788. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7789. if (!lua_interface)
  7790. return 0;
  7791. Item* item = lua_interface->GetItem(state);
  7792. int8 type = lua_interface->GetInt32Value(state, 2);
  7793. if (!item) {
  7794. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7795. return 0;
  7796. }
  7797. if (type == 1)
  7798. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7799. else if (type == 2)
  7800. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7801. return 1;
  7802. }
  7803. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7804. if (!lua_interface)
  7805. return 0;
  7806. Spawn* target = lua_interface->GetSpawn(state);
  7807. float val = lua_interface->GetFloatValue(state, 2);
  7808. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7809. // Added from Gangrenous post
  7810. if (spell && spell->resisted)
  7811. return 0;
  7812. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7813. if (val > 1.0f)
  7814. val = 1.0f - (val / 100.0f);
  7815. if (spell && spell->spell && spell->targets.size() > 0) {
  7816. ZoneServer* zone = spell->caster->GetZone();
  7817. for (int32 i = 0; i != spell->targets.size(); i++) {
  7818. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7819. if (spawn && spawn->IsEntity()) {
  7820. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7821. if (spawn->IsPlayer())
  7822. ((Player*)spawn)->SetCharSheetChanged(true);
  7823. }
  7824. }
  7825. }
  7826. else {
  7827. if (target && target->IsEntity()) {
  7828. ((Entity*)target)->SetSpeedMultiplier(val);
  7829. if (target->IsPlayer())
  7830. ((Player*)target)->SetCharSheetChanged(true);
  7831. }
  7832. }
  7833. return 0;
  7834. }
  7835. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7836. if (!lua_interface)
  7837. return 0;
  7838. Spawn* spawn = lua_interface->GetSpawn(state);
  7839. int16 model = lua_interface->GetInt16Value(state, 2);
  7840. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7841. if (spell && spell->spell && spell->targets.size() > 0) {
  7842. ZoneServer* zone = spell->caster->GetZone();
  7843. for (int32 i = 0; i < spell->targets.size(); i++) {
  7844. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7845. if (target)
  7846. target->SetIllusionModel(model);
  7847. }
  7848. }
  7849. else {
  7850. if (!spawn) {
  7851. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7852. return 0;
  7853. }
  7854. spawn->SetIllusionModel(model);
  7855. }
  7856. return 0;
  7857. }
  7858. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7859. if (!lua_interface)
  7860. return 0;
  7861. Spawn* spawn = lua_interface->GetSpawn(state);
  7862. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7863. if (spell && spell->spell && spell->targets.size() > 0) {
  7864. ZoneServer* zone = spell->caster->GetZone();
  7865. for (int32 i = 0; i < spell->targets.size(); i++) {
  7866. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7867. if (target)
  7868. target->SetIllusionModel(0);
  7869. }
  7870. }
  7871. else {
  7872. if (!spawn) {
  7873. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7874. return 0;
  7875. }
  7876. spawn->SetIllusionModel(0);
  7877. }
  7878. return 0;
  7879. }
  7880. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7881. if (!lua_interface)
  7882. return 0;
  7883. Spawn* caster = lua_interface->GetSpawn(state);
  7884. Spawn* target = lua_interface->GetSpawn(state, 2);
  7885. float chance = lua_interface->GetFloatValue(state, 3);
  7886. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7887. if (!caster) {
  7888. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7889. return 0;
  7890. }
  7891. if (!caster->IsEntity()) {
  7892. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7893. return 0;
  7894. }
  7895. if (!target) {
  7896. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. if (!target->IsEntity()) {
  7900. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7901. return 0;
  7902. }
  7903. if (chance <= 0) {
  7904. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7905. return 0;
  7906. }
  7907. if (!spell) {
  7908. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7909. return 0;
  7910. }
  7911. if(spell->resisted) {
  7912. return 0;
  7913. }
  7914. if (((Entity*)caster)->GetThreatTransfer()) {
  7915. return 0;
  7916. }
  7917. ThreatTransfer* transfer = new ThreatTransfer;
  7918. transfer->Target = target->GetID();
  7919. transfer->Amount = chance;
  7920. transfer->Spell = spell;
  7921. ((Entity*)caster)->SetThreatTransfer(transfer);
  7922. return 0;
  7923. }
  7924. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7925. if (!lua_interface)
  7926. return 0;
  7927. Spawn* spawn = lua_interface->GetSpawn(state);
  7928. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7929. if (!spawn) {
  7930. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7931. return 0;
  7932. }
  7933. if (!spell) {
  7934. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7935. return 0;
  7936. }
  7937. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7938. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7939. if(transfer && transfer->Spell != spell) {
  7940. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  7941. return 0;
  7942. }
  7943. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  7944. }
  7945. return 0;
  7946. }
  7947. int EQ2Emu_lua_CureByType(lua_State* state) {
  7948. if (!lua_interface)
  7949. return 0;
  7950. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7951. int8 cure_count = lua_interface->GetInt8Value(state);
  7952. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7953. string cure_name = lua_interface->GetStringValue(state, 3);
  7954. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7955. Spawn* target = lua_interface->GetSpawn(state, 5);
  7956. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  7957. if(spell && spell->resisted) {
  7958. return 0;
  7959. }
  7960. if (target) {
  7961. if (!target->IsEntity()) {
  7962. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7963. return 0;
  7964. }
  7965. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  7966. std::string alternate_name = "item";
  7967. if(spell)
  7968. alternate_name = std::string(spell->spell->GetName());
  7969. if(!caster && spell)
  7970. caster = (Spawn*)spell->caster;
  7971. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  7972. }
  7973. }
  7974. else {
  7975. ZoneServer* zone = spell->caster->GetZone();
  7976. vector<int32> targets = spell->targets;
  7977. vector<Entity*> targets_to_cure;
  7978. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7979. for (int8 i = 0; i < targets.size(); i++) {
  7980. target = zone->GetSpawnByID(targets.at(i));
  7981. if (!target || !target->IsEntity())
  7982. continue;
  7983. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  7984. targets_to_cure.push_back((Entity*)target);
  7985. }
  7986. }
  7987. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7988. vector<Entity*>::iterator itr;
  7989. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  7990. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7991. }
  7992. }
  7993. return 0;
  7994. }
  7995. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7996. if (!lua_interface)
  7997. return 0;
  7998. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7999. if (!spell) {
  8000. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8001. return 0;
  8002. }
  8003. if(spell->resisted) {
  8004. return 0;
  8005. }
  8006. int8 cure_count = lua_interface->GetInt8Value(state);
  8007. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8008. string cure_name = lua_interface->GetStringValue(state, 3);
  8009. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8010. Spawn* target = lua_interface->GetSpawn(state, 5);
  8011. if (target) {
  8012. if (!target->IsEntity()) {
  8013. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8014. return 0;
  8015. }
  8016. if (((Entity*)target)->GetDetCount() > 0)
  8017. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8018. }
  8019. else {
  8020. ZoneServer* zone = spell->caster->GetZone();
  8021. vector<int32> targets = spell->targets;
  8022. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8023. for (int8 i = 0; i < targets.size(); i++) {
  8024. target = zone->GetSpawnByID(targets.at(i));
  8025. if (!target || !target->IsEntity())
  8026. continue;
  8027. if (((Entity*)target)->GetDetCount() > 0)
  8028. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8029. }
  8030. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8031. }
  8032. return 0;
  8033. }
  8034. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8035. if (!lua_interface)
  8036. return 0;
  8037. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8038. if (!spell) {
  8039. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8040. return 0;
  8041. }
  8042. if (!spell->caster) {
  8043. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8044. return 0;
  8045. }
  8046. if (!spell->caster->GetZone()) {
  8047. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8048. return 0;
  8049. }
  8050. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8051. return 0;
  8052. }
  8053. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8054. if (!lua_interface)
  8055. return 0;
  8056. Spawn* spawn = lua_interface->GetSpawn(state);
  8057. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8058. if (!spell) {
  8059. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8060. return 0;
  8061. }
  8062. if (spawn && spawn->IsEntity())
  8063. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8064. else {
  8065. ZoneServer* zone = spell->caster->GetZone();
  8066. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8067. for (int32 i = 0; i < spell->targets.size(); i++) {
  8068. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8069. if (!spawn || !spawn->IsEntity())
  8070. continue;
  8071. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8072. }
  8073. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8074. }
  8075. return 0;
  8076. }
  8077. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8078. if (!lua_interface)
  8079. return 0;
  8080. Spawn* spawn = lua_interface->GetSpawn(state);
  8081. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8082. if (!spell) {
  8083. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8084. return 0;
  8085. }
  8086. if (spawn && spawn->IsEntity())
  8087. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8088. else {
  8089. ZoneServer* zone = spell->caster->GetZone();
  8090. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8091. for (int32 i = 0; i < spell->targets.size(); i++) {
  8092. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8093. if (!spawn || !spawn->IsEntity())
  8094. continue;
  8095. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8096. }
  8097. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8098. }
  8099. return 0;
  8100. }
  8101. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8102. if (!lua_interface)
  8103. return 0;
  8104. Spawn* caster = lua_interface->GetSpawn(state);
  8105. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8106. if (!caster) {
  8107. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8108. return 0;
  8109. }
  8110. if (!caster->IsPlayer()) {
  8111. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8112. return 0;
  8113. }
  8114. Spawn* target = caster->GetTarget();
  8115. if (!target) {
  8116. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8117. return 0;
  8118. }
  8119. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8120. if (!client) {
  8121. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8122. return 0;
  8123. }
  8124. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8125. if (ho) {
  8126. ho->SetTarget(target->GetID());
  8127. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8128. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8129. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8130. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8131. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8132. deque<GroupMemberInfo*>::iterator itr;
  8133. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8134. if (group)
  8135. {
  8136. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8137. deque<GroupMemberInfo*>* members = group->GetMembers();
  8138. for (itr = members->begin(); itr != members->end(); itr++) {
  8139. if ((*itr)->client)
  8140. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8141. }
  8142. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8143. }
  8144. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8145. }
  8146. else
  8147. safe_delete(ho);
  8148. }
  8149. else {
  8150. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8151. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8152. }
  8153. else
  8154. safe_delete(ho);
  8155. }
  8156. }
  8157. return 0;
  8158. }
  8159. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8160. if (!lua_interface)
  8161. return 0;
  8162. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8163. if (!spell) {
  8164. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8165. return 0;
  8166. }
  8167. int16 triggerCount = lua_interface->GetInt16Value(state);
  8168. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8169. if (!triggerCount) {
  8170. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8171. return 0;
  8172. }
  8173. spell->num_triggers = triggerCount;
  8174. spell->had_triggers = true;
  8175. spell->cancel_after_all_triggers = cancel_after_triggers;
  8176. return 0;
  8177. }
  8178. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8179. if (!lua_interface)
  8180. return 0;
  8181. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8182. if (!spell) {
  8183. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8184. return 0;
  8185. }
  8186. lua_interface->SetInt32Value(state, spell->num_triggers);
  8187. return 1;
  8188. }
  8189. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8190. if (!lua_interface)
  8191. return 0;
  8192. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8193. if (!spell) {
  8194. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8195. return 0;
  8196. }
  8197. int16 remove_count = lua_interface->GetInt16Value(state);
  8198. if (!remove_count)
  8199. remove_count = 1;
  8200. if (remove_count >= spell->num_triggers) {
  8201. spell->num_triggers = 0;
  8202. if (spell->cancel_after_all_triggers)
  8203. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8204. }
  8205. else {
  8206. spell->num_triggers -= remove_count;
  8207. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8208. }
  8209. return 0;
  8210. }
  8211. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8212. if (!lua_interface)
  8213. return 0;
  8214. Spawn* spawn = lua_interface->GetSpawn(state);
  8215. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8216. if (!spawn) {
  8217. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8218. return 0;
  8219. }
  8220. if (!copy_spawn) {
  8221. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8222. return 0;
  8223. }
  8224. spawn->CopySpawnAppearance(copy_spawn);
  8225. return 0;
  8226. }
  8227. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8228. Spawn* spawn = lua_interface->GetSpawn(state);
  8229. int8 type = lua_interface->GetInt8Value(state, 2);
  8230. if (!spawn) {
  8231. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8232. return 0;
  8233. }
  8234. else if (!spawn->IsEntity()) {
  8235. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8236. return 0;
  8237. }
  8238. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8239. return 1;
  8240. }
  8241. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8242. if (!lua_interface)
  8243. return 0;
  8244. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8245. int8 type = lua_interface->GetInt8Value(state);
  8246. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8247. if (!spell) {
  8248. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8249. return 0;
  8250. }
  8251. if(spell->resisted) {
  8252. return 0;
  8253. }
  8254. if (spawn) {
  8255. if (!spawn->IsEntity()) {
  8256. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8257. return 0;
  8258. }
  8259. Entity* entity = ((Entity*)spawn);
  8260. entity->AddImmunity(spell, type);
  8261. }
  8262. else {
  8263. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8264. for (int8 i = 0; i < spell->targets.size(); i++) {
  8265. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8266. if (!spawn || !spawn->IsEntity())
  8267. continue;
  8268. Entity* entity = ((Entity*)spawn);
  8269. entity->AddImmunity(spell, type);
  8270. }
  8271. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8272. }
  8273. return 0;
  8274. }
  8275. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8276. if (!lua_interface)
  8277. return 0;
  8278. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8279. int8 type = lua_interface->GetInt8Value(state);
  8280. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8281. if (!spell) {
  8282. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8283. return 0;
  8284. }
  8285. if (spawn) {
  8286. if (!spawn->IsEntity()) {
  8287. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8288. return 0;
  8289. }
  8290. Entity* entity = ((Entity*)spawn);
  8291. entity->RemoveImmunity(spell, type);
  8292. }
  8293. else {
  8294. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8295. for (int8 i = 0; i < spell->targets.size(); i++) {
  8296. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8297. if (!spawn || !spawn->IsEntity())
  8298. continue;
  8299. Entity* entity = ((Entity*)spawn);
  8300. entity->RemoveImmunity(spell, type);
  8301. }
  8302. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8303. }
  8304. return 0;
  8305. }
  8306. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8307. if (!lua_interface)
  8308. return 0;
  8309. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8310. if (!spell) {
  8311. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8312. return 0;
  8313. }
  8314. if(spell->resisted) {
  8315. return 0;
  8316. }
  8317. float snare = lua_interface->GetFloatValue(state);
  8318. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8319. // convert the val to the speed multipler value (100 - val)
  8320. float val = 100.0 - snare;
  8321. val /= 100.0;
  8322. if (spawn) {
  8323. if (!spawn->IsEntity()) {
  8324. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. ((Entity*)spawn)->SetSnareValue(spell, val);
  8328. }
  8329. else {
  8330. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8331. for (int8 i = 0; i < spell->targets.size(); i++) {
  8332. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8333. if (!spawn || !spawn->IsEntity())
  8334. continue;
  8335. ((Entity*)spawn)->SetSnareValue(spell, val);
  8336. }
  8337. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8338. }
  8339. return 0;
  8340. }
  8341. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8342. if (!lua_interface)
  8343. return 0;
  8344. Spawn* spawn = lua_interface->GetSpawn(state);
  8345. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8346. if (!spawn) {
  8347. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8348. return 0;
  8349. }
  8350. if (race_id == 0) {
  8351. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8352. return 0;
  8353. }
  8354. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8355. return 1;
  8356. }
  8357. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8358. if (!lua_interface)
  8359. return 0;
  8360. Spawn* spawn = lua_interface->GetSpawn(state);
  8361. if (!spawn) {
  8362. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8363. return 0;
  8364. }
  8365. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8366. return 1;
  8367. }
  8368. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8369. if (!lua_interface)
  8370. return 0;
  8371. Spawn* spawn = lua_interface->GetSpawn(state);
  8372. if (!spawn) {
  8373. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8374. return 0;
  8375. }
  8376. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8377. return 1;
  8378. }
  8379. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8380. if (!lua_interface)
  8381. return 0;
  8382. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8383. if (!spell) {
  8384. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8385. return 0;
  8386. }
  8387. lua_interface->SetStringValue(state, spell->spell->GetName());
  8388. return 1;
  8389. }
  8390. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8391. if (!lua_interface)
  8392. return 0;
  8393. Quest* quest = lua_interface->GetQuest(state);
  8394. if (!quest) {
  8395. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8396. return 0;
  8397. }
  8398. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8399. return 1;
  8400. }
  8401. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8402. if (!lua_interface)
  8403. return 0;
  8404. Quest* quest = lua_interface->GetQuest(state);
  8405. int32 flags = lua_interface->GetInt32Value(state, 2);
  8406. if (!quest) {
  8407. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8408. return 0;
  8409. }
  8410. quest->SetQuestFlags(flags);
  8411. return 0;
  8412. }
  8413. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8414. if (!lua_interface)
  8415. return 0;
  8416. Quest* quest = lua_interface->GetQuest(state);
  8417. Spawn* player = lua_interface->GetSpawn(state, 2);
  8418. int32 step = lua_interface->GetInt32Value(state, 3);
  8419. int32 duration = lua_interface->GetInt32Value(state, 4);
  8420. string action = lua_interface->GetStringValue(state, 5);
  8421. if (!quest) {
  8422. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. if (!player) {
  8426. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8427. return 0;
  8428. }
  8429. if (!player->IsPlayer()) {
  8430. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8431. return 0;
  8432. }
  8433. if (step == 0) {
  8434. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8435. return 0;
  8436. }
  8437. if (duration == 0) {
  8438. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8439. return 0;
  8440. }
  8441. if (action.length() == 0) {
  8442. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8443. return 0;
  8444. }
  8445. Client* client = player->GetZone()->GetClientBySpawn(player);
  8446. if (!client) {
  8447. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8448. return 0;
  8449. }
  8450. quest->SetTimerStep(step);
  8451. quest->AddFailedAction(step, action);
  8452. quest->SetStepTimer(duration);
  8453. client->AddQuestTimer(quest->GetQuestID());
  8454. return 0;
  8455. }
  8456. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8457. if (!lua_interface)
  8458. return 0;
  8459. Quest* quest = lua_interface->GetQuest(state);
  8460. Spawn* player = lua_interface->GetSpawn(state, 2);
  8461. if (!quest) {
  8462. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8463. return 0;
  8464. }
  8465. if (!player) {
  8466. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8467. return 0;
  8468. }
  8469. if (!player->IsPlayer()) {
  8470. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8471. return 0;
  8472. }
  8473. Client* client = player->GetZone()->GetClientBySpawn(player);
  8474. if (!client) {
  8475. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8476. return 0;
  8477. }
  8478. quest->SetTimerStep(0);
  8479. quest->SetStepTimer(0);
  8480. client->RemoveQuestTimer(quest->GetQuestID());
  8481. return 0;
  8482. }
  8483. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8484. if (!lua_interface)
  8485. return 0;
  8486. Spawn* player = lua_interface->GetSpawn(state);
  8487. Quest* quest = lua_interface->GetQuest(state, 2);
  8488. int32 step = lua_interface->GetInt32Value(state, 3);
  8489. if (!player) {
  8490. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8491. return 0;
  8492. }
  8493. if (!player->IsPlayer()) {
  8494. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8495. return 0;
  8496. }
  8497. if (!quest) {
  8498. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8499. return 0;
  8500. }
  8501. if (step == 0) {
  8502. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8503. return 0;
  8504. }
  8505. Client* client = player->GetZone()->GetClientBySpawn(player);
  8506. if (!client) {
  8507. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8508. return 0;
  8509. }
  8510. if (quest->RemoveQuestStep(step, client)) {
  8511. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8512. client->GetCurrentZone()->SendQuestUpdates(client);
  8513. }
  8514. else
  8515. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8516. return 0;
  8517. }
  8518. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8519. if (!lua_interface)
  8520. return 0;
  8521. Quest* quest = lua_interface->GetQuest(state, 1);
  8522. int32 step = lua_interface->GetInt32Value(state, 2);
  8523. string desc = lua_interface->GetStringValue(state, 3);
  8524. string task_group = lua_interface->GetStringValue(state, 4);
  8525. if (!quest) {
  8526. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8527. return 0;
  8528. }
  8529. if (step == 0) {
  8530. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8531. return 0;
  8532. }
  8533. QuestStep* quest_step = quest->GetQuestStep(step);
  8534. if (!quest_step) {
  8535. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. quest_step->SetStepProgress(0);
  8539. quest_step->SetTaskGroup(task_group);
  8540. quest_step->SetDescription(desc);
  8541. return 0;
  8542. }
  8543. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8544. if (!lua_interface)
  8545. return 0;
  8546. Quest* quest = lua_interface->GetQuest(state);
  8547. int32 step = lua_interface->GetInt32Value(state, 2);
  8548. string action = lua_interface->GetStringValue(state, 3);
  8549. if (!quest) {
  8550. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8551. return 0;
  8552. }
  8553. if (step == 0) {
  8554. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8555. return 0;
  8556. }
  8557. if (action.length() == 0) {
  8558. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8559. return 0;
  8560. }
  8561. quest->AddFailedAction(step, action);
  8562. return 0;
  8563. }
  8564. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8565. if (!lua_interface)
  8566. return 0;
  8567. Spawn* player = lua_interface->GetSpawn(state);
  8568. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8569. int32 step = lua_interface->GetInt32Value(state, 3);
  8570. if (!player) {
  8571. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8572. return 0;
  8573. }
  8574. if (!player->IsPlayer()) {
  8575. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8576. return 0;
  8577. }
  8578. if (quest_id == 0) {
  8579. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8580. return 0;
  8581. }
  8582. if (step == 0) {
  8583. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8584. return 0;
  8585. }
  8586. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8587. if (!quest) {
  8588. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8589. return 0;
  8590. }
  8591. quest->StepFailed(step);
  8592. return 0;
  8593. }
  8594. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8595. if (!lua_interface)
  8596. return 0;
  8597. Spawn* player = lua_interface->GetSpawn(state);
  8598. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8599. if (!player) {
  8600. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8601. return 0;
  8602. }
  8603. if (!player->IsPlayer()) {
  8604. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8605. return 0;
  8606. }
  8607. if (quest_id == 0) {
  8608. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8609. return 0;
  8610. }
  8611. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8612. if (!quest) {
  8613. lua_interface->SetInt32Value(state, 0);
  8614. return 1;
  8615. }
  8616. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8617. return 1;
  8618. }
  8619. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8620. if (!lua_interface)
  8621. return 0;
  8622. string name = lua_interface->GetStringValue(state);
  8623. string value = lua_interface->GetStringValue(state, 2);
  8624. string comment = lua_interface->GetStringValue(state, 3);
  8625. if (name.length() == 0) {
  8626. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8627. return 0;
  8628. }
  8629. if (value.length() == 0) {
  8630. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8631. return 0;
  8632. }
  8633. string varname = string("lua_").append(name);
  8634. Variable* var = variables.FindVariable(varname);
  8635. if (var)
  8636. var->SetValue(value.c_str());
  8637. else {
  8638. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8639. variables.AddVariable(var);
  8640. }
  8641. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8642. return 0;
  8643. }
  8644. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8645. if (!lua_interface)
  8646. return 0;
  8647. string name = lua_interface->GetStringValue(state);
  8648. if (name.length() == 0) {
  8649. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8650. return 0;
  8651. }
  8652. string varname = string("lua_").append(name);
  8653. Variable* var = variables.FindVariable(varname);
  8654. if (var)
  8655. lua_interface->SetStringValue(state, var->GetValue());
  8656. else
  8657. lua_interface->SetStringValue(state, "NULL");
  8658. return 1;
  8659. }
  8660. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8661. if (!lua_interface)
  8662. return 0;
  8663. Spawn* player = lua_interface->GetSpawn(state);
  8664. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8665. if (!player) {
  8666. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. if (!player->IsPlayer()) {
  8670. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8671. return 0;
  8672. }
  8673. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8674. return 1;
  8675. }
  8676. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8677. if (!lua_interface)
  8678. return 0;
  8679. Spawn* player = lua_interface->GetSpawn(state);
  8680. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8681. if (!player) {
  8682. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8683. return 0;
  8684. }
  8685. if (!player->IsPlayer()) {
  8686. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8687. return 0;
  8688. }
  8689. Language* language = master_languages_list.GetLanguage(language_id);
  8690. if (language)
  8691. {
  8692. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8693. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8694. }
  8695. return 0;
  8696. }
  8697. int EQ2Emu_lua_IsNight(lua_State* state) {
  8698. if (!lua_interface)
  8699. return 0;
  8700. ZoneServer* zone = lua_interface->GetZone(state);
  8701. if (!zone) {
  8702. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8703. return 0;
  8704. }
  8705. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8706. return 1;
  8707. }
  8708. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8709. if (!lua_interface)
  8710. return 0;
  8711. Spawn* spawn = lua_interface->GetSpawn(state);
  8712. if (!spawn) {
  8713. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8714. return 0;
  8715. }
  8716. if (!spawn->IsWidget()) {
  8717. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8718. return 0;
  8719. }
  8720. ((Widget*)spawn)->SetMultiFloorLift(true);
  8721. if (spawn->GetZone())
  8722. spawn->GetZone()->AddTransportSpawn(spawn);
  8723. return 0;
  8724. }
  8725. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8726. if (!lua_interface)
  8727. return 0;
  8728. Spawn* player = lua_interface->GetSpawn(state);
  8729. int32 path = lua_interface->GetInt32Value(state, 2);
  8730. if (!player) {
  8731. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8732. return 0;
  8733. }
  8734. if (!player->IsPlayer()) {
  8735. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8736. return 0;
  8737. }
  8738. if (path == 0) {
  8739. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8740. return 0;
  8741. }
  8742. Client* client = player->GetZone()->GetClientBySpawn(player);
  8743. if (!client) {
  8744. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8745. return 0;
  8746. }
  8747. client->SendFlightAutoMount(path);
  8748. return 0;
  8749. }
  8750. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8751. if (!lua_interface)
  8752. return 0;
  8753. Spawn* player = lua_interface->GetSpawn(state);
  8754. if (!player) {
  8755. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8756. return 0;
  8757. }
  8758. if (!player->IsPlayer()) {
  8759. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8760. return 0;
  8761. }
  8762. Client* client = player->GetZone()->GetClientBySpawn(player);
  8763. if (!client) {
  8764. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8765. return 0;
  8766. }
  8767. client->EndAutoMount();
  8768. return 0;
  8769. }
  8770. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8771. if (!lua_interface)
  8772. return 0;
  8773. Spawn* player = lua_interface->GetSpawn(state);
  8774. if (!player) {
  8775. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8776. return 0;
  8777. }
  8778. if (!player->IsPlayer()) {
  8779. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8780. return 0;
  8781. }
  8782. Client* client = player->GetZone()->GetClientBySpawn(player);
  8783. if (!client) {
  8784. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8785. return 0;
  8786. }
  8787. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8788. return 1;
  8789. }
  8790. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8791. if (!lua_interface)
  8792. return 0;
  8793. Spawn* player = lua_interface->GetSpawn(state);
  8794. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8795. int32 value = lua_interface->GetInt32Value(state, 3);
  8796. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8797. if (!player) {
  8798. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8799. return 0;
  8800. }
  8801. if (!player->IsPlayer()) {
  8802. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8803. return 0;
  8804. }
  8805. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8806. return 0;
  8807. }
  8808. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8809. if (!lua_interface)
  8810. return 0;
  8811. Spawn* player = lua_interface->GetSpawn(state);
  8812. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8813. if (!player) {
  8814. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8815. return 0;
  8816. }
  8817. if (!player->IsPlayer()) {
  8818. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8819. return 0;
  8820. }
  8821. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8822. if (!hd)
  8823. return 0;
  8824. lua_interface->SetInt32Value(state, hd->Value);
  8825. lua_interface->SetInt32Value(state, hd->Value2);
  8826. return 2;
  8827. }
  8828. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8829. if (!lua_interface)
  8830. return 0;
  8831. Spawn* spawn = lua_interface->GetSpawn(state);
  8832. int32 grid = lua_interface->GetInt32Value(state, 2);
  8833. if (!spawn) {
  8834. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8835. return 0;
  8836. }
  8837. if (grid == 0) {
  8838. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8839. return 0;
  8840. }
  8841. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8842. return 0;
  8843. }
  8844. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8845. if (!lua_interface)
  8846. return 0;
  8847. Spawn* spawn = lua_interface->GetSpawn(state);
  8848. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8849. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8850. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8851. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8852. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8853. if (!spawn) {
  8854. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8855. return 0;
  8856. }
  8857. //Add this quest to the list of required quests for this spawn
  8858. spawn->SetRequiredHistory(event_id, value1, value2);
  8859. //If private spawn value set
  8860. if (private_spawn) {
  8861. //Set the spawn to be private when not granted access via history
  8862. spawn->AddAllowAccessSpawn(spawn);
  8863. spawn->SetPrivateQuestSpawn(true);
  8864. }
  8865. //This value will override vis_flags in the vis packet
  8866. if (flag_override > 0)
  8867. spawn->SetQuestsRequiredOverride(flag_override);
  8868. return 0;
  8869. }
  8870. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8871. if (!lua_interface)
  8872. return 0;
  8873. Spawn* player = lua_interface->GetSpawn(state);
  8874. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8875. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8876. if (!player) {
  8877. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8878. return 0;
  8879. }
  8880. if (!player->IsPlayer()) {
  8881. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8882. return 0;
  8883. }
  8884. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8885. return 1;
  8886. }
  8887. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8888. if (!lua_interface)
  8889. return 0;
  8890. Spawn* player = lua_interface->GetSpawn(state);
  8891. int8 level = lua_interface->GetInt8Value(state, 2);
  8892. if (!player) {
  8893. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8894. return 0;
  8895. }
  8896. if (!player->IsPlayer()) {
  8897. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8898. return 0;
  8899. }
  8900. if (level == 0) {
  8901. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8902. return 0;
  8903. }
  8904. Client* client = player->GetZone()->GetClientBySpawn(player);
  8905. if (!client) {
  8906. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8907. return 0;
  8908. }
  8909. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8910. return 0;
  8911. }
  8912. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8913. if (!lua_interface)
  8914. return 0;
  8915. Spawn* player = lua_interface->GetSpawn(state);
  8916. int32 amount = lua_interface->GetInt32Value(state, 2);
  8917. if (!player) {
  8918. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8919. return 0;
  8920. }
  8921. if (!player->IsPlayer()) {
  8922. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8923. return 0;
  8924. }
  8925. if (amount == 0) {
  8926. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8927. return 0;
  8928. }
  8929. ((Player*)player)->AddCoins(amount);
  8930. return 0;
  8931. }
  8932. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8933. if (!lua_interface)
  8934. return 0;
  8935. Spawn* player = lua_interface->GetSpawn(state);
  8936. int32 amount = lua_interface->GetInt32Value(state, 2);
  8937. if (!player) {
  8938. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8939. return 0;
  8940. }
  8941. if (!player->IsPlayer()) {
  8942. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8943. return 0;
  8944. }
  8945. if (amount == 0) {
  8946. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8947. return 0;
  8948. }
  8949. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8950. return 1;
  8951. }
  8952. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8953. if (!lua_interface)
  8954. return 0;
  8955. ZoneServer* zone = lua_interface->GetZone(state);
  8956. if (!zone) {
  8957. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8958. return 0;
  8959. }
  8960. vector<Entity*> players = zone->GetPlayers();
  8961. if (players.size() == 0)
  8962. return 0;
  8963. lua_createtable(state, players.size(), 0);
  8964. int newTable = lua_gettop(state);
  8965. for (int32 i = 0; i < players.size(); i++) {
  8966. lua_interface->SetSpawnValue(state, players.at(i));
  8967. lua_rawseti(state, newTable, i + 1);
  8968. }
  8969. return 1;
  8970. }
  8971. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8972. if (!lua_interface)
  8973. return 0;
  8974. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8975. if (!zone) {
  8976. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8977. return 0;
  8978. }
  8979. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8980. //Map of <placement_id, location_id>
  8981. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8982. map<int32, int32>::iterator itr;
  8983. vector<Spawn*> group;
  8984. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8985. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8986. if (!location) {
  8987. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8988. return 0;
  8989. }
  8990. Spawn* spawn = 0;
  8991. if (location->entities[0]) {
  8992. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8993. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8994. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8995. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8996. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8997. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8998. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8999. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9000. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9001. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9002. if(spawn && spawn->IsOmittedByDBFlag())
  9003. {
  9004. 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);
  9005. safe_delete(spawn);
  9006. continue;
  9007. }
  9008. if (spawn) {
  9009. const char* script = 0;
  9010. for (int x = 0; x < 3; x++) {
  9011. switch (x) {
  9012. case 0:
  9013. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9014. break;
  9015. case 1:
  9016. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9017. break;
  9018. case 2:
  9019. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9020. break;
  9021. }
  9022. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9023. spawn->SetSpawnScript(string(script));
  9024. break;
  9025. }
  9026. }
  9027. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9028. lua_interface->SetSpawnValue(state, spawn);
  9029. group.push_back(spawn);
  9030. }
  9031. else {
  9032. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9033. safe_delete(spawn);
  9034. }
  9035. }
  9036. }
  9037. if (!group.empty()) {
  9038. lua_createtable(state, group.size(), 0);
  9039. int newTable = lua_gettop(state);
  9040. for (int32 i = 0; i < group.size(); i++) {
  9041. lua_interface->SetSpawnValue(state, group[i]);
  9042. lua_rawseti(state, newTable, i + 1);
  9043. }
  9044. }
  9045. else
  9046. lua_pushnil(state);
  9047. return 1;
  9048. }
  9049. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9050. if (!lua_interface)
  9051. return 0;
  9052. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9053. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9054. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9055. if (!spawn) {
  9056. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9057. return 0;
  9058. }
  9059. if (anim_id == 0) {
  9060. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9061. return 0;
  9062. }
  9063. if (leeway == 0)
  9064. leeway = 5000;
  9065. spawn->SetSpawnAnim(anim_id);
  9066. spawn->SetSpawnAnimLeeway(leeway);
  9067. return 0;
  9068. }
  9069. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9070. if (!lua_interface)
  9071. return 0;
  9072. Spawn* player = lua_interface->GetSpawn(state);
  9073. if (!player) {
  9074. return 0;
  9075. }
  9076. Client* client = player->GetZone()->GetClientBySpawn(player);
  9077. if (!client) {
  9078. return 0;
  9079. }
  9080. lua_interface->SetInt32Value(state, client->GetVersion());
  9081. return 1;
  9082. }
  9083. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9084. if (!lua_interface)
  9085. return 0;
  9086. Item* item = lua_interface->GetItem(state);
  9087. if (!item) {
  9088. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9089. return 0;
  9090. }
  9091. lua_interface->SetInt32Value(state, item->details.item_id);
  9092. return 1;
  9093. }
  9094. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9095. if (!lua_interface)
  9096. return 0;
  9097. Spawn* spawn = lua_interface->GetSpawn(state);
  9098. if (!spawn) {
  9099. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9100. return 0;
  9101. }
  9102. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9103. return 1;
  9104. }
  9105. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9106. if (!lua_interface)
  9107. return 0;
  9108. Spawn* spawn = lua_interface->GetSpawn(state);
  9109. if (!spawn) {
  9110. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9111. return 0;
  9112. }
  9113. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9114. return 1;
  9115. }
  9116. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9117. if (!lua_interface)
  9118. return 0;
  9119. Spawn* spawn = lua_interface->GetSpawn(state);
  9120. if (!spawn) {
  9121. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9122. return 0;
  9123. }
  9124. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9125. return 1;
  9126. }
  9127. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9128. if (!lua_interface)
  9129. return 0;
  9130. Spawn* spawn = lua_interface->GetSpawn(state);
  9131. if (!spawn) {
  9132. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9133. return 0;
  9134. }
  9135. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9136. return 1;
  9137. }
  9138. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9139. if (!lua_interface)
  9140. return 0;
  9141. Spawn* spawn = lua_interface->GetSpawn(state);
  9142. float pct = lua_interface->GetFloatValue(state, 2);
  9143. if (!spawn) {
  9144. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9145. return 0;
  9146. }
  9147. if (pct == 0) {
  9148. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9149. return 0;
  9150. }
  9151. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9152. lua_interface->SetInt32Value(state, amount);
  9153. return 1;
  9154. }
  9155. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9156. if (!lua_interface)
  9157. return 0;
  9158. Spawn* spawn = lua_interface->GetSpawn(state);
  9159. float pct = lua_interface->GetFloatValue(state, 2);
  9160. if (!spawn) {
  9161. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9162. return 0;
  9163. }
  9164. if (pct == 0) {
  9165. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9166. return 0;
  9167. }
  9168. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9169. lua_interface->SetInt32Value(state, amount);
  9170. return 1;
  9171. }
  9172. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9173. if (!lua_interface)
  9174. return 0;
  9175. Spawn* spawn = lua_interface->GetSpawn(state);
  9176. if (!spawn) {
  9177. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9178. return 0;
  9179. }
  9180. if (!spawn->IsPlayer()) {
  9181. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9182. return 0;
  9183. }
  9184. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9185. return 1;
  9186. }
  9187. int EQ2Emu_lua_Evac(lua_State* state) {
  9188. if (!lua_interface)
  9189. return 0;
  9190. Spawn* target = lua_interface->GetSpawn(state);
  9191. if (target) {
  9192. float x = target->GetZone()->GetSafeX();
  9193. float y = target->GetZone()->GetSafeY();
  9194. float z = target->GetZone()->GetSafeZ();
  9195. float h = target->GetZone()->GetSafeHeading();
  9196. target->SetX(x);
  9197. target->SetY(y);
  9198. target->SetZ(z);
  9199. target->SetHeading(h);
  9200. target->SetSpawnOrigX(x);
  9201. target->SetSpawnOrigY(y);
  9202. target->SetSpawnOrigZ(z);
  9203. target->SetSpawnOrigHeading(h);
  9204. if (target->IsPlayer()) {
  9205. Client* client = target->GetZone()->GetClientBySpawn(target);
  9206. if (client) {
  9207. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9208. int numargs = lua_interface->GetNumberOfArgs(state);
  9209. if(numargs == 4) {
  9210. x = lua_interface->GetFloatValue(state,1);
  9211. y = lua_interface->GetFloatValue(state,2);
  9212. z = lua_interface->GetFloatValue(state,3);
  9213. h = lua_interface->GetFloatValue(state,4);
  9214. }
  9215. client->SetReloadingZone(true);
  9216. target->SetX(x);
  9217. target->SetY(y);
  9218. target->SetZ(z);
  9219. target->SetHeading(h);
  9220. target->SetSpawnOrigX(x);
  9221. target->SetSpawnOrigY(y);
  9222. target->SetSpawnOrigZ(z);
  9223. target->SetSpawnOrigHeading(h);
  9224. target->SetAppearancePosition(x,y,z);
  9225. client->SetZoningCoords(x,y,z,h);
  9226. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9227. if (packet)
  9228. {
  9229. packet->setDataByName("x", x);
  9230. packet->setDataByName("y", y);
  9231. packet->setDataByName("z", z);
  9232. client->QueuePacket(packet->serialize());
  9233. safe_delete(packet);
  9234. }
  9235. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9236. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9237. }
  9238. }
  9239. }
  9240. else {
  9241. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9242. if(!spell)
  9243. return 0;
  9244. ZoneServer* zone = spell->caster->GetZone();
  9245. float x = spell->caster->GetZone()->GetSafeX();
  9246. float y = spell->caster->GetZone()->GetSafeY();
  9247. float z = spell->caster->GetZone()->GetSafeZ();
  9248. float h = spell->caster->GetZone()->GetSafeHeading();
  9249. int numargs = lua_interface->GetNumberOfArgs(state);
  9250. if(numargs == 4) {
  9251. x = lua_interface->GetFloatValue(state,1);
  9252. y = lua_interface->GetFloatValue(state,2);
  9253. z = lua_interface->GetFloatValue(state,3);
  9254. h = lua_interface->GetFloatValue(state,4);
  9255. }
  9256. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9257. for (int32 i = 0; i < spell->targets.size(); i++) {
  9258. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9259. if (!target2)
  9260. continue;
  9261. if (target2->IsPlayer()) {
  9262. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9263. if (client) {
  9264. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9265. client->SetReloadingZone(true);
  9266. target2->SetX(x);
  9267. target2->SetY(y);
  9268. target2->SetZ(z);
  9269. target2->SetHeading(h);
  9270. target2->SetSpawnOrigX(x);
  9271. target2->SetSpawnOrigY(y);
  9272. target2->SetSpawnOrigZ(z);
  9273. target2->SetSpawnOrigHeading(h);
  9274. target2->SetAppearancePosition(x,y,z);
  9275. client->SetZoningCoords(x,y,z,h);
  9276. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9277. if (packet)
  9278. {
  9279. packet->setDataByName("x", x);
  9280. packet->setDataByName("y", y);
  9281. packet->setDataByName("z", z);
  9282. client->QueuePacket(packet->serialize());
  9283. safe_delete(packet);
  9284. }
  9285. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9286. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9287. }
  9288. }
  9289. }
  9290. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9291. }
  9292. return 0;
  9293. }
  9294. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9295. if (!lua_interface)
  9296. return 0;
  9297. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9298. if (!luaspell) {
  9299. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9300. return 0;
  9301. }
  9302. int8 tier = luaspell->spell->GetSpellTier();
  9303. lua_interface->SetInt32Value(state, tier);
  9304. return 1;
  9305. }
  9306. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9307. if (!lua_interface)
  9308. return 0;
  9309. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9310. if (!luaspell) {
  9311. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9312. return 0;
  9313. }
  9314. int32 spell_id = luaspell->spell->GetSpellID();
  9315. lua_interface->SetInt32Value(state, spell_id);
  9316. return 1;
  9317. }
  9318. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9319. if (!lua_interface)
  9320. return 0;
  9321. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9322. if (!spawn) {
  9323. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9324. return 0;
  9325. }
  9326. if (!spawn->IsPlayer()) {
  9327. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9328. return 0;
  9329. }
  9330. ZoneServer* zone = spawn->GetZone();
  9331. if (!zone) {
  9332. return 0;
  9333. }
  9334. Client* client = zone->GetClientBySpawn(spawn);
  9335. if (!client) {
  9336. return 0;
  9337. }
  9338. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9339. return 0;
  9340. }
  9341. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9342. if (!lua_interface)
  9343. return 0;
  9344. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9345. if (!spawn) {
  9346. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9347. return 0;
  9348. }
  9349. if (!spawn->IsPlayer()) {
  9350. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9351. return 0;
  9352. }
  9353. ZoneServer* zone = spawn->GetZone();
  9354. if (!zone) {
  9355. return 0;
  9356. }
  9357. Client* client = zone->GetClientBySpawn(spawn);
  9358. if (!client) {
  9359. return 0;
  9360. }
  9361. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9362. return 0;
  9363. }
  9364. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9365. if (!lua_interface)
  9366. return 0;
  9367. Spawn* caster = lua_interface->GetSpawn(state);
  9368. Spawn* target = lua_interface->GetSpawn(state, 2);
  9369. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9370. string spell_name = lua_interface->GetStringValue(state, 4);
  9371. if (!caster) {
  9372. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9373. return 0;
  9374. }
  9375. if (!caster->IsEntity()) {
  9376. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9377. return 0;
  9378. }
  9379. if (!target) {
  9380. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9381. return 0;
  9382. }
  9383. if (!target->IsEntity()) {
  9384. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9385. return 0;
  9386. }
  9387. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9388. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9389. return 0;
  9390. }
  9391. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9392. if (!lua_interface)
  9393. return 0;
  9394. Spawn* player = lua_interface->GetSpawn(state);
  9395. int32 amount = lua_interface->GetInt32Value(state, 2);
  9396. if (player && player->IsPlayer() && amount > 0) {
  9397. ((Player*)player)->AddXP(amount);
  9398. ((Player*)player)->SetCharSheetChanged(true);
  9399. Client* client = player->GetZone()->GetClientBySpawn(player);
  9400. if (client) {
  9401. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9402. }
  9403. }
  9404. return 0;
  9405. }
  9406. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9407. if (!lua_interface)
  9408. return 0;
  9409. Spawn* player = lua_interface->GetSpawn(state);
  9410. int8 type = lua_interface->GetInt8Value(state, 2);
  9411. string text = lua_interface->GetStringValue(state, 3);
  9412. Client* client = 0;
  9413. if (player && player->IsPlayer())
  9414. client = player->GetZone()->GetClientBySpawn(player);
  9415. if (!client || text.length() == 0) {
  9416. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9417. return 0;
  9418. }
  9419. client->SimpleMessage(type, text.c_str());
  9420. return 0;
  9421. }
  9422. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9423. if (!lua_interface)
  9424. return 0;
  9425. Spawn* player = lua_interface->GetSpawn(state);
  9426. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9427. Client* client = 0;
  9428. if (player && player->IsPlayer())
  9429. client = player->GetZone()->GetClientBySpawn(player);
  9430. if (!client || !spawn) {
  9431. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9432. return 0;
  9433. }
  9434. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9435. if (!items) {
  9436. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9437. return 0;
  9438. }
  9439. client->Loot(spawn->GetLootCoins(), items, spawn);
  9440. return 0;
  9441. }
  9442. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9443. if (!lua_interface)
  9444. return 0;
  9445. Spawn* spawnref = lua_interface->GetSpawn(state);
  9446. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9447. if (spawn_id > 0 && spawnref) {
  9448. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9449. if (spawns.size() == 0) {
  9450. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9451. return 0;
  9452. }
  9453. Spawn* spawn = 0;
  9454. int16 index = MakeRandomInt(0, spawns.size());
  9455. if (index >= spawns.size() || index < 0)
  9456. index = 0;
  9457. spawn = spawns[index];
  9458. lua_interface->SetSpawnValue(state, spawn);
  9459. return 1;
  9460. }
  9461. else {
  9462. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9463. }
  9464. return 0;
  9465. }
  9466. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9467. Spawn* player = lua_interface->GetSpawn(state);
  9468. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9469. string name = lua_interface->GetStringValue(state, 3);
  9470. float distance = lua_interface->GetFloatValue(state, 4);
  9471. string command = lua_interface->GetStringValue(state, 5);
  9472. string error_text = lua_interface->GetStringValue(state, 6);
  9473. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9474. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9475. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9476. if (distance == 0)
  9477. distance = 10.0f;
  9478. if (command.length() == 0)
  9479. command = name;
  9480. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9481. if (spawns.size() == 0) {
  9482. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9483. return 0;
  9484. }
  9485. Spawn* spawn = 0;
  9486. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9487. spawn = *itr;
  9488. if (spawn) {
  9489. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9490. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9491. }
  9492. }
  9493. }
  9494. return 0;
  9495. }
  9496. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9497. if (!lua_interface)
  9498. return 0;
  9499. Client* client = 0;
  9500. Spawn* player = lua_interface->GetSpawn(state);
  9501. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9502. if (player && player->IsPlayer() && player->GetZone())
  9503. client = player->GetZone()->GetClientBySpawn(player);
  9504. else{
  9505. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9506. return 0;
  9507. }
  9508. if (client) {
  9509. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9510. if (packet) {
  9511. packet->setDataByName("goal_num", goal_num);
  9512. client->QueuePacket(packet->serialize());
  9513. safe_delete(packet);
  9514. }
  9515. }
  9516. return 0;
  9517. }
  9518. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9519. if (!lua_interface)
  9520. return 0;
  9521. Client* client = 0;
  9522. Spawn* player = lua_interface->GetSpawn(state);
  9523. if (player && player->IsPlayer() && player->GetZone())
  9524. client = player->GetZone()->GetClientBySpawn(player);
  9525. else {
  9526. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9527. return 0;
  9528. }
  9529. if (client) {
  9530. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9531. }
  9532. return 0;
  9533. }
  9534. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9535. if (!lua_interface)
  9536. return 0;
  9537. Client* client = 0;
  9538. Spawn* player = lua_interface->GetSpawn(state);
  9539. float duration = lua_interface->GetFloatValue(state, 2);
  9540. string text = lua_interface->GetStringValue(state, 3);
  9541. string voice = lua_interface->GetStringValue(state, 4);
  9542. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9543. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9544. string signal = lua_interface->GetStringValue(state, 7);
  9545. string goal1 = lua_interface->GetStringValue(state, 8);
  9546. string task1 = lua_interface->GetStringValue(state, 9);
  9547. string goal2 = lua_interface->GetStringValue(state, 10);
  9548. string task2 = lua_interface->GetStringValue(state, 11);
  9549. string goal3 = lua_interface->GetStringValue(state, 12);
  9550. string task3 = lua_interface->GetStringValue(state, 13);
  9551. string goal4 = lua_interface->GetStringValue(state, 14);
  9552. string task4 = lua_interface->GetStringValue(state, 15);
  9553. if (!player) {
  9554. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9555. return 0;
  9556. }
  9557. if (!player->IsPlayer()) {
  9558. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9559. return 0;
  9560. }
  9561. else
  9562. client = ((Player*)player)->GetClient();
  9563. if (!client) {
  9564. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9565. return 0;
  9566. }
  9567. if (text.length() == 0) {
  9568. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9569. return 0;
  9570. }
  9571. if (duration >= 0 && duration < 2)
  9572. duration = 2;
  9573. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9574. if (packet) {
  9575. packet->setDataByName("open_seconds_max", duration);
  9576. packet->setDataByName("text", text.c_str());
  9577. packet->setDataByName("voice", voice.c_str());
  9578. int8 num_goals = 1;
  9579. if (task2.length() > 0)
  9580. num_goals++;
  9581. if (task3.length() > 0)
  9582. num_goals++;
  9583. if (task4.length() > 0)
  9584. num_goals++;
  9585. packet->setArrayLengthByName("num_goals", num_goals);
  9586. for (int8 i = 0; i < num_goals; i++) {
  9587. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9588. }
  9589. if (goal1.length() > 0)
  9590. packet->setArrayDataByName("goal_text", goal1.c_str());
  9591. if (goal2.length() > 0)
  9592. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9593. if (goal3.length() > 0)
  9594. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9595. if (goal4.length() > 0)
  9596. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9597. packet->setSubArrayDataByName("task_text", task1.c_str());
  9598. if (task2.length() > 0)
  9599. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9600. if (task3.length() > 0)
  9601. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9602. if (task4.length() > 0)
  9603. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9604. packet->setDataByName("complete_sound", "click");
  9605. packet->setDataByName("signal", signal.c_str());
  9606. packet->setDataByName("voice_key1", voice_key1);
  9607. packet->setDataByName("voice_key2", voice_key2);
  9608. client->QueuePacket(packet->serialize());
  9609. safe_delete(packet);
  9610. }
  9611. return 0;
  9612. }
  9613. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9614. if (!lua_interface)
  9615. return 0;
  9616. Client* client = 0;
  9617. Spawn* player = lua_interface->GetSpawn(state);
  9618. string window = lua_interface->GetStringValue(state, 2);
  9619. int8 show = lua_interface->GetInt8Value(state, 3);
  9620. if (!player) {
  9621. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9622. return 0;
  9623. }
  9624. if (!player->IsPlayer()) {
  9625. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9626. return 0;
  9627. }
  9628. else
  9629. client = ((Player*)player)->GetClient();
  9630. if (!client) {
  9631. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9632. return 0;
  9633. }
  9634. if (window.length() == 0) {
  9635. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9636. return 0;
  9637. }
  9638. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9639. if (packet) {
  9640. packet->setDataByName("window", window.c_str());
  9641. packet->setDataByName("show", show);
  9642. client->QueuePacket(packet->serialize());
  9643. safe_delete(packet);
  9644. }
  9645. return 0;
  9646. }
  9647. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9648. //See GameEvents.txt for options that can be used for this function
  9649. if (!lua_interface)
  9650. return 0;
  9651. Client* client = 0;
  9652. Spawn* player = lua_interface->GetSpawn(state);
  9653. string event_name = lua_interface->GetStringValue(state, 2);
  9654. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9655. if (!player || !player->IsPlayer()) {
  9656. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9657. return 0;
  9658. }
  9659. if (player->GetZone())
  9660. client = player->GetZone()->GetClientBySpawn(player);
  9661. if (!client) {
  9662. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9663. return 0;
  9664. }
  9665. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9666. if (packet) {
  9667. packet->setDataByName("event_name", event_name.c_str());
  9668. packet->setDataByName("enabled", enabled);
  9669. client->QueuePacket(packet->serialize());
  9670. safe_delete(packet);
  9671. }
  9672. return 0;
  9673. }
  9674. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9675. if (!lua_interface)
  9676. return 0;
  9677. Spawn* player = lua_interface->GetSpawn(state);
  9678. if (player && player->IsPlayer()) {
  9679. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9680. return 1;
  9681. }
  9682. return 0;
  9683. }
  9684. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9685. if (!lua_interface)
  9686. return 0;
  9687. Spawn* player = lua_interface->GetSpawn(state);
  9688. int8 step = lua_interface->GetInt8Value(state, 2);
  9689. if (player && player->IsPlayer() && step > 0) {
  9690. ((Player*)player)->SetTutorialStep(step);
  9691. }
  9692. return 0;
  9693. }
  9694. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9695. if (!lua_interface)
  9696. return 0;
  9697. Client* client = 0;
  9698. Spawn* player = lua_interface->GetSpawn(state);
  9699. string window = lua_interface->GetStringValue(state, 2);
  9700. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9701. if (!player) {
  9702. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9703. return 0;
  9704. }
  9705. if (!player->IsPlayer()) {
  9706. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9707. return 0;
  9708. }
  9709. else
  9710. client = ((Player*)player)->GetClient();
  9711. if (!client) {
  9712. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9713. return 0;
  9714. }
  9715. if (window.length() == 0) {
  9716. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9717. return 0;
  9718. }
  9719. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9720. if (packet) {
  9721. packet->setDataByName("window", window.c_str());
  9722. packet->setDataByName("flash_seconds", flash_seconds);
  9723. client->QueuePacket(packet->serialize());
  9724. safe_delete(packet);
  9725. }
  9726. return 0;
  9727. }
  9728. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9729. if (!lua_interface)
  9730. return 0;
  9731. Spawn* spawn = lua_interface->GetSpawn(state);
  9732. Spawn* target = lua_interface->GetSpawn(state, 2);
  9733. if (spawn && target)
  9734. return spawn->CheckLoS(target);
  9735. return 0;
  9736. }
  9737. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9738. if (!lua_interface)
  9739. return 0;
  9740. Spawn* spawn = lua_interface->GetSpawn(state);
  9741. float x = lua_interface->GetFloatValue(state, 2);
  9742. float y = lua_interface->GetFloatValue(state, 3);
  9743. float z = lua_interface->GetFloatValue(state, 4);
  9744. if (spawn)
  9745. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9746. return 0;
  9747. }
  9748. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9749. if (!lua_interface)
  9750. return 0;
  9751. ZoneServer* zone = lua_interface->GetZone(state);
  9752. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9753. if (zone)
  9754. zone->SetExpansionFlag(xpackFlag);
  9755. return 0;
  9756. }
  9757. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9758. if (!lua_interface)
  9759. return 0;
  9760. ZoneServer* zone = lua_interface->GetZone(state);
  9761. if (zone) {
  9762. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9763. return 1;
  9764. }
  9765. return 0;
  9766. }
  9767. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9768. if (!lua_interface)
  9769. return 0;
  9770. ZoneServer* zone = lua_interface->GetZone(state);
  9771. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9772. if (zone)
  9773. zone->SetHolidayFlag(holidayFlag);
  9774. return 0;
  9775. }
  9776. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9777. if (!lua_interface)
  9778. return 0;
  9779. ZoneServer* zone = lua_interface->GetZone(state);
  9780. if (zone) {
  9781. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9782. return 1;
  9783. }
  9784. return 0;
  9785. }
  9786. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  9787. if (!lua_interface)
  9788. return 0;
  9789. Spawn* player = lua_interface->GetSpawn(state);
  9790. ZoneServer* zone = player->GetZone();
  9791. bool canbind = lua_interface->GetInt32Value(state, 2);
  9792. if (zone)
  9793. zone->SetCanBind(canbind);
  9794. return 0;
  9795. }
  9796. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  9797. if (!lua_interface)
  9798. return 0;
  9799. Spawn* player = lua_interface->GetSpawn(state);
  9800. ZoneServer* zone = player->GetZone();
  9801. if (zone) {
  9802. lua_interface->SetInt32Value(state, zone->GetCanBind());
  9803. return 1;
  9804. }
  9805. return 0;
  9806. }
  9807. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  9808. if (!lua_interface)
  9809. return 0;
  9810. Spawn* player = lua_interface->GetSpawn(state);
  9811. ZoneServer* zone = player->GetZone();
  9812. bool cangate = lua_interface->GetInt32Value(state, 2);
  9813. if (zone)
  9814. zone->SetCanGate(cangate);
  9815. return 0;
  9816. }
  9817. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  9818. if (!lua_interface)
  9819. return 0;
  9820. Spawn* player = lua_interface->GetSpawn(state);
  9821. ZoneServer* zone = player->GetZone();
  9822. if (zone) {
  9823. lua_interface->SetInt32Value(state, zone->GetCanGate());
  9824. return 1;
  9825. }
  9826. return 0;
  9827. }
  9828. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9829. if (!lua_interface)
  9830. return 0;
  9831. Spawn* spawn = lua_interface->GetSpawn(state);
  9832. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9833. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9834. float distance = lua_interface->GetFloatValue(state, 4);
  9835. string in_range_function = lua_interface->GetStringValue(state, 5);
  9836. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9837. if (spawn && distance > 0 && in_range_function.length() > 0)
  9838. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9839. return 0;
  9840. }
  9841. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9842. if (!lua_interface)
  9843. return 0;
  9844. Spawn* spawn = lua_interface->GetSpawn(state);
  9845. Spawn* target = lua_interface->GetSpawn(state, 2);
  9846. if (spawn && target)
  9847. {
  9848. if (spawn->IsPlayer() && target->IsEntity())
  9849. {
  9850. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9851. return 1;
  9852. }
  9853. else if (spawn->IsEntity() && target->IsEntity())
  9854. {
  9855. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9856. return 1;
  9857. }
  9858. }
  9859. return 0;
  9860. }
  9861. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9862. if (!lua_interface)
  9863. return 0;
  9864. Spawn* spawn = lua_interface->GetSpawn(state);
  9865. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9866. if (spawn && spawn->IsEntity())
  9867. {
  9868. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9869. if (spawn->IsPlayer())
  9870. {
  9871. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9872. if (client)
  9873. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9874. }
  9875. }
  9876. return 0;
  9877. }
  9878. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9879. if (!lua_interface)
  9880. return 0;
  9881. Spawn* spawn = lua_interface->GetSpawn(state);
  9882. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9883. if (spawn && spawn->IsEntity())
  9884. {
  9885. ((Entity*)spawn)->SetSeeHideSpell(val);
  9886. if (spawn->IsPlayer())
  9887. {
  9888. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9889. if (client)
  9890. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9891. }
  9892. }
  9893. return 0;
  9894. }
  9895. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9896. {
  9897. if (!lua_interface)
  9898. return 0;
  9899. Spawn* player = lua_interface->GetSpawn(state);
  9900. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9901. string command = lua_interface->GetStringValue(state, 3);
  9902. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9903. lua_interface->ResetFunctionStack(state);
  9904. if (spawn && player && player->IsPlayer())
  9905. {
  9906. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9907. bool res = false;
  9908. if (cmd)
  9909. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9910. lua_interface->SetBooleanValue(state, res);
  9911. return 1;
  9912. }
  9913. return 0;
  9914. }
  9915. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9916. {
  9917. if (!lua_interface)
  9918. return 0;
  9919. Spawn* spawn = lua_interface->GetSpawn(state);
  9920. int32 charID = lua_interface->GetInt32Value(state, 2);
  9921. string command = lua_interface->GetStringValue(state, 3);
  9922. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9923. lua_interface->ResetFunctionStack(state);
  9924. if (spawn && charID)
  9925. {
  9926. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9927. bool res = false;
  9928. if (cmd)
  9929. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9930. lua_interface->SetBooleanValue(state, res);
  9931. return 1;
  9932. }
  9933. return 0;
  9934. }
  9935. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9936. {
  9937. if (!lua_interface)
  9938. return 0;
  9939. Spawn* spawn = lua_interface->GetSpawn(state);
  9940. string command = lua_interface->GetStringValue(state, 2);
  9941. lua_interface->ResetFunctionStack(state);
  9942. if (spawn && command.length() > 0)
  9943. spawn->RemovePrimaryEntityCommand(command.c_str());
  9944. return 0;
  9945. }
  9946. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9947. if (!lua_interface)
  9948. return 0;
  9949. Spawn* spawn = lua_interface->GetSpawn(state);
  9950. float distance = lua_interface->GetFloatValue(state, 2);
  9951. string command = lua_interface->GetStringValue(state, 3);
  9952. Spawn* player = lua_interface->GetSpawn(state, 4);
  9953. lua_interface->ResetFunctionStack(state);
  9954. if (spawn) {
  9955. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9956. }
  9957. return 0;
  9958. }
  9959. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9960. if (!lua_interface)
  9961. return 0;
  9962. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9963. Spawn* spawn = lua_interface->GetSpawn(state);
  9964. Spawn* player = lua_interface->GetSpawn(state, 2);
  9965. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9966. lua_interface->ResetFunctionStack(state);
  9967. if (spawn && player && transport_id && player->IsPlayer()) {
  9968. Client* client = 0;
  9969. if (player && player->IsPlayer())
  9970. client = player->GetZone()->GetClientBySpawn(player);
  9971. if (!client)
  9972. return 0;
  9973. vector<TransportDestination*> destinations;
  9974. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9975. if (destinations.size())
  9976. {
  9977. client->SetTemporaryTransportID(transport_id);
  9978. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9979. }
  9980. else
  9981. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9982. }
  9983. return 0;
  9984. }
  9985. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9986. if (!lua_interface)
  9987. return 0;
  9988. Spawn* player = lua_interface->GetSpawn(state);
  9989. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9990. lua_interface->ResetFunctionStack(state);
  9991. if (player && player->IsPlayer()) {
  9992. Client* client = 0;
  9993. if (player && player->IsPlayer())
  9994. client = player->GetZone()->GetClientBySpawn(player);
  9995. if (!client)
  9996. return 0;
  9997. client->SetTemporaryTransportID(transport_id);
  9998. }
  9999. return 0;
  10000. }
  10001. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10002. if (!lua_interface)
  10003. return 0;
  10004. Spawn* player = lua_interface->GetSpawn(state);
  10005. lua_interface->ResetFunctionStack(state);
  10006. if (player && player->IsPlayer()) {
  10007. Client* client = 0;
  10008. if (player && player->IsPlayer())
  10009. client = player->GetZone()->GetClientBySpawn(player);
  10010. if (!client)
  10011. return 0;
  10012. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10013. return 1;
  10014. }
  10015. return 0;
  10016. }
  10017. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10018. if (!lua_interface)
  10019. return 0;
  10020. Spawn* spawn = lua_interface->GetSpawn(state);
  10021. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10022. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10023. if (!spawn) {
  10024. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10025. return 0;
  10026. }
  10027. if (!spawn->IsEntity()) {
  10028. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10029. return 0;
  10030. }
  10031. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10032. {
  10033. 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);
  10034. return 0;
  10035. }
  10036. lua_interface->ResetFunctionStack(state);
  10037. if (spell && spell->targets.size() > 0) {
  10038. ZoneServer* zone = spell->caster->GetZone();
  10039. for (int8 i = 0; i < spell->targets.size(); i++) {
  10040. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10041. if (target && target->IsEntity()) {
  10042. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10043. if (target->IsPlayer())
  10044. ((Player*)target)->SetCharSheetChanged(true);
  10045. }
  10046. }
  10047. }
  10048. else {
  10049. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10050. if (spawn->IsPlayer())
  10051. ((Player*)spawn)->SetCharSheetChanged(true);
  10052. }
  10053. return 0;
  10054. }
  10055. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10056. if (!lua_interface)
  10057. return 0;
  10058. Spawn* spawn = lua_interface->GetSpawn(state);
  10059. lua_interface->ResetFunctionStack(state);
  10060. if (!spawn) {
  10061. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10062. return 0;
  10063. }
  10064. if (!spawn->IsEntity()) {
  10065. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10066. return 0;
  10067. }
  10068. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10069. return 1;
  10070. }
  10071. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10072. if (!lua_interface)
  10073. return 0;
  10074. int32 spell_id = lua_interface->GetInt32Value(state);
  10075. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10076. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10077. if (spell_id > 0) {
  10078. if (spell_tier == 0)
  10079. spell_tier = 1;
  10080. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10081. LuaSpell* lua_spell = 0;
  10082. if(custom_lua_script.size() > 0)
  10083. {
  10084. // attempt to load the custom script since it isn't already loaded
  10085. // we will re-obtain the lua_spell further below
  10086. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10087. {
  10088. 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());
  10089. lua_interface->LoadLuaSpell(custom_lua_script);
  10090. }
  10091. }
  10092. else
  10093. custom_lua_script = spell->GetSpellData()->lua_script;
  10094. if (!lua_spell && lua_interface)
  10095. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10096. if (!lua_spell)
  10097. {
  10098. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10099. return 0;
  10100. }
  10101. lua_spell->spell = new Spell(spell);
  10102. lua_interface->AddCustomSpell(lua_spell);
  10103. lua_interface->SetSpellValue(state, lua_spell);
  10104. return 1;
  10105. }
  10106. return 0;
  10107. }
  10108. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10109. if (!lua_interface)
  10110. return 0;
  10111. LuaSpell* spell = lua_interface->GetSpell(state);
  10112. string field = lua_interface->GetStringValue(state, 2);
  10113. if (!spell) {
  10114. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10115. return 0;
  10116. }
  10117. if (!spell->spell || !spell->spell->GetSpellData()) {
  10118. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10119. return 0;
  10120. }
  10121. boost::to_lower(field);
  10122. return spell->spell->GetSpellData(state, field);
  10123. }
  10124. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10125. if (!lua_interface)
  10126. return 0;
  10127. LuaSpell* spell = lua_interface->GetSpell(state);
  10128. string field = lua_interface->GetStringValue(state, 2);
  10129. int8 fieldArg = 3; // field value after the initial set
  10130. if (!spell) {
  10131. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10132. return 0;
  10133. }
  10134. if (!spell->spell || !spell->spell->GetSpellData()) {
  10135. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10136. return 0;
  10137. }
  10138. boost::to_lower(field);
  10139. bool valSet = false;
  10140. spell->spell->SetSpellData(state, field, fieldArg);
  10141. return valSet;
  10142. }
  10143. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10144. if (!lua_interface)
  10145. return 0;
  10146. LuaSpell* spell = lua_interface->GetSpell(state);
  10147. int8 idx = lua_interface->GetInt32Value(state, 2);
  10148. if (!spell) {
  10149. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10150. return 0;
  10151. }
  10152. if (!spell->spell || !spell->spell->GetSpellData()) {
  10153. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10154. return 0;
  10155. }
  10156. if (spell->spell->lua_data.size() <= idx)
  10157. {
  10158. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10159. return 0;
  10160. }
  10161. bool setVal = true;
  10162. LUAData* data = spell->spell->lua_data[idx];
  10163. switch (data->type)
  10164. {
  10165. case 0:
  10166. {
  10167. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10168. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10169. data->int_value = value;
  10170. data->int_value2 = value2;
  10171. break;
  10172. }
  10173. case 1:
  10174. {
  10175. float value = lua_interface->GetFloatValue(state, 3);
  10176. float value2 = lua_interface->GetFloatValue(state, 4);
  10177. data->float_value = value;
  10178. data->float_value2 = value2;
  10179. break;
  10180. }
  10181. case 2:
  10182. {
  10183. bool value = lua_interface->GetBooleanValue(state, 3);
  10184. data->bool_value = value;
  10185. break;
  10186. }
  10187. case 3:
  10188. {
  10189. string value = lua_interface->GetStringValue(state, 3);
  10190. string value2 = lua_interface->GetStringValue(state, 4);
  10191. data->string_value = value;
  10192. data->string_value2 = value2;
  10193. break;
  10194. }
  10195. default:
  10196. setVal = false;
  10197. }
  10198. return setVal;
  10199. }
  10200. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10201. if (!lua_interface)
  10202. return 0;
  10203. LuaSpell* spell = lua_interface->GetSpell(state);
  10204. int8 idx = lua_interface->GetInt32Value(state, 2);
  10205. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10206. if (!spell) {
  10207. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10208. return 0;
  10209. }
  10210. if (!spell->spell || !spell->spell->GetSpellData()) {
  10211. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10212. return 0;
  10213. }
  10214. if (spell->spell->lua_data.size() <= idx)
  10215. {
  10216. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10217. return 0;
  10218. }
  10219. bool setVal = true;
  10220. LUAData* data = spell->spell->lua_data[idx];
  10221. switch (data->type)
  10222. {
  10223. case 0:
  10224. {
  10225. if(!secondfield)
  10226. lua_interface->SetSInt32Value(state, data->int_value);
  10227. else
  10228. lua_interface->SetSInt32Value(state, data->int_value2);
  10229. break;
  10230. }
  10231. case 1:
  10232. {
  10233. if (!secondfield)
  10234. lua_interface->SetFloatValue(state, data->float_value);
  10235. else
  10236. lua_interface->SetFloatValue(state, data->float_value2);
  10237. break;
  10238. }
  10239. case 2:
  10240. {
  10241. lua_interface->SetBooleanValue(state, data->bool_value);
  10242. break;
  10243. }
  10244. case 3:
  10245. {
  10246. if (!secondfield)
  10247. lua_interface->SetStringValue(state, data->string_value.c_str());
  10248. else
  10249. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10250. break;
  10251. }
  10252. default:
  10253. setVal = false;
  10254. }
  10255. return setVal;
  10256. }
  10257. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10258. if (!lua_interface)
  10259. return 0;
  10260. LuaSpell* spell = lua_interface->GetSpell(state);
  10261. int8 idx = lua_interface->GetInt32Value(state, 2);
  10262. string field = lua_interface->GetStringValue(state, 3);
  10263. boost::to_lower(field);
  10264. if (!spell) {
  10265. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10266. return 0;
  10267. }
  10268. if (!spell->spell || !spell->spell->GetSpellData()) {
  10269. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10270. return 0;
  10271. }
  10272. if (spell->spell->effects.size() <= idx)
  10273. {
  10274. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10275. return 0;
  10276. }
  10277. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10278. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10279. if (field == "description")
  10280. effect->description = string(lua_interface->GetStringValue(state, 4));
  10281. else if (field == "bullet")
  10282. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10283. else if (field == "percentage")
  10284. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10285. else // no match
  10286. return 0;
  10287. return 1;
  10288. }
  10289. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10290. if (!lua_interface)
  10291. return 0;
  10292. LuaSpell* spell = lua_interface->GetSpell(state);
  10293. int8 idx = lua_interface->GetInt32Value(state, 2);
  10294. string field = lua_interface->GetStringValue(state, 3);
  10295. boost::to_lower(field);
  10296. if (!spell) {
  10297. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10298. return 0;
  10299. }
  10300. if (!spell->spell || !spell->spell->GetSpellData()) {
  10301. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10302. return 0;
  10303. }
  10304. if (spell->spell->effects.size() <= idx)
  10305. {
  10306. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10307. return 0;
  10308. }
  10309. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10310. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10311. if (field == "description")
  10312. lua_interface->SetStringValue(state, effect->description.c_str());
  10313. else if (field == "bullet")
  10314. lua_interface->SetInt32Value(state, effect->subbullet);
  10315. else if (field == "percentage")
  10316. lua_interface->SetInt32Value(state, effect->percentage);
  10317. else // no match
  10318. return 0;
  10319. return 1;
  10320. }
  10321. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10322. if (!lua_interface)
  10323. return 0;
  10324. LuaSpell* spell = lua_interface->GetSpell(state);
  10325. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10326. Spawn* target = lua_interface->GetSpawn(state, 3);
  10327. if (!target) {
  10328. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10329. return 0;
  10330. }
  10331. if (!target->IsEntity()) {
  10332. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10333. return 0;
  10334. }
  10335. if (!spell) {
  10336. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10337. return 0;
  10338. }
  10339. if (caster && !caster->IsEntity()) {
  10340. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10341. return 0;
  10342. }
  10343. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10344. return 0;
  10345. }
  10346. int EQ2Emu_lua_InWater(lua_State* state) {
  10347. if (!lua_interface)
  10348. return 0;
  10349. Spawn* spawn = lua_interface->GetSpawn(state);
  10350. lua_interface->ResetFunctionStack(state);
  10351. if (spawn) {
  10352. lua_interface->SetBooleanValue(state, spawn->InWater());
  10353. return 1;
  10354. }
  10355. return 0;
  10356. }
  10357. int EQ2Emu_lua_InLava(lua_State* state) {
  10358. if (!lua_interface)
  10359. return 0;
  10360. Spawn* spawn = lua_interface->GetSpawn(state);
  10361. lua_interface->ResetFunctionStack(state);
  10362. if (spawn) {
  10363. lua_interface->SetBooleanValue(state, spawn->InLava());
  10364. return 1;
  10365. }
  10366. return 0;
  10367. }
  10368. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10369. if (!lua_interface)
  10370. return 0;
  10371. Spawn* attacker = lua_interface->GetSpawn(state);
  10372. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10373. int8 type = lua_interface->GetInt8Value(state, 3);
  10374. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10375. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10376. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10377. string spell_name = lua_interface->GetStringValue(state, 7);
  10378. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10379. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10380. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10381. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10382. lua_interface->ResetFunctionStack(state);
  10383. if (!attacker) {
  10384. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10385. return 0;
  10386. }
  10387. if (!attacker->IsEntity()) {
  10388. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10389. return 0;
  10390. }
  10391. if (!victim) {
  10392. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10393. return 0;
  10394. }
  10395. if (!victim->IsEntity()) {
  10396. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10397. return 0;
  10398. }
  10399. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10400. return 0;
  10401. }
  10402. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10403. if (!lua_interface)
  10404. return 0;
  10405. Spawn* spawn = lua_interface->GetSpawn(state);
  10406. lua_interface->ResetFunctionStack(state);
  10407. if (spawn) {
  10408. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10409. return 1;
  10410. }
  10411. return 0;
  10412. }
  10413. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10414. if (!lua_interface)
  10415. return 0;
  10416. Spawn* spawn = lua_interface->GetSpawn(state);
  10417. bool invul = lua_interface->GetBooleanValue(state, 2);
  10418. lua_interface->ResetFunctionStack(state);
  10419. if (spawn) {
  10420. spawn->SetInvulnerable(invul);
  10421. }
  10422. return 0;
  10423. }
  10424. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10425. if (!lua_interface)
  10426. return 0;
  10427. string category = lua_interface->GetStringValue(state);
  10428. string name = lua_interface->GetStringValue(state, 2);
  10429. lua_interface->ResetFunctionStack(state);
  10430. Rule *ret = 0;
  10431. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10432. lua_interface->SetBooleanValue(state, ret->GetBool());
  10433. return 1;
  10434. }
  10435. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10436. return 0;
  10437. }
  10438. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10439. if (!lua_interface)
  10440. return 0;
  10441. string category = lua_interface->GetStringValue(state);
  10442. string name = lua_interface->GetStringValue(state, 2);
  10443. lua_interface->ResetFunctionStack(state);
  10444. Rule *ret = 0;
  10445. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10446. lua_interface->SetInt32Value(state, ret->GetInt32());
  10447. return 1;
  10448. }
  10449. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10450. return 0;
  10451. }
  10452. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10453. if (!lua_interface)
  10454. return 0;
  10455. string category = lua_interface->GetStringValue(state);
  10456. string name = lua_interface->GetStringValue(state, 2);
  10457. lua_interface->ResetFunctionStack(state);
  10458. Rule *ret = 0;
  10459. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10460. lua_interface->SetFloatValue(state, ret->GetFloat());
  10461. return 1;
  10462. }
  10463. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10464. return 0;
  10465. }
  10466. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10467. if (!lua_interface)
  10468. return 0;
  10469. Spawn* spawn = lua_interface->GetSpawn(state);
  10470. string type = lua_interface->GetStringValue(state, 2);
  10471. lua_interface->ResetFunctionStack(state);
  10472. if (spawn) {
  10473. int res = 1;
  10474. boost::to_lower(type);
  10475. if(type == "assigned_aa")
  10476. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10477. else if ( type == "unassigned_aa")
  10478. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10479. else if ( type == "assigned_tradeskill_aa")
  10480. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10481. else if ( type == "unassigned_tradeskill_aa")
  10482. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10483. else if ( type == "assigned_prestige_aa")
  10484. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10485. else if ( type == "unassigned_prestige_aa")
  10486. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10487. else if ( type == "assigned_tradeskill_prestige_aa")
  10488. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10489. else if ( type == "unassigned_tradeskill_prestige_aa")
  10490. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10491. else
  10492. res = 0;
  10493. return res;
  10494. }
  10495. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10496. return 0;
  10497. }
  10498. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10499. if (!lua_interface)
  10500. return 0;
  10501. Spawn* spawn = lua_interface->GetSpawn(state);
  10502. string type = lua_interface->GetStringValue(state, 2);
  10503. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10504. lua_interface->ResetFunctionStack(state);
  10505. if (spawn) {
  10506. boost::to_lower(type);
  10507. if(type == "assigned_aa")
  10508. spawn->SetAssignedAA((sint16)value);
  10509. else if ( type == "unassigned_aa")
  10510. spawn->SetUnassignedAA((sint16)value);
  10511. else if ( type == "assigned_tradeskill_aa")
  10512. spawn->SetTradeskillAA((sint16)value);
  10513. else if ( type == "unassigned_tradeskill_aa")
  10514. spawn->SetUnassignedTradeskillAA((sint16)value);
  10515. else if ( type == "assigned_prestige_aa")
  10516. spawn->SetPrestigeAA((sint16)value);
  10517. else if ( type == "unassigned_prestige_aa")
  10518. spawn->SetUnassignedPrestigeAA((sint16)value);
  10519. else if ( type == "assigned_tradeskill_prestige_aa")
  10520. spawn->SetTradeskillPrestigeAA((sint16)value);
  10521. else if ( type == "unassigned_tradeskill_prestige_aa")
  10522. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10523. if(spawn->IsPlayer())
  10524. ((Player*)spawn)->SetCharSheetChanged(true);
  10525. }
  10526. return 0;
  10527. }
  10528. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10529. if (!lua_interface)
  10530. return 0;
  10531. string titleName = lua_interface->GetStringValue(state);
  10532. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10533. lua_interface->ResetFunctionStack(state);
  10534. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10535. lua_interface->SetSInt32Value(state, index);
  10536. return 1;
  10537. }
  10538. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10539. if (!lua_interface)
  10540. return 0;
  10541. Spawn* spawn = lua_interface->GetSpawn(state);
  10542. string titleName = lua_interface->GetStringValue(state, 2);
  10543. lua_interface->ResetFunctionStack(state);
  10544. if(!spawn->IsPlayer())
  10545. {
  10546. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10547. lua_interface->SetSInt32Value(state, -1);
  10548. return 1;
  10549. }
  10550. Player* player = (Player*)spawn;
  10551. // check if player already has the title, don't need to add twice
  10552. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10553. if ( playerHasTitle)
  10554. {
  10555. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10556. return 1;
  10557. }
  10558. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10559. if(!title)
  10560. {
  10561. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10562. lua_interface->SetSInt32Value(state, -1);
  10563. return 1;
  10564. }
  10565. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10566. if(returnIdx < 0)
  10567. {
  10568. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10569. }
  10570. lua_interface->SetSInt32Value(state, returnIdx);
  10571. player->GetClient()->SendTitleUpdate();
  10572. return 1;
  10573. }
  10574. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10575. if (!lua_interface)
  10576. return 0;
  10577. Spawn* spawn = lua_interface->GetSpawn(state);
  10578. string titleName = lua_interface->GetStringValue(state, 2);
  10579. lua_interface->ResetFunctionStack(state);
  10580. if(!spawn->IsPlayer())
  10581. {
  10582. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10583. return 0;
  10584. }
  10585. Player* player = (Player*)spawn;
  10586. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10587. if(!title)
  10588. {
  10589. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10590. return 0;
  10591. }
  10592. if(title->GetPrefix())
  10593. {
  10594. 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());
  10595. return 0;
  10596. }
  10597. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10598. player->GetClient()->SendTitleUpdate();
  10599. return 1;
  10600. }
  10601. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10602. if (!lua_interface)
  10603. return 0;
  10604. Spawn* spawn = lua_interface->GetSpawn(state);
  10605. string titleName = lua_interface->GetStringValue(state, 2);
  10606. lua_interface->ResetFunctionStack(state);
  10607. if(!spawn->IsPlayer())
  10608. {
  10609. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10610. return 0;
  10611. }
  10612. Player* player = (Player*)spawn;
  10613. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10614. if(!title)
  10615. {
  10616. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10617. return 0;
  10618. }
  10619. if(!title->GetPrefix())
  10620. {
  10621. 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());
  10622. return 0;
  10623. }
  10624. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10625. player->GetClient()->SendTitleUpdate();
  10626. return 1;
  10627. }
  10628. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10629. if (!lua_interface)
  10630. return 0;
  10631. Spawn* spawn = lua_interface->GetSpawn(state);
  10632. lua_interface->ResetFunctionStack(state);
  10633. if(!spawn->IsPlayer())
  10634. {
  10635. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10636. return 0;
  10637. }
  10638. Player* player = (Player*)spawn;
  10639. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10640. player->GetClient()->SendTitleUpdate();
  10641. return 1;
  10642. }
  10643. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10644. if (!lua_interface)
  10645. return 0;
  10646. Spawn* spawn = lua_interface->GetSpawn(state);
  10647. lua_interface->ResetFunctionStack(state);
  10648. if(!spawn->IsPlayer())
  10649. {
  10650. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10651. return 0;
  10652. }
  10653. Player* player = (Player*)spawn;
  10654. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10655. player->GetClient()->SendTitleUpdate();
  10656. return 1;
  10657. }
  10658. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10659. if (!lua_interface)
  10660. return 0;
  10661. Spawn* spawn = lua_interface->GetSpawn(state);
  10662. string field = lua_interface->GetStringValue(state, 2);
  10663. lua_interface->ResetFunctionStack(state);
  10664. if(!spawn || !spawn->IsEntity())
  10665. {
  10666. 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));
  10667. return 0;
  10668. }
  10669. Entity* ent = (Entity*)spawn;
  10670. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10671. return 1;
  10672. }
  10673. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10674. if (!lua_interface)
  10675. return 0;
  10676. Spawn* spawn = lua_interface->GetSpawn(state);
  10677. string field = lua_interface->GetStringValue(state, 2);
  10678. lua_interface->ResetFunctionStack(state);
  10679. if(!spawn || !spawn->IsEntity())
  10680. {
  10681. 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));
  10682. return 0;
  10683. }
  10684. Entity* ent = (Entity*)spawn;
  10685. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10686. return 1;
  10687. }
  10688. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10689. if (!lua_interface)
  10690. return 0;
  10691. Spawn* spawn = lua_interface->GetSpawn(state);
  10692. string field = lua_interface->GetStringValue(state, 2);
  10693. lua_interface->ResetFunctionStack(state);
  10694. if(!spawn || !spawn->IsEntity())
  10695. {
  10696. 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));
  10697. return 0;
  10698. }
  10699. Entity* ent = (Entity*)spawn;
  10700. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10701. return 1;
  10702. }
  10703. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10704. if (!lua_interface)
  10705. return 0;
  10706. Spawn* spawn = lua_interface->GetSpawn(state);
  10707. string field = lua_interface->GetStringValue(state, 2);
  10708. lua_interface->ResetFunctionStack(state);
  10709. if(!spawn || !spawn->IsEntity())
  10710. {
  10711. 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));
  10712. return 0;
  10713. }
  10714. Entity* ent = (Entity*)spawn;
  10715. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10716. return 1;
  10717. }
  10718. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10719. if (!lua_interface)
  10720. return 0;
  10721. Spawn* spawn = lua_interface->GetSpawn(state);
  10722. string field = lua_interface->GetStringValue(state, 2);
  10723. string value = lua_interface->GetStringValue(state, 3);
  10724. lua_interface->ResetFunctionStack(state);
  10725. if(!spawn || !spawn->IsEntity())
  10726. {
  10727. 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));
  10728. return 0;
  10729. }
  10730. Entity* ent = (Entity*)spawn;
  10731. bool set_ = ent->SetInfoStructString(field, value);
  10732. lua_interface->SetBooleanValue(state, set_);
  10733. return 1;
  10734. }
  10735. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10736. if (!lua_interface)
  10737. return 0;
  10738. Spawn* spawn = lua_interface->GetSpawn(state);
  10739. string field = lua_interface->GetStringValue(state, 2);
  10740. int64 value = lua_interface->GetInt64Value(state, 3);
  10741. lua_interface->ResetFunctionStack(state);
  10742. if(!spawn || !spawn->IsEntity())
  10743. {
  10744. 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));
  10745. return 0;
  10746. }
  10747. Entity* ent = (Entity*)spawn;
  10748. bool set_ = ent->SetInfoStructUInt(field, value);
  10749. lua_interface->SetBooleanValue(state, set_);
  10750. return 1;
  10751. }
  10752. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10753. if (!lua_interface)
  10754. return 0;
  10755. Spawn* spawn = lua_interface->GetSpawn(state);
  10756. string field = lua_interface->GetStringValue(state, 2);
  10757. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10758. lua_interface->ResetFunctionStack(state);
  10759. if(!spawn || !spawn->IsEntity())
  10760. {
  10761. 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));
  10762. return 0;
  10763. }
  10764. Entity* ent = (Entity*)spawn;
  10765. bool set_ = ent->SetInfoStructSInt(field, value);
  10766. lua_interface->SetBooleanValue(state, set_);
  10767. return 1;
  10768. }
  10769. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10770. if (!lua_interface)
  10771. return 0;
  10772. Spawn* spawn = lua_interface->GetSpawn(state);
  10773. string field = lua_interface->GetStringValue(state, 2);
  10774. float value = lua_interface->GetFloatValue(state, 3);
  10775. lua_interface->ResetFunctionStack(state);
  10776. if(!spawn || !spawn->IsEntity())
  10777. {
  10778. 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));
  10779. return 0;
  10780. }
  10781. Entity* ent = (Entity*)spawn;
  10782. bool set_ = ent->SetInfoStructFloat(field, value);
  10783. lua_interface->SetBooleanValue(state, set_);
  10784. return 1;
  10785. }
  10786. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10787. if (!lua_interface)
  10788. return 0;
  10789. Spawn* spawn = lua_interface->GetSpawn(state);
  10790. bool value = lua_interface->GetBooleanValue(state, 2);
  10791. lua_interface->ResetFunctionStack(state);
  10792. if(!spawn || !spawn->IsPlayer())
  10793. {
  10794. 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));
  10795. return 0;
  10796. }
  10797. ((Player*)spawn)->SetCharSheetChanged(value);
  10798. return 0;
  10799. }
  10800. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10801. if (!lua_interface)
  10802. return 0;
  10803. Spawn* spawn = lua_interface->GetSpawn(state);
  10804. std::string fromName = lua_interface->GetStringValue(state, 2);
  10805. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10806. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10807. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10808. int32 copper = lua_interface->GetInt32Value(state, 6);
  10809. int32 silver = lua_interface->GetInt32Value(state, 7);
  10810. int32 gold = lua_interface->GetInt32Value(state, 8);
  10811. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10812. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10813. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10814. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10815. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10816. lua_interface->ResetFunctionStack(state);
  10817. if(!spawn || !spawn->IsPlayer())
  10818. {
  10819. 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));
  10820. lua_interface->SetBooleanValue(state, false);
  10821. return 1;
  10822. }
  10823. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10824. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10825. lua_interface->SetBooleanValue(state, true);
  10826. return 1;
  10827. }
  10828. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10829. if (!lua_interface)
  10830. return 0;
  10831. int32 char_id = lua_interface->GetInt32Value(state);
  10832. std::string fromName = lua_interface->GetStringValue(state, 2);
  10833. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10834. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10835. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10836. int32 copper = lua_interface->GetInt32Value(state, 6);
  10837. int32 silver = lua_interface->GetInt32Value(state, 7);
  10838. int32 gold = lua_interface->GetInt32Value(state, 8);
  10839. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10840. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10841. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10842. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10843. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10844. lua_interface->ResetFunctionStack(state);
  10845. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10846. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10847. lua_interface->SetBooleanValue(state, true);
  10848. return 1;
  10849. }
  10850. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10851. Spawn* widget;
  10852. if (lua_interface) {
  10853. widget = lua_interface->GetSpawn(state);
  10854. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10855. lua_interface->ResetFunctionStack(state);
  10856. if (widget && widget->IsWidget())
  10857. {
  10858. ((Widget*)widget)->OpenDoor();
  10859. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10860. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10861. }
  10862. else
  10863. 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));
  10864. }
  10865. return 0;
  10866. }
  10867. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10868. Spawn* widget;
  10869. if (lua_interface) {
  10870. widget = lua_interface->GetSpawn(state);
  10871. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10872. lua_interface->ResetFunctionStack(state);
  10873. if (widget && widget->IsWidget())
  10874. {
  10875. ((Widget*)widget)->CloseDoor();
  10876. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10877. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10878. }
  10879. else
  10880. 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));
  10881. }
  10882. return 0;
  10883. }
  10884. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10885. if (!lua_interface)
  10886. return 0;
  10887. Spawn* widget = lua_interface->GetSpawn(state);
  10888. lua_interface->ResetFunctionStack(state);
  10889. if (widget && widget->IsWidget())
  10890. {
  10891. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10892. return 1;
  10893. }
  10894. return 0;
  10895. }
  10896. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10897. if (!lua_interface)
  10898. return 0;
  10899. sint32 min = lua_interface->GetSInt32Value(state);
  10900. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10901. lua_interface->ResetFunctionStack(state);
  10902. sint32 result = MakeRandomInt(min, max);
  10903. lua_interface->SetSInt32Value(state, result);
  10904. return 1;
  10905. }
  10906. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10907. if (!lua_interface)
  10908. return 0;
  10909. float min = lua_interface->GetFloatValue(state);
  10910. float max = lua_interface->GetFloatValue(state, 2);
  10911. lua_interface->ResetFunctionStack(state);
  10912. float result = MakeRandomFloat(min, max);
  10913. lua_interface->SetFloatValue(state, result);
  10914. return 1;
  10915. }
  10916. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10917. if (!lua_interface)
  10918. return 0;
  10919. Spawn* spawn = lua_interface->GetSpawn(state);
  10920. int32 value = lua_interface->GetInt32Value(state, 2);
  10921. lua_interface->ResetFunctionStack(state);
  10922. if(!spawn)
  10923. {
  10924. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10925. lua_interface->SetBooleanValue(state, false);
  10926. return 1;
  10927. }
  10928. spawn->AddIconValue(value);
  10929. lua_interface->SetBooleanValue(state, true);
  10930. return 1;
  10931. }
  10932. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10933. if (!lua_interface)
  10934. return 0;
  10935. Spawn* spawn = lua_interface->GetSpawn(state);
  10936. int32 value = lua_interface->GetInt32Value(state, 2);
  10937. lua_interface->ResetFunctionStack(state);
  10938. if(!spawn)
  10939. {
  10940. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10941. lua_interface->SetBooleanValue(state, false);
  10942. return 1;
  10943. }
  10944. spawn->RemoveIconValue(value);
  10945. lua_interface->SetBooleanValue(state, true);
  10946. return 1;
  10947. }
  10948. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10949. Spawn* npc = lua_interface->GetSpawn(state);
  10950. lua_interface->ResetFunctionStack(state);
  10951. if (npc && npc->IsNPC()) {
  10952. NPC* shard = (NPC*)npc;
  10953. int32 shardid = shard->GetShardID();
  10954. lua_interface->SetInt32Value(state, shardid);
  10955. return 1;
  10956. }
  10957. lua_interface->SetInt32Value(state, 0);
  10958. return 1;
  10959. }
  10960. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10961. Spawn* npc = lua_interface->GetSpawn(state);
  10962. lua_interface->ResetFunctionStack(state);
  10963. if (npc && npc->IsNPC()) {
  10964. NPC* shard = (NPC*)npc;
  10965. int32 charid = shard->GetShardCharID();
  10966. lua_interface->SetInt32Value(state, charid);
  10967. return 1;
  10968. }
  10969. lua_interface->SetInt32Value(state, 0);
  10970. return 1;
  10971. }
  10972. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10973. Spawn* npc = lua_interface->GetSpawn(state);
  10974. lua_interface->ResetFunctionStack(state);
  10975. if (npc && npc->IsNPC()) {
  10976. NPC* shard = (NPC*)npc;
  10977. int64 timestamp = shard->GetShardCreatedTimestamp();
  10978. lua_interface->SetSInt64Value(state, timestamp);
  10979. return 1;
  10980. }
  10981. lua_interface->SetSInt64Value(state, 0);
  10982. return 1;
  10983. }
  10984. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10985. if (!lua_interface)
  10986. return 0;
  10987. int32 shardid = lua_interface->GetInt32Value(state);
  10988. lua_interface->ResetFunctionStack(state);
  10989. if(shardid < 1)
  10990. lua_interface->SetBooleanValue(state, false);
  10991. else
  10992. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10993. return 1;
  10994. }
  10995. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10996. if (!lua_interface)
  10997. return 0;
  10998. Spawn* spawn = lua_interface->GetSpawn(state);
  10999. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11000. if (spawn) {
  11001. spawn->PauseMovement(delay_in_ms);
  11002. }
  11003. lua_interface->ResetFunctionStack(state);
  11004. return 0;
  11005. }
  11006. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11007. if (!lua_interface)
  11008. return 0;
  11009. Spawn* spawn = lua_interface->GetSpawn(state);
  11010. if (spawn) {
  11011. spawn->StopMovement();
  11012. }
  11013. lua_interface->ResetFunctionStack(state);
  11014. return 0;
  11015. }
  11016. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11017. Player* player = (Player*)lua_interface->GetSpawn(state);
  11018. int8 level = lua_interface->GetInt8Value(state, 2);
  11019. lua_interface->ResetFunctionStack(state);
  11020. if (player && player->IsPlayer() && level > 0) {
  11021. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11022. return 1;
  11023. }
  11024. return 0;
  11025. }
  11026. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11027. Player* player = (Player*)lua_interface->GetSpawn(state);
  11028. int8 level = lua_interface->GetInt8Value(state, 2);
  11029. lua_interface->ResetFunctionStack(state);
  11030. if (player && player->IsPlayer() && level > 0) {
  11031. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11032. return 1;
  11033. }
  11034. return 0;
  11035. }
  11036. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11037. ZoneServer* zone = lua_interface->GetZone(state);
  11038. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11039. lua_interface->ResetFunctionStack(state);
  11040. if (zone) {
  11041. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11042. if (spawn) {
  11043. lua_interface->SetSpawnValue(state, spawn);
  11044. return 1;
  11045. }
  11046. }
  11047. return 0;
  11048. }
  11049. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11050. if (!lua_interface)
  11051. return 0;
  11052. Spawn* spawn = lua_interface->GetSpawn(state);
  11053. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11054. lua_interface->ResetFunctionStack(state);
  11055. bool res = false;
  11056. if(spawn && spawn->IsTransportSpawn())
  11057. {
  11058. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11059. spawn->SetRailID(rail_id);
  11060. res = true;
  11061. }
  11062. else if (!spawn) {
  11063. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11064. }
  11065. else if(!spawn->IsTransportSpawn()) {
  11066. 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());
  11067. }
  11068. lua_interface->SetBooleanValue(state, res);
  11069. return 1;
  11070. }
  11071. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11072. if (!lua_interface)
  11073. return 0;
  11074. ZoneServer* zone = lua_interface->GetZone(state);
  11075. lua_interface->ResetFunctionStack(state);
  11076. if (zone) {
  11077. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11078. return 1;
  11079. }
  11080. return 0;
  11081. }
  11082. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11083. if (!lua_interface)
  11084. return 0;
  11085. Spawn* spawn = lua_interface->GetSpawn(state);
  11086. lua_interface->ResetFunctionStack(state);
  11087. if (spawn) {
  11088. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11089. return 1;
  11090. }
  11091. return 0;
  11092. }
  11093. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11094. if (!lua_interface)
  11095. return 0;
  11096. Spawn* player = lua_interface->GetSpawn(state);
  11097. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11098. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11099. lua_interface->ResetFunctionStack(state);
  11100. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11101. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11102. }
  11103. else if(!zoneID) {
  11104. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11105. }
  11106. else
  11107. {
  11108. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11109. return 1;
  11110. }
  11111. return 0;
  11112. }
  11113. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11114. if (!lua_interface)
  11115. return 0;
  11116. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11117. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11118. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11119. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11120. lua_interface->ResetFunctionStack(state);
  11121. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11122. world.GetWorldTimeStruct()->year = newYear;
  11123. world.GetWorldTimeStruct()->month = newMonth;
  11124. world.GetWorldTimeStruct()->hour = newHour;
  11125. world.GetWorldTimeStruct()->minute = newMinute;
  11126. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11127. return 0;
  11128. }
  11129. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11130. if (!lua_interface)
  11131. return 0;
  11132. lua_interface->ResetFunctionStack(state);
  11133. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11134. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11135. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11136. return 1;
  11137. }
  11138. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11139. if (!lua_interface)
  11140. return 0;
  11141. lua_interface->ResetFunctionStack(state);
  11142. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11143. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11144. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11145. return 1;
  11146. }
  11147. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11148. if (!lua_interface)
  11149. return 0;
  11150. lua_interface->ResetFunctionStack(state);
  11151. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11152. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11153. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11154. return 1;
  11155. }
  11156. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11157. if (!lua_interface)
  11158. return 0;
  11159. lua_interface->ResetFunctionStack(state);
  11160. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11161. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11162. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11163. return 1;
  11164. }
  11165. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11166. if (!lua_interface)
  11167. return 0;
  11168. lua_interface->ResetFunctionStack(state);
  11169. world.SendTimeUpdate();
  11170. return 0;
  11171. }
  11172. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11173. bool update_result = false;
  11174. Faction* faction = 0;
  11175. Player* player = (Player*)lua_interface->GetSpawn(state);
  11176. Client* client = player->GetZone()->GetClientBySpawn(player);
  11177. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11178. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11179. lua_interface->ResetFunctionStack(state);
  11180. if (player && player->IsPlayer() && faction_id > 0) {
  11181. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11182. if(hasfaction == 0) {
  11183. //they do not have the faction. Lets get the default value and feed it in.
  11184. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11185. //add the default faction for the player.
  11186. player->SetFactionValue(faction_id, defaultfaction);
  11187. }
  11188. if(increase >= 0) {
  11189. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11190. faction = master_faction_list.GetFaction(faction_id);
  11191. if(faction && update_result)
  11192. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11193. else if(faction)
  11194. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11195. lua_interface->SetBooleanValue(state, true);
  11196. return 1;
  11197. }
  11198. if(increase < 0){
  11199. //change the negative to a positive, since thats how decreasefaction() likes it.
  11200. increase *= -1;
  11201. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11202. faction = master_faction_list.GetFaction(faction_id);
  11203. if(faction && update_result)
  11204. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11205. else if(faction)
  11206. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11207. lua_interface->SetBooleanValue(state, true);
  11208. return 1;
  11209. }
  11210. }
  11211. lua_interface->SetBooleanValue(state, false);
  11212. return 1;
  11213. }
  11214. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11215. bool hascoin = 0;
  11216. Player* player = (Player*)lua_interface->GetSpawn(state);
  11217. int32 coins = lua_interface->GetInt32Value(state, 2);
  11218. lua_interface->ResetFunctionStack(state);
  11219. if (player && player->IsPlayer()) {
  11220. hascoin = player->HasCoins(coins);
  11221. if(hascoin == 0) {
  11222. lua_interface->SetBooleanValue(state, false);
  11223. return 1;
  11224. }
  11225. if(hascoin == 1) {
  11226. lua_interface->SetBooleanValue(state, true);
  11227. return 1;
  11228. }
  11229. }
  11230. return 0;
  11231. }
  11232. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11233. int32 loot_tier = 0;
  11234. Spawn* spawn = lua_interface->GetSpawn(state);
  11235. lua_interface->ResetFunctionStack(state);
  11236. if (spawn) {
  11237. loot_tier = spawn->GetLootTier();
  11238. lua_interface->SetInt32Value(state, loot_tier);
  11239. return 1;
  11240. }
  11241. return 0;
  11242. }
  11243. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11244. if (!lua_interface)
  11245. return 0;
  11246. Spawn* spawn = lua_interface->GetSpawn(state);
  11247. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11248. lua_interface->ResetFunctionStack(state);
  11249. if (spawn) {
  11250. spawn->SetLootTier(loot_tier);
  11251. lua_interface->SetBooleanValue(state, true);
  11252. return 1;
  11253. }
  11254. lua_interface->SetBooleanValue(state, false);
  11255. return 1;
  11256. }
  11257. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11258. int32 loot_drop_type = 0;
  11259. Spawn* spawn = lua_interface->GetSpawn(state);
  11260. lua_interface->ResetFunctionStack(state);
  11261. if (spawn) {
  11262. loot_drop_type = spawn->GetLootDropType();
  11263. lua_interface->SetInt32Value(state, loot_drop_type);
  11264. return 1;
  11265. }
  11266. return 0;
  11267. }
  11268. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11269. if (!lua_interface)
  11270. return 0;
  11271. Spawn* spawn = lua_interface->GetSpawn(state);
  11272. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11273. lua_interface->ResetFunctionStack(state);
  11274. if (spawn) {
  11275. spawn->SetLootDropType(loot_drop_type);
  11276. lua_interface->SetBooleanValue(state, true);
  11277. return 1;
  11278. }
  11279. lua_interface->SetBooleanValue(state, false);
  11280. return 1;
  11281. }