LuaFunctions.cpp 387 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = spawn->GetZone()->GetClientBySpawn(player);
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlaySound(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. string sound_string = lua_interface->GetStringValue(state, 2);
  183. float x = lua_interface->GetFloatValue(state, 3);
  184. float y = lua_interface->GetFloatValue(state, 4);
  185. float z = lua_interface->GetFloatValue(state, 5);
  186. Spawn* player = lua_interface->GetSpawn(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn && sound_string.length() > 0) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = spawn->GetZone()->GetClientBySpawn(player);
  192. if (client)
  193. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  194. else
  195. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  196. }
  197. return 0;
  198. }
  199. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  200. if (!lua_interface)
  201. return 0;
  202. Spawn* spawn = lua_interface->GetSpawn(state);
  203. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  204. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  205. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  206. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  207. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  208. lua_interface->ResetFunctionStack(state);
  209. if (!spawn) {
  210. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  211. return 0;
  212. }
  213. if (quest_id > 0) {
  214. //Add this quest to the list of required quests for this spawn
  215. spawn->SetQuestsRequired(quest_id, quest_step);
  216. //If private spawn value set
  217. if (private_spawn) {
  218. //Set the spawn to be private when not granted access through this quest
  219. spawn->AddAllowAccessSpawn(spawn);
  220. spawn->SetPrivateQuestSpawn(true);
  221. }
  222. //This value allows access after a quest step, or the whole quest has been completed
  223. if (continued_access)
  224. spawn->SetQuestsRequiredContinuedAccess(true);
  225. //This value will override vis_flags in the vis packet
  226. if (flag_override > 0)
  227. spawn->SetQuestsRequiredOverride(flag_override);
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. Spawn* spawn = lua_interface->GetSpawn(state);
  235. float max_distance = lua_interface->GetFloatValue(state, 2);
  236. string variable = lua_interface->GetStringValue(state, 3);
  237. string value = lua_interface->GetStringValue(state, 4);
  238. lua_interface->ResetFunctionStack(state);
  239. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  240. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  241. return 0;
  242. }
  243. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  244. if (!lua_interface)
  245. return 0;
  246. Client* client = 0;
  247. Spawn* player = lua_interface->GetSpawn(state);
  248. if (!player) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  250. return 0;
  251. }
  252. if (!player->IsPlayer()) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  254. return 0;
  255. }
  256. if (player->GetZone())
  257. client = player->GetZone()->GetClientBySpawn(player);
  258. if (!client) {
  259. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  260. return 0;
  261. }
  262. float intensity = lua_interface->GetFloatValue(state, 2);
  263. int8 direction = lua_interface->GetInt8Value(state, 3);
  264. lua_interface->ResetFunctionStack(state);
  265. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  266. if (packet) {
  267. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  268. v1 = *(float *)(a1 + 4);
  269. if ( v1 > 0.0 )
  270. v2 = fminf(v1, 1.0);
  271. else
  272. v2 = 0.1;
  273. */
  274. packet->setDataByName("intensity", intensity);
  275. if ( client->GetVersion() > 546 )
  276. packet->setDataByName("direction", direction);
  277. client->QueuePacket(packet->serialize());
  278. safe_delete(packet);
  279. }
  280. return 0;
  281. }
  282. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  283. if (!lua_interface)
  284. return 0;
  285. Spawn* dead = lua_interface->GetSpawn(state);
  286. Spawn* killer = lua_interface->GetSpawn(state, 2);
  287. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  288. lua_interface->ResetFunctionStack(state);
  289. if (dead && dead->Alive() && dead->GetZone())
  290. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  291. return 0;
  292. }
  293. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  294. if (!lua_interface)
  295. return 0;
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. float max_distance = lua_interface->GetFloatValue(state, 2);
  298. bool include_players = lua_interface->GetInt8Value(state, 3);
  299. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  300. lua_interface->ResetFunctionStack(state);
  301. if (max_distance > 0 && spawn && spawn->GetZone())
  302. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_Despawn(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int32 delay = lua_interface->GetInt32Value(state, 2);
  310. lua_interface->ResetFunctionStack(state);
  311. if (spawn && spawn->GetZone())
  312. spawn->GetZone()->Despawn(spawn, delay);
  313. return 0;
  314. }
  315. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  316. if (!lua_interface)
  317. return 0;
  318. Spawn* spawn = lua_interface->GetSpawn(state);
  319. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  320. lua_interface->ResetFunctionStack(state);
  321. if (spawn) {
  322. spawn->info_changed = true;
  323. spawn->SetShowHandIcon(displayHandIcon);
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  329. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. lua_interface->ResetFunctionStack(state);
  334. if (spawn) {
  335. spawn->vis_changed = true;
  336. spawn->GetZone()->AddChangedSpawn(spawn);
  337. }
  338. return 0;
  339. }
  340. //this function is used to force an update packet to be sent.
  341. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  342. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. lua_interface->ResetFunctionStack(state);
  347. if (spawn) {
  348. spawn->info_changed = true;
  349. spawn->GetZone()->AddChangedSpawn(spawn);
  350. }
  351. return 0;
  352. }
  353. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  354. if (!lua_interface)
  355. return 0;
  356. Spawn* spawn = lua_interface->GetSpawn(state);
  357. int32 new_state = lua_interface->GetInt32Value(state, 2);
  358. Spawn* player = lua_interface->GetSpawn(state, 3);
  359. lua_interface->ResetFunctionStack(state);
  360. if (spawn) {
  361. if(player)
  362. {
  363. if(player->IsPlayer())
  364. {
  365. Client* client = ((Player*)player)->GetClient();
  366. if(client)
  367. {
  368. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  369. lua_interface->SetBooleanValue(state, true);
  370. return 1;
  371. }
  372. else
  373. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  374. }
  375. else
  376. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  377. }
  378. else
  379. {
  380. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  381. lua_interface->SetBooleanValue(state, true);
  382. return 1;
  383. }
  384. }
  385. lua_interface->SetBooleanValue(state, false);
  386. return 1;
  387. }
  388. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  389. if (!lua_interface)
  390. return 0;
  391. Spawn* spawn = lua_interface->GetSpawn(state);
  392. string variable = lua_interface->GetStringValue(state, 2);
  393. string value = lua_interface->GetStringValue(state, 3);
  394. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  395. bool temporary_flag = true;
  396. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  397. int8 index = 0;
  398. if(num_args >= 5)
  399. {
  400. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  401. index = lua_interface->GetInt8Value(state, 6);
  402. }
  403. lua_interface->ResetFunctionStack(state);
  404. int32 type = commands.GetSpawnSetType(variable);
  405. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  406. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  407. return 0;
  408. }
  409. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  410. if (!lua_interface)
  411. return 0;
  412. Spawn* spawn = lua_interface->GetSpawn(state);
  413. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  414. lua_interface->ResetFunctionStack(state);
  415. if (spawn && spawn_id > 0) {
  416. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  417. if (closest_spawn) {
  418. lua_interface->SetSpawnValue(state, closest_spawn);
  419. return 1;
  420. }
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. int32 position = lua_interface->GetInt32Value(state, 2);
  429. lua_interface->ResetFunctionStack(state);
  430. if (spawnList) {
  431. if (spawnList->size() > position) {
  432. lua_interface->SetSpawnValue(state, spawnList->at(position));
  433. return 1;
  434. }
  435. else {
  436. return 0;
  437. }
  438. return spawnList->size();
  439. }
  440. return 0;
  441. }
  442. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  443. if (!lua_interface)
  444. return 0;
  445. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  446. lua_interface->ResetFunctionStack(state);
  447. if (spawnList) {
  448. return spawnList->size();
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = new vector<Spawn*>();
  456. lua_interface->SetSpawnListValue(state, spawnList);
  457. return 1;
  458. }
  459. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  460. if (!lua_interface)
  461. return 0;
  462. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  463. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  464. lua_interface->ResetFunctionStack(state);
  465. if (spawnList) {
  466. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  467. if (it == spawnList->end())
  468. spawnList->push_back(spawn);
  469. }
  470. return 0;
  471. }
  472. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  473. if (!lua_interface)
  474. return 0;
  475. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  476. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  477. lua_interface->ResetFunctionStack(state);
  478. if (spawnList) {
  479. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  480. if(it != spawnList->end())
  481. spawnList->erase(it);
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* spawn = lua_interface->GetSpawn(state);
  489. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  490. lua_interface->ResetFunctionStack(state);
  491. if (spawn) {
  492. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  493. if (spawns.size() > 0) {
  494. vector<Spawn*>* spawnList = new vector<Spawn*>();
  495. vector<Spawn*>::iterator itr;
  496. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  497. spawnList->push_back(*itr);
  498. }
  499. lua_interface->SetSpawnListValue(state, spawnList);
  500. return 1;
  501. }
  502. }
  503. return 0;
  504. }
  505. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. Spawn* spawn = lua_interface->GetSpawn(state);
  509. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  510. lua_interface->ResetFunctionStack(state);
  511. if (spawn) {
  512. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  513. if (spawns.size() > 0) {
  514. vector<Spawn*>* spawnList = new vector<Spawn*>();
  515. vector<Spawn*>::iterator itr;
  516. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  517. spawnList->push_back(*itr);
  518. }
  519. lua_interface->SetSpawnListValue(state, spawnList);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  526. if (!lua_interface)
  527. return 0;
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. lua_interface->ResetFunctionStack(state);
  530. if (spawn) {
  531. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  532. if (spawns.size() > 0) {
  533. lua_createtable(state, spawns.size(), 0);
  534. int newTable = lua_gettop(state);
  535. for (int32 i = 0; i < spawns.size(); i++) {
  536. lua_interface->SetSpawnValue(state, spawns.at(i));
  537. lua_rawseti(state, newTable, i + 1);
  538. }
  539. return 1;
  540. }
  541. }
  542. return 0;
  543. }
  544. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  545. if (!lua_interface)
  546. return 0;
  547. string variable_name = lua_interface->GetStringValue(state);
  548. lua_interface->ResetFunctionStack(state);
  549. Variable* var = variables.FindVariable(variable_name);
  550. if (var) {
  551. lua_interface->SetStringValue(state, var->GetValue());
  552. return 1;
  553. }
  554. return 0;
  555. }
  556. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  557. if (!lua_interface)
  558. return 0;
  559. int32 total_coins = lua_interface->GetInt32Value(state);
  560. lua_interface->ResetFunctionStack(state);
  561. if (total_coins == 0) {
  562. lua_interface->SetStringValue(state, "0 copper");
  563. return 1;
  564. }
  565. char tmp[64] = { 0 };
  566. string message = "";
  567. int32 val = 0;
  568. if (total_coins >= 1000000) {
  569. val = total_coins / 1000000;
  570. total_coins -= 1000000 * val;
  571. sprintf(tmp, " %u Platinum", val);
  572. message.append(tmp);
  573. memset(tmp, 0, 64);
  574. }
  575. if (total_coins >= 10000) {
  576. val = total_coins / 10000;
  577. total_coins -= 10000 * val;
  578. sprintf(tmp, " %u Gold", val);
  579. message.append(tmp);
  580. memset(tmp, 0, 64);
  581. }
  582. if (total_coins >= 100) {
  583. val = total_coins / 100;
  584. total_coins -= 100 * val;
  585. sprintf(tmp, " %u Silver", val);
  586. message.append(tmp);
  587. memset(tmp, 0, 64);
  588. }
  589. if (total_coins > 0) {
  590. sprintf(tmp, " %u Copper", (int32)total_coins);
  591. message.append(tmp);
  592. }
  593. lua_interface->SetStringValue(state, message.c_str());
  594. return 1;
  595. }
  596. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  597. ZoneServer* zone = lua_interface->GetZone(state);
  598. int32 group_id = lua_interface->GetInt32Value(state, 2);
  599. lua_interface->ResetFunctionStack(state);
  600. if (zone) {
  601. Spawn* spawn = zone->GetSpawnGroup(group_id);
  602. if (spawn) {
  603. lua_interface->SetSpawnValue(state, spawn);
  604. return 1;
  605. }
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  610. ZoneServer* zone = lua_interface->GetZone(state);
  611. int32 location_id = lua_interface->GetInt32Value(state, 2);
  612. lua_interface->ResetFunctionStack(state);
  613. if (zone) {
  614. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  615. if (spawn) {
  616. lua_interface->SetSpawnValue(state, spawn);
  617. return 1;
  618. }
  619. }
  620. return 0;
  621. }
  622. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. lua_interface->ResetFunctionStack(state);
  625. if (spawn) {
  626. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  632. Spawn* spawn = lua_interface->GetSpawn(state);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  636. return 1;
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  645. lua_interface->ResetFunctionStack(state);
  646. if (spawn) {
  647. spawn->SetSpawnGroupID(new_group_id);
  648. lua_interface->SetBooleanValue(state, true);
  649. return 1;
  650. }
  651. lua_interface->SetBooleanValue(state, false);
  652. return 1;
  653. }
  654. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  659. lua_interface->ResetFunctionStack(state);
  660. if (spawn) {
  661. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  662. lua_interface->SetBooleanValue(state, true);
  663. return 1;
  664. }
  665. lua_interface->SetBooleanValue(state, false);
  666. return 1;
  667. }
  668. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  669. Spawn* spawn = lua_interface->GetSpawn(state);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  673. return 1;
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. lua_interface->ResetFunctionStack(state);
  680. if (spawn) {
  681. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  682. return 1;
  683. }
  684. return 0;
  685. }
  686. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  687. Player* player = (Player*)lua_interface->GetSpawn(state);
  688. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  689. lua_interface->ResetFunctionStack(state);
  690. if (player && player->IsPlayer() && faction_id > 0) {
  691. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  692. return 1;
  693. }
  694. return 0;
  695. }
  696. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  697. if (!lua_interface)
  698. return 0;
  699. Spawn* spawn = lua_interface->GetSpawn(state);
  700. int32 value = lua_interface->GetInt32Value(state, 2);
  701. lua_interface->ResetFunctionStack(state);
  702. if (spawn) {
  703. spawn->SetFactionID(value);
  704. }
  705. return 0;
  706. }
  707. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  708. Spawn* spawn = lua_interface->GetSpawn(state);
  709. lua_interface->ResetFunctionStack(state);
  710. if (spawn) {
  711. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_GetGender(lua_State* state) {
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. lua_interface->ResetFunctionStack(state);
  719. if (spawn) {
  720. lua_interface->SetInt32Value(state, spawn->GetGender());
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_GetTarget(lua_State* state) {
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. lua_interface->ResetFunctionStack(state);
  728. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  730. return 1;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. string mp3_string = lua_interface->GetStringValue(state, 2);
  739. int32 key1 = lua_interface->GetInt32Value(state, 3);
  740. int32 key2 = lua_interface->GetInt32Value(state, 4);
  741. Spawn* player = lua_interface->GetSpawn(state, 5);
  742. lua_interface->ResetFunctionStack(state);
  743. if (spawn && mp3_string.length() > 0) {
  744. Client* client = 0;
  745. if (player && player->IsPlayer())
  746. client = spawn->GetZone()->GetClientBySpawn(player);
  747. if (client) {
  748. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  749. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  750. }
  751. else
  752. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  753. }
  754. return 0;
  755. }
  756. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  757. if (!lua_interface)
  758. return 0;
  759. Spawn* spawn = lua_interface->GetSpawn(state);
  760. lua_interface->ResetFunctionStack(state);
  761. if (spawn) {
  762. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  763. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  764. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  765. return 3;
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 item_id = lua_interface->GetInt32Value(state, 2);
  775. lua_interface->ResetFunctionStack(state);
  776. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  777. return 1;
  778. }
  779. lua_interface->ResetFunctionStack(state);
  780. return 0;
  781. }
  782. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  783. if (!lua_interface)
  784. return 0;
  785. Spawn* spawn = lua_interface->GetSpawn(state);
  786. if (spawn && spawn->IsEntity()) {
  787. int32 item_id = lua_interface->GetInt32Value(state, 2);
  788. int16 charges = lua_interface->GetInt16Value(state, 3);
  789. if (charges == 0)
  790. charges = 1;
  791. ((Entity*)spawn)->AddLootItem(item_id, charges);
  792. }
  793. lua_interface->ResetFunctionStack(state);
  794. return 0;
  795. }
  796. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn && spawn->IsEntity()) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. Item* item = spawn->LootItem(item_id);
  803. safe_delete(item);
  804. }
  805. lua_interface->ResetFunctionStack(state);
  806. return 0;
  807. }
  808. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  809. if (!lua_interface)
  810. return 0;
  811. Spawn* spawn = lua_interface->GetSpawn(state);
  812. if (spawn) {
  813. int32 val = lua_interface->GetInt32Value(state, 2);
  814. spawn->AddLootCoins(val);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* entity = lua_interface->GetSpawn(state);
  823. Spawn* player = lua_interface->GetSpawn(state, 2);
  824. if (entity && player && player->IsPlayer()) {
  825. int32 coins = lua_interface->GetInt32Value(state, 3);
  826. vector<Item*>* items = 0;
  827. int i = 0;
  828. int32 item_id = 0;
  829. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  830. if (items == 0)
  831. items = new vector<Item*>;
  832. if (master_item_list.GetItem(item_id))
  833. items->push_back(master_item_list.GetItem(item_id));
  834. i++;
  835. }
  836. Client* client = 0;
  837. client = player->GetZone()->GetClientBySpawn(player);
  838. if (client)
  839. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  840. if(coins > 0)
  841. entity->AddLootCoins(coins);
  842. safe_delete(items);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. int32 item_id = lua_interface->GetInt32Value(state, 3);
  853. lua_interface->ResetFunctionStack(state);
  854. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  855. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  856. return 1;
  857. }
  858. return 0;
  859. }
  860. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* entity = lua_interface->GetSpawn(state);
  864. Spawn* player = lua_interface->GetSpawn(state, 2);
  865. lua_interface->ResetFunctionStack(state);
  866. if (entity && player && player->IsPlayer()) {
  867. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  868. return 1;
  869. }
  870. return 0;
  871. }
  872. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  876. safe_delete(conversation);
  877. lua_interface->ResetFunctionStack(state);
  878. conversation = new vector<ConversationOption>();
  879. lua_interface->SetConversationValue(state, conversation);
  880. return 1;
  881. }
  882. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  883. if (!lua_interface)
  884. return 0;
  885. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  886. if (conversation) {
  887. ConversationOption conv_option;
  888. conv_option.option = lua_interface->GetStringValue(state, 2);
  889. conv_option.function = lua_interface->GetStringValue(state, 3);
  890. if (conv_option.option.length() > 0)
  891. conversation->push_back(conv_option);
  892. }
  893. lua_interface->ResetFunctionStack(state);
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. Spawn* npc = lua_interface->GetSpawn(state);
  900. Spawn* player = lua_interface->GetSpawn(state, 2);
  901. lua_interface->ResetFunctionStack(state);
  902. if (npc && player && player->IsPlayer() && player->GetZone()) {
  903. Client* client = player->GetZone()->GetClientBySpawn(player);
  904. if (client) {
  905. int32 conversation_id = client->GetConversationID(npc, 0);
  906. client->CloseDialog(conversation_id);
  907. }
  908. }
  909. return 0;
  910. }
  911. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. Item* item = lua_interface->GetItem(state);
  915. Spawn* player = lua_interface->GetSpawn(state, 2);
  916. lua_interface->ResetFunctionStack(state);
  917. if (item && player && player->IsPlayer() && player->GetZone()) {
  918. Client* client = player->GetZone()->GetClientBySpawn(player);
  919. if (client) {
  920. int32 conversation_id = client->GetConversationID(0, item);
  921. client->CloseDialog(conversation_id);
  922. }
  923. }
  924. return 0;
  925. }
  926. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  927. if (!lua_interface)
  928. return 0;
  929. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  930. Spawn* spawn = 0;
  931. Item* item = 0;
  932. int8 type = lua_interface->GetInt8Value(state, 2);
  933. if (type == 1 || type == 3)
  934. spawn = lua_interface->GetSpawn(state, 3);
  935. else if (type == 2 || type == 4)
  936. item = lua_interface->GetItem(state, 3);
  937. Spawn* player = lua_interface->GetSpawn(state, 4);
  938. string text = lua_interface->GetStringValue(state, 5);
  939. string mp3 = lua_interface->GetStringValue(state, 6);
  940. int32 key1 = lua_interface->GetInt32Value(state, 7);
  941. int32 key2 = lua_interface->GetInt32Value(state, 8);
  942. lua_interface->ResetFunctionStack(state);
  943. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  944. Client* client = player->GetZone()->GetClientBySpawn(player);
  945. if (client) {
  946. if (spawn) {
  947. // Need to do this so the function works the same as it did before
  948. if (type == 1)
  949. type++;
  950. if (mp3.length() > 0)
  951. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  952. else
  953. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  954. }
  955. else {
  956. if (mp3.length() > 0)
  957. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  958. else
  959. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  960. }
  961. }
  962. }
  963. safe_delete(conversation);
  964. lua_interface->SetConversationValue(state, NULL);
  965. return 0;
  966. }
  967. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  968. if(!lua_interface)
  969. return 0;
  970. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  971. Item* item = lua_interface->GetItem(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. string text = lua_interface->GetStringValue(state, 4);
  974. string mp3 = lua_interface->GetStringValue(state, 5);
  975. int32 key1 = lua_interface->GetInt32Value(state, 6);
  976. int32 key2 = lua_interface->GetInt32Value(state, 7);
  977. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  978. Client* client = player->GetZone()->GetClientBySpawn(player);
  979. if(client){
  980. if(mp3.length() > 0)
  981. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  982. else
  983. client->DisplayConversation(item, conversation, (char*)text.c_str());
  984. }
  985. safe_delete(conversation);
  986. }
  987. return 0;
  988. }*/
  989. int EQ2Emu_lua_StartConversation(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  993. Spawn* source = lua_interface->GetSpawn(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. string text = lua_interface->GetStringValue(state, 4);
  996. string mp3 = lua_interface->GetStringValue(state, 5);
  997. int32 key1 = lua_interface->GetInt32Value(state, 6);
  998. int32 key2 = lua_interface->GetInt32Value(state, 7);
  999. lua_interface->ResetFunctionStack(state);
  1000. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1001. Client* client = source->GetZone()->GetClientBySpawn(player);
  1002. if (mp3.length() > 0)
  1003. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  1004. else
  1005. client->DisplayConversation(source, 1, conversation, text.c_str());
  1006. safe_delete(conversation);
  1007. lua_interface->SetConversationValue(state, NULL);
  1008. }
  1009. else
  1010. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1011. return 0;
  1012. }
  1013. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1014. if (!lua_interface)
  1015. return 0;
  1016. Spawn* spawn = lua_interface->GetSpawn(state);
  1017. float distance = lua_interface->GetFloatValue(state, 2);
  1018. string in_range_function = lua_interface->GetStringValue(state, 3);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1020. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1021. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1022. return 0;
  1023. }
  1024. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1025. ZoneServer* zone = lua_interface->GetZone(state);
  1026. float x = lua_interface->GetFloatValue(state, 2);
  1027. float y = lua_interface->GetFloatValue(state, 3);
  1028. float z = lua_interface->GetFloatValue(state, 4);
  1029. float max_variation = lua_interface->GetFloatValue(state, 5);
  1030. string in_range_function = lua_interface->GetStringValue(state, 6);
  1031. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1032. lua_interface->ResetFunctionStack(state);
  1033. if (zone && in_range_function.length() > 0)
  1034. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1038. if (!lua_interface)
  1039. return 0;
  1040. Spawn* spawn = lua_interface->GetSpawn(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. int32 val = lua_interface->GetInt32Value(state, 2);
  1043. ((Entity*)spawn)->SetLootCoins(val);
  1044. }
  1045. lua_interface->ResetFunctionStack(state);
  1046. return 0;
  1047. }
  1048. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1049. if (!lua_interface)
  1050. return 0;
  1051. Spawn* spawn = lua_interface->GetSpawn(state);
  1052. lua_interface->ResetFunctionStack(state);
  1053. if (spawn && spawn->IsEntity()) {
  1054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1060. if (!lua_interface)
  1061. return 0;
  1062. Spawn* spawn = lua_interface->GetSpawn(state);
  1063. float x = lua_interface->GetFloatValue(state, 2);
  1064. float y = lua_interface->GetFloatValue(state, 3);
  1065. float z = lua_interface->GetFloatValue(state, 4);
  1066. float speed = lua_interface->GetFloatValue(state, 5);
  1067. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1068. string function = lua_interface->GetStringValue(state, 7);
  1069. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1070. float heading = lua_interface->GetFloatValue(state, 8);
  1071. if (spawn) {
  1072. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1073. spawn->GetZone()->AddMovementNPC(spawn);
  1074. }
  1075. lua_interface->ResetFunctionStack(state);
  1076. return 0;
  1077. }
  1078. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1079. if (!lua_interface)
  1080. return 0;
  1081. Spawn* spawn = lua_interface->GetSpawn(state);
  1082. lua_interface->ResetFunctionStack(state);
  1083. if (spawn) {
  1084. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1085. return 1;
  1086. }
  1087. return 0;
  1088. }
  1089. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. lua_interface->ResetFunctionStack(state);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1096. return 1;
  1097. }
  1098. lua_interface->SetInt32Value(state, 0);
  1099. return 1;
  1100. }
  1101. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1102. if (!lua_interface)
  1103. return 0;
  1104. Spawn* spawn = lua_interface->GetSpawn(state);
  1105. Spawn* target = lua_interface->GetSpawn(state, 2);
  1106. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1107. bool reset_action_state = true;
  1108. if(num_args > 2)
  1109. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1110. if (spawn && target) {
  1111. if (spawn->IsEntity())
  1112. // ((Entity*)spawn)->FaceTarget(target);
  1113. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1114. }
  1115. lua_interface->ResetFunctionStack(state);
  1116. return 0;
  1117. }
  1118. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. float x = lua_interface->GetFloatValue(state, 2);
  1123. float y = lua_interface->GetFloatValue(state, 3);
  1124. float z = lua_interface->GetFloatValue(state, 4);
  1125. float speed = lua_interface->GetFloatValue(state, 5);
  1126. string lua_function = lua_interface->GetStringValue(state, 6);
  1127. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1128. if (spawn) {
  1129. if (speed == 0)
  1130. speed = spawn->GetSpeed();
  1131. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1132. }
  1133. lua_interface->ResetFunctionStack(state);
  1134. return 0;
  1135. }
  1136. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1137. if (!lua_interface)
  1138. return 0;
  1139. Spawn* spawn = lua_interface->GetSpawn(state);
  1140. lua_interface->ResetFunctionStack(state);
  1141. if (spawn) {
  1142. spawn->ClearRunningLocations();
  1143. }
  1144. return 0;
  1145. }
  1146. int EQ2Emu_lua_Say(lua_State* state) {
  1147. if (!lua_interface)
  1148. return 0;
  1149. Spawn* spawn = lua_interface->GetSpawn(state);
  1150. string message = lua_interface->GetStringValue(state, 2);
  1151. Spawn* player = lua_interface->GetSpawn(state, 3);
  1152. int32 language = lua_interface->GetInt32Value(state, 4);
  1153. if (spawn && message.length() > 0) {
  1154. Client* client = 0;
  1155. if (player && player->IsPlayer())
  1156. client = spawn->GetZone()->GetClientBySpawn(player);
  1157. if (client)
  1158. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1159. else
  1160. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1161. }
  1162. lua_interface->ResetFunctionStack(state);
  1163. return 0;
  1164. }
  1165. int EQ2Emu_lua_Shout(lua_State* state) {
  1166. if (!lua_interface)
  1167. return 0;
  1168. Spawn* spawn = lua_interface->GetSpawn(state);
  1169. string message = lua_interface->GetStringValue(state, 2);
  1170. Spawn* player = lua_interface->GetSpawn(state, 3);
  1171. float dist = lua_interface->GetFloatValue(state, 4);
  1172. if (spawn && message.length() > 0) {
  1173. Client* client = 0;
  1174. if (player && player->IsPlayer())
  1175. client = spawn->GetZone()->GetClientBySpawn(player);
  1176. if (client)
  1177. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1178. else
  1179. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1180. }
  1181. lua_interface->ResetFunctionStack(state);
  1182. return 0;
  1183. }
  1184. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1185. if (!lua_interface)
  1186. return 0;
  1187. Spawn* spawn = lua_interface->GetSpawn(state);
  1188. string message = lua_interface->GetStringValue(state, 2);
  1189. Spawn* player = lua_interface->GetSpawn(state, 3);
  1190. if (spawn && message.length() > 0) {
  1191. Client* client = 0;
  1192. if (player && player->IsPlayer())
  1193. client = spawn->GetZone()->GetClientBySpawn(player);
  1194. if (client)
  1195. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1196. else
  1197. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1198. }
  1199. lua_interface->ResetFunctionStack(state);
  1200. return 0;
  1201. }
  1202. int EQ2Emu_lua_Emote(lua_State* state) {
  1203. if (!lua_interface)
  1204. return 0;
  1205. Spawn* spawn = lua_interface->GetSpawn(state);
  1206. string message = lua_interface->GetStringValue(state, 2);
  1207. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1208. Spawn* player = lua_interface->GetSpawn(state, 4);
  1209. char* to = 0;
  1210. if (spawn2)
  1211. to = spawn2->GetName();
  1212. if (spawn && message.length() > 0) {
  1213. Client* client = 0;
  1214. if (player && player->IsPlayer())
  1215. client = spawn->GetZone()->GetClientBySpawn(player);
  1216. if (client)
  1217. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1218. else
  1219. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1220. }
  1221. lua_interface->ResetFunctionStack(state);
  1222. return 0;
  1223. }
  1224. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1225. if (!lua_interface)
  1226. return 0;
  1227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1228. if (!luaspell)
  1229. return 0;
  1230. Spawn* caster = luaspell->caster;
  1231. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1232. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1233. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1234. Spawn* target = lua_interface->GetSpawn(state, 4);
  1235. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1236. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1237. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1238. lua_interface->ResetFunctionStack(state);
  1239. boost::to_lower(heal_type);
  1240. if (caster && caster->IsEntity()) {
  1241. bool success = false;
  1242. luaspell->resisted = false;
  1243. if (target) {
  1244. float distance = caster->GetDistance(target, true);
  1245. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1246. success = true;
  1247. }
  1248. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1249. Spawn* target = 0;
  1250. ZoneServer* zone = luaspell->caster->GetZone();
  1251. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1252. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1253. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1254. float distance = caster->GetDistance(target, true);
  1255. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1256. }
  1257. }
  1258. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1259. success = true;
  1260. }
  1261. if (success) {
  1262. if (caster->GetZone())
  1263. caster->GetZone()->TriggerCharSheetTimer();
  1264. }
  1265. }
  1266. return 0;
  1267. }
  1268. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1269. if (!lua_interface)
  1270. return 0;
  1271. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1272. if (!luaspell)
  1273. return 0;
  1274. Spawn* caster = luaspell->caster;
  1275. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1276. float percentage = lua_interface->GetFloatValue(state, 2);
  1277. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1278. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1279. Spawn* target = lua_interface->GetSpawn(state, 5);
  1280. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1281. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1282. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1283. lua_interface->ResetFunctionStack(state);
  1284. boost::to_lower(heal_type);
  1285. int32 min_heal = 0, max_heal = 0;
  1286. if (caster && caster->IsEntity() && target) {
  1287. if(percentage <= 0.0f)
  1288. {
  1289. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1290. return 0;
  1291. }
  1292. if(heal_type == "power")
  1293. {
  1294. if(current_value)
  1295. {
  1296. if(caster_value)
  1297. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1298. else
  1299. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1300. }
  1301. else
  1302. {
  1303. if(caster_value)
  1304. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1305. else
  1306. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1307. }
  1308. }
  1309. else
  1310. {
  1311. if(current_value)
  1312. {
  1313. if(caster_value)
  1314. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1315. else
  1316. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1317. }
  1318. else
  1319. {
  1320. if(caster_value)
  1321. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1322. else
  1323. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1324. }
  1325. }
  1326. bool success = false;
  1327. luaspell->resisted = false;
  1328. if (target) {
  1329. float distance = caster->GetDistance(target, true);
  1330. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1331. success = true;
  1332. }
  1333. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1334. Spawn* target = 0;
  1335. ZoneServer* zone = luaspell->caster->GetZone();
  1336. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1337. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1338. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1339. float distance = caster->GetDistance(target, true);
  1340. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1341. }
  1342. }
  1343. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1344. success = true;
  1345. }
  1346. if (success) {
  1347. if (caster->GetZone())
  1348. caster->GetZone()->TriggerCharSheetTimer();
  1349. }
  1350. }
  1351. return 0;
  1352. }
  1353. int EQ2Emu_lua_AddItem(lua_State* state) {
  1354. if (!lua_interface)
  1355. return 0;
  1356. Spawn* spawn = lua_interface->GetSpawn(state);
  1357. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1358. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1359. lua_interface->ResetFunctionStack(state);
  1360. // default of 1 quantity to add
  1361. if (quantity == 0)
  1362. quantity = 1;
  1363. if (spawn && spawn->IsPlayer()) {
  1364. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1365. if (client && item_id > 0) {
  1366. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1367. return 1;
  1368. }
  1369. }
  1370. lua_interface->SetBooleanValue(state, false);
  1371. return 1;
  1372. }
  1373. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1374. if (!lua_interface)
  1375. return 0;
  1376. Spawn* spawn = lua_interface->GetSpawn(state);
  1377. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1378. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1379. string location = lua_interface->GetStringValue(state, 4);
  1380. lua_interface->ResetFunctionStack(state);
  1381. if (spawn && spawn->IsPlayer()) {
  1382. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1383. if (client && item_id > 0) {
  1384. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1385. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1386. else
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1388. if (send_messages) {
  1389. Item* item = master_item_list.GetItem(item_id);
  1390. if (item) {
  1391. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1392. string popup_text = "You receive " + item->name;
  1393. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1394. }
  1395. }
  1396. return 1;
  1397. }
  1398. }
  1399. lua_interface->SetBooleanValue(state, false);
  1400. return 1;
  1401. }
  1402. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1403. Spawn* spawn = lua_interface->GetSpawn(state);
  1404. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1405. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1406. lua_interface->ResetFunctionStack(state);
  1407. // default of 1 to remove
  1408. if (quantity == 0)
  1409. quantity = 1;
  1410. Client* client;
  1411. Item* item;
  1412. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1413. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1414. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1415. if (client->RemoveItem(item, quantity)) {
  1416. lua_interface->SetBooleanValue(state, true);
  1417. return 1;
  1418. }
  1419. }
  1420. }
  1421. }
  1422. lua_interface->SetBooleanValue(state, false);
  1423. return 1;
  1424. }
  1425. int EQ2Emu_lua_HasItem(lua_State* state) {
  1426. Spawn* player = lua_interface->GetSpawn(state);
  1427. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1428. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1429. lua_interface->ResetFunctionStack(state);
  1430. if (player && player->IsPlayer()) {
  1431. bool hasItem = false;
  1432. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1433. if (!hasItem)
  1434. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1435. lua_interface->SetBooleanValue(state, hasItem);
  1436. return 1;
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_Spawn(lua_State* state) {
  1442. if (!lua_interface)
  1443. return 0;
  1444. ZoneServer* zone = lua_interface->GetZone(state);
  1445. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1446. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1447. float x = lua_interface->GetFloatValue(state, 4);
  1448. float y = lua_interface->GetFloatValue(state, 5);
  1449. float z = lua_interface->GetFloatValue(state, 6);
  1450. float heading = lua_interface->GetFloatValue(state, 7);
  1451. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1452. Spawn* spawn = zone->GetSpawn(spawn_id);
  1453. if (!spawn)
  1454. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1455. else {
  1456. spawn->SetX(x);
  1457. spawn->SetZ(z);
  1458. spawn->SetY(y,true,true);
  1459. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1460. spawn->SetHeading(heading);
  1461. if (restricted_npc)
  1462. spawn->AddAllowAccessSpawn(spawn);
  1463. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1464. bool scriptActive = false;
  1465. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1466. scriptActive = true;
  1467. spawn->SetSpawnScript(string(spawn_script));
  1468. }
  1469. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1470. zone->AddSpawn(spawn);
  1471. if (scriptActive) {
  1472. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1473. }
  1474. lua_interface->ResetFunctionStack(state);
  1475. lua_interface->SetSpawnValue(state, spawn);
  1476. return 1;
  1477. }
  1478. }
  1479. else {
  1480. string output = "Invalid paramaters to LUA Spawn command: \n";
  1481. if (!zone)
  1482. output = output.append("\t").append("Missing zone reference. \n");
  1483. if (spawn_id == 0)
  1484. output = output.append("\t").append("Missing spawn_id.");
  1485. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1486. }
  1487. lua_interface->ResetFunctionStack(state);
  1488. return 0;
  1489. }
  1490. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1491. if (!lua_interface)
  1492. return 0;
  1493. ZoneServer* zone = lua_interface->GetZone(state);
  1494. lua_interface->ResetFunctionStack(state);
  1495. if (zone) {
  1496. lua_interface->SetStringValue(state, zone->GetZoneName());
  1497. return 1;
  1498. }
  1499. return 0;
  1500. }
  1501. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1502. if (!lua_interface)
  1503. return 0;
  1504. ZoneServer* zone = lua_interface->GetZone(state);
  1505. lua_interface->ResetFunctionStack(state);
  1506. if (zone) {
  1507. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1508. return 1;
  1509. }
  1510. return 0;
  1511. }
  1512. int EQ2Emu_lua_GetZone(lua_State* state) {
  1513. if (!lua_interface)
  1514. return 0;
  1515. int32 zone_id = lua_interface->GetInt32Value(state);
  1516. ZoneServer* zone = 0;
  1517. if (zone_id > 0)
  1518. zone = zone_list.Get(zone_id);
  1519. else {
  1520. string zone_name = lua_interface->GetStringValue(state);
  1521. if (zone_name.length() > 0) {
  1522. zone = zone_list.Get(zone_name.c_str());
  1523. }
  1524. else {
  1525. Spawn* spawn = lua_interface->GetSpawn(state);
  1526. if (spawn)
  1527. zone = spawn->GetZone();
  1528. }
  1529. }
  1530. lua_interface->ResetFunctionStack(state);
  1531. if (zone) {
  1532. lua_interface->SetZoneValue(state, zone);
  1533. return 1;
  1534. }
  1535. return 0;
  1536. }
  1537. int EQ2Emu_lua_AddHate(lua_State* state) {
  1538. Spawn* entity = lua_interface->GetSpawn(state);
  1539. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1540. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1541. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1542. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1543. if (entity && entity->IsEntity() && amount != 0) {
  1544. if (luaspell) {
  1545. ZoneServer* zone = luaspell->caster->GetZone();
  1546. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1547. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1548. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1549. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1550. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1551. if (send_packet)
  1552. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1553. }
  1554. }
  1555. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1556. }
  1557. else if (npc && npc->IsNPC() && npc->GetZone())
  1558. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1559. }
  1560. lua_interface->ResetFunctionStack(state);
  1561. return 0;
  1562. }
  1563. int EQ2Emu_lua_Zone(lua_State* state) {
  1564. if (!lua_interface)
  1565. return 0;
  1566. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1567. ZoneServer* zone = lua_interface->GetZone(state);
  1568. Spawn* player = lua_interface->GetSpawn(state, 2);
  1569. Client* client = 0;
  1570. if (player && player->IsPlayer())
  1571. client = player->GetZone()->GetClientBySpawn(player);
  1572. float x = lua_interface->GetFloatValue(state, 3);
  1573. float y = lua_interface->GetFloatValue(state, 4);
  1574. float z = lua_interface->GetFloatValue(state, 5);
  1575. float heading = lua_interface->GetFloatValue(state, 6);
  1576. if (zone && client) {
  1577. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1578. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1579. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1580. {
  1581. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1582. return 0;
  1583. }
  1584. if (x != 0 || y != 0 || z != 0) {
  1585. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1586. player->SetX(x);
  1587. player->SetY(y);
  1588. player->SetZ(z);
  1589. player->SetHeading(heading);
  1590. client->Zone(zone->GetZoneName(), false);
  1591. }
  1592. else
  1593. client->Zone(zone->GetZoneName());
  1594. }
  1595. else
  1596. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1597. lua_interface->ResetFunctionStack(state);
  1598. return 0;
  1599. }
  1600. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1601. if (!lua_interface)
  1602. return 0;
  1603. Spawn* spawn = lua_interface->GetSpawn(state);
  1604. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1605. if (spawn && spawn2)
  1606. spawn->AddAllowAccessSpawn(spawn2);
  1607. lua_interface->ResetFunctionStack(state);
  1608. return 0;
  1609. }
  1610. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1611. if (!lua_interface)
  1612. return 0;
  1613. Spawn* target = lua_interface->GetSpawn(state);
  1614. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1615. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1616. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1617. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1618. lua_interface->ResetFunctionStack(state);
  1619. if (!target) {
  1620. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1621. return 0;
  1622. }
  1623. if (!target->IsEntity()) {
  1624. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1625. return 0;
  1626. }
  1627. if (spell_id <= 0) {
  1628. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1629. return 0;
  1630. }
  1631. if (caster && !caster->IsEntity()) {
  1632. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1633. return 0;
  1634. }
  1635. if (spell_tier == 0)
  1636. spell_tier = 1;
  1637. if (!caster)
  1638. caster = target;
  1639. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* target = lua_interface->GetSpawn(state);
  1646. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1647. if (!luaspell)
  1648. return 0;
  1649. Spawn* caster = luaspell->caster;
  1650. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1651. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1652. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1653. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1654. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1655. //lua_interface->ResetFunctionStack(state);
  1656. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1657. vector<int16> faction_req;
  1658. vector<int16> race_req;
  1659. int32 class_req = 0;
  1660. int32 i = 0;
  1661. int8 f = 0;
  1662. int8 r = 0;
  1663. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1664. if (class_id < 100) {
  1665. class_req += pow(2.0, double(class_id - 1));
  1666. }
  1667. else if (class_id > 100 && class_id < 1000) {
  1668. race_req.push_back(class_id);
  1669. r++;
  1670. }
  1671. else {
  1672. faction_req.push_back(class_id);
  1673. f++;
  1674. }
  1675. i++;
  1676. }
  1677. lua_interface->ResetFunctionStack(state);
  1678. if (caster && caster->IsEntity()) {
  1679. bool race_match = false;
  1680. bool success = false;
  1681. luaspell->resisted = false;
  1682. if (luaspell->targets.size() > 0) {
  1683. ZoneServer* zone = luaspell->caster->GetZone();
  1684. Spawn* target = 0;
  1685. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1686. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1687. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1688. if (race_req.size() > 0) {
  1689. for (int8 i = 0; i < race_req.size(); i++) {
  1690. if (target->GetLuaRaceId() == race_req[i]) {
  1691. race_match = true;
  1692. }
  1693. }
  1694. }
  1695. else
  1696. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1697. if (race_match == true) {
  1698. float distance = caster->GetDistance(target, true);
  1699. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1700. }
  1701. }
  1702. }
  1703. success = true;
  1704. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1705. }
  1706. else if (target) {
  1707. //check class and race/faction here
  1708. if (race_req.size() > 0) {
  1709. for (int8 i = 0; i < race_req.size(); i++) {
  1710. if (target->GetLuaRaceId() == race_req[i]) {
  1711. race_match = true;
  1712. }
  1713. }
  1714. }
  1715. else
  1716. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1717. if (race_match == true) {
  1718. float distance = caster->GetDistance(target, true);
  1719. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1720. success = true;
  1721. }
  1722. }
  1723. if (success) {
  1724. Spell* spell = luaspell->spell;
  1725. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1726. ((Player*)caster)->InCombat(true);
  1727. if (caster->GetZone())
  1728. caster->GetZone()->TriggerCharSheetTimer();
  1729. }
  1730. }
  1731. }
  1732. return 0;
  1733. }
  1734. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1735. if (!lua_interface)
  1736. return 0;
  1737. Spawn* spawn = lua_interface->GetSpawn(state);
  1738. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1739. lua_interface->ResetFunctionStack(state);
  1740. if (spawn && value != 0) {
  1741. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1742. spawn->SetPower(spawn->GetTotalPower());
  1743. else
  1744. spawn->SetPower(spawn->GetPower() + value);
  1745. }
  1746. return 0;
  1747. }
  1748. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1749. if (!lua_interface)
  1750. return 0;
  1751. Spawn* spawn = lua_interface->GetSpawn(state);
  1752. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1753. lua_interface->ResetFunctionStack(state);
  1754. if (spawn && value != 0) {
  1755. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1756. spawn->SetHP(spawn->GetTotalHP());
  1757. else
  1758. spawn->SetHP(spawn->GetHP() + value);
  1759. }
  1760. return 0;
  1761. }
  1762. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1763. if (!lua_interface)
  1764. return 0;
  1765. Spawn* spawn = lua_interface->GetSpawn(state);
  1766. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1767. lua_interface->ResetFunctionStack(state);
  1768. if (spawn && value != 0) {
  1769. spawn->SetPower(spawn->GetPower() + value);
  1770. if (value > spawn->GetTotalHPBase())
  1771. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1772. }
  1773. return 0;
  1774. }
  1775. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1776. if (!lua_interface)
  1777. return 0;
  1778. Spawn* spawn = lua_interface->GetSpawn(state);
  1779. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1780. lua_interface->ResetFunctionStack(state);
  1781. if (spawn && value != 0) {
  1782. spawn->SetHP(spawn->GetHP() + value);
  1783. if (value > spawn->GetTotalHPBase())
  1784. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1785. }
  1786. return 0;
  1787. }
  1788. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1789. if (!lua_interface)
  1790. return 0;
  1791. Spawn* spawn = lua_interface->GetSpawn(state);
  1792. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1793. lua_interface->ResetFunctionStack(state);
  1794. if (spawn) {
  1795. spawn->SetHP(value);
  1796. if (value > spawn->GetTotalHPBase())
  1797. spawn->SetTotalHP(value);
  1798. }
  1799. return 0;
  1800. }
  1801. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1802. if (!lua_interface)
  1803. return 0;
  1804. Spawn* spawn = lua_interface->GetSpawn(state);
  1805. float value = lua_interface->GetFloatValue(state, 2);
  1806. lua_interface->ResetFunctionStack(state);
  1807. if (spawn && spawn->IsEntity() && value > 0)
  1808. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1809. if (spawn->IsPlayer())
  1810. ((Player*)spawn)->SetCharSheetChanged(true);
  1811. return 0;
  1812. }
  1813. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1814. if (!lua_interface)
  1815. return 0;
  1816. Spawn* spawn = lua_interface->GetSpawn(state);
  1817. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1818. lua_interface->ResetFunctionStack(state);
  1819. if (spawn && spawn->IsEntity() && value > 0)
  1820. ((Entity*)spawn)->SetTotalHPBase(value);
  1821. return 0;
  1822. }
  1823. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1824. if (!lua_interface)
  1825. return 0;
  1826. Spawn* spawn = lua_interface->GetSpawn(state);
  1827. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1828. lua_interface->ResetFunctionStack(state);
  1829. if (spawn && value > 0) {
  1830. spawn->SetPower(value);
  1831. if (value > spawn->GetTotalPowerBase())
  1832. spawn->SetTotalPower(value);
  1833. }
  1834. return 0;
  1835. }
  1836. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1837. if (!lua_interface)
  1838. return 0;
  1839. Spawn* spawn = lua_interface->GetSpawn(state);
  1840. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1841. lua_interface->ResetFunctionStack(state);
  1842. if (spawn && spawn->IsEntity() && value > 0)
  1843. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1844. return 0;
  1845. }
  1846. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1847. if (!lua_interface)
  1848. return 0;
  1849. Spawn* spawn = lua_interface->GetSpawn(state);
  1850. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1851. lua_interface->ResetFunctionStack(state);
  1852. if (spawn && spawn->IsEntity() && value > 0)
  1853. ((Entity*)spawn)->SetTotalPowerBase(value);
  1854. return 0;
  1855. }
  1856. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1857. if (!lua_interface)
  1858. return 0;
  1859. Spawn* spawn = lua_interface->GetSpawn(state);
  1860. float x = lua_interface->GetFloatValue(state, 2);
  1861. float y = lua_interface->GetFloatValue(state, 3);
  1862. float z = lua_interface->GetFloatValue(state, 4);
  1863. float heading = lua_interface->GetFloatValue(state, 5);
  1864. lua_interface->ResetFunctionStack(state);
  1865. if (spawn) {
  1866. spawn->SetX(x);
  1867. spawn->SetY(y);
  1868. spawn->SetZ(z);
  1869. if (heading != 0)
  1870. spawn->SetHeading(heading);
  1871. spawn->SetSpawnOrigX(spawn->GetX());
  1872. spawn->SetSpawnOrigY(spawn->GetY());
  1873. spawn->SetSpawnOrigZ(spawn->GetZ());
  1874. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1875. if (spawn->IsPlayer()) {
  1876. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1877. if (client) {
  1878. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1879. client->QueuePacket(packet);
  1880. }
  1881. }
  1882. }
  1883. return 0;
  1884. }
  1885. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1886. if (!lua_interface)
  1887. return 0;
  1888. Spawn* spawn = lua_interface->GetSpawn(state);
  1889. float value = lua_interface->GetFloatValue(state, 2);
  1890. lua_interface->ResetFunctionStack(state);
  1891. if (spawn) {
  1892. spawn->SetHeading(value);
  1893. if (spawn->IsPlayer()) {
  1894. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1895. if (client) {
  1896. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1897. client->QueuePacket(packet);
  1898. }
  1899. }
  1900. }
  1901. return 0;
  1902. }
  1903. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1904. if (!lua_interface)
  1905. return 0;
  1906. Spawn* spawn = lua_interface->GetSpawn(state);
  1907. int16 value = lua_interface->GetInt16Value(state, 2);
  1908. lua_interface->ResetFunctionStack(state);
  1909. if (spawn)
  1910. spawn->SetModelType(value);
  1911. return 0;
  1912. }
  1913. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1914. if (!lua_interface)
  1915. return 0;
  1916. Spawn* spawn = lua_interface->GetSpawn(state);
  1917. int8 value = lua_interface->GetInt8Value(state, 2);
  1918. lua_interface->ResetFunctionStack(state);
  1919. if (spawn) {
  1920. if (spawn->IsPlayer())
  1921. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1922. else
  1923. spawn->SetAdventureClass(value);
  1924. }
  1925. return 0;
  1926. }
  1927. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1928. if (!lua_interface)
  1929. return 0;
  1930. Spawn* spawn = lua_interface->GetSpawn(state);
  1931. int8 value = lua_interface->GetInt8Value(state, 2);
  1932. lua_interface->ResetFunctionStack(state);
  1933. if (spawn) {
  1934. spawn->SetTradeskillClass(value);
  1935. if (spawn->IsEntity()) {
  1936. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1937. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1938. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1939. }
  1940. if (spawn->IsPlayer())
  1941. ((Player*)spawn)->SetCharSheetChanged(true);
  1942. }
  1943. return 0;
  1944. }
  1945. int EQ2Emu_lua_SetMount(lua_State* state) {
  1946. if (!lua_interface)
  1947. return 0;
  1948. Spawn* spawn = lua_interface->GetSpawn(state);
  1949. int16 value = lua_interface->GetInt16Value(state, 2);
  1950. if (spawn && spawn->IsEntity()) {
  1951. ((Entity*)spawn)->SetMount(value);
  1952. EQ2_Color color;
  1953. color.red = 255;
  1954. color.green = 255;
  1955. color.blue = 255;
  1956. ((Entity*)spawn)->SetMountColor(&color);
  1957. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1958. }
  1959. return 0;
  1960. }
  1961. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1962. if (!lua_interface)
  1963. return 0;
  1964. Spawn* spawn = lua_interface->GetSpawn(state);
  1965. EQ2_Color mount_color;
  1966. EQ2_Color saddle_color;
  1967. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1968. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1969. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1970. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1971. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1972. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1973. if (spawn && spawn->IsEntity()) {
  1974. ((Entity*)spawn)->SetMountColor(&mount_color);
  1975. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1976. }
  1977. return 0;
  1978. }
  1979. int EQ2Emu_lua_GetMount(lua_State* state) {
  1980. if (!lua_interface)
  1981. return 0;
  1982. Spawn* spawn = lua_interface->GetSpawn(state);
  1983. if (spawn && spawn->IsEntity()) {
  1984. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1985. return 1;
  1986. }
  1987. return 0;
  1988. }
  1989. int EQ2Emu_lua_GetRace(lua_State* state) {
  1990. if (!lua_interface)
  1991. return 0;
  1992. Spawn* spawn = lua_interface->GetSpawn(state);
  1993. if (spawn)
  1994. {
  1995. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1996. lua_interface->SetInt32Value(state, spawn->GetRace());
  1997. return 1;
  1998. }
  1999. return 0;
  2000. }
  2001. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2002. if (!lua_interface)
  2003. return 0;
  2004. Spawn* spawn = lua_interface->GetSpawn(state);
  2005. if (spawn) {
  2006. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2007. return 1;
  2008. }
  2009. return 0;
  2010. }
  2011. int EQ2Emu_lua_GetClass(lua_State* state) {
  2012. Spawn* spawn = lua_interface->GetSpawn(state);
  2013. if (spawn) {
  2014. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2015. return 1;
  2016. }
  2017. return 0;
  2018. }
  2019. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2020. Spawn* spawn = lua_interface->GetSpawn(state);
  2021. if (spawn) {
  2022. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2023. return 1;
  2024. }
  2025. return 0;
  2026. }
  2027. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2028. if (!lua_interface)
  2029. return 0;
  2030. Spawn* spawn = lua_interface->GetSpawn(state);
  2031. float value = lua_interface->GetFloatValue(state, 2);
  2032. lua_interface->ResetFunctionStack(state);
  2033. if (spawn) {
  2034. spawn->SetSpeed(value);
  2035. if(spawn->IsEntity())
  2036. ((Entity*)spawn)->SetSpeed(value);
  2037. if (spawn->IsPlayer()) {
  2038. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2039. if (client) {
  2040. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2041. if (packet) {
  2042. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2043. packet->setDataByName("speed", value);
  2044. packet->setDataByName("size", 0.51);
  2045. EQ2Packet* app = packet->serialize();
  2046. client->QueuePacket(app);
  2047. safe_delete(packet);
  2048. }
  2049. }
  2050. }
  2051. }
  2052. return 0;
  2053. }
  2054. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2055. if (!lua_interface)
  2056. return 0;
  2057. Spawn* spawn = lua_interface->GetSpawn(state);
  2058. const int16 type = lua_interface->GetInt16Value(state, 2);
  2059. const float value = lua_interface->GetFloatValue(state, 3);
  2060. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2061. int64 class_req = 0;
  2062. int32 class_id = 0;
  2063. vector<int16> faction_req;
  2064. vector<int16> race_req;
  2065. int32 i = 0;
  2066. int8 f = 0;
  2067. int8 r = 0;
  2068. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2069. if (class_id < 100) {
  2070. class_req += pow(2.0, double(class_id - 1));
  2071. }
  2072. else if (class_id > 100 && class_id < 1000) {
  2073. race_req.push_back(class_id);
  2074. r++;
  2075. }
  2076. else {
  2077. faction_req.push_back(class_id);
  2078. f++;
  2079. }
  2080. i++;
  2081. }
  2082. if (value != 0 && type >= 0) {
  2083. if (luaspell && luaspell->spell && luaspell->caster) {
  2084. ZoneServer* zone = luaspell->caster->GetZone();
  2085. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2086. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2087. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2088. if (target) {
  2089. if (target->IsPlayer()) {
  2090. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2091. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2092. if (((Player*)target)->GetGroupMemberInfo())
  2093. ((Player*)target)->UpdateGroupMemberInfo();
  2094. ((Player*)target)->SetCharSheetChanged(true);
  2095. }
  2096. else if (target->IsNPC())
  2097. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2098. else
  2099. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2100. }
  2101. }
  2102. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2103. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2104. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2105. }
  2106. else if (spawn && spawn->IsEntity()) {
  2107. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2108. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2109. if (spawn->IsPlayer())
  2110. ((Player*)spawn)->SetCharSheetChanged(true);
  2111. }
  2112. else
  2113. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2114. }
  2115. else
  2116. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2117. return 0;
  2118. }
  2119. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2120. if (!lua_interface)
  2121. return 0;
  2122. Spawn* spawn = lua_interface->GetSpawn(state);
  2123. int16 type = lua_interface->GetInt16Value(state, 2);
  2124. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2125. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2126. if (!spawn) {
  2127. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2128. return 0;
  2129. }
  2130. if (!spawn->IsEntity()) {
  2131. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2132. return 0;
  2133. }
  2134. if (value == 0) {
  2135. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2136. return 0;
  2137. }
  2138. if (!luaspell || !luaspell->spell) {
  2139. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2140. return 0;
  2141. }
  2142. int32 class_req = 0;
  2143. vector<int16> faction_req;
  2144. vector<int16> race_req;
  2145. int32 class_id = 0;
  2146. int32 i = 0;
  2147. int8 f = 0;
  2148. int8 r = 0;
  2149. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2150. if (class_id < 100) {
  2151. class_req += pow(2.0, double(class_id - 1));
  2152. }
  2153. else if (class_id > 100 && class_id < 1000) {
  2154. race_req.push_back(class_id);
  2155. r++;
  2156. }
  2157. else {
  2158. faction_req.push_back(class_id);
  2159. f++;
  2160. }
  2161. i++;
  2162. }
  2163. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2164. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2165. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2166. if (spawn->IsPlayer())
  2167. ((Player*)spawn)->SetCharSheetChanged(true);
  2168. return 0;
  2169. }
  2170. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2171. if (!lua_interface)
  2172. return 0;
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2175. if (!spawn) {
  2176. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2177. return 0;
  2178. }
  2179. if (!spawn->IsEntity()) {
  2180. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2181. return 0;
  2182. }
  2183. if (!luaspell || !luaspell->spell) {
  2184. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2185. return 0;
  2186. }
  2187. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2188. if (spawn->IsPlayer())
  2189. ((Player*)spawn)->SetCharSheetChanged(true);
  2190. return 0;
  2191. }
  2192. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2193. if (!lua_interface)
  2194. return 0;
  2195. Spawn* spawn = lua_interface->GetSpawn(state);
  2196. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2197. if (luaspell && luaspell->spell) {
  2198. ZoneServer* zone = luaspell->caster->GetZone();
  2199. Spawn* target = 0;
  2200. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2201. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2202. target = zone->GetSpawnByID(luaspell->targets[i]);
  2203. if (target && target->IsEntity()) {
  2204. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2205. if (target->IsPlayer())
  2206. ((Player*)target)->SetCharSheetChanged(true);
  2207. }
  2208. }
  2209. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2210. }
  2211. else if (spawn && spawn->IsEntity()) {
  2212. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2213. if (spawn->IsPlayer())
  2214. ((Player*)spawn)->SetCharSheetChanged(true);
  2215. }
  2216. return 0;
  2217. }
  2218. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2219. if (!lua_interface)
  2220. return 0;
  2221. Spawn* spawn = lua_interface->GetSpawn(state);
  2222. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2223. float value = lua_interface->GetFloatValue(state, 3);
  2224. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2225. if (value != 0) {
  2226. int32 spell_id = 0;
  2227. if (luaspell && luaspell->spell && luaspell->caster) {
  2228. spell_id = luaspell->spell->GetSpellID();
  2229. ZoneServer* zone = luaspell->caster->GetZone();
  2230. Spawn* target = 0;
  2231. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2232. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2233. target = zone->GetSpawnByID(luaspell->targets[i]);
  2234. if (target && target->Alive()) {
  2235. if (target->IsPlayer()) {
  2236. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2237. Client* client = target->GetZone()->GetClientBySpawn(target);
  2238. if (client) {
  2239. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2240. if (packet)
  2241. client->QueuePacket(packet);
  2242. }
  2243. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2244. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2245. }
  2246. else if (target->IsNPC()) {
  2247. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2248. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2249. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2250. }
  2251. else
  2252. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2253. }
  2254. }
  2255. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2256. }
  2257. else if (spawn) {
  2258. if (spawn->IsPlayer()) {
  2259. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2260. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2261. if (client) {
  2262. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2263. if (packet)
  2264. client->QueuePacket(packet);
  2265. }
  2266. }
  2267. else if (spawn->IsNPC())
  2268. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2269. else
  2270. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2271. }
  2272. }
  2273. else
  2274. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2275. return 0;
  2276. }
  2277. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2278. if (!lua_interface)
  2279. return 0;
  2280. Spawn* spawn = lua_interface->GetSpawn(state);
  2281. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2282. if (spawn && spawn->IsPlayer()) {
  2283. int32 spell_id = 0;
  2284. if (luaspell && luaspell->spell) {
  2285. spell_id = luaspell->spell->GetSpellID();
  2286. ZoneServer* zone = luaspell->caster->GetZone();
  2287. Spawn* target = 0;
  2288. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2289. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2290. target = zone->GetSpawnByID(luaspell->targets[i]);
  2291. if (target) {
  2292. if (target->IsPlayer()) {
  2293. ((Player*)target)->RemoveSkillBonus(spell_id);
  2294. Client* client = target->GetZone()->GetClientBySpawn(target);
  2295. if (client) {
  2296. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2297. if (packet)
  2298. client->QueuePacket(packet);
  2299. }
  2300. }
  2301. else if (target->IsNPC())
  2302. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2303. else
  2304. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2305. }
  2306. }
  2307. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2308. }
  2309. else if (spawn) {
  2310. if (spawn->IsPlayer()) {
  2311. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2312. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2313. if (client) {
  2314. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2315. if (packet)
  2316. client->QueuePacket(packet);
  2317. }
  2318. }
  2319. else if (spawn->IsNPC())
  2320. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2321. else
  2322. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2323. }
  2324. }
  2325. return 0;
  2326. }
  2327. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2328. if (!lua_interface)
  2329. return 0;
  2330. Spawn* spawn = lua_interface->GetSpawn(state);
  2331. int8 type = lua_interface->GetInt32Value(state, 2);
  2332. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2333. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2334. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2335. ZoneServer* zone = luaspell->caster->GetZone();
  2336. Spawn* target = 0;
  2337. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2338. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2339. target = zone->GetSpawnByID(luaspell->targets[i]);
  2340. if (target && target->IsEntity()) {
  2341. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2342. ((Entity*)target)->AddMezSpell(luaspell);
  2343. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2344. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2345. if (target->IsNPC())
  2346. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2347. }
  2348. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2349. ((Entity*)target)->AddStifleSpell(luaspell);
  2350. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2351. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2352. if (target->IsNPC())
  2353. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2354. }
  2355. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2356. ((Entity*)target)->AddDazeSpell(luaspell);
  2357. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2358. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2359. if (target->IsNPC())
  2360. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2361. }
  2362. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2363. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2364. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2365. ((Entity*)target)->AddStunSpell(luaspell);
  2366. if (target->IsNPC())
  2367. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2368. }
  2369. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2370. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2371. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2372. ((Entity*)target)->AddRootSpell(luaspell);
  2373. if (target->IsNPC())
  2374. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2375. }
  2376. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2377. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2378. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2379. ((Entity*)target)->AddFearSpell(luaspell);
  2380. if (target->IsNPC())
  2381. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2382. }
  2383. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2384. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2385. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2386. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2387. }
  2388. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2389. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2390. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2391. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2392. }
  2393. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2394. ((Entity*)target)->AddSnareSpell(luaspell);
  2395. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2396. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2397. if (target->IsNPC())
  2398. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2399. }
  2400. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2401. ((Entity*)target)->AddFlightSpell(luaspell);
  2402. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2403. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2404. }
  2405. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2406. ((Entity*)target)->AddGlideSpell(luaspell);
  2407. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2408. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2409. }
  2410. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2411. ((Entity*)target)->AddSafefallSpell(luaspell);
  2412. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2413. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2414. }
  2415. else
  2416. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2417. }
  2418. else
  2419. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2420. }
  2421. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2422. }
  2423. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2424. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2425. ((Entity*)spawn)->AddMezSpell(luaspell);
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2428. }
  2429. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2430. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2431. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2432. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2433. }
  2434. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2435. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2436. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2437. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2438. }
  2439. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2440. ((Entity*)spawn)->AddStunSpell(luaspell);
  2441. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2442. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2443. }
  2444. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2445. ((Entity*)spawn)->AddRootSpell(luaspell);
  2446. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2447. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2448. }
  2449. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2450. ((Entity*)spawn)->AddFearSpell(luaspell);
  2451. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2452. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2453. }
  2454. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2455. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2456. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2457. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2458. }
  2459. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2460. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2461. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2462. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2463. }
  2464. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2465. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2466. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2467. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2468. }
  2469. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2470. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2471. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2472. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2473. }
  2474. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2475. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2476. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2477. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2478. }
  2479. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2480. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2481. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2482. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2483. }
  2484. else
  2485. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2486. }
  2487. else
  2488. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2489. return 0;
  2490. }
  2491. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2492. if (!lua_interface)
  2493. return 0;
  2494. Spawn* spawn = lua_interface->GetSpawn(state);
  2495. int8 type = lua_interface->GetInt8Value(state, 2);
  2496. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2497. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2498. if (spawn && spawn->IsEntity()) {
  2499. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2500. ZoneServer* zone = luaspell->caster->GetZone();
  2501. Spawn* target = 0;
  2502. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2503. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2504. target = zone->GetSpawnByID(luaspell->targets[i]);
  2505. if (target) {
  2506. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2507. ((Entity*)target)->RemoveMezSpell(luaspell);
  2508. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2509. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2510. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2511. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2512. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2513. ((Entity*)target)->RemoveStunSpell(luaspell);
  2514. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2515. ((Entity*)target)->RemoveRootSpell(luaspell);
  2516. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2517. ((Entity*)target)->RemoveFearSpell(luaspell);
  2518. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2519. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2520. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2521. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2522. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2523. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2524. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2525. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2526. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2527. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2528. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2529. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2530. else
  2531. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2532. }
  2533. }
  2534. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2535. }
  2536. else if (only_remove_spawn) {
  2537. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2538. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2539. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2540. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2541. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2542. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2543. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2544. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2545. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2546. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2547. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2548. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2549. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2550. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2551. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2552. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2553. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2554. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2555. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2556. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2557. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2558. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2559. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2560. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2561. else
  2562. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2563. }
  2564. }
  2565. return 0;
  2566. }
  2567. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2568. if (!lua_interface)
  2569. return 0;
  2570. Spawn* spawn = lua_interface->GetSpawn(state);
  2571. int8 type = lua_interface->GetInt8Value(state, 2);
  2572. bool hasEffect = false;
  2573. if (!spawn)
  2574. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2575. else if (!spawn->IsEntity())
  2576. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2577. else if (type < CONTROL_MAX_EFFECTS)
  2578. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2579. else
  2580. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2581. lua_interface->SetBooleanValue(state, hasEffect);
  2582. return 1;
  2583. }
  2584. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2585. if (!lua_interface)
  2586. return 0;
  2587. Spawn* spawn = lua_interface->GetSpawn(state);
  2588. float distance = 0.0f;
  2589. if (!spawn)
  2590. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2591. else if (!spawn->IsNPC())
  2592. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2593. else
  2594. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2595. lua_interface->SetFloatValue(state, distance);
  2596. return 1;
  2597. }
  2598. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2599. if (!lua_interface)
  2600. return 0;
  2601. Spawn* spawn = lua_interface->GetSpawn(state);
  2602. float distance = 0.0f;
  2603. if (!spawn)
  2604. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2605. else if (!spawn->IsNPC())
  2606. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2607. else
  2608. distance = ((NPC*)spawn)->GetAggroRadius();
  2609. lua_interface->SetFloatValue(state, distance);
  2610. return 1;
  2611. }
  2612. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2613. if (!lua_interface)
  2614. return 0;
  2615. Spawn* spawn = lua_interface->GetSpawn(state);
  2616. float distance = lua_interface->GetFloatValue(state, 2);
  2617. bool override = lua_interface->GetBooleanValue(state, 3);
  2618. bool result = false;
  2619. lua_interface->ResetFunctionStack(state);
  2620. if (!spawn)
  2621. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2622. else if (!spawn->IsNPC())
  2623. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2624. else
  2625. {
  2626. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2627. result = true;
  2628. }
  2629. lua_interface->SetBooleanValue(state, result);
  2630. return 1;
  2631. }
  2632. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2633. if (!lua_interface)
  2634. return 0;
  2635. Spawn* spawn = lua_interface->GetSpawn(state);
  2636. int16 value = lua_interface->GetInt16Value(state, 2);
  2637. if (spawn && spawn->IsEntity()) {
  2638. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2639. if (spawn->IsPlayer())
  2640. ((Player*)spawn)->SetCharSheetChanged(true);
  2641. }
  2642. return 0;
  2643. }
  2644. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2645. if (!lua_interface)
  2646. return 0;
  2647. Spawn* spawn = lua_interface->GetSpawn(state);
  2648. int16 value = lua_interface->GetInt16Value(state, 2);
  2649. if (spawn && spawn->IsEntity()) {
  2650. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2651. if (spawn->IsPlayer())
  2652. ((Player*)spawn)->SetCharSheetChanged(true);
  2653. }
  2654. return 0;
  2655. }
  2656. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2657. if (!lua_interface)
  2658. return 0;
  2659. Spawn* spawn = lua_interface->GetSpawn(state);
  2660. int16 value = lua_interface->GetInt16Value(state, 2);
  2661. if (spawn && spawn->IsEntity()) {
  2662. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2663. if (spawn->IsPlayer())
  2664. ((Player*)spawn)->SetCharSheetChanged(true);
  2665. }
  2666. return 0;
  2667. }
  2668. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2669. if (!lua_interface)
  2670. return 0;
  2671. Spawn* spawn = lua_interface->GetSpawn(state);
  2672. int16 value = lua_interface->GetInt16Value(state, 2);
  2673. if (spawn && spawn->IsEntity()) {
  2674. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2675. if (spawn->IsPlayer())
  2676. ((Player*)spawn)->SetCharSheetChanged(true);
  2677. }
  2678. return 0;
  2679. }
  2680. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2681. if (!lua_interface)
  2682. return 0;
  2683. Spawn* spawn = lua_interface->GetSpawn(state);
  2684. int16 value = lua_interface->GetInt16Value(state, 2);
  2685. if (spawn && spawn->IsEntity()) {
  2686. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2687. if (spawn->IsPlayer())
  2688. ((Player*)spawn)->SetCharSheetChanged(true);
  2689. }
  2690. return 0;
  2691. }
  2692. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2693. if (!lua_interface)
  2694. return 0;
  2695. Spawn* spawn = lua_interface->GetSpawn(state);
  2696. int8 value = lua_interface->GetInt8Value(state, 2);
  2697. if (spawn && spawn->IsEntity()) {
  2698. ((Entity*)spawn)->SetDeity(value);
  2699. if (spawn->IsPlayer())
  2700. ((Player*)spawn)->SetCharSheetChanged(true);
  2701. }
  2702. lua_interface->ResetFunctionStack(state);
  2703. return 0;
  2704. }
  2705. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2706. if (!lua_interface)
  2707. return 0;
  2708. Spawn* spawn = lua_interface->GetSpawn(state);
  2709. if (spawn && spawn->IsEntity()) {
  2710. int8 deity = ((Entity*)spawn)->GetDeity();
  2711. lua_interface->SetInt32Value(state, deity);
  2712. return 1;
  2713. }
  2714. return 0;
  2715. }
  2716. int EQ2Emu_lua_SetInt(lua_State* state) {
  2717. if (!lua_interface)
  2718. return 0;
  2719. Spawn* spawn = lua_interface->GetSpawn(state);
  2720. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2721. if (spawn && spawn->IsEntity()) {
  2722. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2723. if (spawn->IsPlayer())
  2724. ((Player*)spawn)->SetCharSheetChanged(true);
  2725. }
  2726. return 0;
  2727. }
  2728. int EQ2Emu_lua_SetWis(lua_State* state) {
  2729. if (!lua_interface)
  2730. return 0;
  2731. Spawn* spawn = lua_interface->GetSpawn(state);
  2732. float value = lua_interface->GetFloatValue(state, 2);
  2733. if (spawn && spawn->IsEntity()) {
  2734. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2735. if (spawn->IsPlayer())
  2736. ((Player*)spawn)->SetCharSheetChanged(true);
  2737. }
  2738. return 0;
  2739. }
  2740. int EQ2Emu_lua_SetSta(lua_State* state) {
  2741. if (!lua_interface)
  2742. return 0;
  2743. Spawn* spawn = lua_interface->GetSpawn(state);
  2744. float value = lua_interface->GetFloatValue(state, 2);
  2745. if (spawn && spawn->IsEntity()) {
  2746. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2747. if (spawn->IsPlayer())
  2748. ((Player*)spawn)->SetCharSheetChanged(true);
  2749. }
  2750. return 0;
  2751. }
  2752. int EQ2Emu_lua_SetStr(lua_State* state) {
  2753. if (!lua_interface)
  2754. return 0;
  2755. Spawn* spawn = lua_interface->GetSpawn(state);
  2756. float value = lua_interface->GetFloatValue(state, 2);
  2757. if (spawn && spawn->IsEntity()) {
  2758. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2759. if (spawn->IsPlayer())
  2760. ((Player*)spawn)->SetCharSheetChanged(true);
  2761. }
  2762. return 0;
  2763. }
  2764. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2765. if (!lua_interface)
  2766. return 0;
  2767. Spawn* spawn = lua_interface->GetSpawn(state);
  2768. float value = lua_interface->GetFloatValue(state, 2);
  2769. if (spawn && spawn->IsEntity()) {
  2770. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2771. if (spawn->IsPlayer())
  2772. ((Player*)spawn)->SetCharSheetChanged(true);
  2773. }
  2774. return 0;
  2775. }
  2776. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2777. if (!lua_interface)
  2778. return 0;
  2779. Spawn* spawn = lua_interface->GetSpawn(state);
  2780. if (spawn) {
  2781. lua_interface->SetInt32Value(state, spawn->GetHP());
  2782. return 1;
  2783. }
  2784. return 0;
  2785. }
  2786. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2787. if (!lua_interface)
  2788. return 0;
  2789. Spawn* spawn = lua_interface->GetSpawn(state);
  2790. if (spawn) {
  2791. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2792. return 1;
  2793. }
  2794. return 0;
  2795. }
  2796. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2797. if (!lua_interface)
  2798. return 0;
  2799. Spawn* spawn = lua_interface->GetSpawn(state);
  2800. if (spawn) {
  2801. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2802. return 1;
  2803. }
  2804. return 0;
  2805. }
  2806. int EQ2Emu_lua_GetName(lua_State* state) {
  2807. if (!lua_interface)
  2808. return 0;
  2809. Spawn* spawn = lua_interface->GetSpawn(state);
  2810. if (spawn) {
  2811. lua_interface->SetStringValue(state, spawn->GetName());
  2812. return 1;
  2813. }
  2814. return 0;
  2815. }
  2816. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2817. Spawn* spawn = lua_interface->GetSpawn(state);
  2818. if (spawn) {
  2819. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2820. return 1;
  2821. }
  2822. return 0;
  2823. }
  2824. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2825. if (!lua_interface)
  2826. return 0;
  2827. Spawn* spawn = lua_interface->GetSpawn(state);
  2828. if (spawn) {
  2829. lua_interface->SetInt32Value(state, spawn->GetPower());
  2830. return 1;
  2831. }
  2832. return 0;
  2833. }
  2834. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2835. if (!lua_interface)
  2836. return 0;
  2837. Spawn* spawn = lua_interface->GetSpawn(state);
  2838. if (spawn) {
  2839. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2840. return 1;
  2841. }
  2842. return 0;
  2843. }
  2844. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2845. if (!lua_interface)
  2846. return 0;
  2847. Spawn* spawn = lua_interface->GetSpawn(state);
  2848. if (spawn) {
  2849. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2850. return 1;
  2851. }
  2852. return 0;
  2853. }
  2854. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2855. if (!lua_interface)
  2856. return 0;
  2857. Spawn* spawn = lua_interface->GetSpawn(state);
  2858. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2859. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2860. if (spawn && spawn2) {
  2861. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2862. lua_interface->SetFloatValue(state, distance);
  2863. return 1;
  2864. }
  2865. return 0;
  2866. }
  2867. int EQ2Emu_lua_GetX(lua_State* state) {
  2868. if (!lua_interface)
  2869. return 0;
  2870. Spawn* spawn = lua_interface->GetSpawn(state);
  2871. if (spawn) {
  2872. lua_interface->SetFloatValue(state, spawn->GetX());
  2873. return 1;
  2874. }
  2875. return 0;
  2876. }
  2877. int EQ2Emu_lua_GetY(lua_State* state) {
  2878. if (!lua_interface)
  2879. return 0;
  2880. Spawn* spawn = lua_interface->GetSpawn(state);
  2881. if (spawn) {
  2882. lua_interface->SetFloatValue(state, spawn->GetY());
  2883. return 1;
  2884. }
  2885. return 0;
  2886. }
  2887. int EQ2Emu_lua_GetZ(lua_State* state) {
  2888. if (!lua_interface)
  2889. return 0;
  2890. Spawn* spawn = lua_interface->GetSpawn(state);
  2891. if (spawn) {
  2892. lua_interface->SetFloatValue(state, spawn->GetZ());
  2893. return 1;
  2894. }
  2895. return 0;
  2896. }
  2897. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2898. if (!lua_interface)
  2899. return 0;
  2900. Spawn* spawn = lua_interface->GetSpawn(state);
  2901. if (spawn) {
  2902. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2908. if (!lua_interface)
  2909. return 0;
  2910. Spawn* spawn = lua_interface->GetSpawn(state);
  2911. if (spawn) {
  2912. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2913. return 1;
  2914. }
  2915. return 0;
  2916. }
  2917. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2918. if (!lua_interface)
  2919. return 0;
  2920. Spawn* spawn = lua_interface->GetSpawn(state);
  2921. if (spawn) {
  2922. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2923. return 1;
  2924. }
  2925. return 0;
  2926. }
  2927. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2928. if (!lua_interface)
  2929. return 0;
  2930. Spawn* spawn = lua_interface->GetSpawn(state);
  2931. if (spawn && spawn->IsEntity()) {
  2932. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2933. return 1;
  2934. }
  2935. return 0;
  2936. }
  2937. int EQ2Emu_lua_GetInt(lua_State* state) {
  2938. if (!lua_interface)
  2939. return 0;
  2940. Spawn* spawn = lua_interface->GetSpawn(state);
  2941. if (spawn && spawn->IsEntity()) {
  2942. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2943. return 1;
  2944. }
  2945. return 0;
  2946. }
  2947. int EQ2Emu_lua_GetWis(lua_State* state) {
  2948. if (!lua_interface)
  2949. return 0;
  2950. Spawn* spawn = lua_interface->GetSpawn(state);
  2951. if (spawn && spawn->IsEntity()) {
  2952. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2953. return 1;
  2954. }
  2955. return 0;
  2956. }
  2957. int EQ2Emu_lua_GetSta(lua_State* state) {
  2958. if (!lua_interface)
  2959. return 0;
  2960. Spawn* spawn = lua_interface->GetSpawn(state);
  2961. if (spawn && spawn->IsEntity()) {
  2962. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2963. return 1;
  2964. }
  2965. return 0;
  2966. }
  2967. int EQ2Emu_lua_GetStr(lua_State* state) {
  2968. if (!lua_interface)
  2969. return 0;
  2970. Spawn* spawn = lua_interface->GetSpawn(state);
  2971. if (spawn && spawn->IsEntity()) {
  2972. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2973. return 1;
  2974. }
  2975. return 0;
  2976. }
  2977. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2978. if (!lua_interface)
  2979. return 0;
  2980. Spawn* spawn = lua_interface->GetSpawn(state);
  2981. if (spawn && spawn->IsEntity()) {
  2982. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2983. return 1;
  2984. }
  2985. return 0;
  2986. }
  2987. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2988. if (!lua_interface)
  2989. return 0;
  2990. Spawn* spawn = lua_interface->GetSpawn(state);
  2991. if (spawn && spawn->IsEntity()) {
  2992. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2993. return 1;
  2994. }
  2995. return 0;
  2996. }
  2997. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2998. if (!lua_interface)
  2999. return 0;
  3000. Spawn* spawn = lua_interface->GetSpawn(state);
  3001. if (spawn && spawn->IsEntity()) {
  3002. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3003. return 1;
  3004. }
  3005. return 0;
  3006. }
  3007. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3008. if (!lua_interface)
  3009. return 0;
  3010. Spawn* spawn = lua_interface->GetSpawn(state);
  3011. if (spawn && spawn->IsEntity()) {
  3012. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3013. return 1;
  3014. }
  3015. return 0;
  3016. }
  3017. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3018. if (!lua_interface)
  3019. return 0;
  3020. Spawn* spawn = lua_interface->GetSpawn(state);
  3021. if (spawn && spawn->IsEntity()) {
  3022. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3023. return 1;
  3024. }
  3025. return 0;
  3026. }
  3027. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3028. if (!lua_interface)
  3029. return 0;
  3030. Spawn* spawn = lua_interface->GetSpawn(state);
  3031. if (spawn && spawn->IsEntity()) {
  3032. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3033. return 1;
  3034. }
  3035. return 0;
  3036. }
  3037. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3038. if (!lua_interface)
  3039. return 0;
  3040. Spawn* player = lua_interface->GetSpawn(state);
  3041. if (!player || !player->IsPlayer()) {
  3042. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3043. return 0;
  3044. }
  3045. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3046. if (quest_id <= 0) {
  3047. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3048. return 0;
  3049. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3050. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3051. return 0;
  3052. }
  3053. int32 step = lua_interface->GetInt32Value(state, 3);
  3054. if (step > 0) {
  3055. Client* client = player->GetZone()->GetClientBySpawn(player);
  3056. if (client)
  3057. client->AddPendingQuestUpdate(quest_id, step);
  3058. } else {
  3059. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3060. }
  3061. return 0;
  3062. }
  3063. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3064. Spawn* player = lua_interface->GetSpawn(state);
  3065. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3066. int32 step = lua_interface->GetInt32Value(state, 3);
  3067. int32 progress = lua_interface->GetInt32Value(state, 4);
  3068. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3069. Client* client = player->GetZone()->GetClientBySpawn(player);
  3070. if (client)
  3071. client->AddPendingQuestUpdate(quest_id, step, progress);
  3072. }
  3073. return 0;
  3074. }
  3075. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3076. if (!lua_interface)
  3077. return 0;
  3078. Spawn* player = lua_interface->GetSpawn(state);
  3079. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3080. if (player && player->IsPlayer() && quest_id > 0) {
  3081. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3082. return 1;
  3083. }
  3084. return 0;
  3085. }
  3086. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3087. if (!lua_interface)
  3088. return 0;
  3089. Spawn* player = lua_interface->GetSpawn(state);
  3090. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3091. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3092. if (player && player->IsPlayer() && quest_id > 0) {
  3093. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3094. return 1;
  3095. }
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3099. if (!lua_interface)
  3100. return 0;
  3101. Spawn* player = lua_interface->GetSpawn(state);
  3102. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3103. if (player && player->IsPlayer() && quest_id > 0) {
  3104. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3105. return 1;
  3106. }
  3107. return 0;
  3108. }
  3109. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3110. if (!lua_interface)
  3111. return 0;
  3112. Quest* quest = lua_interface->GetQuest(state);
  3113. string name = lua_interface->GetStringValue(state, 2);
  3114. string type = lua_interface->GetStringValue(state, 3);
  3115. string zone = lua_interface->GetStringValue(state, 4);
  3116. int16 level = lua_interface->GetInt16Value(state, 5);
  3117. string description = lua_interface->GetStringValue(state, 6);
  3118. bool load = true;
  3119. if (!quest) {
  3120. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3121. load = false;
  3122. }
  3123. if (load && name.length() == 0) {
  3124. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3125. load = false;
  3126. }
  3127. if (load && type.length() == 0) {
  3128. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3129. load = false;
  3130. }
  3131. if (load && zone.length() == 0) {
  3132. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3133. load = false;
  3134. }
  3135. if (load && description.length() == 0) {
  3136. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3137. load = false;
  3138. }
  3139. if (load && level == 0) {
  3140. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3141. load = false;
  3142. }
  3143. if (load)
  3144. quest->RegisterQuest(name, type, zone, level, description);
  3145. return 0;
  3146. }
  3147. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3148. if (!lua_interface)
  3149. return 0;
  3150. Quest* quest = lua_interface->GetQuest(state);
  3151. if (quest) {
  3152. int8 level = lua_interface->GetInt16Value(state, 2);
  3153. quest->SetPrereqLevel(level);
  3154. }
  3155. return 0;
  3156. }
  3157. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3158. if (!lua_interface)
  3159. return 0;
  3160. Quest* quest = lua_interface->GetQuest(state);
  3161. if (quest) {
  3162. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3163. quest->AddPrereqQuest(quest_id);
  3164. }
  3165. return 0;
  3166. }
  3167. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3168. if (!lua_interface)
  3169. return 0;
  3170. Quest* quest = lua_interface->GetQuest(state);
  3171. if (quest) {
  3172. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3173. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3174. if (quantity == 0)
  3175. quantity = 1;
  3176. Item* master_item = master_item_list.GetItem(item_id);
  3177. if (master_item) {
  3178. Item* item = new Item(master_item);
  3179. item->details.count = quantity;
  3180. quest->AddPrereqItem(item);
  3181. }
  3182. }
  3183. return 0;
  3184. }
  3185. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3186. if (!lua_interface)
  3187. return 0;
  3188. Spawn* player = lua_interface->GetSpawn(state);
  3189. if(!player || !player->IsPlayer()) {
  3190. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3191. return 0;
  3192. }
  3193. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3194. if (quest_id > 0) {
  3195. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3196. return 1;
  3197. } else {
  3198. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3199. }
  3200. return 0;
  3201. }
  3202. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3203. if (!lua_interface)
  3204. return 0;
  3205. Quest* quest = lua_interface->GetQuest(state);
  3206. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3207. lua_interface->ResetFunctionStack(state);
  3208. if (quest && spawn_id > 0)
  3209. quest->SetQuestReturnNPC(spawn_id);
  3210. return 0;
  3211. }
  3212. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3213. if (!lua_interface)
  3214. return 0;
  3215. Spawn* spawn = lua_interface->GetSpawn(state);
  3216. int32 time = lua_interface->GetInt32Value(state, 2);
  3217. string function = lua_interface->GetStringValue(state, 3);
  3218. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3219. Spawn* player = lua_interface->GetSpawn(state, 5);
  3220. lua_interface->ResetFunctionStack(state);
  3221. if (!spawn) {
  3222. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3223. return 0;
  3224. }
  3225. if (time <= 0) {
  3226. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3227. return 0;
  3228. }
  3229. if (function.length() == 0) {
  3230. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3231. return 0;
  3232. }
  3233. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3234. if ( time < 10)
  3235. time = 10;
  3236. timer->timer = Timer::GetCurrentTime2() + time;
  3237. timer->function = function;
  3238. timer->spawn = spawn->GetID();
  3239. timer->player = player ? player->GetID() : 0;
  3240. if (max_count == 0)
  3241. max_count = 1;
  3242. timer->max_count = max_count;
  3243. timer->current_count = 0;
  3244. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3245. return 0;
  3246. }
  3247. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3248. if (!lua_interface)
  3249. return 0;
  3250. Spawn* spawn = lua_interface->GetSpawn(state);
  3251. string function = lua_interface->GetStringValue(state, 2);
  3252. lua_interface->ResetFunctionStack(state);
  3253. if (!spawn) {
  3254. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3255. return 0;
  3256. }
  3257. if(!spawn->GetZone()) {
  3258. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3259. return 0;
  3260. }
  3261. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3262. return 0;
  3263. }
  3264. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3265. if (!lua_interface)
  3266. return 0;
  3267. Spawn* player = lua_interface->GetSpawn(state);
  3268. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3269. lua_interface->ResetFunctionStack(state);
  3270. if (player && player->IsPlayer() && quest_id > 0) {
  3271. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3272. return 1;
  3273. }
  3274. return 0;
  3275. }
  3276. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3277. if (!lua_interface)
  3278. return 0;
  3279. Spawn* player = lua_interface->GetSpawn(state);
  3280. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3281. lua_interface->ResetFunctionStack(state);
  3282. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3283. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3284. if (quest)
  3285. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3286. return 1;
  3287. }
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Spawn* player = lua_interface->GetSpawn(state);
  3294. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3295. lua_interface->ResetFunctionStack(state);
  3296. if (player && player->IsPlayer() && quest_id > 0) {
  3297. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3298. return 1;
  3299. }
  3300. return 0;
  3301. }
  3302. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3303. if (!lua_interface)
  3304. return 0;
  3305. Spawn* npc = lua_interface->GetSpawn(state);
  3306. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3307. lua_interface->ResetFunctionStack(state);
  3308. if (npc && !npc->IsPlayer() && quest_id > 0)
  3309. npc->AddProvidedQuest(quest_id);
  3310. return 0;
  3311. }
  3312. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3313. if (!lua_interface)
  3314. return 0;
  3315. Spawn* npc = lua_interface->GetSpawn(state);
  3316. Spawn* player = lua_interface->GetSpawn(state, 2);
  3317. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3318. bool forced = lua_interface->GetBooleanValue(state, 4);
  3319. lua_interface->ResetFunctionStack(state);
  3320. /* NPC is allowed to be null */
  3321. if (player && player->IsPlayer() && quest_id > 0) {
  3322. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3323. if (master_quest) {
  3324. Client* client = player->GetZone()->GetClientBySpawn(player);
  3325. if (!client) {
  3326. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3327. }
  3328. Quest* quest = new Quest(master_quest);
  3329. if (!quest) {
  3330. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3331. }
  3332. if (client && quest) {
  3333. if (npc)
  3334. quest->SetQuestGiver(npc->GetDatabaseID());
  3335. else
  3336. quest->SetQuestGiver(0);
  3337. client->AddPendingQuest(quest, forced);
  3338. }
  3339. }
  3340. else {
  3341. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3342. }
  3343. }
  3344. else {
  3345. 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);
  3346. }
  3347. return 0;
  3348. }
  3349. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3350. if (!lua_interface)
  3351. return 0;
  3352. Quest* quest = lua_interface->GetQuest(state);
  3353. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3354. lua_interface->ResetFunctionStack(state);
  3355. if (quest) {
  3356. quest->AddPrereqClass(class_id);
  3357. }
  3358. return 0;
  3359. }
  3360. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3361. if (!lua_interface)
  3362. return 0;
  3363. Quest* quest = lua_interface->GetQuest(state);
  3364. int8 race = lua_interface->GetInt8Value(state, 2);
  3365. lua_interface->ResetFunctionStack(state);
  3366. if (quest) {
  3367. quest->AddPrereqRace(race);
  3368. }
  3369. return 0;
  3370. }
  3371. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3372. if (!lua_interface)
  3373. return 0;
  3374. Quest* quest = lua_interface->GetQuest(state);
  3375. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3376. lua_interface->ResetFunctionStack(state);
  3377. if (quest) {
  3378. quest->AddPrereqModelType(model_type);
  3379. }
  3380. return 0;
  3381. }
  3382. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3383. if (!lua_interface)
  3384. return 0;
  3385. Quest* quest = lua_interface->GetQuest(state);
  3386. int8 level = lua_interface->GetInt8Value(state, 2);
  3387. lua_interface->ResetFunctionStack(state);
  3388. if (!quest) {
  3389. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3390. return 0;
  3391. }
  3392. quest->SetPrereqTSLevel(level);
  3393. return 0;
  3394. }
  3395. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3396. if (!lua_interface)
  3397. return 0;
  3398. Quest* quest = lua_interface->GetQuest(state);
  3399. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3400. lua_interface->ResetFunctionStack(state);
  3401. if (!quest) {
  3402. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3403. return 0;
  3404. }
  3405. quest->AddPrereqTradeskillClass(class_id);
  3406. return 0;
  3407. }
  3408. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3409. if (!lua_interface)
  3410. return 0;
  3411. Quest* quest = lua_interface->GetQuest(state);
  3412. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3413. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3414. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3415. lua_interface->ResetFunctionStack(state);
  3416. if (quest) {
  3417. quest->AddPrereqFaction(faction_id, min, max);
  3418. }
  3419. return 0;
  3420. }
  3421. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3422. if (!lua_interface)
  3423. return 0;
  3424. Quest* quest = lua_interface->GetQuest(state);
  3425. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3426. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3427. lua_interface->ResetFunctionStack(state);
  3428. if (quest) {
  3429. if (quantity == 0)
  3430. quantity = 1;
  3431. Item* master_item = master_item_list.GetItem(item_id);
  3432. if (master_item) {
  3433. Item* item = new Item(master_item);
  3434. item->details.count = quantity;
  3435. quest->AddSelectableRewardItem(item);
  3436. }
  3437. }
  3438. return 0;
  3439. }
  3440. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3441. if (!lua_interface)
  3442. return 0;
  3443. Quest* quest = lua_interface->GetQuest(state);
  3444. if (quest) {
  3445. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3446. vector<Item*>* items = quest->GetRewardItems();
  3447. if (items) {
  3448. vector<Item*>::iterator itr;
  3449. for (itr = items->begin(); itr != items->end(); itr++) {
  3450. if (*itr && (*itr)->details.item_id == item_id) {
  3451. lua_interface->SetBooleanValue(state, true);
  3452. return 1;
  3453. }
  3454. }
  3455. }
  3456. }
  3457. lua_interface->SetBooleanValue(state, false);
  3458. return 1;
  3459. }
  3460. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3461. if (!lua_interface)
  3462. return 0;
  3463. Quest* quest = lua_interface->GetQuest(state);
  3464. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3465. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3466. lua_interface->ResetFunctionStack(state);
  3467. if (quest) {
  3468. if (quantity == 0)
  3469. quantity = 1;
  3470. Item* master_item = master_item_list.GetItem(item_id);
  3471. if (master_item) {
  3472. Item* item = new Item(master_item);
  3473. item->details.count = quantity;
  3474. quest->AddRewardItem(item);
  3475. }
  3476. }
  3477. return 0;
  3478. }
  3479. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3480. if (!lua_interface)
  3481. return 0;
  3482. Quest* quest = lua_interface->GetQuest(state);
  3483. int32 copper = lua_interface->GetInt32Value(state, 2);
  3484. int32 silver = lua_interface->GetInt32Value(state, 3);
  3485. int32 gold = lua_interface->GetInt32Value(state, 4);
  3486. int32 plat = lua_interface->GetInt32Value(state, 5);
  3487. lua_interface->ResetFunctionStack(state);
  3488. if (quest) {
  3489. quest->AddRewardCoins(copper, silver, gold, plat);
  3490. }
  3491. return 0;
  3492. }
  3493. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3494. if (!lua_interface)
  3495. return 0;
  3496. Quest* quest = lua_interface->GetQuest(state);
  3497. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3498. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3499. lua_interface->ResetFunctionStack(state);
  3500. if (quest && faction_id > 0 && amount != 0)
  3501. quest->AddRewardFaction(faction_id, amount);
  3502. return 0;
  3503. }
  3504. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3505. if (!lua_interface)
  3506. return 0;
  3507. Quest* quest = lua_interface->GetQuest(state);
  3508. int32 status = lua_interface->GetInt32Value(state, 2);
  3509. lua_interface->ResetFunctionStack(state);
  3510. if (quest) {
  3511. quest->SetRewardStatus(status);
  3512. }
  3513. return 0;
  3514. }
  3515. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3516. if (!lua_interface)
  3517. return 0;
  3518. Quest* quest = lua_interface->GetQuest(state);
  3519. int32 status = lua_interface->GetInt32Value(state, 2);
  3520. lua_interface->ResetFunctionStack(state);
  3521. if (quest) {
  3522. quest->SetStatusTmpReward(status);
  3523. }
  3524. return 0;
  3525. }
  3526. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3527. if (!lua_interface)
  3528. return 0;
  3529. Quest* quest = lua_interface->GetQuest(state);
  3530. int64 coins = lua_interface->GetInt64Value(state, 2);
  3531. lua_interface->ResetFunctionStack(state);
  3532. if (quest) {
  3533. quest->SetCoinTmpReward(coins);
  3534. }
  3535. return 0;
  3536. }
  3537. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3538. if (!lua_interface)
  3539. return 0;
  3540. Quest* quest = lua_interface->GetQuest(state);
  3541. string comment = lua_interface->GetStringValue(state, 2);
  3542. lua_interface->ResetFunctionStack(state);
  3543. if (quest) {
  3544. quest->SetRewardComment(comment);
  3545. }
  3546. return 0;
  3547. }
  3548. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3549. if (!lua_interface)
  3550. return 0;
  3551. Quest* quest = lua_interface->GetQuest(state);
  3552. int32 exp = lua_interface->GetInt32Value(state, 2);
  3553. lua_interface->ResetFunctionStack(state);
  3554. if (quest) {
  3555. quest->SetRewardXP(exp);
  3556. }
  3557. return 0;
  3558. }
  3559. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3560. Quest* quest = lua_interface->GetQuest(state);
  3561. int32 step = lua_interface->GetInt32Value(state, 2);
  3562. string description = lua_interface->GetStringValue(state, 3);
  3563. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3564. float percentage = lua_interface->GetFloatValue(state, 5);
  3565. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3566. int16 icon = lua_interface->GetInt16Value(state, 7);
  3567. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3568. if (quest) {
  3569. const char* taskgroup = 0;
  3570. if (str_taskgroup.length() > 0)
  3571. taskgroup = str_taskgroup.c_str();
  3572. int32 id = 0;
  3573. vector<int32>* ids = 0;
  3574. int i = 0;
  3575. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3576. if (ids == 0)
  3577. ids = new vector<int32>;
  3578. ids->push_back(id);
  3579. i++;
  3580. }
  3581. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3582. if (quest_step && icon && quantity > 0)
  3583. quest_step->SetIcon(icon);
  3584. if (quest->GetPlayer()) {
  3585. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3586. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3587. }
  3588. }
  3589. lua_interface->ResetFunctionStack(state);
  3590. return 0;
  3591. }
  3592. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3593. {
  3594. if (!lua_interface)
  3595. return 0;
  3596. Quest* quest = lua_interface->GetQuest(state);
  3597. int32 step = lua_interface->GetInt32Value(state, 2);
  3598. string description = lua_interface->GetStringValue(state, 3);
  3599. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3600. float percentage = lua_interface->GetFloatValue(state, 5);
  3601. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3602. int16 icon = lua_interface->GetInt16Value(state, 7);
  3603. if (quest) {
  3604. const char* taskgroup = 0;
  3605. if (str_taskgroup.length() > 0)
  3606. taskgroup = str_taskgroup.c_str();
  3607. int32 id = 0;
  3608. vector<int32>* ids = 0;
  3609. int i = 0;
  3610. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3611. if (ids == 0)
  3612. ids = new vector<int32>;
  3613. ids->push_back(id);
  3614. i++;
  3615. }
  3616. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3617. if (quest_step && icon > 0 && quantity > 0)
  3618. quest_step->SetIcon(icon);
  3619. if (quest->GetPlayer()) {
  3620. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3621. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3622. }
  3623. safe_delete(ids);
  3624. }
  3625. lua_interface->ResetFunctionStack(state);
  3626. return 0;
  3627. }
  3628. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3629. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3630. }
  3631. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3632. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3633. }
  3634. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3635. if (!lua_interface)
  3636. return 0;
  3637. Quest* quest = lua_interface->GetQuest(state);
  3638. int32 step = lua_interface->GetInt32Value(state, 2);
  3639. string description = lua_interface->GetStringValue(state, 3);
  3640. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3641. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3642. int16 icon = lua_interface->GetInt16Value(state, 6);
  3643. if (quest) {
  3644. const char* taskgroup = 0;
  3645. if (str_taskgroup.length() > 0)
  3646. taskgroup = str_taskgroup.c_str();
  3647. int32 npc_id = 0;
  3648. vector<int32>* ids = 0;
  3649. int i = 0;
  3650. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3651. if (ids == 0)
  3652. ids = new vector<int32>;
  3653. ids->push_back(npc_id);
  3654. i++;
  3655. }
  3656. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3657. if (quest_step && icon > 0)
  3658. quest_step->SetIcon(icon);
  3659. if (quest->GetPlayer()) {
  3660. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3661. if(client)
  3662. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3663. }
  3664. safe_delete(ids);
  3665. }
  3666. lua_interface->ResetFunctionStack(state);
  3667. return 0;
  3668. }
  3669. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3670. if (!lua_interface)
  3671. return 0;
  3672. Quest* quest = lua_interface->GetQuest(state);
  3673. int32 step = lua_interface->GetInt32Value(state, 2);
  3674. string description = lua_interface->GetStringValue(state, 3);
  3675. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3676. float percentage = lua_interface->GetFloatValue(state, 5);
  3677. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3678. int16 icon = lua_interface->GetInt16Value(state, 7);
  3679. if (quest) {
  3680. const char* taskgroup = 0;
  3681. if (str_taskgroup.length() > 0)
  3682. taskgroup = str_taskgroup.c_str();
  3683. int32 item_id = 0;
  3684. vector<int32>* ids = 0;
  3685. int i = 0;
  3686. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3687. if (ids == 0)
  3688. ids = new vector<int32>;
  3689. ids->push_back(item_id);
  3690. i++;
  3691. }
  3692. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3693. if (quest_step && icon > 0 && quantity > 0)
  3694. quest_step->SetIcon(icon);
  3695. if (quest->GetPlayer()) {
  3696. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3697. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3698. }
  3699. safe_delete(ids);
  3700. }
  3701. lua_interface->ResetFunctionStack(state);
  3702. return 0;
  3703. }
  3704. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3705. if (!lua_interface)
  3706. return 0;
  3707. Quest* quest = lua_interface->GetQuest(state);
  3708. int32 step = lua_interface->GetInt32Value(state, 2);
  3709. string description = lua_interface->GetStringValue(state, 3);
  3710. float max_variation = lua_interface->GetFloatValue(state, 4);
  3711. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3712. int16 icon = lua_interface->GetInt16Value(state, 6);
  3713. if (quest) {
  3714. const char* taskgroup = 0;
  3715. if (str_taskgroup.length() > 0)
  3716. taskgroup = str_taskgroup.c_str();
  3717. vector<Location>* locations = 0;
  3718. int8 i = 7;
  3719. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3720. while (true) {
  3721. Location loc;
  3722. loc.x = lua_interface->GetFloatValue(state, i);
  3723. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3724. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3725. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3726. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3727. break;
  3728. if (locations == 0)
  3729. locations = new vector<Location>;
  3730. locations->push_back(loc);
  3731. i += 4;
  3732. }
  3733. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3734. if (quest_step && icon > 0)
  3735. quest_step->SetIcon(icon);
  3736. if (quest->GetPlayer()) {
  3737. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3738. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3739. }
  3740. }
  3741. lua_interface->ResetFunctionStack(state);
  3742. return 0;
  3743. }
  3744. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3745. if (!lua_interface)
  3746. return 0;
  3747. Quest* quest = lua_interface->GetQuest(state);
  3748. int32 step = lua_interface->GetInt32Value(state, 2);
  3749. string description = lua_interface->GetStringValue(state, 3);
  3750. float max_variation = lua_interface->GetFloatValue(state, 4);
  3751. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3752. int16 icon = lua_interface->GetInt16Value(state, 6);
  3753. if (quest) {
  3754. const char* taskgroup = 0;
  3755. if (str_taskgroup.length() > 0)
  3756. taskgroup = str_taskgroup.c_str();
  3757. vector<Location>* locations = 0;
  3758. int8 i = 7;
  3759. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3760. while (true) {
  3761. Location loc;
  3762. loc.x = lua_interface->GetFloatValue(state, i);
  3763. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3764. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3765. loc.zone_id = 0;
  3766. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3767. break;
  3768. if (locations == 0)
  3769. locations = new vector<Location>;
  3770. locations->push_back(loc);
  3771. i += 3;
  3772. }
  3773. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3774. if (quest_step && icon > 0)
  3775. quest_step->SetIcon(icon);
  3776. if (quest->GetPlayer()) {
  3777. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3778. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3779. }
  3780. }
  3781. lua_interface->ResetFunctionStack(state);
  3782. return 0;
  3783. }
  3784. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3785. if (!lua_interface)
  3786. return 0;
  3787. Quest* quest = lua_interface->GetQuest(state);
  3788. int32 step = lua_interface->GetInt32Value(state, 2);
  3789. string description = lua_interface->GetStringValue(state, 3);
  3790. float max_variation = lua_interface->GetFloatValue(state, 4);
  3791. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3792. int16 icon = lua_interface->GetInt16Value(state, 6);
  3793. if (quest) {
  3794. const char* taskgroup = 0;
  3795. if (str_taskgroup.length() > 0)
  3796. taskgroup = str_taskgroup.c_str();
  3797. vector<Location>* locations = 0;
  3798. int i = 7;
  3799. while (true) {
  3800. Location loc;
  3801. loc.x = lua_interface->GetFloatValue(state, i);
  3802. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3803. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3804. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3805. break;
  3806. if (locations == 0)
  3807. locations = new vector<Location>;
  3808. locations->push_back(loc);
  3809. i += 3;
  3810. }
  3811. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3812. if (quest_step && icon > 0)
  3813. quest_step->SetIcon(icon);
  3814. if (quest->GetPlayer()) {
  3815. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3816. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3817. }
  3818. }
  3819. lua_interface->ResetFunctionStack(state);
  3820. return 0;
  3821. }
  3822. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3823. Quest* quest = lua_interface->GetQuest(state);
  3824. int32 step = lua_interface->GetInt32Value(state, 2);
  3825. string description = lua_interface->GetStringValue(state, 3);
  3826. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3827. float percentage = lua_interface->GetFloatValue(state, 5);
  3828. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3829. int16 icon = lua_interface->GetInt16Value(state, 7);
  3830. if (quest) {
  3831. const char* taskgroup = 0;
  3832. if (str_taskgroup.length() > 0)
  3833. taskgroup = str_taskgroup.c_str();
  3834. int32 spell_id = 0;
  3835. vector<int32>* ids = 0;
  3836. int i = 0;
  3837. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3838. if (ids == 0)
  3839. ids = new vector<int32>;
  3840. ids->push_back(spell_id);
  3841. i++;
  3842. }
  3843. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3844. if (quest_step && icon > 0 && quantity > 0)
  3845. quest_step->SetIcon(icon);
  3846. if (quest->GetPlayer()) {
  3847. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3848. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3849. }
  3850. safe_delete(ids);
  3851. }
  3852. lua_interface->ResetFunctionStack(state);
  3853. return 0;
  3854. }
  3855. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3856. if (!lua_interface)
  3857. return 0;
  3858. Quest* quest = lua_interface->GetQuest(state);
  3859. int32 step = lua_interface->GetInt32Value(state, 2);
  3860. string description = lua_interface->GetStringValue(state, 3);
  3861. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3862. float percentage = lua_interface->GetFloatValue(state, 5);
  3863. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3864. int16 icon = lua_interface->GetInt16Value(state, 7);
  3865. if (quest) {
  3866. const char* taskgroup = 0;
  3867. if (str_taskgroup.length() > 0)
  3868. taskgroup = str_taskgroup.c_str();
  3869. int32 item_id = 0;
  3870. vector<int32>* ids = 0;
  3871. int i = 0;
  3872. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3873. if (ids == 0)
  3874. ids = new vector<int32>;
  3875. ids->push_back(item_id);
  3876. i++;
  3877. }
  3878. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3879. if (quest_step && icon > 0 && quantity > 0)
  3880. quest_step->SetIcon(icon);
  3881. if (quest->GetPlayer()) {
  3882. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3883. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3884. }
  3885. safe_delete(ids);
  3886. }
  3887. lua_interface->ResetFunctionStack(state);
  3888. return 0;
  3889. }
  3890. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3891. if (!lua_interface)
  3892. return 0;
  3893. Quest* quest = lua_interface->GetQuest(state);
  3894. int32 step = lua_interface->GetInt32Value(state, 2);
  3895. string description = lua_interface->GetStringValue(state, 3);
  3896. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3897. float percentage = lua_interface->GetFloatValue(state, 5);
  3898. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3899. int16 icon = lua_interface->GetInt16Value(state, 7);
  3900. if (quest) {
  3901. const char* taskgroup = 0;
  3902. if (str_taskgroup.length() > 0)
  3903. taskgroup = str_taskgroup.c_str();
  3904. int32 item_id = 0;
  3905. vector<int32>* ids = 0;
  3906. int i = 0;
  3907. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3908. if (ids == 0)
  3909. ids = new vector<int32>;
  3910. ids->push_back(item_id);
  3911. i++;
  3912. }
  3913. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3914. if (quest_step && icon > 0 && quantity > 0)
  3915. quest_step->SetIcon(icon);
  3916. if (quest->GetPlayer()) {
  3917. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3918. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3919. }
  3920. safe_delete(ids);
  3921. }
  3922. lua_interface->ResetFunctionStack(state);
  3923. return 0;
  3924. }
  3925. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3926. if (!lua_interface)
  3927. return 0;
  3928. Quest* quest = lua_interface->GetQuest(state);
  3929. string action = lua_interface->GetStringValue(state, 2);
  3930. lua_interface->ResetFunctionStack(state);
  3931. if (quest) {
  3932. if (action.length() > 0)
  3933. quest->SetCompleteAction(action);
  3934. }
  3935. return 0;
  3936. }
  3937. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3938. if (!lua_interface)
  3939. return 0;
  3940. Quest* quest = lua_interface->GetQuest(state);
  3941. int32 step = lua_interface->GetInt32Value(state, 2);
  3942. string action = lua_interface->GetStringValue(state, 3);
  3943. lua_interface->ResetFunctionStack(state);
  3944. if (quest) {
  3945. if (step > 0 && action.length() > 0)
  3946. quest->AddCompleteAction(step, action);
  3947. }
  3948. return 0;
  3949. }
  3950. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3951. if (!lua_interface)
  3952. return 0;
  3953. Quest* quest = lua_interface->GetQuest(state);
  3954. int32 step = lua_interface->GetInt32Value(state, 2);
  3955. string action = lua_interface->GetStringValue(state, 3);
  3956. lua_interface->ResetFunctionStack(state);
  3957. if (quest) {
  3958. if (step > 0 && action.length() > 0)
  3959. quest->AddProgressAction(step, action);
  3960. }
  3961. return 0;
  3962. }
  3963. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3964. if (!lua_interface)
  3965. return 0;
  3966. Quest* quest = lua_interface->GetQuest(state);
  3967. string description = lua_interface->GetStringValue(state, 2);
  3968. lua_interface->ResetFunctionStack(state);
  3969. if (quest && description.length() > 0)
  3970. quest->SetDescription(description);
  3971. return 0;
  3972. }
  3973. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3974. if (!lua_interface)
  3975. return 0;
  3976. Quest* quest = lua_interface->GetQuest(state);
  3977. string description = lua_interface->GetStringValue(state, 2);
  3978. lua_interface->ResetFunctionStack(state);
  3979. if (quest && description.length() > 0)
  3980. quest->SetCompletedDescription(description);
  3981. return 0;
  3982. }
  3983. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3984. if (!lua_interface)
  3985. return 0;
  3986. Quest* quest = lua_interface->GetQuest(state);
  3987. int32 step = lua_interface->GetInt32Value(state, 2);
  3988. string description = lua_interface->GetStringValue(state, 3);
  3989. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3990. lua_interface->ResetFunctionStack(state);
  3991. if (quest && step > 0 && description.length() > 0) {
  3992. quest->SetTaskGroupDescription(step, description, display_bullets);
  3993. /* if (quest->GetPlayer()) {
  3994. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3995. if (client)
  3996. client->SendQuestUpdateStep(quest, step, false);
  3997. }*/
  3998. }
  3999. return 0;
  4000. }
  4001. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4002. if (!lua_interface)
  4003. return 0;
  4004. Quest* quest = lua_interface->GetQuest(state);
  4005. int32 step = lua_interface->GetInt32Value(state, 2);
  4006. string description = lua_interface->GetStringValue(state, 3);
  4007. lua_interface->ResetFunctionStack(state);
  4008. if (quest && step > 0 && description.length() > 0) {
  4009. quest->SetStepDescription(step, description);
  4010. /*if (quest->GetPlayer()) {
  4011. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4012. if (client)
  4013. client->SendQuestUpdateStepImmediately(quest, step);
  4014. }*/
  4015. }
  4016. return 0;
  4017. }
  4018. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4019. Quest* quest = lua_interface->GetQuest(state);
  4020. string zone = lua_interface->GetStringValue(state, 2);
  4021. lua_interface->ResetFunctionStack(state);
  4022. if (quest && zone.length() > 0)
  4023. quest->SetZone(zone);
  4024. return 0;
  4025. }
  4026. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4027. if (!lua_interface)
  4028. return 0;
  4029. Quest* quest = lua_interface->GetQuest(state);
  4030. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4031. lua_interface->ResetFunctionStack(state);
  4032. if (quest && spawn) {
  4033. if (spawn->IsPlayer()) {
  4034. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4035. if (client)
  4036. {
  4037. client->AddPendingQuestAcceptReward(quest);
  4038. client->AddPendingQuestReward(quest);
  4039. }
  4040. }
  4041. }
  4042. return 0;
  4043. }
  4044. int EQ2Emu_lua_Harvest(lua_State* state) {
  4045. if (!lua_interface)
  4046. return 0;
  4047. Spawn* player = lua_interface->GetSpawn(state);
  4048. Spawn* node = lua_interface->GetSpawn(state, 2);
  4049. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4050. Client* client = player->GetZone()->GetClientBySpawn(player);
  4051. if (client) {
  4052. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4053. ((GroundSpawn*)node)->ProcessHarvest(client);
  4054. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4055. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4056. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4057. }
  4058. }
  4059. }
  4060. else if (player && player->IsPlayer()) {
  4061. Client* client = player->GetZone()->GetClientBySpawn(player);
  4062. if (client)
  4063. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4064. }
  4065. lua_interface->ResetFunctionStack(state);
  4066. return 0;
  4067. }
  4068. int EQ2Emu_lua_Bind(lua_State* state) {
  4069. if (!lua_interface)
  4070. return 0;
  4071. Spawn* spawn = lua_interface->GetSpawn(state);
  4072. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4073. float x = lua_interface->GetFloatValue(state, 3);
  4074. float y = lua_interface->GetFloatValue(state, 4);
  4075. float z = lua_interface->GetFloatValue(state, 5);
  4076. float h = lua_interface->GetFloatValue(state, 6);
  4077. lua_interface->ResetFunctionStack(state);
  4078. if (!spawn) {
  4079. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4080. return 0;
  4081. }
  4082. if (!spawn->IsPlayer()) {
  4083. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4084. return 0;
  4085. }
  4086. if (zone_id == 0) {
  4087. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4088. if (!client) {
  4089. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4090. return 0;
  4091. }
  4092. if (!client->Bind())
  4093. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4094. }
  4095. else {
  4096. Player* player = (Player*)spawn;
  4097. player->GetPlayerInfo()->SetBindZone(zone_id);
  4098. player->GetPlayerInfo()->SetBindX(x);
  4099. player->GetPlayerInfo()->SetBindY(y);
  4100. player->GetPlayerInfo()->SetBindZ(z);
  4101. player->GetPlayerInfo()->SetBindHeading(h);
  4102. }
  4103. return 0;
  4104. }
  4105. int EQ2Emu_lua_Gate(lua_State* state) {
  4106. if (!lua_interface)
  4107. return 0;
  4108. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4109. Spawn* spawn = lua_interface->GetSpawn(state);
  4110. lua_interface->ResetFunctionStack(state);
  4111. if (spawn) {
  4112. if (spawn->IsPlayer()) {
  4113. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4114. if (client) {
  4115. if (!client->Gate((spell != nullptr) ? true : false))
  4116. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4117. }
  4118. }
  4119. }
  4120. return 0;
  4121. }
  4122. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4123. if (!lua_interface)
  4124. return 0;
  4125. bool ret = false;
  4126. Spawn* spawn = lua_interface->GetSpawn(state);
  4127. lua_interface->ResetFunctionStack(state);
  4128. if (spawn) {
  4129. if (spawn->IsPlayer()) {
  4130. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4131. if (client)
  4132. ret = client->BindAllowed();
  4133. }
  4134. }
  4135. lua_interface->SetBooleanValue(state, ret);
  4136. return 1;
  4137. }
  4138. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4139. if (!lua_interface)
  4140. return 0;
  4141. bool ret = false;
  4142. Spawn* spawn = lua_interface->GetSpawn(state);
  4143. lua_interface->ResetFunctionStack(state);
  4144. if (spawn) {
  4145. if (spawn->IsPlayer()) {
  4146. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4147. if (client)
  4148. ret = client->GateAllowed();
  4149. }
  4150. }
  4151. lua_interface->SetBooleanValue(state, ret);
  4152. return 1;
  4153. }
  4154. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4155. Spawn* spawn = lua_interface->GetSpawn(state);
  4156. lua_interface->ResetFunctionStack(state);
  4157. if (spawn) {
  4158. lua_interface->SetBooleanValue(state, spawn->Alive());
  4159. return 1;
  4160. }
  4161. return 0;
  4162. }
  4163. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4164. if (!lua_interface)
  4165. return 0;
  4166. Spawn* spawn = lua_interface->GetSpawn(state);
  4167. lua_interface->ResetFunctionStack(state);
  4168. if (spawn && spawn->IsEntity()) {
  4169. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4170. return 1;
  4171. }
  4172. return 0;
  4173. }
  4174. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4175. Spawn* spawn = lua_interface->GetSpawn(state);
  4176. string message = lua_interface->GetStringValue(state, 2);
  4177. string color_str = lua_interface->GetStringValue(state, 3);
  4178. lua_interface->ResetFunctionStack(state);
  4179. int8 color = CHANNEL_NARRATIVE;
  4180. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4181. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4182. if (client) {
  4183. if (color_str.length() > 0) {
  4184. // leave for backwards compat, but all future should just use the number
  4185. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4186. color = CHANNEL_COLOR_RED;
  4187. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4188. color = CHANNEL_COLOR_YELLOW;
  4189. else
  4190. {
  4191. // use a number to specify the channel as per Commands/Commands.h defines
  4192. color = (int8)atoul(color_str.c_str());
  4193. }
  4194. }
  4195. client->SimpleMessage(color, message.c_str());
  4196. }
  4197. }
  4198. return 0;
  4199. }
  4200. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4201. Spawn* spawn = lua_interface->GetSpawn(state);
  4202. string message = lua_interface->GetStringValue(state, 2);
  4203. int8 red = lua_interface->GetInt8Value(state, 3);
  4204. int8 green = lua_interface->GetInt8Value(state, 4);
  4205. int8 blue = lua_interface->GetInt8Value(state, 5);
  4206. lua_interface->ResetFunctionStack(state);
  4207. if (!spawn) {
  4208. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4209. return 0;
  4210. }
  4211. int32 words = ::CountWordsInString(message.c_str());
  4212. if (words < 5)
  4213. words = 5;
  4214. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4215. if (client)
  4216. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4217. return 0;
  4218. }
  4219. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4220. Spawn* spawn = lua_interface->GetSpawn(state);
  4221. int8 param = lua_interface->GetInt8Value(state, 2);
  4222. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4223. int8 value = lua_interface->GetInt8Value(state, 4);
  4224. lua_interface->ResetFunctionStack(state);
  4225. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4226. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4227. if (client) {
  4228. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4229. switch (param) {
  4230. case 1: {
  4231. packet->setDataByName("parameter1", param_value);
  4232. break;
  4233. }
  4234. case 2: {
  4235. packet->setDataByName("parameter2", param_value);
  4236. break;
  4237. }
  4238. case 3: {
  4239. packet->setDataByName("parameter3", param_value);
  4240. break;
  4241. }
  4242. case 4: {
  4243. packet->setDataByName("parameter4", param_value);
  4244. break;
  4245. }
  4246. case 5: {
  4247. packet->setDataByName("parameter5", param_value);
  4248. break;
  4249. }
  4250. }
  4251. packet->setDataByName("value", value);
  4252. client->QueuePacket(packet->serialize());
  4253. safe_delete(packet);
  4254. }
  4255. }
  4256. return 0;
  4257. }
  4258. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4259. Spawn* spawn = lua_interface->GetSpawn(state);
  4260. lua_interface->ResetFunctionStack(state);
  4261. if (spawn && spawn->IsPlayer()) {
  4262. if (((Player*)spawn)->GetIsTracking())
  4263. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4264. else
  4265. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4266. }
  4267. return 0;
  4268. }
  4269. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4270. Spawn* player = lua_interface->GetSpawn(state);
  4271. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4272. string name = lua_interface->GetStringValue(state, 3);
  4273. float distance = lua_interface->GetFloatValue(state, 4);
  4274. string command = lua_interface->GetStringValue(state, 5);
  4275. string error_text = lua_interface->GetStringValue(state, 6);
  4276. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4277. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4278. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4279. lua_interface->ResetFunctionStack(state);
  4280. if (spawn) {
  4281. if (distance == 0)
  4282. distance = 10.0f;
  4283. if (command.length() == 0)
  4284. command = name;
  4285. if (command.length() < 1 && name.length() < 1)
  4286. {
  4287. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4288. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4289. spawn->RemovePrimaryCommands();
  4290. }
  4291. else
  4292. {
  4293. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4294. }
  4295. }
  4296. return 0;
  4297. }
  4298. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4299. if (!lua_interface)
  4300. return 0;
  4301. Spawn* player = lua_interface->GetSpawn(state);
  4302. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4303. int16 tier = lua_interface->GetInt16Value(state, 3);
  4304. lua_interface->ResetFunctionStack(state);
  4305. if (player && player->IsPlayer()) {
  4306. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4307. return 1;
  4308. }
  4309. return 0;
  4310. }
  4311. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4312. if (!lua_interface)
  4313. return 0;
  4314. Spawn* player = lua_interface->GetSpawn(state);
  4315. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4316. int16 tier = lua_interface->GetInt16Value(state, 3);
  4317. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4318. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4319. bool add_to_hotbar = true;
  4320. if (num_args > 4) {
  4321. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4322. }
  4323. lua_interface->ResetFunctionStack(state);
  4324. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4325. if (player && spell && player->IsPlayer()) {
  4326. Client* client = player->GetClient();
  4327. if (client) {
  4328. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4329. {
  4330. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4331. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4332. client->GetPlayer()->UnlockSpell(spell);
  4333. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4334. }
  4335. else
  4336. {
  4337. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4338. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4339. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4340. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4341. client->GetPlayer()->UnlockSpell(spell);
  4342. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4343. }
  4344. //if (client ) {
  4345. // ((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);
  4346. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4347. if (outapp)
  4348. client->QueuePacket(outapp);
  4349. }
  4350. }
  4351. return 0;
  4352. }
  4353. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4354. if (!lua_interface)
  4355. return 0;
  4356. Spawn* player = lua_interface->GetSpawn(state);
  4357. lua_interface->ResetFunctionStack(state);
  4358. if (player && player->IsPlayer()) {
  4359. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4360. return 1;
  4361. }
  4362. return 0;
  4363. }
  4364. int EQ2Emu_lua_Attack(lua_State* state) {
  4365. if (lua_interface) {
  4366. Spawn* npc = lua_interface->GetSpawn(state);
  4367. Spawn* player = lua_interface->GetSpawn(state, 2);
  4368. lua_interface->ResetFunctionStack(state);
  4369. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4370. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4371. }
  4372. return 0;
  4373. }
  4374. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4375. if (lua_interface) {
  4376. Spawn* target = lua_interface->GetSpawn(state);
  4377. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4378. lua_interface->ResetFunctionStack(state);
  4379. if (target && target->GetZone())
  4380. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4381. }
  4382. return 0;
  4383. }
  4384. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4385. Spawn* player;
  4386. if (lua_interface) {
  4387. player = lua_interface->GetSpawn(state);
  4388. lua_interface->ResetFunctionStack(state);
  4389. if (player && player->IsPlayer()) {
  4390. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4391. return 1;
  4392. }
  4393. }
  4394. return 0;
  4395. }
  4396. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4397. Spawn* player;
  4398. Client* client;
  4399. if (lua_interface) {
  4400. player = lua_interface->GetSpawn(state);
  4401. lua_interface->ResetFunctionStack(state);
  4402. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4403. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4404. client->HandInCollections();
  4405. }
  4406. return 0;
  4407. }
  4408. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4409. Spawn* widget;
  4410. if (lua_interface) {
  4411. widget = lua_interface->GetSpawn(state);
  4412. lua_interface->ResetFunctionStack(state);
  4413. if (widget && widget->IsWidget())
  4414. ((Widget*)widget)->HandleUse(nullptr, "");
  4415. }
  4416. return 0;
  4417. }
  4418. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4419. Spawn* spawn = 0;
  4420. int32 primary_list = 0;
  4421. int32 secondary_list = 0;
  4422. if (lua_interface) {
  4423. spawn = lua_interface->GetSpawn(state);
  4424. primary_list = lua_interface->GetInt32Value(state, 2);
  4425. secondary_list = lua_interface->GetInt32Value(state, 3);
  4426. lua_interface->ResetFunctionStack(state);
  4427. if (!spawn->IsNPC()) {
  4428. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4429. return 0;
  4430. }
  4431. NPC* npc = (NPC*)spawn;
  4432. npc->SetPrimarySpellList(primary_list);
  4433. npc->SetSecondarySpellList(secondary_list);
  4434. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4435. }
  4436. return 0;
  4437. }
  4438. int EQ2Emu_lua_GetPet(lua_State* state) {
  4439. if (!lua_interface)
  4440. return 0;
  4441. Spawn* spawn = lua_interface->GetSpawn(state);
  4442. lua_interface->ResetFunctionStack(state);
  4443. if (spawn) {
  4444. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4445. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4446. return 1;
  4447. }
  4448. }
  4449. return 0;
  4450. }
  4451. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4452. if (!lua_interface)
  4453. return 0;
  4454. Spawn* spawn = lua_interface->GetSpawn(state);
  4455. lua_interface->ResetFunctionStack(state);
  4456. if (spawn) {
  4457. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4458. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4459. return 1;
  4460. }
  4461. }
  4462. return 0;
  4463. }
  4464. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4465. if (!lua_interface)
  4466. return 0;
  4467. Spawn* spawn = lua_interface->GetSpawn(state);
  4468. lua_interface->ResetFunctionStack(state);
  4469. if (spawn) {
  4470. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4471. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4472. return 1;
  4473. }
  4474. }
  4475. return 0;
  4476. }
  4477. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4478. if (!lua_interface)
  4479. return 0;
  4480. Spawn* spawn = lua_interface->GetSpawn(state);
  4481. lua_interface->ResetFunctionStack(state);
  4482. if (spawn) {
  4483. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4484. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4485. return 1;
  4486. }
  4487. }
  4488. return 0;
  4489. }
  4490. int EQ2Emu_lua_Charm(lua_State* state) {
  4491. if (!lua_interface)
  4492. return 0;
  4493. Spawn* owner = lua_interface->GetSpawn(state);
  4494. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4495. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4496. lua_interface->ResetFunctionStack(state);
  4497. if (!luaspell) {
  4498. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4499. return 0;
  4500. }
  4501. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4502. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4503. pet->SetPet(true);
  4504. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4505. ((NPC*)pet)->SetOwner((Entity*)owner);
  4506. // If owner is player and player does not have a summoned pet set the players charsheet
  4507. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4508. Player* player = (Player*)owner;
  4509. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4510. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4511. player->GetInfoStruct()->set_pet_movement(2);
  4512. player->GetInfoStruct()->set_pet_behavior(3);
  4513. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4514. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4515. // Make sure the values get sent to the client
  4516. player->SetCharSheetChanged(true);
  4517. }
  4518. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4519. pet->SetSpawnScript("");
  4520. // Set faction to the same as the owner
  4521. pet->SetFactionID(owner->GetFactionID());
  4522. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4523. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4524. // Clear hate list
  4525. ((NPC*)pet)->Brain()->ClearHate();
  4526. // Set the brain to a pet brain
  4527. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4528. }
  4529. return 0;
  4530. }
  4531. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4532. if (!lua_interface)
  4533. return 0;
  4534. Spawn* spawn = lua_interface->GetSpawn(state);
  4535. lua_interface->ResetFunctionStack(state);
  4536. if (!spawn) {
  4537. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4538. return 0;
  4539. }
  4540. vector<Spawn*> groupMembers;
  4541. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4542. groupMembers = *spawn->GetSpawnGroup();
  4543. }
  4544. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4545. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4546. deque<GroupMemberInfo*>::iterator itr;
  4547. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4548. if (group)
  4549. {
  4550. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4551. deque<GroupMemberInfo*>* members = group->GetMembers();
  4552. GroupMemberInfo* info = 0;
  4553. for (itr = members->begin(); itr != members->end(); itr++) {
  4554. info = *itr;
  4555. if (info->client)
  4556. groupMembers.push_back(info->client->GetPlayer());
  4557. }
  4558. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4559. }
  4560. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4561. }
  4562. else
  4563. return 0;
  4564. lua_createtable(state, groupMembers.size(), 0);
  4565. int newTable = lua_gettop(state);
  4566. for (int32 i = 0; i < groupMembers.size(); i++) {
  4567. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4568. lua_rawseti(state, newTable, i + 1);
  4569. }
  4570. return 1;
  4571. }
  4572. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4573. if (!lua_interface)
  4574. return 0;
  4575. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4576. lua_interface->SetOptionWindowValue(state, option_window);
  4577. return 1;
  4578. }
  4579. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4580. if (!lua_interface)
  4581. return 0;
  4582. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4583. if (option_window) {
  4584. OptionWindowOption option_window_option;
  4585. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4586. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4587. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4588. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4589. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4590. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4591. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4592. option_window->push_back(option_window_option);
  4593. }
  4594. return 0;
  4595. }
  4596. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4597. if (!lua_interface)
  4598. return 0;
  4599. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4600. Spawn* player = lua_interface->GetSpawn(state, 2);
  4601. string window_title = lua_interface->GetStringValue(state, 3);
  4602. string cancel_command = lua_interface->GetStringValue(state, 4);
  4603. Client* client = player->GetZone()->GetClientBySpawn(player);
  4604. if (option_window && window_title.length() > 0 && client) {
  4605. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4606. if (!packet)
  4607. return 0;
  4608. packet->setDataByName("title_text", window_title.c_str());
  4609. if (cancel_command.length() > 0)
  4610. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4611. packet->setArrayLengthByName("num_selections", option_window->size());
  4612. vector<OptionWindowOption>::iterator itr;
  4613. int8 i = 0;
  4614. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4615. OptionWindowOption opt = *itr;
  4616. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4617. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4618. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4619. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4620. if (opt.optionCommand.length() > 0)
  4621. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4622. if (opt.optionConfirmTitle.length() > 0)
  4623. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4624. i++;
  4625. }
  4626. client->QueuePacket(packet->serialize());
  4627. safe_delete(option_window);
  4628. safe_delete(packet);
  4629. }
  4630. return 0;
  4631. }
  4632. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4633. if (!lua_interface)
  4634. return 0;
  4635. Spawn* spawn = lua_interface->GetSpawn(state);
  4636. if (spawn) {
  4637. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4638. return 1;
  4639. }
  4640. else
  4641. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4642. return 0;
  4643. }
  4644. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4645. if (!lua_interface)
  4646. return 0;
  4647. Spawn* spawn = lua_interface->GetSpawn(state);
  4648. if (spawn) {
  4649. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4650. return 1;
  4651. }
  4652. else
  4653. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4654. return 0;
  4655. }
  4656. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4657. if (!lua_interface)
  4658. return 0;
  4659. Spawn* spawn = lua_interface->GetSpawn(state);
  4660. if (spawn) {
  4661. int8 class_id = spawn->GetTradeskillClass();
  4662. // Need to add 42 for the offset in the array
  4663. class_id += 44;
  4664. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4665. return 1;
  4666. }
  4667. else
  4668. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4669. return 0;
  4670. }
  4671. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4672. if (!lua_interface)
  4673. return 0;
  4674. Spawn* spawn = lua_interface->GetSpawn(state);
  4675. int16 level = lua_interface->GetInt8Value(state, 2);
  4676. if (spawn) {
  4677. if (spawn->IsPlayer())
  4678. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4679. else
  4680. spawn->SetTSLevel(level);
  4681. }
  4682. else
  4683. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4684. return 0;
  4685. }
  4686. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4687. if (!lua_interface)
  4688. return 0;
  4689. Spawn* spawn = lua_interface->GetSpawn(state);
  4690. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4691. if (spawn) {
  4692. spawn->SetAttackable(attackable);
  4693. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4694. }
  4695. return 0;
  4696. }
  4697. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4698. // Check to see if we have a valid lua_interface
  4699. if (!lua_interface)
  4700. return 0;
  4701. // Get the spawn that is getting the pet
  4702. Spawn* spawn = lua_interface->GetSpawn(state);
  4703. // Get the DB ID of the pet
  4704. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4705. // The max level the pet can gain
  4706. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4707. // Get the spell that this command was called from
  4708. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4709. // Check to make sure the spawn pointer is valid
  4710. if (!spawn) {
  4711. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4712. return 0;
  4713. }
  4714. // Check to make sure the spawn is an entity
  4715. if (!spawn->IsEntity()) {
  4716. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4717. return 0;
  4718. }
  4719. // Check to make sure the spawn doesn't already have a pet of this type
  4720. if (((Entity*)spawn)->GetPet()) {
  4721. if (spawn->IsPlayer()) {
  4722. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4723. if (client)
  4724. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4725. }
  4726. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4727. return 0;
  4728. }
  4729. // Check to see if the DB ID for the pet is set
  4730. if (pet_id == 0) {
  4731. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4732. return 0;
  4733. }
  4734. // Check to see if the pointer to the spell is valid
  4735. if (!luaspell) {
  4736. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4737. return 0;
  4738. }
  4739. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4740. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4741. if (!pet) {
  4742. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4743. return 0;
  4744. }
  4745. // Check to make sure the pet is an npc
  4746. if (!pet->IsNPC()) {
  4747. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4748. return 0;
  4749. }
  4750. // Spawn the pet at the same location as the owner
  4751. pet->SetX(spawn->GetX());
  4752. pet->SetY(spawn->GetY());
  4753. pet->SetZ(spawn->GetZ());
  4754. pet->SetLocation(spawn->GetLocation());
  4755. pet->SetHeading(spawn->GetHeading());
  4756. spawn->GetZone()->AddSpawn(pet);
  4757. /*
  4758. const char* spawn_script = world.GetSpawnScript(pet_id);
  4759. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4760. spawn->SetSpawnScript(string(spawn_script));
  4761. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4762. }*/
  4763. // Get a random pet name
  4764. string random_pet_name;
  4765. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4766. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4767. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4768. // If player set various values for the char sheet (pet window)
  4769. if (spawn->IsPlayer()) {
  4770. Player* player = (Player*)spawn;
  4771. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4772. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4773. player->GetInfoStruct()->set_pet_movement(2);
  4774. player->GetInfoStruct()->set_pet_behavior(3);
  4775. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4776. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4777. // Make sure the values get sent to the client
  4778. player->SetCharSheetChanged(true);
  4779. }
  4780. // Set the pets name
  4781. pet->SetName(random_pet_name.c_str());
  4782. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4783. if (max_level > 0)
  4784. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4785. else
  4786. pet->SetLevel(spawn->GetLevel());
  4787. // Set the max level this pet can reach
  4788. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4789. // Set the faction of the pet to the same faction as the owner
  4790. pet->SetFactionID(spawn->GetFactionID());
  4791. // Set the spawn as a pet
  4792. pet->SetPet(true);
  4793. // Give a pointer of the owner to the pet
  4794. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4795. // Give a pointer of the pet to the owner
  4796. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4797. // Set the pet type
  4798. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4799. // Set the spell id used to create this pet
  4800. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4801. // Set the spell tier used to create this pet
  4802. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4803. // Set the pets spawn type to 6
  4804. pet->SetSpawnType(6);
  4805. // Set the pets brain
  4806. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4807. // Check to see if the pet has a subtitle
  4808. if (strlen(pet->GetSubTitle()) > 0) {
  4809. // Add the players name to the front of the sub title
  4810. string pet_subtitle;
  4811. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4812. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4813. // Set the pets subtitle to the new one
  4814. pet->SetSubTitle(pet_subtitle.c_str());
  4815. }
  4816. // Add the "Pet Options" entity command to the pet
  4817. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4818. // Set the pet as the return value for this function
  4819. lua_interface->SetSpawnValue(state, pet);
  4820. return 1;
  4821. }
  4822. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4823. if (!lua_interface)
  4824. return 0;
  4825. Spawn* spawn = lua_interface->GetSpawn(state);
  4826. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4827. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4828. if (!spawn) {
  4829. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4830. return 0;
  4831. }
  4832. if (!spawn->IsEntity()) {
  4833. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4834. return 0;
  4835. }
  4836. if (((Entity*)spawn)->GetDeityPet()) {
  4837. if (spawn->IsPlayer()) {
  4838. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4839. if (client)
  4840. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4841. }
  4842. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4843. return 0;
  4844. }
  4845. if (pet_id == 0) {
  4846. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4847. return 0;
  4848. }
  4849. if (!luaspell) {
  4850. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4851. return 0;
  4852. }
  4853. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4854. if (!pet) {
  4855. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4856. return 0;
  4857. }
  4858. if (!pet->IsNPC()) {
  4859. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4860. return 0;
  4861. }
  4862. pet->SetX(spawn->GetX());
  4863. pet->SetY(spawn->GetY());
  4864. pet->SetZ(spawn->GetZ());
  4865. pet->SetLocation(spawn->GetLocation());
  4866. pet->SetHeading(spawn->GetHeading());
  4867. spawn->GetZone()->AddSpawn(pet);
  4868. string random_pet_name;
  4869. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4870. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4871. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4872. pet->SetName(random_pet_name.c_str());
  4873. pet->SetLevel(spawn->GetLevel());
  4874. pet->SetFactionID(spawn->GetFactionID());
  4875. pet->SetPet(true);
  4876. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4877. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4878. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4879. pet->SetSpawnType(6);
  4880. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4881. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4882. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4883. if (strlen(pet->GetSubTitle()) > 0) {
  4884. string pet_subtitle;
  4885. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4886. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4887. pet->SetSubTitle(pet_subtitle.c_str());
  4888. }
  4889. // deity and cosmetic pets are not attackable
  4890. pet->SetAttackable(false);
  4891. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4892. lua_interface->SetSpawnValue(state, pet);
  4893. return 1;
  4894. }
  4895. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4896. if (!lua_interface)
  4897. return 0;
  4898. Spawn* spawn = lua_interface->GetSpawn(state);
  4899. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4900. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4901. if (!spawn) {
  4902. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4903. return 0;
  4904. }
  4905. if (!spawn->IsEntity()) {
  4906. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4907. return 0;
  4908. }
  4909. if (((Entity*)spawn)->GetCosmeticPet()) {
  4910. if (spawn->IsPlayer()) {
  4911. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4912. if (client)
  4913. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4914. }
  4915. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4916. return 0;
  4917. }
  4918. if (pet_id == 0) {
  4919. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4920. return 0;
  4921. }
  4922. if (!luaspell) {
  4923. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4924. return 0;
  4925. }
  4926. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4927. if (!pet) {
  4928. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4929. return 0;
  4930. }
  4931. if (!pet->IsNPC()) {
  4932. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4933. return 0;
  4934. }
  4935. pet->SetX(spawn->GetX());
  4936. pet->SetY(spawn->GetY());
  4937. pet->SetZ(spawn->GetZ());
  4938. pet->SetLocation(spawn->GetLocation());
  4939. pet->SetHeading(spawn->GetHeading());
  4940. spawn->GetZone()->AddSpawn(pet);
  4941. string random_pet_name;
  4942. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4943. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4944. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4945. pet->SetName(random_pet_name.c_str());
  4946. pet->SetLevel(spawn->GetLevel());
  4947. pet->SetFactionID(spawn->GetFactionID());
  4948. pet->SetPet(true);
  4949. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4950. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4951. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4952. pet->SetSpawnType(6);
  4953. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4954. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4955. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4956. if (strlen(pet->GetSubTitle()) > 0) {
  4957. string pet_subtitle;
  4958. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4959. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4960. pet->SetSubTitle(pet_subtitle.c_str());
  4961. }
  4962. pet->SetAttackable(false);
  4963. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4964. lua_interface->SetSpawnValue(state, pet);
  4965. return 1;
  4966. }
  4967. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4968. if (!lua_interface)
  4969. return 0;
  4970. Spawn* spawn = lua_interface->GetSpawn(state);
  4971. if (!spawn) {
  4972. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4973. return 0;
  4974. }
  4975. if (!spawn->IsPet()) {
  4976. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4977. return 0;
  4978. }
  4979. if (!((NPC*)spawn)->IsDismissing())
  4980. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4981. return 0;
  4982. }
  4983. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4984. if (!lua_interface)
  4985. return 0;
  4986. Quest* quest = lua_interface->GetQuest(state);
  4987. if (!quest) {
  4988. 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));
  4989. return 0;
  4990. }
  4991. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4992. if (feather_color > 0)
  4993. quest->SetFeatherColor(feather_color);
  4994. return 0;
  4995. }
  4996. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4997. if (!lua_interface)
  4998. return 0;
  4999. Spawn* spawn = lua_interface->GetSpawn(state);
  5000. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5001. if (!spawn) {
  5002. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5003. return 0;
  5004. }
  5005. if (!spawn2) {
  5006. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5007. return 0;
  5008. }
  5009. spawn->RemoveSpawnAccess(spawn2);
  5010. return 0;
  5011. }
  5012. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5013. if (!lua_interface)
  5014. return 0;
  5015. ZoneServer* zone = lua_interface->GetZone(state);
  5016. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5017. if (!zone) {
  5018. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5019. return 0;
  5020. }
  5021. if (location_id == 0) {
  5022. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5026. if (!location) {
  5027. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5028. return 0;
  5029. }
  5030. Spawn* spawn = 0;
  5031. if (location->entities[0]) {
  5032. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5033. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5034. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5035. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5036. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5037. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5038. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5039. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5040. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5041. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5042. if(spawn && spawn->IsOmittedByDBFlag())
  5043. {
  5044. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5045. safe_delete(spawn);
  5046. spawn = 0;
  5047. return 0;
  5048. }
  5049. if (spawn) {
  5050. const char* script = 0;
  5051. for (int x = 0; x < 3; x++) {
  5052. switch (x) {
  5053. case 0:
  5054. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5055. break;
  5056. case 1:
  5057. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5058. break;
  5059. case 2:
  5060. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5061. break;
  5062. }
  5063. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5064. spawn->SetSpawnScript(string(script));
  5065. break;
  5066. }
  5067. }
  5068. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5069. lua_interface->SetSpawnValue(state, spawn);
  5070. return 1;
  5071. }
  5072. else {
  5073. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5074. safe_delete(spawn);
  5075. }
  5076. }
  5077. return 0;
  5078. }
  5079. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5080. if (!lua_interface)
  5081. return 0;
  5082. Spawn* caster = lua_interface->GetSpawn(state);
  5083. Spawn* target = lua_interface->GetSpawn(state, 2);
  5084. int32 id = lua_interface->GetInt32Value(state, 3);
  5085. string command = lua_interface->GetStringValue(state, 4);
  5086. if (!caster) {
  5087. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5088. return 0;
  5089. }
  5090. if (!target) {
  5091. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5092. return 0;
  5093. }
  5094. if (!caster->IsPlayer()) {
  5095. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5096. return 0;
  5097. }
  5098. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5099. if (!entity_command) {
  5100. 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());
  5101. return 0;
  5102. }
  5103. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5104. if (!client) {
  5105. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5106. return 0;
  5107. }
  5108. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5109. return 0;
  5110. }
  5111. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5112. if (!lua_interface)
  5113. return 0;
  5114. Spawn* spawn = lua_interface->GetSpawn(state);
  5115. if (!spawn) {
  5116. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5117. return 0;
  5118. }
  5119. if (!spawn->IsNPC()) {
  5120. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5121. return 0;
  5122. }
  5123. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5124. return 0;
  5125. }
  5126. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5127. if (!lua_interface)
  5128. return 0;
  5129. Spawn* spawn = lua_interface->GetSpawn(state);
  5130. int16 tick = lua_interface->GetInt16Value(state, 2);
  5131. if (!spawn) {
  5132. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5133. return 0;
  5134. }
  5135. if (!spawn->IsNPC()) {
  5136. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5137. return 0;
  5138. }
  5139. if (tick < 20) {
  5140. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5141. return 0;
  5142. }
  5143. ((NPC*)spawn)->Brain()->SetTick(tick);
  5144. return 0;
  5145. }
  5146. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5147. if (!lua_interface)
  5148. return 0;
  5149. Spawn* spawn = lua_interface->GetSpawn(state);
  5150. Spawn* target = lua_interface->GetSpawn(state, 2);
  5151. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5152. if (!spawn) {
  5153. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5154. return 0;
  5155. }
  5156. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5157. spawn->SetFollowTarget(target, follow_distance);
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. Spawn* spawn = lua_interface->GetSpawn(state);
  5164. if (!spawn) {
  5165. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5166. return 0;
  5167. }
  5168. Spawn* target = spawn->GetFollowTarget();
  5169. if (target) {
  5170. lua_interface->SetSpawnValue(state, target);
  5171. return 1;
  5172. }
  5173. return 0;
  5174. }
  5175. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5176. if (!lua_interface)
  5177. return 0;
  5178. Spawn* spawn = lua_interface->GetSpawn(state);
  5179. if (!spawn) {
  5180. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5181. return 0;
  5182. }
  5183. if (spawn->following)
  5184. spawn->following = false;
  5185. else
  5186. spawn->following = true;
  5187. return 0;
  5188. }
  5189. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5190. if (!lua_interface)
  5191. return 0;
  5192. Spawn* spawn = lua_interface->GetSpawn(state);
  5193. if (!spawn) {
  5194. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5195. return 0;
  5196. }
  5197. lua_interface->SetBooleanValue(state, spawn->following);
  5198. return 1;
  5199. }
  5200. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5201. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5202. // I will attempt to explain how this function works for future refrence
  5203. // Fist lets make sure lua_interface is valid, if not return out
  5204. if (!lua_interface)
  5205. return 0;
  5206. // Next we grab the first 2 params same as we usually would
  5207. Spawn* spawn = lua_interface->GetSpawn(state);
  5208. string var = lua_interface->GetStringValue(state, 2);
  5209. // 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
  5210. // 1 = Spawn
  5211. // 2 = Zone
  5212. // 3 = Item
  5213. // 4 = Quest
  5214. // 5 = String
  5215. // 6 = nil (null)
  5216. int8 dataType = 0;
  5217. // Define pointers for each potential type
  5218. Spawn* spawnVal = 0;
  5219. ZoneServer* zone = 0;
  5220. Item* item = 0;
  5221. Quest* quest = 0;
  5222. string val;
  5223. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5224. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5225. // options window are also light user data be we do not handle those.
  5226. // We check with lua_islightuserdata(lua_State*, index)
  5227. if (lua_islightuserdata(state, 3)) {
  5228. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5229. // and convert it to LUAUserData*
  5230. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5231. // Check to make sure the data we got is valid, if not give an error
  5232. if (!data || !data->IsCorrectlyInitialized()) {
  5233. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5234. }
  5235. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5236. else if (data->IsSpawn()) {
  5237. spawnVal = data->spawn;
  5238. dataType = 1;
  5239. }
  5240. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5241. else if (data->IsZone()) {
  5242. zone = data->zone;
  5243. dataType = 2;
  5244. }
  5245. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5246. else if (data->IsItem()) {
  5247. item = data->item;
  5248. dataType = 3;
  5249. }
  5250. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5251. else if (data->IsQuest()) {
  5252. quest = data->quest;
  5253. dataType = 4;
  5254. }
  5255. }
  5256. // Wasn't light user data, check if it is nil(null)
  5257. else if (lua_isnil(state, 3)) {
  5258. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5259. dataType = 6;
  5260. }
  5261. // Wasn't light user data or nil (null), must be a string
  5262. else {
  5263. // Set the string and dataType variable
  5264. val = lua_interface->GetStringValue(state, 3);
  5265. dataType = 5;
  5266. }
  5267. // We now have all the params, lets check to make sure they are valid
  5268. if (!spawn) {
  5269. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5270. return 0;
  5271. }
  5272. if (var.length() == 0) {
  5273. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5274. return 0;
  5275. }
  5276. if (dataType == 0) {
  5277. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5278. return 0;
  5279. }
  5280. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5281. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5282. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5283. switch (dataType) {
  5284. case 1:
  5285. // 1 = Spawn
  5286. spawn->AddTempVariable(var, spawnVal);
  5287. break;
  5288. case 2:
  5289. // 2 = Zone
  5290. spawn->AddTempVariable(var, zone);
  5291. break;
  5292. case 3:
  5293. // 3 = Item
  5294. spawn->AddTempVariable(var, item);
  5295. break;
  5296. case 4:
  5297. // 4 = Quest
  5298. spawn->AddTempVariable(var, quest);
  5299. break;
  5300. case 5:
  5301. // 5 = String
  5302. spawn->AddTempVariable(var, val);
  5303. break;
  5304. case 6:
  5305. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5306. spawn->DeleteTempVariable(var);
  5307. break;
  5308. }
  5309. // And we are done so return out
  5310. return 0;
  5311. }
  5312. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5313. if (!lua_interface)
  5314. return 0;
  5315. Spawn* spawn = lua_interface->GetSpawn(state);
  5316. string var = lua_interface->GetStringValue(state, 2);
  5317. if (!spawn) {
  5318. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. if (var.length() == 0) {
  5322. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5323. return 0;
  5324. }
  5325. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5326. int8 type = spawn->GetTempVariableType(var);
  5327. Spawn* spawn2 = 0;
  5328. ZoneServer* zone = 0;
  5329. Item* item = 0;
  5330. Quest* quest = 0;
  5331. // Set the lua function return value based on the type of data the variable contains
  5332. switch (type) {
  5333. case 1:
  5334. spawn2 = spawn->GetTempVariableSpawn(var);
  5335. if (!spawn2)
  5336. return 0;
  5337. lua_interface->SetSpawnValue(state, spawn2);
  5338. break;
  5339. case 2:
  5340. zone = spawn->GetTempVariableZone(var);
  5341. if (!zone)
  5342. return 0;
  5343. lua_interface->SetZoneValue(state, zone);
  5344. break;
  5345. case 3:
  5346. item = spawn->GetTempVariableItem(var);
  5347. if (!item)
  5348. return 0;
  5349. lua_interface->SetItemValue(state, item);
  5350. break;
  5351. case 4:
  5352. quest = spawn->GetTempVariableQuest(var);
  5353. if (!quest)
  5354. return 0;
  5355. lua_interface->SetQuestValue(state, quest);
  5356. break;
  5357. case 5:
  5358. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5359. break;
  5360. default:
  5361. // Not a valid type then the variable was not set so return out
  5362. return 0;
  5363. }
  5364. // Return value was set so return out
  5365. return 1;
  5366. }
  5367. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5368. {
  5369. if (!lua_interface)
  5370. return 0;
  5371. Quest* quest = lua_interface->GetQuest(state);
  5372. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5373. string description = lua_interface->GetStringValue(state, 3);
  5374. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5375. if (!quest) {
  5376. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5377. lua_interface->SetBooleanValue(state, false);
  5378. return 1;
  5379. }
  5380. if (!spawn) {
  5381. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5382. lua_interface->SetBooleanValue(state, false);
  5383. return 1;
  5384. }
  5385. if (!spawn->IsPlayer()) {
  5386. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5387. lua_interface->SetBooleanValue(state, false);
  5388. return 1;
  5389. }
  5390. if (item_id == 0) {
  5391. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5392. lua_interface->SetBooleanValue(state, false);
  5393. return 1;
  5394. }
  5395. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5396. if (!client) {
  5397. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5398. lua_interface->SetBooleanValue(state, false);
  5399. return 1;
  5400. }
  5401. Item* item = master_item_list.GetItem(item_id);
  5402. if (!item) {
  5403. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5404. lua_interface->SetBooleanValue(state, false);
  5405. return 1;
  5406. }
  5407. Item* firstItem = new Item(item);
  5408. quest->AddTmpRewardItem(firstItem);
  5409. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5410. bool itemsAddedSuccessfully = true;
  5411. if(num_args > 4)
  5412. {
  5413. for(int8 n=5;n<num_args+1;n++)
  5414. {
  5415. int32 new_item = lua_interface->GetInt32Value(state, n);
  5416. Item* tmpItem = master_item_list.GetItem(new_item);
  5417. if(tmpItem)
  5418. {
  5419. Item* newTmpItem = new Item(tmpItem);
  5420. quest->AddTmpRewardItem(newTmpItem);
  5421. }
  5422. else
  5423. itemsAddedSuccessfully = false;
  5424. }
  5425. }
  5426. client->AddPendingQuestAcceptReward(quest);
  5427. client->DisplayQuestComplete(quest, true, description);
  5428. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5429. return 1;
  5430. }
  5431. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5432. if (!lua_interface)
  5433. return 0;
  5434. Quest* quest = lua_interface->GetQuest(state);
  5435. if (!quest) {
  5436. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5437. return 0;
  5438. }
  5439. quest->SetRepeatable(true);
  5440. return 0;
  5441. }
  5442. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5443. if (!lua_interface)
  5444. return 0;
  5445. Spawn* spawn = lua_interface->GetSpawn(state);
  5446. if (!spawn) {
  5447. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5448. return 0;
  5449. }
  5450. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5451. string ret = classes.GetClassNameCase(base_class);
  5452. if (ret.length() > 0) {
  5453. lua_interface->SetStringValue(state, ret.c_str());
  5454. return 1;
  5455. }
  5456. return 0;
  5457. }
  5458. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5459. if (!lua_interface)
  5460. return 0;
  5461. Spawn* player = lua_interface->GetSpawn(state);
  5462. if (player && player->IsPlayer()) {
  5463. Client* client = player->GetClient();
  5464. if (client)
  5465. client->SendWaypoints();
  5466. }
  5467. return 0;
  5468. }
  5469. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5470. if (!lua_interface)
  5471. return 0;
  5472. Spawn* player = lua_interface->GetSpawn(state);
  5473. string name = lua_interface->GetStringValue(state, 2);
  5474. int32 type = lua_interface->GetInt32Value(state, 3);
  5475. if (type == 0)
  5476. type = 2;
  5477. if (name.length() > 0) {
  5478. if (player && player->IsPlayer()) {
  5479. Client* client = player->GetClient();
  5480. if (client)
  5481. client->AddWaypoint(name, type);
  5482. }
  5483. }
  5484. return 0;
  5485. }
  5486. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5487. if (!lua_interface)
  5488. return 0;
  5489. Spawn* player = lua_interface->GetSpawn(state);
  5490. string name = lua_interface->GetStringValue(state, 2);
  5491. if (name.length() > 0) {
  5492. if (player && player->IsPlayer()) {
  5493. Client* client = player->GetClient();
  5494. if (client)
  5495. client->RemoveWaypoint(name);
  5496. }
  5497. }
  5498. return 0;
  5499. }
  5500. int EQ2Emu_lua_AddWard(lua_State* state) {
  5501. if (!lua_interface)
  5502. return 0;
  5503. int32 damage = lua_interface->GetInt32Value(state);
  5504. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5505. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5506. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5507. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5508. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5509. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5510. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5511. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5512. bool ward_was_added = false;
  5513. ZoneServer* zone = spell->caster->GetZone();
  5514. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5515. for (int32 i = 0; i < spell->targets.size(); i++) {
  5516. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5517. if (!target)
  5518. continue;
  5519. if (target->IsEntity()) {
  5520. // If the ward is already active remove it
  5521. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5522. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5523. // Create new ward info
  5524. WardInfo* ward = new WardInfo;
  5525. ward->Spell = spell;
  5526. ward->BaseDamage = damage;
  5527. ward->DamageLeft = damage;
  5528. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5529. ward->keepWard = keepWard;
  5530. ward->WardType = wardType;
  5531. if (damageAbsorptionPercent > 100)
  5532. damageAbsorptionPercent = 100;
  5533. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5534. if (damageAbsorptionMaxHealthPercent > 100)
  5535. damageAbsorptionMaxHealthPercent = 100;
  5536. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5537. ward->RedirectDamagePercent = redirectDamagePercent;
  5538. ward->LastRedirectDamage = 0;
  5539. ward->LastAbsorbedDamage = 0;
  5540. ward->HitCount = 0;
  5541. spell->num_triggers = maxHitCount;
  5542. spell->had_triggers = true;
  5543. spell->cancel_after_all_triggers = false;
  5544. ward->MaxHitCount = maxHitCount;
  5545. if (wardType == WARD_TYPE_MAGICAL)
  5546. ward->DamageType = damageTypes;
  5547. // Add the ward to the entity
  5548. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5549. ward_was_added = true;
  5550. }
  5551. }
  5552. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5553. if (ward_was_added && spell->caster->IsPlayer()) {
  5554. spell->had_dmg_remaining = true;
  5555. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5556. }
  5557. return 0;
  5558. }
  5559. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5560. if (!lua_interface)
  5561. return 0;
  5562. int32 amount = lua_interface->GetInt32Value(state);
  5563. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5564. WardInfo* ward = 0;
  5565. ZoneServer* zone = spell->caster->GetZone();
  5566. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5567. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5568. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5569. ward = target->GetWard(spell->spell->GetSpellID());
  5570. if (target && ward) {
  5571. ward->DamageLeft += amount;
  5572. if (ward->DamageLeft > ward->BaseDamage)
  5573. ward->DamageLeft = ward->BaseDamage;
  5574. for (int32 i = 0; i < spell->targets.size(); i++) {
  5575. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5576. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5577. }
  5578. }
  5579. }
  5580. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5581. if (ward && spell->caster->IsPlayer())
  5582. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5583. return 0;
  5584. }
  5585. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5586. if (!lua_interface)
  5587. return 0;
  5588. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5589. if (!spell) {
  5590. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5591. return 0;
  5592. }
  5593. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5594. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5595. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5596. if (ward) {
  5597. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5598. return 1;
  5599. }
  5600. }
  5601. return 0;
  5602. }
  5603. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5604. if (!lua_interface)
  5605. return 0;
  5606. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5607. if (!spell) {
  5608. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5609. return 0;
  5610. }
  5611. string type = lua_interface->GetStringValue(state, 2);
  5612. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5613. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5614. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5615. if (ward) {
  5616. if (boost::iequals(type, "damageleft"))
  5617. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5618. else if (boost::iequals(type, "basedamage"))
  5619. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5620. else if (boost::iequals(type, "keepward"))
  5621. lua_interface->SetBooleanValue(state, ward->keepWard);
  5622. else if (boost::iequals(type, "wardtype"))
  5623. lua_interface->SetInt32Value(state, ward->WardType);
  5624. else if (boost::iequals(type, "dmgabsorptionpct"))
  5625. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5626. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5627. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5628. else if (boost::iequals(type, "redirectdamagepercent"))
  5629. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5630. else if (boost::iequals(type, "lastredirectdamage"))
  5631. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5632. else if (boost::iequals(type, "lastabsorbeddamage"))
  5633. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5634. else if (boost::iequals(type, "hitcount"))
  5635. lua_interface->SetInt32Value(state, ward->HitCount);
  5636. else if (boost::iequals(type, "maxhitcount"))
  5637. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5638. else
  5639. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5640. return 1;
  5641. }
  5642. }
  5643. return 0;
  5644. }
  5645. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5646. if (!lua_interface)
  5647. return 0;
  5648. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5649. ZoneServer* zone = spell->caster->GetZone();
  5650. Spawn* target = 0;
  5651. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5652. for (int32 i = 0; i < spell->targets.size(); i++) {
  5653. target = zone->GetSpawnByID(spell->targets.at(i));
  5654. if (target && target->IsEntity()) {
  5655. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5656. }
  5657. }
  5658. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5659. return 0;
  5660. }
  5661. int EQ2Emu_lua_Interrupt(lua_State* state)
  5662. {
  5663. if (!lua_interface)
  5664. return 0;
  5665. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5666. Spawn* target = lua_interface->GetSpawn(state, 2);
  5667. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5668. if (!caster)
  5669. {
  5670. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5671. return 0;
  5672. }
  5673. if (!target)
  5674. {
  5675. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5676. return 0;
  5677. }
  5678. if (!spell) {
  5679. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5680. return 0;
  5681. }
  5682. if (!target->IsEntity() && !spell)
  5683. {
  5684. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5685. return 0;
  5686. }
  5687. if (!target && spell) {
  5688. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5689. for (int8 i = 0; i < spell->targets.size(); i++) {
  5690. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5691. if (!target || !target->IsEntity())
  5692. continue;
  5693. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5694. }
  5695. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5696. }
  5697. else
  5698. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5699. return 0;
  5700. }
  5701. int EQ2Emu_lua_Stealth(lua_State* state) {
  5702. if (!lua_interface)
  5703. return 0;
  5704. int8 type = lua_interface->GetInt8Value(state);
  5705. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5706. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5707. if (!spell) {
  5708. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5709. return 0;
  5710. }
  5711. ZoneServer* zone = spell->caster->GetZone();
  5712. if (spawn) {
  5713. if (spawn->IsEntity()) {
  5714. if (type == 1) {
  5715. ((Entity*)spawn)->AddStealthSpell(spell);
  5716. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5717. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5718. }
  5719. else if (type == 2) {
  5720. ((Entity*)spawn)->AddInvisSpell(spell);
  5721. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5722. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5723. }
  5724. return 0;
  5725. }
  5726. else {
  5727. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5728. return 0;
  5729. }
  5730. }
  5731. else {
  5732. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5733. for (int32 i = 0; i < spell->targets.size(); i++) {
  5734. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5735. if (!spawn || !spawn->IsEntity())
  5736. continue;
  5737. if (type == 1) {
  5738. ((Entity*)spawn)->AddStealthSpell(spell);
  5739. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5740. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5741. }
  5742. else if (type == 2) {
  5743. ((Entity*)spawn)->AddInvisSpell(spell);
  5744. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5745. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5746. }
  5747. else {
  5748. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5749. break;
  5750. }
  5751. }
  5752. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5753. }
  5754. return 0;
  5755. }
  5756. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5757. if (!lua_interface)
  5758. return 0;
  5759. Spawn* spawn = lua_interface->GetSpawn(state);
  5760. if (!spawn) {
  5761. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5762. return 0;
  5763. }
  5764. if (spawn->IsEntity()) {
  5765. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5766. return 1;
  5767. }
  5768. else
  5769. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5770. return 0;
  5771. }
  5772. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5773. if (!lua_interface)
  5774. return 0;
  5775. Spawn* spawn = lua_interface->GetSpawn(state);
  5776. if (!spawn) {
  5777. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. if (spawn->IsEntity()) {
  5781. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5782. return 1;
  5783. }
  5784. else
  5785. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5786. return 0;
  5787. }
  5788. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5789. if (!lua_interface)
  5790. return 0;
  5791. Spawn* player = lua_interface->GetSpawn(state);
  5792. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5793. lua_interface->ResetFunctionStack(state);
  5794. if (!player->IsPlayer()) {
  5795. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5796. return 0;
  5797. }
  5798. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5799. return 1;
  5800. }
  5801. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5802. if (!lua_interface)
  5803. return 0;
  5804. Spawn* player = lua_interface->GetSpawn(state);
  5805. int8 slot = lua_interface->GetInt8Value(state, 2);
  5806. lua_interface->ResetFunctionStack(state);
  5807. if (!player) {
  5808. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5809. return 0;
  5810. }
  5811. if (!player->IsPlayer()) {
  5812. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5813. return 0;
  5814. }
  5815. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5816. if (!item) {
  5817. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. lua_interface->SetItemValue(state, item);
  5821. return 1;
  5822. }
  5823. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5824. if (!lua_interface)
  5825. return 0;
  5826. Spawn* player = lua_interface->GetSpawn(state);
  5827. int32 id = lua_interface->GetInt32Value(state, 2);
  5828. lua_interface->ResetFunctionStack(state);
  5829. if (!player) {
  5830. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5831. return 0;
  5832. }
  5833. if (!player->IsPlayer()) {
  5834. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5835. return 0;
  5836. }
  5837. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5838. if (!item) {
  5839. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5840. return 0;
  5841. }
  5842. lua_interface->SetItemValue(state, item);
  5843. return 1;
  5844. }
  5845. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5846. if (!lua_interface)
  5847. return 0;
  5848. Spawn* spawn = lua_interface->GetSpawn(state);
  5849. int8 slot = lua_interface->GetInt8Value(state, 2);
  5850. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5851. lua_interface->ResetFunctionStack(state);
  5852. if (!spawn) {
  5853. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5854. return 0;
  5855. }
  5856. if (!spawn->IsEntity()) {
  5857. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5858. return 0;
  5859. }
  5860. Item* item = master_item_list.GetItem(item_id);
  5861. if (!item) {
  5862. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. Item* copy = new Item(item);
  5866. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5867. if(result)
  5868. {
  5869. ((Entity*)spawn)->SetEquipment(copy, slot);
  5870. spawn->vis_changed = true;
  5871. if(spawn->IsPlayer())
  5872. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5873. }
  5874. else
  5875. {
  5876. safe_delete(copy);
  5877. }
  5878. lua_interface->SetBooleanValue(state, result);
  5879. return 1;
  5880. }
  5881. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5882. if (!lua_interface)
  5883. return 0;
  5884. Spawn* spawn = lua_interface->GetSpawn(state);
  5885. int8 slot = lua_interface->GetInt8Value(state, 2);
  5886. Item* item = lua_interface->GetItem(state, 3);
  5887. lua_interface->ResetFunctionStack(state);
  5888. if (!spawn) {
  5889. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5890. return 0;
  5891. }
  5892. if (!spawn->IsEntity()) {
  5893. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5894. return 0;
  5895. }
  5896. if (!item) {
  5897. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5898. return 0;
  5899. }
  5900. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5901. if(result)
  5902. {
  5903. ((Entity*)spawn)->SetEquipment(item, slot);
  5904. spawn->vis_changed = true;
  5905. if(spawn->IsPlayer())
  5906. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5907. }
  5908. lua_interface->SetBooleanValue(state, result);
  5909. return 1;
  5910. }
  5911. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5912. if (!lua_interface)
  5913. return 0;
  5914. Spawn* spawn = lua_interface->GetSpawn(state);
  5915. int8 slot = lua_interface->GetInt8Value(state, 2);
  5916. 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
  5917. lua_interface->ResetFunctionStack(state);
  5918. if (!spawn) {
  5919. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5920. return 0;
  5921. }
  5922. if (!spawn->IsEntity()) {
  5923. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5924. return 0;
  5925. }
  5926. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5927. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5928. spawn->vis_changed = true;
  5929. if(spawn->IsPlayer())
  5930. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5931. lua_interface->SetBooleanValue(state, true);
  5932. return 1;
  5933. }
  5934. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5935. if (!lua_interface)
  5936. return 0;
  5937. Spawn* spawn = lua_interface->GetSpawn(state);
  5938. int8 slot = lua_interface->GetInt8Value(state, 2);
  5939. int16 type = lua_interface->GetInt16Value(state, 3);
  5940. int8 r = lua_interface->GetInt8Value(state, 4);
  5941. int8 g = lua_interface->GetInt8Value(state, 5);
  5942. int8 b = lua_interface->GetInt8Value(state, 6);
  5943. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5944. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5945. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5946. lua_interface->ResetFunctionStack(state);
  5947. if (!spawn) {
  5948. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. if (!spawn->IsEntity()) {
  5952. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5953. return 0;
  5954. }
  5955. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5956. spawn->vis_changed = true;
  5957. lua_interface->SetBooleanValue(state, true);
  5958. return 1;
  5959. }
  5960. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5961. if (!lua_interface)
  5962. return 0;
  5963. Spawn* player = lua_interface->GetSpawn(state);
  5964. int32 id = lua_interface->GetInt32Value(state, 2);
  5965. int8 count = lua_interface->GetInt8Value(state, 3);
  5966. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5967. lua_interface->ResetFunctionStack(state);
  5968. if (!player) {
  5969. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5970. return 0;
  5971. }
  5972. if (!player->IsPlayer()) {
  5973. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5974. return 0;
  5975. }
  5976. if (!count)
  5977. count = 1;
  5978. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5979. if (!item) {
  5980. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5981. return 0;
  5982. }
  5983. lua_interface->SetItemValue(state, item);
  5984. return 1;
  5985. }
  5986. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5987. if (!lua_interface)
  5988. return 0;
  5989. Spawn* spawn = lua_interface->GetSpawn(state);
  5990. int32 anim = lua_interface->GetInt32Value(state, 2);
  5991. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5992. int8 type = lua_interface->GetInt8Value(state, 4);
  5993. if (!spawn) {
  5994. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5995. return 0;
  5996. }
  5997. if (spawn2) {
  5998. if (spawn2->IsPlayer()) {
  5999. if (type != 1 && type != 2)
  6000. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6001. else
  6002. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6003. return 0;
  6004. }
  6005. else {
  6006. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. }
  6010. else
  6011. spawn->GetZone()->PlayAnimation(spawn, anim);
  6012. return 0;
  6013. }
  6014. int EQ2Emu_lua_IsPet(lua_State* state) {
  6015. if (!lua_interface)
  6016. return 0;
  6017. Spawn* spawn = lua_interface->GetSpawn(state);
  6018. if (!spawn) {
  6019. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6020. return 0;
  6021. }
  6022. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6023. return 1;
  6024. }
  6025. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6026. if (!lua_interface)
  6027. return 0;
  6028. Spawn* spawn = lua_interface->GetSpawn(state);
  6029. if (!spawn) {
  6030. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6031. return 0;
  6032. }
  6033. if (!spawn->IsNPC()) {
  6034. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6035. return 0;
  6036. }
  6037. if (((NPC*)spawn)->GetOwner()) {
  6038. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6039. return 1;
  6040. }
  6041. return 0;
  6042. }
  6043. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6044. if (!lua_interface)
  6045. return 0;
  6046. Spawn* spawn = lua_interface->GetSpawn(state);
  6047. Spawn* target = lua_interface->GetSpawn(state, 2);
  6048. if (!spawn) {
  6049. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6050. return 0;
  6051. }
  6052. if (!spawn) {
  6053. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6054. return 0;
  6055. }
  6056. spawn->SetTarget(target);
  6057. return 0;
  6058. }
  6059. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6060. if (!lua_interface)
  6061. return 0;
  6062. Spawn* spawn = lua_interface->GetSpawn(state);
  6063. bool val = lua_interface->GetBooleanValue(state, 2);
  6064. if (!spawn) {
  6065. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6066. return 0;
  6067. }
  6068. if (!spawn->IsEntity()) {
  6069. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6070. return 0;
  6071. }
  6072. ((Entity*)spawn)->InCombat(val);
  6073. if (val) {
  6074. spawn->ClearRunningLocations();
  6075. spawn->CalculateRunningLocation(true);
  6076. }
  6077. return 0;
  6078. }
  6079. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6080. if (!lua_interface)
  6081. return 0;
  6082. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6083. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6084. if (!spawn1) {
  6085. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6086. return 0;
  6087. }
  6088. if (!spawn2) {
  6089. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6090. return 0;
  6091. }
  6092. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6093. return 1;
  6094. }
  6095. int EQ2Emu_lua_Runback(lua_State* state) {
  6096. if (!lua_interface)
  6097. return 0;
  6098. Spawn* spawn = lua_interface->GetSpawn(state);
  6099. if (!spawn) {
  6100. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6101. return 0;
  6102. }
  6103. if (!spawn->IsNPC()) {
  6104. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6105. return 0;
  6106. }
  6107. ((NPC*)spawn)->Runback();
  6108. return 0;
  6109. }
  6110. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6111. if (!lua_interface)
  6112. return 0;
  6113. Spawn* spawn = lua_interface->GetSpawn(state);
  6114. if (!spawn) {
  6115. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6116. return 0;
  6117. }
  6118. if (!spawn->IsNPC()) {
  6119. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6120. return 0;
  6121. }
  6122. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6123. return 1;
  6124. }
  6125. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6126. if (!lua_interface)
  6127. return 0;
  6128. Spawn* spawn = lua_interface->GetSpawn(state);
  6129. if (!spawn) {
  6130. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6131. return 0;
  6132. }
  6133. if (!spawn->IsEntity()) {
  6134. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6135. return 0;
  6136. }
  6137. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6138. return 1;
  6139. }
  6140. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6141. if (!lua_interface)
  6142. return 0;
  6143. Spawn* spawn = lua_interface->GetSpawn(state);
  6144. if (!spawn) {
  6145. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6146. return 0;
  6147. }
  6148. if (!spawn->IsEntity()) {
  6149. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6150. return 0;
  6151. }
  6152. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6153. return 1;
  6154. }
  6155. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6156. if (!lua_interface)
  6157. return 0;
  6158. Spawn* spawn = lua_interface->GetSpawn(state);
  6159. if (!spawn) {
  6160. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6161. return 0;
  6162. }
  6163. if (!spawn->IsEntity()) {
  6164. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6165. return 0;
  6166. }
  6167. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6168. return 1;
  6169. }
  6170. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6171. if (!lua_interface)
  6172. return 0;
  6173. Spawn* spawn = lua_interface->GetSpawn(state);
  6174. if (!spawn) {
  6175. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6176. return 0;
  6177. }
  6178. if (!spawn->IsEntity()) {
  6179. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6180. return 0;
  6181. }
  6182. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6183. return 1;
  6184. }
  6185. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6186. if (!lua_interface)
  6187. return 0;
  6188. Spawn* spawn = lua_interface->GetSpawn(state);
  6189. Spawn* target = lua_interface->GetSpawn(state, 2);
  6190. float distance = lua_interface->GetFloatValue(state, 3);
  6191. if (!spawn) {
  6192. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6193. return 0;
  6194. }
  6195. if (!target) {
  6196. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6197. return 0;
  6198. }
  6199. if (!spawn->IsNPC()) {
  6200. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6201. return 0;
  6202. }
  6203. if (!target->IsEntity()) {
  6204. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6205. return 0;
  6206. }
  6207. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6208. return 1;
  6209. }
  6210. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6211. if (!lua_interface)
  6212. return 0;
  6213. Spawn* spawn = lua_interface->GetSpawn(state);
  6214. Spawn* target = lua_interface->GetSpawn(state, 2);
  6215. float distance = lua_interface->GetFloatValue(state, 3);
  6216. if (!spawn) {
  6217. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6218. return 0;
  6219. }
  6220. if (!target) {
  6221. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6222. return 0;
  6223. }
  6224. if (!spawn->IsNPC()) {
  6225. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. if (!target->IsEntity()) {
  6229. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6230. return 0;
  6231. }
  6232. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6233. return 0;
  6234. }
  6235. int EQ2Emu_lua_HasRecovered(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 HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6241. return 0;
  6242. }
  6243. if (!spawn->IsNPC()) {
  6244. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6245. return 0;
  6246. }
  6247. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6248. return 1;
  6249. }
  6250. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6251. if (!lua_interface)
  6252. return 0;
  6253. Spawn* spawn = lua_interface->GetSpawn(state);
  6254. if (!spawn) {
  6255. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6256. return 0;
  6257. }
  6258. if (!spawn->IsNPC()) {
  6259. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6260. return 0;
  6261. }
  6262. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6263. return 1;
  6264. }
  6265. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6266. if (!lua_interface)
  6267. return 0;
  6268. Spawn* spawn = lua_interface->GetSpawn(state);
  6269. if (!spawn) {
  6270. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6271. return 0;
  6272. }
  6273. if (!spawn->IsNPC()) {
  6274. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6275. return 0;
  6276. }
  6277. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6278. if (hated) {
  6279. lua_interface->SetSpawnValue(state, hated);
  6280. return 1;
  6281. }
  6282. return 0;
  6283. }
  6284. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6285. if (!lua_interface)
  6286. return 0;
  6287. Spawn* spawn = lua_interface->GetSpawn(state);
  6288. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6289. if (!spawn) {
  6290. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. if (!spawn->IsNPC()) {
  6294. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6295. return 0;
  6296. }
  6297. if (!hated) {
  6298. ((NPC*)spawn)->Brain()->ClearHate();
  6299. return 0;
  6300. }
  6301. else
  6302. {
  6303. if (!hated->IsEntity()) {
  6304. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6305. return 0;
  6306. }
  6307. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6308. return 0;
  6309. }
  6310. return 0;
  6311. }
  6312. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6313. if (!lua_interface)
  6314. return 0;
  6315. Spawn* spawn = lua_interface->GetSpawn(state);
  6316. if (!spawn) {
  6317. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6318. return 0;
  6319. }
  6320. if (!spawn->IsNPC()) {
  6321. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6322. return 0;
  6323. }
  6324. ((NPC*)spawn)->Brain()->ClearEncounter();
  6325. return 0;
  6326. }
  6327. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6328. if (!lua_interface)
  6329. return 0;
  6330. Spawn* spawn = lua_interface->GetSpawn(state);
  6331. if (!spawn) {
  6332. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6333. return 0;
  6334. }
  6335. if (!spawn->IsNPC()) {
  6336. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6337. return 0;
  6338. }
  6339. // Temp list to store hate list
  6340. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6341. if (encounterList->size() == 0) {
  6342. safe_delete(encounterList);
  6343. return 0;
  6344. }
  6345. lua_createtable(state, encounterList->size(), 0);
  6346. int newTable = lua_gettop(state);
  6347. for (int32 i = 0; i < encounterList->size(); i++) {
  6348. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6349. if (temp)
  6350. lua_interface->SetSpawnValue(state, temp);
  6351. lua_rawseti(state, newTable, i + 1);
  6352. }
  6353. safe_delete(encounterList);
  6354. return 1;
  6355. }
  6356. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6357. if (!lua_interface)
  6358. return 0;
  6359. Spawn* spawn = lua_interface->GetSpawn(state);
  6360. if (!spawn) {
  6361. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6362. return 0;
  6363. }
  6364. if (!spawn->IsNPC()) {
  6365. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6366. return 0;
  6367. }
  6368. // Temp list to store hate list
  6369. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6370. if (hateList->size() == 0) {
  6371. safe_delete(hateList);
  6372. return 0;
  6373. }
  6374. lua_createtable(state, hateList->size(), 0);
  6375. int newTable = lua_gettop(state);
  6376. for (int32 i = 0; i < hateList->size(); i++) {
  6377. lua_interface->SetSpawnValue(state, hateList->at(i));
  6378. lua_rawseti(state, newTable, i + 1);
  6379. }
  6380. safe_delete(hateList);
  6381. return 1;
  6382. }
  6383. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6384. if (!lua_interface)
  6385. return 0;
  6386. Spawn* spawn = lua_interface->GetSpawn(state);
  6387. if (!spawn) {
  6388. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. if (spawn->IsPlayer()) {
  6392. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6393. lua_interface->SetBooleanValue(state, true);
  6394. else
  6395. lua_interface->SetBooleanValue(state, false);
  6396. return 1;
  6397. }
  6398. else {
  6399. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6400. return 1;
  6401. }
  6402. }
  6403. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6404. if (!lua_interface)
  6405. return 0;
  6406. Quest* quest = lua_interface->GetQuest(state);
  6407. if (!quest) {
  6408. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6409. return 0;
  6410. }
  6411. quest->SetCompletedFlag(true);
  6412. return 0;
  6413. }
  6414. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6415. if (!lua_interface)
  6416. return 0;
  6417. Spawn* spawn = lua_interface->GetSpawn(state);
  6418. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6419. int8 tier = lua_interface->GetInt8Value(state, 3);
  6420. if (!spawn) {
  6421. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6422. return 0;
  6423. }
  6424. if (!spawn->IsEntity()) {
  6425. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6426. return 0;
  6427. }
  6428. if (spellID == 0) {
  6429. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6430. return 0;
  6431. }
  6432. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6433. if (effect) {
  6434. if (tier > 0) {
  6435. // If a tier was passed chec to see if it is the same as the effect
  6436. if (tier == effect->tier)
  6437. lua_interface->SetBooleanValue(state, true);
  6438. else
  6439. lua_interface->SetBooleanValue(state, false);
  6440. return 1;
  6441. }
  6442. else {
  6443. // Have an effect but no tier was passed so return true
  6444. lua_interface->SetBooleanValue(state, true);
  6445. }
  6446. return 1;
  6447. }
  6448. // no effect so return false
  6449. lua_interface->SetBooleanValue(state, false);
  6450. return 1;
  6451. }
  6452. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6453. if (!lua_interface)
  6454. return 0;
  6455. Spawn* spawn = lua_interface->GetSpawn(state);
  6456. int32 id = lua_interface->GetInt32Value(state, 2);
  6457. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6458. Spawn* spawn2 = 0;
  6459. vector<Spawn*> list;
  6460. if (!spawn) {
  6461. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6462. return 0;
  6463. }
  6464. //If zone not provided, use spawn's zone
  6465. if (!zone)
  6466. zone = spawn->GetZone();
  6467. list = zone->GetSpawnsByID(id);
  6468. if (list.size() == 0) {
  6469. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6470. return 0;
  6471. }
  6472. vector<Spawn*>::iterator itr = list.begin();
  6473. for (int8 i = 0; i < list.size(); i++) {
  6474. spawn2 = itr[i];
  6475. if (spawn2)
  6476. spawn2->AddAllowAccessSpawn(spawn);
  6477. }
  6478. return 0;
  6479. }
  6480. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6481. if (!lua_interface)
  6482. return 0;
  6483. Spawn* spawn = lua_interface->GetSpawn(state);
  6484. int32 id = lua_interface->GetInt32Value(state, 2);
  6485. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6486. Spawn* spawn2 = 0;
  6487. if (!spawn) {
  6488. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6489. return 0;
  6490. }
  6491. //If zone not provided, use spawn's zone
  6492. if (!zone)
  6493. zone = spawn->GetZone();
  6494. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6495. vector<Spawn*>::iterator itr = list.begin();
  6496. if (list.size() == 0) {
  6497. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6498. return 0;
  6499. }
  6500. for (int8 i = 0; i < list.size(); i++) {
  6501. spawn2 = itr[i];
  6502. if (spawn2)
  6503. spawn2->RemoveSpawnAccess(spawn);
  6504. }
  6505. return 0;
  6506. }
  6507. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6508. if (!lua_interface)
  6509. return 0;
  6510. Quest* quest = lua_interface->GetQuest(state);
  6511. if (!quest) {
  6512. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6513. return 0;
  6514. }
  6515. quest->SetYellowName(true);
  6516. return 0;
  6517. }
  6518. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6519. if (!lua_interface)
  6520. return 0;
  6521. Spawn* spawn = lua_interface->GetSpawn(state);
  6522. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6523. if (!spawn) {
  6524. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6525. return 0;
  6526. }
  6527. if (!spawn->IsPlayer()) {
  6528. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6529. return 0;
  6530. }
  6531. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6532. return 1;
  6533. }
  6534. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6535. if (!lua_interface)
  6536. return 0;
  6537. Spawn* spawn = lua_interface->GetSpawn(state);
  6538. if (!spawn) {
  6539. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6540. return 0;
  6541. }
  6542. if (!spawn->IsPlayer()) {
  6543. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6544. return 0;
  6545. }
  6546. ZoneServer* zone = spawn->GetZone();
  6547. if (!zone) {
  6548. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6549. return 0;
  6550. }
  6551. Instance_Type iType = zone->GetInstanceType();
  6552. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6553. iType == GROUP_LOCKOUT_INSTANCE ||
  6554. iType == RAID_LOCKOUT_INSTANCE ||
  6555. iType == SOLO_PERSIST_INSTANCE ||
  6556. iType == GROUP_PERSIST_INSTANCE ||
  6557. iType == RAID_PERSIST_INSTANCE) {
  6558. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6559. if (data) {
  6560. // Check to see if the timer has already been set, if it has return out.
  6561. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6562. return 0;
  6563. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6564. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6565. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6566. if (client) {
  6567. string time_msg = "";
  6568. int32 time = data->success_lockout_time;
  6569. int16 hour;
  6570. int8 min;
  6571. int8 sec;
  6572. hour = time / 3600;
  6573. time = time % 3600;
  6574. min = time / 60;
  6575. time = time % 60;
  6576. sec = time;
  6577. if (hour > 0) {
  6578. char temp[10];
  6579. sprintf(temp, " %i", hour);
  6580. time_msg.append(temp);
  6581. time_msg.append(" hour");
  6582. time_msg.append((hour > 1) ? "s" : "");
  6583. }
  6584. if (min > 0) {
  6585. char temp[5];
  6586. sprintf(temp, " %i", min);
  6587. time_msg.append(temp);
  6588. time_msg.append(" minute");
  6589. time_msg.append((min > 1) ? "s" : "");
  6590. }
  6591. // Only add seconds if minutes and hours are 0
  6592. if (hour == 0 && min == 0 && sec > 0) {
  6593. char temp[5];
  6594. sprintf(temp, " %i", sec);
  6595. time_msg.append(temp);
  6596. time_msg.append(" second");
  6597. time_msg.append((sec > 1) ? "s" : "");
  6598. }
  6599. 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());
  6600. }
  6601. }
  6602. else
  6603. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6604. }
  6605. else
  6606. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6607. return 0;
  6608. }
  6609. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6610. if (!lua_interface)
  6611. return 0;
  6612. Spawn* spawn = lua_interface->GetSpawn(state);
  6613. if (!spawn) {
  6614. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6615. return 0;
  6616. }
  6617. if (!spawn->IsPlayer()) {
  6618. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6619. return 0;
  6620. }
  6621. ZoneServer* zone = spawn->GetZone();
  6622. if (!zone) {
  6623. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6624. return 0;
  6625. }
  6626. Instance_Type iType = zone->GetInstanceType();
  6627. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6628. iType == GROUP_LOCKOUT_INSTANCE ||
  6629. iType == RAID_LOCKOUT_INSTANCE ||
  6630. iType == SOLO_PERSIST_INSTANCE ||
  6631. iType == GROUP_PERSIST_INSTANCE ||
  6632. iType == RAID_PERSIST_INSTANCE) {
  6633. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6634. if (data) {
  6635. // Check to see if the timer has already been set, if it has return out.
  6636. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6637. return 0;
  6638. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6639. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6640. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6641. if (client) {
  6642. string time_msg = "";
  6643. int32 time = data->failure_lockout_time;
  6644. int16 hour;
  6645. int8 min;
  6646. int8 sec;
  6647. hour = time / 3600;
  6648. time = time % 3600;
  6649. min = time / 60;
  6650. time = time % 60;
  6651. sec = time;
  6652. if (hour > 0) {
  6653. char temp[10];
  6654. sprintf(temp, " %i", hour);
  6655. time_msg.append(temp);
  6656. time_msg.append(" hour");
  6657. time_msg.append((hour > 1) ? "s" : "");
  6658. }
  6659. if (min > 0) {
  6660. char temp[5];
  6661. sprintf(temp, " %i", min);
  6662. time_msg.append(temp);
  6663. time_msg.append(" minute");
  6664. time_msg.append((min > 1) ? "s" : "");
  6665. }
  6666. // Only add seconds if minutes and hours are 0
  6667. if (hour == 0 && min == 0 && sec > 0) {
  6668. char temp[5];
  6669. sprintf(temp, " %i", sec);
  6670. time_msg.append(temp);
  6671. time_msg.append(" second");
  6672. time_msg.append((sec > 1) ? "s" : "");
  6673. }
  6674. 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());
  6675. }
  6676. }
  6677. else
  6678. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6679. }
  6680. else
  6681. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6682. return 0;
  6683. }
  6684. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6685. if (!lua_interface)
  6686. return 0;
  6687. Spawn* spawn = lua_interface->GetSpawn(state);
  6688. if (!spawn) {
  6689. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6690. return 0;
  6691. }
  6692. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6693. return 1;
  6694. }
  6695. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6696. if (!lua_interface)
  6697. return 0;
  6698. Spawn* player = lua_interface->GetSpawn(state);
  6699. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6700. if (!player) {
  6701. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6702. return 0;
  6703. }
  6704. if (!player->IsPlayer()) {
  6705. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. if (!ground) {
  6709. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6710. return 0;
  6711. }
  6712. if (!ground->IsGroundSpawn()) {
  6713. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6714. return 0;
  6715. }
  6716. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6717. if (!groundspawn_entries) {
  6718. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6719. return 0;
  6720. }
  6721. Skill* skill = 0;
  6722. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6723. if (collection_skill == "Collecting")
  6724. skill = ((Player*)player)->GetSkillByName("Gathering");
  6725. else
  6726. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6727. if (!skill) {
  6728. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6729. return 0;
  6730. }
  6731. vector<GroundSpawnEntry*>::iterator itr;
  6732. GroundSpawnEntry* entry = 0;
  6733. bool can_harvest = false;
  6734. sint32 min_skill = -1;
  6735. int16 totalSkill = skill->current_val;
  6736. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6737. if(skillID != 0xFFFFFFFF)
  6738. {
  6739. ((Entity*)player)->MStats.lock();
  6740. totalSkill += ((Entity*)player)->stats[skillID];
  6741. ((Entity*)player)->MStats.unlock();
  6742. }
  6743. // first, iterate through groundspawn_entries, discard tables player cannot use
  6744. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6745. {
  6746. entry = *itr;
  6747. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6748. min_skill = entry->min_skill_level;
  6749. // if player lacks skill, skip table
  6750. if (entry->min_skill_level > totalSkill)
  6751. continue;
  6752. // if bonus, but player lacks level, skip table
  6753. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6754. continue;
  6755. can_harvest = true;
  6756. break;
  6757. }
  6758. lua_interface->SetBooleanValue(state, can_harvest);
  6759. // If false, send the message to the client
  6760. if (!can_harvest) {
  6761. Client* client = player->GetZone()->GetClientBySpawn(player);
  6762. if (client) {
  6763. string msg = "You do not have enough skill to ";
  6764. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6765. msg.append("gather");
  6766. else if (collection_skill == "Mining")
  6767. msg.append("mine");
  6768. else if (collection_skill == "Trapping")
  6769. msg.append("trap");
  6770. else if (collection_skill == "Foresting")
  6771. msg.append("forest");
  6772. else if (collection_skill == "Fishing")
  6773. msg.append("catch");
  6774. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6775. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6776. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6777. }
  6778. }
  6779. return 1;
  6780. }
  6781. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6782. if (!lua_interface)
  6783. return 0;
  6784. Spawn* player = lua_interface->GetSpawn(state);
  6785. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6786. if (!player) {
  6787. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6788. return 0;
  6789. }
  6790. if (!player->IsPlayer()) {
  6791. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6792. return 0;
  6793. }
  6794. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6795. lua_interface->SetBooleanValue(state, ret);
  6796. return 1;
  6797. }
  6798. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6799. // Check to see if we have a valid lua_interface
  6800. if (!lua_interface)
  6801. return 0;
  6802. // Get the spawn that is getting the pet
  6803. Spawn* spawn = lua_interface->GetSpawn(state);
  6804. Spawn* target = lua_interface->GetSpawn(state, 2);
  6805. // Get the DB ID of the pet
  6806. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6807. float x = lua_interface->GetFloatValue(state, 4);
  6808. float y = lua_interface->GetFloatValue(state, 5);
  6809. float z = lua_interface->GetFloatValue(state, 6);
  6810. // Get the spell that this command was called from
  6811. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6812. // Check to make sure the spawn pointer is valid
  6813. if (!spawn) {
  6814. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6815. return 0;
  6816. }
  6817. // Check to make sure the spawn is an entity
  6818. if (!spawn->IsEntity()) {
  6819. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6820. return 0;
  6821. }
  6822. if (!target) {
  6823. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6824. return 0;
  6825. }
  6826. if (!target->IsEntity()) {
  6827. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6828. return 0;
  6829. }
  6830. // Check to see if the DB ID for the pet is set
  6831. if (pet_id == 0) {
  6832. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6833. return 0;
  6834. }
  6835. // Check to see if the pointer to the spell is valid
  6836. if (!luaspell) {
  6837. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6841. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6842. if (!pet) {
  6843. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6844. return 0;
  6845. }
  6846. // Check to make sure the pet is an npc
  6847. if (!pet->IsNPC()) {
  6848. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6849. return 0;
  6850. }
  6851. if (x == 0)
  6852. x = spawn->GetX();
  6853. if (y == 0)
  6854. y = spawn->GetY();
  6855. if (z == 0)
  6856. z = spawn->GetZ();
  6857. // Spawn the pet at the same location as the owner
  6858. pet->SetX(x);
  6859. pet->SetY(y);
  6860. pet->SetZ(z);
  6861. pet->SetLocation(spawn->GetLocation());
  6862. pet->SetHeading(spawn->GetHeading());
  6863. spawn->GetZone()->AddSpawn(pet);
  6864. /*
  6865. const char* spawn_script = world.GetSpawnScript(pet_id);
  6866. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6867. spawn->SetSpawnScript(string(spawn_script));
  6868. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6869. }*/
  6870. // Get a random pet name
  6871. string random_pet_name;
  6872. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6873. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6874. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6875. // Set the pets name
  6876. pet->SetName(random_pet_name.c_str());
  6877. // Set the level of the pet to the owners level
  6878. pet->SetLevel(spawn->GetLevel());
  6879. // Set the faction of the pet to the same faction as the owner
  6880. pet->SetFactionID(spawn->GetFactionID());
  6881. // Set the spawn as a pet
  6882. pet->SetPet(true);
  6883. // Give a pointer of the owner to the pet
  6884. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6885. // Set the pet type
  6886. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6887. // Set the spell id used to create this pet
  6888. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6889. // Set the spell tier used to create this pet
  6890. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6891. // Set the pets spawn type to 6
  6892. pet->SetSpawnType(6);
  6893. // Set the pets brain
  6894. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6895. // Check to see if the pet has a subtitle
  6896. if (strlen(pet->GetSubTitle()) > 0) {
  6897. // Add the players name to the front of the sub title
  6898. string pet_subtitle;
  6899. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6900. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6901. // Set the pets subtitle to the new one
  6902. pet->SetSubTitle(pet_subtitle.c_str());
  6903. }
  6904. // Set the pet as the return value for this function
  6905. lua_interface->SetSpawnValue(state, pet);
  6906. return 1;
  6907. }
  6908. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6909. if (!lua_interface)
  6910. return 0;
  6911. Spawn* spawn = lua_interface->GetSpawn(state);
  6912. Spawn* player = lua_interface->GetSpawn(state, 2);
  6913. float max_distance = lua_interface->GetFloatValue(state, 3);
  6914. string type = lua_interface->GetStringValue(state, 4);
  6915. if (!spawn || (spawn && spawn->IsPlayer())) {
  6916. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6917. return 0;
  6918. }
  6919. if (!player || (player && !player->IsPlayer())) {
  6920. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6921. return 0;
  6922. }
  6923. Client* client = 0;
  6924. if (player->GetZone())
  6925. client = player->GetZone()->GetClientBySpawn(player);
  6926. if (!client) {
  6927. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6928. return 0;
  6929. }
  6930. //Set max_distance to default if not set or not proper value
  6931. if (max_distance <= 0)
  6932. max_distance = 500;
  6933. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6934. if (packet) {
  6935. float unknown2_3 = 0;
  6936. int8 placement_mode = 0;
  6937. if (type == "wall") {
  6938. placement_mode = 2;
  6939. unknown2_3 = 150;
  6940. }
  6941. else if (type == "ceiling")
  6942. placement_mode = 1;
  6943. packet->setDataByName("placement_mode", placement_mode);
  6944. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6945. packet->setDataByName("model_type", spawn->GetModelType());
  6946. packet->setDataByName("unknown", 1); //size
  6947. packet->setDataByName("unknown2", 1); //size 2
  6948. packet->setDataByName("unknown2", .5, 1); //size 3
  6949. packet->setDataByName("unknown2", 3, 2);
  6950. packet->setDataByName("unknown2", unknown2_3, 3);
  6951. packet->setDataByName("max_distance", max_distance);
  6952. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6953. client->QueuePacket(packet->serialize());
  6954. safe_delete(packet);
  6955. }
  6956. return 0;
  6957. }
  6958. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6959. if (!lua_interface)
  6960. return 0;
  6961. Item* item = lua_interface->GetItem(state);
  6962. if (!item) {
  6963. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6964. return 0;
  6965. }
  6966. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6967. return 1;
  6968. }
  6969. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6970. if (!lua_interface)
  6971. return 0;
  6972. Spawn* spawn = lua_interface->GetSpawn(state);
  6973. if (!spawn) {
  6974. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6975. return 0;
  6976. }
  6977. if (spawn->GetZone())
  6978. spawn->GetZone()->AddTransportSpawn(spawn);
  6979. return 0;
  6980. }
  6981. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6982. if (!lua_interface)
  6983. return 0;
  6984. Spawn* spawn = lua_interface->GetSpawn(state);
  6985. if (!spawn) {
  6986. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6987. return 0;
  6988. }
  6989. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  6990. return 1;
  6991. }
  6992. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6993. if (!lua_interface)
  6994. return 0;
  6995. Skill* skill = lua_interface->GetSkill(state);
  6996. if (!skill) {
  6997. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6998. return 0;
  6999. }
  7000. lua_interface->SetInt32Value(state, skill->current_val);
  7001. return 1;
  7002. }
  7003. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7004. if (!lua_interface)
  7005. return 0;
  7006. Skill* skill = lua_interface->GetSkill(state);
  7007. if (!skill) {
  7008. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7009. return 0;
  7010. }
  7011. lua_interface->SetInt32Value(state, skill->max_val);
  7012. return 1;
  7013. }
  7014. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7015. if (!lua_interface)
  7016. return 0;
  7017. Skill* skill = lua_interface->GetSkill(state);
  7018. if (!skill) {
  7019. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7020. return 0;
  7021. }
  7022. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7023. return 1;
  7024. }
  7025. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7026. if (!lua_interface)
  7027. return 0;
  7028. Skill* skill = lua_interface->GetSkill(state);
  7029. int16 value = lua_interface->GetInt16Value(state, 2);
  7030. if (!skill) {
  7031. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7032. return 0;
  7033. }
  7034. skill->max_val = value;
  7035. if (skill->max_val < skill->current_val)
  7036. skill->current_val = skill->max_val;
  7037. return 0;
  7038. }
  7039. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7040. if (!lua_interface)
  7041. return 0;
  7042. Skill* skill = lua_interface->GetSkill(state);
  7043. int16 value = lua_interface->GetInt16Value(state, 2);
  7044. if (!skill) {
  7045. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7046. return 0;
  7047. }
  7048. if (value > skill->max_val)
  7049. skill->current_val = skill->max_val;
  7050. else
  7051. skill->current_val = value;
  7052. return 0;
  7053. }
  7054. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7055. if (!lua_interface)
  7056. return 0;
  7057. Spawn* player = lua_interface->GetSpawn(state);
  7058. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7059. if (skill_id > 0 && player && player->IsPlayer()) {
  7060. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7061. return 1;
  7062. }
  7063. return 0;
  7064. }
  7065. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7066. if (!lua_interface)
  7067. return 0;
  7068. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7069. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7070. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7071. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7072. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7073. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7074. if (player_spawn && player_spawn->IsPlayer()) {
  7075. Player* player = (Player*)player_spawn;
  7076. bool added = false;
  7077. if (!player->skill_list.HasSkill(skill_id)) {
  7078. player->AddSkill(skill_id, current_val, max_val, true);
  7079. added = true;
  7080. }
  7081. 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
  7082. Client* client = player->GetClient();
  7083. if (client) {
  7084. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7085. if (packet)
  7086. client->QueuePacket(packet);
  7087. }
  7088. }
  7089. if (added) {
  7090. lua_interface->SetBooleanValue(state, true);
  7091. return 1;
  7092. }
  7093. }
  7094. else {
  7095. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7096. }
  7097. }
  7098. else {
  7099. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7100. }
  7101. lua_interface->SetBooleanValue(state, false);
  7102. return 1;
  7103. }
  7104. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7105. if (!lua_interface)
  7106. return 0;
  7107. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7108. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7109. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7110. if (skill_id > 0) {
  7111. if (player_spawn && player_spawn->IsPlayer()) {
  7112. Player* player = (Player*)player_spawn;
  7113. if (player->skill_list.HasSkill(skill_id)) {
  7114. player->RemovePlayerSkill(skill_id);
  7115. if (!more_to_remove) {
  7116. Client* client = player->GetClient();
  7117. if (client) {
  7118. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7119. if (packet)
  7120. client->QueuePacket(packet);
  7121. }
  7122. }
  7123. }
  7124. }
  7125. else {
  7126. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7127. }
  7128. }
  7129. else {
  7130. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7131. }
  7132. return 0;
  7133. }
  7134. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7135. if (!lua_interface)
  7136. return 0;
  7137. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7138. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7139. int16 amount = lua_interface->GetInt8Value(state, 3);
  7140. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7141. if (amount > 0 && skill_type < 100) {
  7142. if (player_spawn && player_spawn->IsPlayer()) {
  7143. Player* player = (Player*)player_spawn;
  7144. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7145. if (!more_to_increase) {
  7146. Client* client = player->GetClient();
  7147. if (client) {
  7148. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7149. if (packet)
  7150. client->QueuePacket(packet);
  7151. }
  7152. }
  7153. }
  7154. else {
  7155. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7156. }
  7157. }
  7158. else {
  7159. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7160. }
  7161. return 0;
  7162. }
  7163. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7164. if (!lua_interface)
  7165. return 0;
  7166. Spawn* spawn = lua_interface->GetSpawn(state);
  7167. string name = lua_interface->GetStringValue(state, 2);
  7168. if (!spawn) {
  7169. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7170. return 0;
  7171. }
  7172. if (!spawn->IsEntity()) {
  7173. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7174. return 0;
  7175. }
  7176. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7177. if (skill) {
  7178. lua_interface->SetSkillValue(state, skill);
  7179. return 1;
  7180. }
  7181. return 0;
  7182. }
  7183. int EQ2Emu_lua_AddProc(lua_State* state) {
  7184. if (!lua_interface)
  7185. return 0;
  7186. Spawn* spawn = lua_interface->GetSpawn(state);
  7187. int8 type = lua_interface->GetInt8Value(state, 2);
  7188. float chance = lua_interface->GetFloatValue(state, 3);
  7189. Item* item = lua_interface->GetItem(state, 4);
  7190. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7191. LuaSpell* spell = 0;
  7192. if (!spawn && (!spell || !use_all_spelltargets)) {
  7193. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7194. return 0;
  7195. }
  7196. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7197. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7198. return 0;
  7199. }
  7200. if (!item)
  7201. spell = lua_interface->GetCurrentSpell(state);
  7202. if (!item && !spell) {
  7203. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7204. return 0;
  7205. }
  7206. if (spell && use_all_spelltargets) {
  7207. Spawn* target;
  7208. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7209. for (int8 i = 0; i < spell->targets.size(); i++) {
  7210. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7211. if (!target || !target->IsEntity())
  7212. continue;
  7213. ((Entity*)target)->AddProc(type, chance, item, spell);
  7214. }
  7215. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7216. }
  7217. else
  7218. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7219. return 0;
  7220. }
  7221. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7222. if (!lua_interface)
  7223. return 0;
  7224. Spawn* spawn = lua_interface->GetSpawn(state);
  7225. Item* item = lua_interface->GetItem(state, 2);
  7226. LuaSpell* spell = 0;
  7227. if (!spawn) {
  7228. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7229. return 0;
  7230. }
  7231. if (!spawn->IsEntity()) {
  7232. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7233. return 0;
  7234. }
  7235. if (!item)
  7236. spell = lua_interface->GetCurrentSpell(state);
  7237. if (!item && !spell) {
  7238. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7239. return 0;
  7240. }
  7241. if (spell) {
  7242. Spawn* target;
  7243. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7244. for (int8 i = 0; i < spell->targets.size(); i++) {
  7245. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7246. if (!target || !target->IsEntity())
  7247. continue;
  7248. ((Entity*)target)->RemoveProc(item, spell);
  7249. }
  7250. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7251. spell->caster->RemoveProc(item, spell);
  7252. }
  7253. else
  7254. ((Entity*)spawn)->RemoveProc(item, spell);
  7255. return 0;
  7256. }
  7257. int EQ2Emu_lua_Knockback(lua_State* state) {
  7258. if (!lua_interface)
  7259. return 0;
  7260. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7261. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7262. int32 duration = lua_interface->GetInt32Value(state, 3);
  7263. float vertical = lua_interface->GetFloatValue(state, 4);
  7264. float horizontal = lua_interface->GetFloatValue(state, 5);
  7265. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7266. if (!target_spawn) {
  7267. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7268. return 0;
  7269. }
  7270. if (!spawn) {
  7271. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7272. return 0;
  7273. }
  7274. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7275. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7276. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7277. if (packet) {
  7278. packet->setDataByName("target_x", target_spawn->GetX());
  7279. packet->setDataByName("target_y", target_spawn->GetY());
  7280. packet->setDataByName("target_z", target_spawn->GetZ());
  7281. packet->setDataByName("vertical_movement", vertical);
  7282. packet->setDataByName("horizontal_movement", horizontal);
  7283. if (use_heading)
  7284. packet->setDataByName("use_player_heading", 1);
  7285. client->QueuePacket(packet->serialize());
  7286. }
  7287. safe_delete(packet);
  7288. }
  7289. return 0;
  7290. }
  7291. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7292. if (!lua_interface)
  7293. return 0;
  7294. Spawn* spawn = lua_interface->GetSpawn(state);
  7295. if (!spawn) {
  7296. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7297. return 0;
  7298. }
  7299. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7300. return 1;
  7301. }
  7302. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7303. if (!lua_interface)
  7304. return 0;
  7305. Spawn* caster = lua_interface->GetSpawn(state);
  7306. Spawn* target = lua_interface->GetSpawn(state, 2);
  7307. string name = lua_interface->GetStringValue(state, 3);
  7308. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7309. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7310. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7311. string success_msg = lua_interface->GetStringValue(state, 7);
  7312. string effect_msg = lua_interface->GetStringValue(state, 8);
  7313. if (!caster) {
  7314. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. if (!caster->IsEntity()) {
  7318. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7319. return 0;
  7320. }
  7321. if (!target) {
  7322. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7323. return 0;
  7324. }
  7325. if (!target->IsEntity()) {
  7326. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7327. return 0;
  7328. }
  7329. if (name.length() == 0) {
  7330. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7331. return 0;
  7332. }
  7333. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7334. return 0;
  7335. }
  7336. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7337. if (!lua_interface)
  7338. return 0;
  7339. string name = lua_interface->GetStringValue(state);
  7340. if (name.length() == 0) {
  7341. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7342. return 0;
  7343. }
  7344. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7345. if (!skill) {
  7346. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7347. return 0;
  7348. }
  7349. lua_interface->SetInt32Value(state, skill->skill_id);
  7350. return 1;
  7351. }
  7352. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7353. if (!lua_interface)
  7354. return 0;
  7355. Spawn* spawn = lua_interface->GetSpawn(state);
  7356. if (!spawn) {
  7357. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7358. return 0;
  7359. }
  7360. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7361. return 1;
  7362. }
  7363. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7364. if (!lua_interface)
  7365. return 0;
  7366. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7367. if (!luaspell) {
  7368. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7369. return 0;
  7370. }
  7371. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7372. return 1;
  7373. }
  7374. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7375. if (!lua_interface)
  7376. return 0;
  7377. Spawn* spawn = lua_interface->GetSpawn(state);
  7378. Spawn* target = lua_interface->GetSpawn(state, 2);
  7379. if (!spawn) {
  7380. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7381. return 0;
  7382. }
  7383. if (!spawn->IsEntity()) {
  7384. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7385. return 0;
  7386. }
  7387. if (!target) {
  7388. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7389. return 0;
  7390. }
  7391. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7392. return 1;
  7393. }
  7394. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7395. if (!lua_interface)
  7396. return 0;
  7397. Spawn* spawn = lua_interface->GetSpawn(state);
  7398. Spawn* target = lua_interface->GetSpawn(state, 2);
  7399. if (!spawn) {
  7400. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7401. return 0;
  7402. }
  7403. if (!spawn->IsEntity()) {
  7404. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7405. return 0;
  7406. }
  7407. if (!target) {
  7408. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7409. return 0;
  7410. }
  7411. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7412. return 1;
  7413. }
  7414. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7415. if (!lua_interface)
  7416. return 0;
  7417. Item* item = lua_interface->GetItem(state);
  7418. if (!item) {
  7419. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7420. return 0;
  7421. }
  7422. lua_interface->SetInt32Value(state, item->details.count);
  7423. return 1;
  7424. }
  7425. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7426. if (!lua_interface)
  7427. return 0;
  7428. Item* item = lua_interface->GetItem(state);
  7429. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7430. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7431. if (!item) {
  7432. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7433. return 0;
  7434. }
  7435. if (!owner) {
  7436. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7437. return 0;
  7438. }
  7439. if (!owner->IsPlayer()) {
  7440. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7441. return 0;
  7442. }
  7443. if (item->stack_count < new_count) {
  7444. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7445. return 0;
  7446. }
  7447. if (new_count > 0) {
  7448. item->details.count = new_count;
  7449. item->save_needed = true;
  7450. }
  7451. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7452. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7453. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7454. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7455. else
  7456. {
  7457. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7458. return 0;
  7459. }
  7460. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7461. if (!client)
  7462. return 0;
  7463. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7464. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7465. if (app)
  7466. client->QueuePacket(app);
  7467. return 0;
  7468. }
  7469. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7470. if (!lua_interface)
  7471. return 0;
  7472. int32 time = lua_interface->GetInt32Value(state);
  7473. string function = lua_interface->GetStringValue(state, 2);
  7474. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7475. Spawn* target = lua_interface->GetSpawn(state, 4);
  7476. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7477. if (time == 0) {
  7478. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7479. return 0;
  7480. }
  7481. if (function.length() == 0) {
  7482. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7483. return 0;
  7484. }
  7485. if (!spell) {
  7486. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. SpellScriptTimer* timer = new SpellScriptTimer;
  7490. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7491. #ifdef WIN32
  7492. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7493. #else
  7494. bzero(timer, sizeof(SpellScriptTimer));
  7495. #endif*/
  7496. timer->caster = 0;
  7497. timer->deleteWhenDone = false;
  7498. timer->target = 0;
  7499. timer->time = Timer::GetCurrentTime2() + time;
  7500. timer->customFunction = function;
  7501. timer->spell = spell;
  7502. if (caster)
  7503. timer->caster = caster->GetID();
  7504. if (target)
  7505. timer->target = target->GetID();
  7506. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7507. return 0;
  7508. }
  7509. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7510. if (!lua_interface)
  7511. return 0;
  7512. float hp_perc = lua_interface->GetFloatValue(state);
  7513. float power_perc = lua_interface->GetFloatValue(state, 2);
  7514. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7515. Spawn* target = lua_interface->GetSpawn(state, 4);
  7516. string heal_name = lua_interface->GetStringValue(state, 5);
  7517. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7518. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7519. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7520. if (!spell) {
  7521. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7522. return 0;
  7523. }
  7524. Entity* caster = spell->caster;
  7525. if (!caster) {
  7526. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7527. return 0;
  7528. }
  7529. Client* client = 0;
  7530. PendingResurrection* rez = 0;
  7531. ZoneServer* zone = spell->caster->GetZone();
  7532. if (!target) {
  7533. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7534. if (spell->targets.size() > 0) {
  7535. vector<int32> spell_targets = spell->targets;
  7536. for (int8 i = 0; i < spell_targets.size(); i++) {
  7537. target = zone->GetSpawnByID(spell_targets.at(i));
  7538. if (!target)
  7539. continue;
  7540. if (!target->IsPlayer())
  7541. continue;
  7542. client = target->GetZone()->GetClientBySpawn(target);
  7543. if (!client)
  7544. continue;
  7545. rez = client->GetCurrentRez();
  7546. if (rez->active)
  7547. continue;
  7548. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7549. rez->active = true;
  7550. rez->caster = caster;
  7551. rez->expire_timer = new Timer;
  7552. int32 duration = spell->spell->GetSpellDuration();
  7553. rez->expire_timer->Start(duration * 100);
  7554. rez->hp_perc = hp_perc;
  7555. rez->mp_perc = power_perc;
  7556. rez->range = spell->spell->GetSpellData()->range;
  7557. rez->spell_name = spell->spell->GetName();
  7558. if (heal_name.length() > 0)
  7559. rez->heal_name = heal_name;
  7560. else
  7561. rez->heal_name = rez->spell_name;
  7562. rez->no_calcs = no_calcs;
  7563. rez->crit_mod = crit_mod;
  7564. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7565. if (send_window)
  7566. client->SendResurrectionWindow();
  7567. else {
  7568. target->GetZone()->ResurrectSpawn(target, client);
  7569. rez->should_delete = true;
  7570. }
  7571. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7572. }
  7573. }
  7574. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7575. }
  7576. else {
  7577. client = target->GetZone()->GetClientBySpawn(target);
  7578. if (!client)
  7579. return 0;
  7580. rez = client->GetCurrentRez();
  7581. if (rez->active)
  7582. return 0;
  7583. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7584. rez->active = true;
  7585. rez->caster = caster;
  7586. rez->expire_timer = new Timer;
  7587. int32 duration = spell->spell->GetSpellDuration();
  7588. rez->expire_timer->Start(duration * 100);
  7589. rez->hp_perc = hp_perc;
  7590. rez->mp_perc = power_perc;
  7591. rez->range = spell->spell->GetSpellData()->range;
  7592. rez->spell_name = spell->spell->GetName();
  7593. if (heal_name.length() > 0)
  7594. rez->heal_name = heal_name;
  7595. else
  7596. rez->heal_name = rez->spell_name;
  7597. rez->no_calcs = no_calcs;
  7598. rez->crit_mod = crit_mod;
  7599. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7600. if (send_window)
  7601. client->SendResurrectionWindow();
  7602. else {
  7603. target->GetZone()->ResurrectSpawn(target, client);
  7604. rez->should_delete = true;
  7605. }
  7606. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7607. }
  7608. return 0;
  7609. }
  7610. int EQ2Emu_lua_SetVision(lua_State* state) {
  7611. if (!lua_interface)
  7612. return 0;
  7613. Spawn* spawn = lua_interface->GetSpawn(state);
  7614. int8 vision = lua_interface->GetInt8Value(state, 2);
  7615. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7616. if (!spawn) {
  7617. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7618. return 0;
  7619. }
  7620. if (!spawn->IsEntity()) {
  7621. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7622. return 0;
  7623. }
  7624. if (spell && spell->targets.size() > 0) {
  7625. ZoneServer* zone = spell->caster->GetZone();
  7626. for (int8 i = 0; i < spell->targets.size(); i++) {
  7627. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7628. if (target && target->IsEntity()) {
  7629. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7630. if (target->IsPlayer())
  7631. ((Player*)target)->SetCharSheetChanged(true);
  7632. }
  7633. }
  7634. }
  7635. else {
  7636. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7637. if (spawn->IsPlayer())
  7638. ((Player*)spawn)->SetCharSheetChanged(true);
  7639. }
  7640. return 0;
  7641. }
  7642. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7643. if (!lua_interface)
  7644. return 0;
  7645. Spawn* spawn = lua_interface->GetSpawn(state);
  7646. float intensity = lua_interface->GetFloatValue(state, 2);
  7647. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7648. if (!spawn) {
  7649. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7650. return 0;
  7651. }
  7652. if (!spawn->IsEntity()) {
  7653. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7654. return 0;
  7655. }
  7656. if (spell && spell->targets.size() > 0) {
  7657. ZoneServer* zone = spell->caster->GetZone();
  7658. for (int8 i = 0; i < spell->targets.size(); i++) {
  7659. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7660. if (target && target->IsEntity()) {
  7661. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7662. if (target->IsPlayer())
  7663. ((Player*)target)->SetCharSheetChanged(true);
  7664. }
  7665. }
  7666. }
  7667. else {
  7668. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7669. if (spawn->IsPlayer())
  7670. ((Player*)spawn)->SetCharSheetChanged(true);
  7671. }
  7672. return 0;
  7673. }
  7674. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7675. if (!lua_interface)
  7676. return 0;
  7677. Spawn* spawn = lua_interface->GetSpawn(state);
  7678. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7679. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7680. if (!spawn) {
  7681. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7682. return 0;
  7683. }
  7684. if (!spawn->IsEntity()) {
  7685. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7686. return 0;
  7687. }
  7688. if (spell && spell->targets.size() > 0) {
  7689. ZoneServer* zone = spell->caster->GetZone();
  7690. for (int8 i = 0; i < spell->targets.size(); i++) {
  7691. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7692. if (target && target->IsEntity()) {
  7693. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7694. if (target->IsPlayer())
  7695. ((Player*)target)->SetCharSheetChanged(true);
  7696. }
  7697. }
  7698. }
  7699. else {
  7700. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7701. if (spawn->IsPlayer())
  7702. ((Player*)spawn)->SetCharSheetChanged(true);
  7703. }
  7704. return 0;
  7705. }
  7706. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7707. if (!lua_interface)
  7708. return 0;
  7709. Item* item = lua_interface->GetItem(state);
  7710. int8 type = lua_interface->GetInt32Value(state, 2);
  7711. if (!item) {
  7712. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7713. return 0;
  7714. }
  7715. if (type == 1)
  7716. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7717. else if (type == 2)
  7718. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7719. return 1;
  7720. }
  7721. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7722. if (!lua_interface)
  7723. return 0;
  7724. Spawn* target = lua_interface->GetSpawn(state);
  7725. float val = lua_interface->GetFloatValue(state, 2);
  7726. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7727. // Added from Gangrenous post
  7728. if (spell && spell->resisted)
  7729. return 0;
  7730. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7731. if (val > 1.0f)
  7732. val = 1.0f - (val / 100.0f);
  7733. if (spell && spell->spell && spell->targets.size() > 0) {
  7734. ZoneServer* zone = spell->caster->GetZone();
  7735. for (int32 i = 0; i != spell->targets.size(); i++) {
  7736. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7737. if (spawn && spawn->IsEntity()) {
  7738. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7739. if (spawn->IsPlayer())
  7740. ((Player*)spawn)->SetCharSheetChanged(true);
  7741. }
  7742. }
  7743. }
  7744. else {
  7745. if (target && target->IsEntity()) {
  7746. ((Entity*)target)->SetSpeedMultiplier(val);
  7747. if (target->IsPlayer())
  7748. ((Player*)target)->SetCharSheetChanged(true);
  7749. }
  7750. }
  7751. return 0;
  7752. }
  7753. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7754. if (!lua_interface)
  7755. return 0;
  7756. Spawn* spawn = lua_interface->GetSpawn(state);
  7757. int16 model = lua_interface->GetInt16Value(state, 2);
  7758. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7759. if (spell && spell->spell && spell->targets.size() > 0) {
  7760. ZoneServer* zone = spell->caster->GetZone();
  7761. for (int32 i = 0; i < spell->targets.size(); i++) {
  7762. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7763. if (target)
  7764. target->SetIllusionModel(model);
  7765. }
  7766. }
  7767. else {
  7768. if (!spawn) {
  7769. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7770. return 0;
  7771. }
  7772. spawn->SetIllusionModel(model);
  7773. }
  7774. return 0;
  7775. }
  7776. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7777. if (!lua_interface)
  7778. return 0;
  7779. Spawn* spawn = lua_interface->GetSpawn(state);
  7780. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7781. if (spell && spell->spell && spell->targets.size() > 0) {
  7782. ZoneServer* zone = spell->caster->GetZone();
  7783. for (int32 i = 0; i < spell->targets.size(); i++) {
  7784. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7785. if (target)
  7786. target->SetIllusionModel(0);
  7787. }
  7788. }
  7789. else {
  7790. if (!spawn) {
  7791. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7792. return 0;
  7793. }
  7794. spawn->SetIllusionModel(0);
  7795. }
  7796. return 0;
  7797. }
  7798. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7799. if (!lua_interface)
  7800. return 0;
  7801. Spawn* caster = lua_interface->GetSpawn(state);
  7802. Spawn* target = lua_interface->GetSpawn(state, 2);
  7803. float chance = lua_interface->GetFloatValue(state, 3);
  7804. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7805. if (!caster) {
  7806. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7807. return 0;
  7808. }
  7809. if (!caster->IsEntity()) {
  7810. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7811. return 0;
  7812. }
  7813. if (!target) {
  7814. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7815. return 0;
  7816. }
  7817. if (!target->IsEntity()) {
  7818. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7819. return 0;
  7820. }
  7821. if (chance <= 0) {
  7822. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7823. return 0;
  7824. }
  7825. if (!spell) {
  7826. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7827. return 0;
  7828. }
  7829. if (((Entity*)caster)->GetThreatTransfer()) {
  7830. return 0;
  7831. }
  7832. ThreatTransfer* transfer = new ThreatTransfer;
  7833. transfer->Target = target->GetID();
  7834. transfer->Amount = chance;
  7835. transfer->Spell = spell;
  7836. ((Entity*)caster)->SetThreatTransfer(transfer);
  7837. return 0;
  7838. }
  7839. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7840. if (!lua_interface)
  7841. return 0;
  7842. Spawn* spawn = lua_interface->GetSpawn(state);
  7843. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7844. if (!spawn) {
  7845. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7846. return 0;
  7847. }
  7848. if (!spell) {
  7849. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7850. return 0;
  7851. }
  7852. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7853. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7854. ((Entity*)spawn)->SetThreatTransfer(0);
  7855. safe_delete(transfer);
  7856. }
  7857. return 0;
  7858. }
  7859. int EQ2Emu_lua_CureByType(lua_State* state) {
  7860. if (!lua_interface)
  7861. return 0;
  7862. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7863. if (!spell) {
  7864. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7865. return 0;
  7866. }
  7867. int8 cure_count = lua_interface->GetInt8Value(state);
  7868. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7869. string cure_name = lua_interface->GetStringValue(state, 3);
  7870. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7871. Spawn* target = lua_interface->GetSpawn(state, 5);
  7872. if (target) {
  7873. if (!target->IsEntity()) {
  7874. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7875. return 0;
  7876. }
  7877. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7878. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7879. }
  7880. else {
  7881. ZoneServer* zone = spell->caster->GetZone();
  7882. vector<int32> targets = spell->targets;
  7883. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7884. for (int8 i = 0; i < targets.size(); i++) {
  7885. target = zone->GetSpawnByID(targets.at(i));
  7886. if (!target || !target->IsEntity())
  7887. continue;
  7888. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7889. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7890. }
  7891. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7892. }
  7893. return 0;
  7894. }
  7895. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7896. if (!lua_interface)
  7897. return 0;
  7898. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7899. if (!spell) {
  7900. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7901. return 0;
  7902. }
  7903. int8 cure_count = lua_interface->GetInt8Value(state);
  7904. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7905. string cure_name = lua_interface->GetStringValue(state, 3);
  7906. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7907. Spawn* target = lua_interface->GetSpawn(state, 5);
  7908. if (target) {
  7909. if (!target->IsEntity()) {
  7910. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7911. return 0;
  7912. }
  7913. if (((Entity*)target)->GetDetCount() > 0)
  7914. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7915. }
  7916. else {
  7917. ZoneServer* zone = spell->caster->GetZone();
  7918. vector<int32> targets = spell->targets;
  7919. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7920. for (int8 i = 0; i < targets.size(); i++) {
  7921. target = zone->GetSpawnByID(targets.at(i));
  7922. if (!target || !target->IsEntity())
  7923. continue;
  7924. if (((Entity*)target)->GetDetCount() > 0)
  7925. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7926. }
  7927. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7928. }
  7929. return 0;
  7930. }
  7931. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7932. if (!lua_interface)
  7933. return 0;
  7934. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7935. if (!spell) {
  7936. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7937. return 0;
  7938. }
  7939. if (!spell->caster) {
  7940. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7941. return 0;
  7942. }
  7943. if (!spell->caster->GetZone()) {
  7944. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7945. return 0;
  7946. }
  7947. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7948. return 0;
  7949. }
  7950. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7951. if (!lua_interface)
  7952. return 0;
  7953. Spawn* spawn = lua_interface->GetSpawn(state);
  7954. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7955. if (!spell) {
  7956. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7957. return 0;
  7958. }
  7959. if (spawn && spawn->IsEntity())
  7960. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7961. else {
  7962. ZoneServer* zone = spell->caster->GetZone();
  7963. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7964. for (int32 i = 0; i < spell->targets.size(); i++) {
  7965. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7966. if (!spawn || !spawn->IsEntity())
  7967. continue;
  7968. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7969. }
  7970. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7971. }
  7972. return 0;
  7973. }
  7974. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7975. if (!lua_interface)
  7976. return 0;
  7977. Spawn* spawn = lua_interface->GetSpawn(state);
  7978. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7979. if (!spell) {
  7980. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7981. return 0;
  7982. }
  7983. if (spawn && spawn->IsEntity())
  7984. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7985. else {
  7986. ZoneServer* zone = spell->caster->GetZone();
  7987. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7988. for (int32 i = 0; i < spell->targets.size(); i++) {
  7989. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7990. if (!spawn || !spawn->IsEntity())
  7991. continue;
  7992. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7993. }
  7994. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7995. }
  7996. return 0;
  7997. }
  7998. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7999. if (!lua_interface)
  8000. return 0;
  8001. Spawn* caster = lua_interface->GetSpawn(state);
  8002. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8003. if (!caster) {
  8004. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8005. return 0;
  8006. }
  8007. if (!caster->IsPlayer()) {
  8008. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8009. return 0;
  8010. }
  8011. Spawn* target = caster->GetTarget();
  8012. if (!target) {
  8013. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8014. return 0;
  8015. }
  8016. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8017. if (!client) {
  8018. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8022. if (ho) {
  8023. ho->SetTarget(target->GetID());
  8024. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8025. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8026. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8027. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8028. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8029. deque<GroupMemberInfo*>::iterator itr;
  8030. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8031. if (group)
  8032. {
  8033. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8034. deque<GroupMemberInfo*>* members = group->GetMembers();
  8035. for (itr = members->begin(); itr != members->end(); itr++) {
  8036. if ((*itr)->client)
  8037. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8038. }
  8039. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8040. }
  8041. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8042. }
  8043. else
  8044. safe_delete(ho);
  8045. }
  8046. else {
  8047. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8048. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8049. }
  8050. else
  8051. safe_delete(ho);
  8052. }
  8053. }
  8054. return 0;
  8055. }
  8056. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8057. if (!lua_interface)
  8058. return 0;
  8059. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8060. if (!spell) {
  8061. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8062. return 0;
  8063. }
  8064. int16 triggerCount = lua_interface->GetInt16Value(state);
  8065. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8066. if (!triggerCount) {
  8067. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8068. return 0;
  8069. }
  8070. spell->num_triggers = triggerCount;
  8071. spell->had_triggers = true;
  8072. spell->cancel_after_all_triggers = cancel_after_triggers;
  8073. return 0;
  8074. }
  8075. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8076. if (!lua_interface)
  8077. return 0;
  8078. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8079. if (!spell) {
  8080. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8081. return 0;
  8082. }
  8083. lua_interface->SetInt32Value(state, spell->num_triggers);
  8084. return 1;
  8085. }
  8086. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8087. if (!lua_interface)
  8088. return 0;
  8089. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8090. if (!spell) {
  8091. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8092. return 0;
  8093. }
  8094. int16 remove_count = lua_interface->GetInt16Value(state);
  8095. if (!remove_count)
  8096. remove_count = 1;
  8097. if (remove_count >= spell->num_triggers) {
  8098. spell->num_triggers = 0;
  8099. if (spell->cancel_after_all_triggers)
  8100. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8101. }
  8102. else {
  8103. spell->num_triggers -= remove_count;
  8104. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8105. }
  8106. return 0;
  8107. }
  8108. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8109. if (!lua_interface)
  8110. return 0;
  8111. Spawn* spawn = lua_interface->GetSpawn(state);
  8112. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8113. if (!spawn) {
  8114. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8115. return 0;
  8116. }
  8117. if (!copy_spawn) {
  8118. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8119. return 0;
  8120. }
  8121. spawn->CopySpawnAppearance(copy_spawn);
  8122. return 0;
  8123. }
  8124. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8125. Spawn* spawn = lua_interface->GetSpawn(state);
  8126. int8 type = lua_interface->GetInt8Value(state, 2);
  8127. if (!spawn) {
  8128. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8129. return 0;
  8130. }
  8131. else if (!spawn->IsEntity()) {
  8132. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8133. return 0;
  8134. }
  8135. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8136. return 1;
  8137. }
  8138. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8139. if (!lua_interface)
  8140. return 0;
  8141. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8142. int8 type = lua_interface->GetInt8Value(state);
  8143. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8144. if (!spell) {
  8145. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8146. return 0;
  8147. }
  8148. if (spawn) {
  8149. if (!spawn->IsEntity()) {
  8150. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8151. return 0;
  8152. }
  8153. Entity* entity = ((Entity*)spawn);
  8154. entity->AddImmunity(spell, type);
  8155. }
  8156. else {
  8157. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8158. for (int8 i = 0; i < spell->targets.size(); i++) {
  8159. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8160. if (!spawn || !spawn->IsEntity())
  8161. continue;
  8162. Entity* entity = ((Entity*)spawn);
  8163. entity->AddImmunity(spell, type);
  8164. }
  8165. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8166. }
  8167. return 0;
  8168. }
  8169. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8170. if (!lua_interface)
  8171. return 0;
  8172. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8173. int8 type = lua_interface->GetInt8Value(state);
  8174. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8175. if (!spell) {
  8176. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8177. return 0;
  8178. }
  8179. if (spawn) {
  8180. if (!spawn->IsEntity()) {
  8181. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8182. return 0;
  8183. }
  8184. Entity* entity = ((Entity*)spawn);
  8185. entity->RemoveImmunity(spell, type);
  8186. }
  8187. else {
  8188. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8189. for (int8 i = 0; i < spell->targets.size(); i++) {
  8190. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8191. if (!spawn || !spawn->IsEntity())
  8192. continue;
  8193. Entity* entity = ((Entity*)spawn);
  8194. entity->RemoveImmunity(spell, type);
  8195. }
  8196. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8197. }
  8198. return 0;
  8199. }
  8200. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8201. if (!lua_interface)
  8202. return 0;
  8203. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8204. if (!spell) {
  8205. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8206. return 0;
  8207. }
  8208. float snare = lua_interface->GetFloatValue(state);
  8209. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8210. // convert the val to the speed multipler value (100 - val)
  8211. float val = 100.0 - snare;
  8212. val /= 100.0;
  8213. if (spawn) {
  8214. if (!spawn->IsEntity()) {
  8215. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8216. return 0;
  8217. }
  8218. ((Entity*)spawn)->SetSnareValue(spell, val);
  8219. }
  8220. else {
  8221. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8222. for (int8 i = 0; i < spell->targets.size(); i++) {
  8223. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8224. if (!spawn || !spawn->IsEntity())
  8225. continue;
  8226. ((Entity*)spawn)->SetSnareValue(spell, val);
  8227. }
  8228. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8229. }
  8230. return 0;
  8231. }
  8232. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8233. if (!lua_interface)
  8234. return 0;
  8235. Spawn* spawn = lua_interface->GetSpawn(state);
  8236. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8237. if (!spawn) {
  8238. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8239. return 0;
  8240. }
  8241. if (race_id == 0) {
  8242. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8243. return 0;
  8244. }
  8245. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8246. return 1;
  8247. }
  8248. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8249. if (!lua_interface)
  8250. return 0;
  8251. Spawn* spawn = lua_interface->GetSpawn(state);
  8252. if (!spawn) {
  8253. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8254. return 0;
  8255. }
  8256. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8257. return 1;
  8258. }
  8259. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8260. if (!lua_interface)
  8261. return 0;
  8262. Spawn* spawn = lua_interface->GetSpawn(state);
  8263. if (!spawn) {
  8264. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8265. return 0;
  8266. }
  8267. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8268. return 1;
  8269. }
  8270. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8271. if (!lua_interface)
  8272. return 0;
  8273. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8274. if (!spell) {
  8275. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8276. return 0;
  8277. }
  8278. lua_interface->SetStringValue(state, spell->spell->GetName());
  8279. return 1;
  8280. }
  8281. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8282. if (!lua_interface)
  8283. return 0;
  8284. Quest* quest = lua_interface->GetQuest(state);
  8285. if (!quest) {
  8286. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8287. return 0;
  8288. }
  8289. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8290. return 1;
  8291. }
  8292. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8293. if (!lua_interface)
  8294. return 0;
  8295. Quest* quest = lua_interface->GetQuest(state);
  8296. int32 flags = lua_interface->GetInt32Value(state, 2);
  8297. if (!quest) {
  8298. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8299. return 0;
  8300. }
  8301. quest->SetQuestFlags(flags);
  8302. return 0;
  8303. }
  8304. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8305. if (!lua_interface)
  8306. return 0;
  8307. Quest* quest = lua_interface->GetQuest(state);
  8308. Spawn* player = lua_interface->GetSpawn(state, 2);
  8309. int32 step = lua_interface->GetInt32Value(state, 3);
  8310. int32 duration = lua_interface->GetInt32Value(state, 4);
  8311. string action = lua_interface->GetStringValue(state, 5);
  8312. if (!quest) {
  8313. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8314. return 0;
  8315. }
  8316. if (!player) {
  8317. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. if (!player->IsPlayer()) {
  8321. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (step == 0) {
  8325. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. if (duration == 0) {
  8329. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8330. return 0;
  8331. }
  8332. if (action.length() == 0) {
  8333. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8334. return 0;
  8335. }
  8336. Client* client = player->GetZone()->GetClientBySpawn(player);
  8337. if (!client) {
  8338. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8339. return 0;
  8340. }
  8341. quest->SetTimerStep(step);
  8342. quest->AddFailedAction(step, action);
  8343. quest->SetStepTimer(duration);
  8344. client->AddQuestTimer(quest->GetQuestID());
  8345. return 0;
  8346. }
  8347. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8348. if (!lua_interface)
  8349. return 0;
  8350. Quest* quest = lua_interface->GetQuest(state);
  8351. Spawn* player = lua_interface->GetSpawn(state, 2);
  8352. if (!quest) {
  8353. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8354. return 0;
  8355. }
  8356. if (!player) {
  8357. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8358. return 0;
  8359. }
  8360. if (!player->IsPlayer()) {
  8361. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8362. return 0;
  8363. }
  8364. Client* client = player->GetZone()->GetClientBySpawn(player);
  8365. if (!client) {
  8366. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8367. return 0;
  8368. }
  8369. quest->SetTimerStep(0);
  8370. quest->SetStepTimer(0);
  8371. client->RemoveQuestTimer(quest->GetQuestID());
  8372. return 0;
  8373. }
  8374. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8375. if (!lua_interface)
  8376. return 0;
  8377. Spawn* player = lua_interface->GetSpawn(state);
  8378. Quest* quest = lua_interface->GetQuest(state, 2);
  8379. int32 step = lua_interface->GetInt32Value(state, 3);
  8380. if (!player) {
  8381. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8382. return 0;
  8383. }
  8384. if (!player->IsPlayer()) {
  8385. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8386. return 0;
  8387. }
  8388. if (!quest) {
  8389. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8390. return 0;
  8391. }
  8392. if (step == 0) {
  8393. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8394. return 0;
  8395. }
  8396. Client* client = player->GetZone()->GetClientBySpawn(player);
  8397. if (!client) {
  8398. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8399. return 0;
  8400. }
  8401. if (quest->RemoveQuestStep(step, client)) {
  8402. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8403. client->GetCurrentZone()->SendQuestUpdates(client);
  8404. }
  8405. else
  8406. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8407. return 0;
  8408. }
  8409. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8410. if (!lua_interface)
  8411. return 0;
  8412. Quest* quest = lua_interface->GetQuest(state, 1);
  8413. int32 step = lua_interface->GetInt32Value(state, 2);
  8414. string desc = lua_interface->GetStringValue(state, 3);
  8415. string task_group = lua_interface->GetStringValue(state, 4);
  8416. if (!quest) {
  8417. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8418. return 0;
  8419. }
  8420. if (step == 0) {
  8421. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8422. return 0;
  8423. }
  8424. QuestStep* quest_step = quest->GetQuestStep(step);
  8425. if (!quest_step) {
  8426. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8427. return 0;
  8428. }
  8429. quest_step->SetStepProgress(0);
  8430. quest_step->SetTaskGroup(task_group);
  8431. quest_step->SetDescription(desc);
  8432. return 0;
  8433. }
  8434. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8435. if (!lua_interface)
  8436. return 0;
  8437. Quest* quest = lua_interface->GetQuest(state);
  8438. int32 step = lua_interface->GetInt32Value(state, 2);
  8439. string action = lua_interface->GetStringValue(state, 3);
  8440. if (!quest) {
  8441. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8442. return 0;
  8443. }
  8444. if (step == 0) {
  8445. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8446. return 0;
  8447. }
  8448. if (action.length() == 0) {
  8449. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8450. return 0;
  8451. }
  8452. quest->AddFailedAction(step, action);
  8453. return 0;
  8454. }
  8455. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8456. if (!lua_interface)
  8457. return 0;
  8458. Spawn* player = lua_interface->GetSpawn(state);
  8459. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8460. int32 step = lua_interface->GetInt32Value(state, 3);
  8461. if (!player) {
  8462. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8463. return 0;
  8464. }
  8465. if (!player->IsPlayer()) {
  8466. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8467. return 0;
  8468. }
  8469. if (quest_id == 0) {
  8470. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8471. return 0;
  8472. }
  8473. if (step == 0) {
  8474. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8475. return 0;
  8476. }
  8477. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8478. if (!quest) {
  8479. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8480. return 0;
  8481. }
  8482. quest->StepFailed(step);
  8483. return 0;
  8484. }
  8485. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8486. if (!lua_interface)
  8487. return 0;
  8488. Spawn* player = lua_interface->GetSpawn(state);
  8489. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8490. if (!player) {
  8491. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8492. return 0;
  8493. }
  8494. if (!player->IsPlayer()) {
  8495. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8496. return 0;
  8497. }
  8498. if (quest_id == 0) {
  8499. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8500. return 0;
  8501. }
  8502. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8503. if (!quest) {
  8504. lua_interface->SetInt32Value(state, 0);
  8505. return 1;
  8506. }
  8507. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8508. return 1;
  8509. }
  8510. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8511. if (!lua_interface)
  8512. return 0;
  8513. string name = lua_interface->GetStringValue(state);
  8514. string value = lua_interface->GetStringValue(state, 2);
  8515. string comment = lua_interface->GetStringValue(state, 3);
  8516. if (name.length() == 0) {
  8517. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8518. return 0;
  8519. }
  8520. if (value.length() == 0) {
  8521. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8522. return 0;
  8523. }
  8524. string varname = string("lua_").append(name);
  8525. Variable* var = variables.FindVariable(varname);
  8526. if (var)
  8527. var->SetValue(value.c_str());
  8528. else {
  8529. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8530. variables.AddVariable(var);
  8531. }
  8532. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8533. return 0;
  8534. }
  8535. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8536. if (!lua_interface)
  8537. return 0;
  8538. string name = lua_interface->GetStringValue(state);
  8539. if (name.length() == 0) {
  8540. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8541. return 0;
  8542. }
  8543. string varname = string("lua_").append(name);
  8544. Variable* var = variables.FindVariable(varname);
  8545. if (var)
  8546. lua_interface->SetStringValue(state, var->GetValue());
  8547. else
  8548. lua_interface->SetStringValue(state, "NULL");
  8549. return 1;
  8550. }
  8551. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8552. if (!lua_interface)
  8553. return 0;
  8554. Spawn* player = lua_interface->GetSpawn(state);
  8555. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8556. if (!player) {
  8557. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8558. return 0;
  8559. }
  8560. if (!player->IsPlayer()) {
  8561. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8562. return 0;
  8563. }
  8564. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8565. return 1;
  8566. }
  8567. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8568. if (!lua_interface)
  8569. return 0;
  8570. Spawn* player = lua_interface->GetSpawn(state);
  8571. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8572. if (!player) {
  8573. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8574. return 0;
  8575. }
  8576. if (!player->IsPlayer()) {
  8577. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8578. return 0;
  8579. }
  8580. Language* language = master_languages_list.GetLanguage(language_id);
  8581. if (language)
  8582. {
  8583. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8584. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8585. }
  8586. return 0;
  8587. }
  8588. int EQ2Emu_lua_IsNight(lua_State* state) {
  8589. if (!lua_interface)
  8590. return 0;
  8591. ZoneServer* zone = lua_interface->GetZone(state);
  8592. if (!zone) {
  8593. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8594. return 0;
  8595. }
  8596. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8597. return 1;
  8598. }
  8599. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8600. if (!lua_interface)
  8601. return 0;
  8602. Spawn* spawn = lua_interface->GetSpawn(state);
  8603. if (!spawn) {
  8604. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8605. return 0;
  8606. }
  8607. if (!spawn->IsWidget()) {
  8608. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8609. return 0;
  8610. }
  8611. ((Widget*)spawn)->SetMultiFloorLift(true);
  8612. if (spawn->GetZone())
  8613. spawn->GetZone()->AddTransportSpawn(spawn);
  8614. return 0;
  8615. }
  8616. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8617. if (!lua_interface)
  8618. return 0;
  8619. Spawn* player = lua_interface->GetSpawn(state);
  8620. int32 path = lua_interface->GetInt32Value(state, 2);
  8621. if (!player) {
  8622. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8623. return 0;
  8624. }
  8625. if (!player->IsPlayer()) {
  8626. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8627. return 0;
  8628. }
  8629. if (path == 0) {
  8630. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8631. return 0;
  8632. }
  8633. Client* client = player->GetZone()->GetClientBySpawn(player);
  8634. if (!client) {
  8635. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8636. return 0;
  8637. }
  8638. client->SendFlightAutoMount(path);
  8639. return 0;
  8640. }
  8641. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8642. if (!lua_interface)
  8643. return 0;
  8644. Spawn* player = lua_interface->GetSpawn(state);
  8645. if (!player) {
  8646. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8647. return 0;
  8648. }
  8649. if (!player->IsPlayer()) {
  8650. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8651. return 0;
  8652. }
  8653. Client* client = player->GetZone()->GetClientBySpawn(player);
  8654. if (!client) {
  8655. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. client->EndAutoMount();
  8659. return 0;
  8660. }
  8661. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8662. if (!lua_interface)
  8663. return 0;
  8664. Spawn* player = lua_interface->GetSpawn(state);
  8665. if (!player) {
  8666. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. if (!player->IsPlayer()) {
  8670. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8671. return 0;
  8672. }
  8673. Client* client = player->GetZone()->GetClientBySpawn(player);
  8674. if (!client) {
  8675. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8676. return 0;
  8677. }
  8678. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8679. return 1;
  8680. }
  8681. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8682. if (!lua_interface)
  8683. return 0;
  8684. Spawn* player = lua_interface->GetSpawn(state);
  8685. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8686. int32 value = lua_interface->GetInt32Value(state, 3);
  8687. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8688. if (!player) {
  8689. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8690. return 0;
  8691. }
  8692. if (!player->IsPlayer()) {
  8693. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8694. return 0;
  8695. }
  8696. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8697. return 0;
  8698. }
  8699. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8700. if (!lua_interface)
  8701. return 0;
  8702. Spawn* player = lua_interface->GetSpawn(state);
  8703. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8704. if (!player) {
  8705. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8706. return 0;
  8707. }
  8708. if (!player->IsPlayer()) {
  8709. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8710. return 0;
  8711. }
  8712. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8713. if (!hd)
  8714. return 0;
  8715. lua_interface->SetInt32Value(state, hd->Value);
  8716. lua_interface->SetInt32Value(state, hd->Value2);
  8717. return 2;
  8718. }
  8719. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8720. if (!lua_interface)
  8721. return 0;
  8722. Spawn* spawn = lua_interface->GetSpawn(state);
  8723. int32 grid = lua_interface->GetInt32Value(state, 2);
  8724. if (!spawn) {
  8725. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8726. return 0;
  8727. }
  8728. if (grid == 0) {
  8729. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8730. return 0;
  8731. }
  8732. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8733. return 0;
  8734. }
  8735. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8736. if (!lua_interface)
  8737. return 0;
  8738. Spawn* spawn = lua_interface->GetSpawn(state);
  8739. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8740. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8741. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8742. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8743. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8744. if (!spawn) {
  8745. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8746. return 0;
  8747. }
  8748. //Add this quest to the list of required quests for this spawn
  8749. spawn->SetRequiredHistory(event_id, value1, value2);
  8750. //If private spawn value set
  8751. if (private_spawn) {
  8752. //Set the spawn to be private when not granted access via history
  8753. spawn->AddAllowAccessSpawn(spawn);
  8754. spawn->SetPrivateQuestSpawn(true);
  8755. }
  8756. //This value will override vis_flags in the vis packet
  8757. if (flag_override > 0)
  8758. spawn->SetQuestsRequiredOverride(flag_override);
  8759. return 0;
  8760. }
  8761. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8762. if (!lua_interface)
  8763. return 0;
  8764. Spawn* player = lua_interface->GetSpawn(state);
  8765. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8766. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8767. if (!player) {
  8768. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8769. return 0;
  8770. }
  8771. if (!player->IsPlayer()) {
  8772. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8773. return 0;
  8774. }
  8775. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8776. return 1;
  8777. }
  8778. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8779. if (!lua_interface)
  8780. return 0;
  8781. Spawn* player = lua_interface->GetSpawn(state);
  8782. int8 level = lua_interface->GetInt8Value(state, 2);
  8783. if (!player) {
  8784. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8785. return 0;
  8786. }
  8787. if (!player->IsPlayer()) {
  8788. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8789. return 0;
  8790. }
  8791. if (level == 0) {
  8792. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8793. return 0;
  8794. }
  8795. Client* client = player->GetZone()->GetClientBySpawn(player);
  8796. if (!client) {
  8797. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8798. return 0;
  8799. }
  8800. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8801. return 0;
  8802. }
  8803. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8804. if (!lua_interface)
  8805. return 0;
  8806. Spawn* player = lua_interface->GetSpawn(state);
  8807. int32 amount = lua_interface->GetInt32Value(state, 2);
  8808. if (!player) {
  8809. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8810. return 0;
  8811. }
  8812. if (!player->IsPlayer()) {
  8813. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8814. return 0;
  8815. }
  8816. if (amount == 0) {
  8817. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8818. return 0;
  8819. }
  8820. ((Player*)player)->AddCoins(amount);
  8821. return 0;
  8822. }
  8823. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8824. if (!lua_interface)
  8825. return 0;
  8826. Spawn* player = lua_interface->GetSpawn(state);
  8827. int32 amount = lua_interface->GetInt32Value(state, 2);
  8828. if (!player) {
  8829. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8830. return 0;
  8831. }
  8832. if (!player->IsPlayer()) {
  8833. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8834. return 0;
  8835. }
  8836. if (amount == 0) {
  8837. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8838. return 0;
  8839. }
  8840. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8841. return 1;
  8842. }
  8843. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8844. if (!lua_interface)
  8845. return 0;
  8846. ZoneServer* zone = lua_interface->GetZone(state);
  8847. if (!zone) {
  8848. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8849. return 0;
  8850. }
  8851. vector<Entity*> players = zone->GetPlayers();
  8852. if (players.size() == 0)
  8853. return 0;
  8854. lua_createtable(state, players.size(), 0);
  8855. int newTable = lua_gettop(state);
  8856. for (int32 i = 0; i < players.size(); i++) {
  8857. lua_interface->SetSpawnValue(state, players.at(i));
  8858. lua_rawseti(state, newTable, i + 1);
  8859. }
  8860. return 1;
  8861. }
  8862. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8863. if (!lua_interface)
  8864. return 0;
  8865. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8866. if (!zone) {
  8867. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8868. return 0;
  8869. }
  8870. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8871. //Map of <placement_id, location_id>
  8872. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8873. map<int32, int32>::iterator itr;
  8874. vector<Spawn*> group;
  8875. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8876. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8877. if (!location) {
  8878. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8879. return 0;
  8880. }
  8881. Spawn* spawn = 0;
  8882. if (location->entities[0]) {
  8883. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8884. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8885. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8886. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8887. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8888. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8889. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8890. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8891. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8892. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8893. if(spawn && spawn->IsOmittedByDBFlag())
  8894. {
  8895. 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);
  8896. safe_delete(spawn);
  8897. continue;
  8898. }
  8899. if (spawn) {
  8900. const char* script = 0;
  8901. for (int x = 0; x < 3; x++) {
  8902. switch (x) {
  8903. case 0:
  8904. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8905. break;
  8906. case 1:
  8907. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8908. break;
  8909. case 2:
  8910. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8911. break;
  8912. }
  8913. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8914. spawn->SetSpawnScript(string(script));
  8915. break;
  8916. }
  8917. }
  8918. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8919. lua_interface->SetSpawnValue(state, spawn);
  8920. group.push_back(spawn);
  8921. }
  8922. else {
  8923. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  8924. safe_delete(spawn);
  8925. }
  8926. }
  8927. }
  8928. if (!group.empty()) {
  8929. lua_createtable(state, group.size(), 0);
  8930. int newTable = lua_gettop(state);
  8931. for (int32 i = 0; i < group.size(); i++) {
  8932. lua_interface->SetSpawnValue(state, group[i]);
  8933. lua_rawseti(state, newTable, i + 1);
  8934. }
  8935. }
  8936. else
  8937. lua_pushnil(state);
  8938. return 1;
  8939. }
  8940. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8941. if (!lua_interface)
  8942. return 0;
  8943. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8944. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8945. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8946. if (!spawn) {
  8947. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8948. return 0;
  8949. }
  8950. if (anim_id == 0) {
  8951. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8952. return 0;
  8953. }
  8954. if (leeway == 0)
  8955. leeway = 5000;
  8956. spawn->SetSpawnAnim(anim_id);
  8957. spawn->SetSpawnAnimLeeway(leeway);
  8958. return 0;
  8959. }
  8960. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8961. if (!lua_interface)
  8962. return 0;
  8963. Spawn* player = lua_interface->GetSpawn(state);
  8964. if (!player) {
  8965. return 0;
  8966. }
  8967. Client* client = player->GetZone()->GetClientBySpawn(player);
  8968. if (!client) {
  8969. return 0;
  8970. }
  8971. lua_interface->SetInt32Value(state, client->GetVersion());
  8972. return 1;
  8973. }
  8974. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8975. if (!lua_interface)
  8976. return 0;
  8977. Item* item = lua_interface->GetItem(state);
  8978. if (!item) {
  8979. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8980. return 0;
  8981. }
  8982. lua_interface->SetInt32Value(state, item->details.item_id);
  8983. return 1;
  8984. }
  8985. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8986. if (!lua_interface)
  8987. return 0;
  8988. Spawn* spawn = lua_interface->GetSpawn(state);
  8989. if (!spawn) {
  8990. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8991. return 0;
  8992. }
  8993. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8994. return 1;
  8995. }
  8996. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8997. if (!lua_interface)
  8998. return 0;
  8999. Spawn* spawn = lua_interface->GetSpawn(state);
  9000. if (!spawn) {
  9001. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9002. return 0;
  9003. }
  9004. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9005. return 1;
  9006. }
  9007. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9008. if (!lua_interface)
  9009. return 0;
  9010. Spawn* spawn = lua_interface->GetSpawn(state);
  9011. if (!spawn) {
  9012. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9013. return 0;
  9014. }
  9015. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9016. return 1;
  9017. }
  9018. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9019. if (!lua_interface)
  9020. return 0;
  9021. Spawn* spawn = lua_interface->GetSpawn(state);
  9022. if (!spawn) {
  9023. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9024. return 0;
  9025. }
  9026. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9027. return 1;
  9028. }
  9029. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9030. if (!lua_interface)
  9031. return 0;
  9032. Spawn* spawn = lua_interface->GetSpawn(state);
  9033. float pct = lua_interface->GetFloatValue(state, 2);
  9034. if (!spawn) {
  9035. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9036. return 0;
  9037. }
  9038. if (pct == 0) {
  9039. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9040. return 0;
  9041. }
  9042. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9043. lua_interface->SetInt32Value(state, amount);
  9044. return 1;
  9045. }
  9046. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9047. if (!lua_interface)
  9048. return 0;
  9049. Spawn* spawn = lua_interface->GetSpawn(state);
  9050. float pct = lua_interface->GetFloatValue(state, 2);
  9051. if (!spawn) {
  9052. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. if (pct == 0) {
  9056. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9057. return 0;
  9058. }
  9059. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9060. lua_interface->SetInt32Value(state, amount);
  9061. return 1;
  9062. }
  9063. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9064. if (!lua_interface)
  9065. return 0;
  9066. Spawn* spawn = lua_interface->GetSpawn(state);
  9067. if (!spawn) {
  9068. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9069. return 0;
  9070. }
  9071. if (!spawn->IsPlayer()) {
  9072. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9073. return 0;
  9074. }
  9075. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9076. return 1;
  9077. }
  9078. int EQ2Emu_lua_Evac(lua_State* state) {
  9079. if (!lua_interface)
  9080. return 0;
  9081. Spawn* target = lua_interface->GetSpawn(state);
  9082. if (target) {
  9083. float x = target->GetZone()->GetSafeX();
  9084. float y = target->GetZone()->GetSafeY();
  9085. float z = target->GetZone()->GetSafeZ();
  9086. float h = target->GetZone()->GetSafeHeading();
  9087. target->SetX(x);
  9088. target->SetY(y);
  9089. target->SetZ(z);
  9090. target->SetHeading(h);
  9091. target->SetSpawnOrigX(x);
  9092. target->SetSpawnOrigY(y);
  9093. target->SetSpawnOrigZ(z);
  9094. target->SetSpawnOrigHeading(h);
  9095. if (target->IsPlayer()) {
  9096. Client* client = target->GetZone()->GetClientBySpawn(target);
  9097. if (client) {
  9098. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9099. client->SetReloadingZone(true);
  9100. target->SetX(x);
  9101. target->SetY(y);
  9102. target->SetZ(z);
  9103. target->SetHeading(h);
  9104. target->SetSpawnOrigX(x);
  9105. target->SetSpawnOrigY(y);
  9106. target->SetSpawnOrigZ(z);
  9107. target->SetSpawnOrigHeading(h);
  9108. target->SetAppearancePosition(x,y,z);
  9109. client->SetZoningCoords(x,y,z,h);
  9110. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9111. if (packet)
  9112. {
  9113. packet->setDataByName("x", x);
  9114. packet->setDataByName("y", y);
  9115. packet->setDataByName("z", z);
  9116. client->QueuePacket(packet->serialize());
  9117. safe_delete(packet);
  9118. }
  9119. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9120. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9121. }
  9122. }
  9123. }
  9124. else {
  9125. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9126. ZoneServer* zone = spell->caster->GetZone();
  9127. float x = spell->caster->GetZone()->GetSafeX();
  9128. float y = spell->caster->GetZone()->GetSafeY();
  9129. float z = spell->caster->GetZone()->GetSafeZ();
  9130. float h = spell->caster->GetZone()->GetSafeHeading();
  9131. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9132. for (int32 i = 0; i < spell->targets.size(); i++) {
  9133. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9134. if (!target2)
  9135. continue;
  9136. if (target2->IsPlayer()) {
  9137. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9138. if (client) {
  9139. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9140. client->SetReloadingZone(true);
  9141. target2->SetX(x);
  9142. target2->SetY(y);
  9143. target2->SetZ(z);
  9144. target2->SetHeading(h);
  9145. target2->SetSpawnOrigX(x);
  9146. target2->SetSpawnOrigY(y);
  9147. target2->SetSpawnOrigZ(z);
  9148. target2->SetSpawnOrigHeading(h);
  9149. target2->SetAppearancePosition(x,y,z);
  9150. client->SetZoningCoords(x,y,z,h);
  9151. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9152. if (packet)
  9153. {
  9154. packet->setDataByName("x", x);
  9155. packet->setDataByName("y", y);
  9156. packet->setDataByName("z", z);
  9157. client->QueuePacket(packet->serialize());
  9158. safe_delete(packet);
  9159. }
  9160. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9161. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9162. }
  9163. }
  9164. }
  9165. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9166. }
  9167. return 0;
  9168. }
  9169. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9170. if (!lua_interface)
  9171. return 0;
  9172. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9173. if (!luaspell) {
  9174. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9175. return 0;
  9176. }
  9177. int8 tier = luaspell->spell->GetSpellTier();
  9178. lua_interface->SetInt32Value(state, tier);
  9179. return 1;
  9180. }
  9181. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9182. if (!lua_interface)
  9183. return 0;
  9184. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9185. if (!luaspell) {
  9186. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9187. return 0;
  9188. }
  9189. int32 spell_id = luaspell->spell->GetSpellID();
  9190. lua_interface->SetInt32Value(state, spell_id);
  9191. return 1;
  9192. }
  9193. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9194. if (!lua_interface)
  9195. return 0;
  9196. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9197. if (!spawn) {
  9198. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9199. return 0;
  9200. }
  9201. if (!spawn->IsPlayer()) {
  9202. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9203. return 0;
  9204. }
  9205. ZoneServer* zone = spawn->GetZone();
  9206. if (!zone) {
  9207. return 0;
  9208. }
  9209. Client* client = zone->GetClientBySpawn(spawn);
  9210. if (!client) {
  9211. return 0;
  9212. }
  9213. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9214. return 0;
  9215. }
  9216. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9217. if (!lua_interface)
  9218. return 0;
  9219. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9220. if (!spawn) {
  9221. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9222. return 0;
  9223. }
  9224. if (!spawn->IsPlayer()) {
  9225. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9226. return 0;
  9227. }
  9228. ZoneServer* zone = spawn->GetZone();
  9229. if (!zone) {
  9230. return 0;
  9231. }
  9232. Client* client = zone->GetClientBySpawn(spawn);
  9233. if (!client) {
  9234. return 0;
  9235. }
  9236. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9237. return 0;
  9238. }
  9239. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9240. if (!lua_interface)
  9241. return 0;
  9242. Spawn* caster = lua_interface->GetSpawn(state);
  9243. Spawn* target = lua_interface->GetSpawn(state, 2);
  9244. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9245. string spell_name = lua_interface->GetStringValue(state, 4);
  9246. if (!caster) {
  9247. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9248. return 0;
  9249. }
  9250. if (!caster->IsEntity()) {
  9251. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9252. return 0;
  9253. }
  9254. if (!target) {
  9255. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9256. return 0;
  9257. }
  9258. if (!target->IsEntity()) {
  9259. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9260. return 0;
  9261. }
  9262. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9263. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9264. return 0;
  9265. }
  9266. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9267. if (!lua_interface)
  9268. return 0;
  9269. Spawn* player = lua_interface->GetSpawn(state);
  9270. int32 amount = lua_interface->GetInt32Value(state, 2);
  9271. if (player && player->IsPlayer() && amount > 0) {
  9272. ((Player*)player)->AddXP(amount);
  9273. ((Player*)player)->SetCharSheetChanged(true);
  9274. Client* client = player->GetZone()->GetClientBySpawn(player);
  9275. if (client) {
  9276. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9277. }
  9278. }
  9279. return 0;
  9280. }
  9281. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9282. if (!lua_interface)
  9283. return 0;
  9284. Spawn* player = lua_interface->GetSpawn(state);
  9285. int8 type = lua_interface->GetInt8Value(state, 2);
  9286. string text = lua_interface->GetStringValue(state, 3);
  9287. Client* client = 0;
  9288. if (player && player->IsPlayer())
  9289. client = player->GetZone()->GetClientBySpawn(player);
  9290. if (!client || text.length() == 0) {
  9291. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9292. return 0;
  9293. }
  9294. client->SimpleMessage(type, text.c_str());
  9295. return 0;
  9296. }
  9297. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9298. if (!lua_interface)
  9299. return 0;
  9300. Spawn* player = lua_interface->GetSpawn(state);
  9301. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9302. Client* client = 0;
  9303. if (player && player->IsPlayer())
  9304. client = player->GetZone()->GetClientBySpawn(player);
  9305. if (!client || !spawn) {
  9306. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9307. return 0;
  9308. }
  9309. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9310. if (!items) {
  9311. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9312. return 0;
  9313. }
  9314. client->Loot(spawn->GetLootCoins(), items, spawn);
  9315. return 0;
  9316. }
  9317. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9318. if (!lua_interface)
  9319. return 0;
  9320. Spawn* spawnref = lua_interface->GetSpawn(state);
  9321. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9322. if (spawn_id > 0 && spawnref) {
  9323. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9324. if (spawns.size() == 0) {
  9325. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9326. return 0;
  9327. }
  9328. Spawn* spawn = 0;
  9329. int16 index = MakeRandomInt(0, spawns.size());
  9330. if (index >= spawns.size() || index < 0)
  9331. index = 0;
  9332. spawn = spawns[index];
  9333. lua_interface->SetSpawnValue(state, spawn);
  9334. return 1;
  9335. }
  9336. else {
  9337. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9338. }
  9339. return 0;
  9340. }
  9341. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9342. Spawn* player = lua_interface->GetSpawn(state);
  9343. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9344. string name = lua_interface->GetStringValue(state, 3);
  9345. float distance = lua_interface->GetFloatValue(state, 4);
  9346. string command = lua_interface->GetStringValue(state, 5);
  9347. string error_text = lua_interface->GetStringValue(state, 6);
  9348. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9349. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9350. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9351. if (distance == 0)
  9352. distance = 10.0f;
  9353. if (command.length() == 0)
  9354. command = name;
  9355. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9356. if (spawns.size() == 0) {
  9357. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9358. return 0;
  9359. }
  9360. Spawn* spawn = 0;
  9361. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9362. spawn = *itr;
  9363. if (spawn) {
  9364. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9365. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9366. }
  9367. }
  9368. }
  9369. return 0;
  9370. }
  9371. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9372. if (!lua_interface)
  9373. return 0;
  9374. Client* client = 0;
  9375. Spawn* player = lua_interface->GetSpawn(state);
  9376. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9377. if (player && player->IsPlayer() && player->GetZone())
  9378. client = player->GetZone()->GetClientBySpawn(player);
  9379. else{
  9380. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9381. return 0;
  9382. }
  9383. if (client) {
  9384. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9385. if (packet) {
  9386. packet->setDataByName("goal_num", goal_num);
  9387. client->QueuePacket(packet->serialize());
  9388. safe_delete(packet);
  9389. }
  9390. }
  9391. return 0;
  9392. }
  9393. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9394. if (!lua_interface)
  9395. return 0;
  9396. Client* client = 0;
  9397. Spawn* player = lua_interface->GetSpawn(state);
  9398. if (player && player->IsPlayer() && player->GetZone())
  9399. client = player->GetZone()->GetClientBySpawn(player);
  9400. else {
  9401. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9402. return 0;
  9403. }
  9404. if (client) {
  9405. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9406. }
  9407. return 0;
  9408. }
  9409. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9410. if (!lua_interface)
  9411. return 0;
  9412. Client* client = 0;
  9413. Spawn* player = lua_interface->GetSpawn(state);
  9414. float duration = lua_interface->GetFloatValue(state, 2);
  9415. string text = lua_interface->GetStringValue(state, 3);
  9416. string voice = lua_interface->GetStringValue(state, 4);
  9417. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9418. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9419. string signal = lua_interface->GetStringValue(state, 7);
  9420. string goal1 = lua_interface->GetStringValue(state, 8);
  9421. string task1 = lua_interface->GetStringValue(state, 9);
  9422. string goal2 = lua_interface->GetStringValue(state, 10);
  9423. string task2 = lua_interface->GetStringValue(state, 11);
  9424. string goal3 = lua_interface->GetStringValue(state, 12);
  9425. string task3 = lua_interface->GetStringValue(state, 13);
  9426. string goal4 = lua_interface->GetStringValue(state, 14);
  9427. string task4 = lua_interface->GetStringValue(state, 15);
  9428. if (!player) {
  9429. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9430. return 0;
  9431. }
  9432. if (!player->IsPlayer()) {
  9433. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9434. return 0;
  9435. }
  9436. else
  9437. client = ((Player*)player)->GetClient();
  9438. if (!client) {
  9439. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9440. return 0;
  9441. }
  9442. if (text.length() == 0) {
  9443. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9444. return 0;
  9445. }
  9446. if (duration >= 0 && duration < 2)
  9447. duration = 2;
  9448. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9449. if (packet) {
  9450. packet->setDataByName("open_seconds_max", duration);
  9451. packet->setDataByName("text", text.c_str());
  9452. packet->setDataByName("voice", voice.c_str());
  9453. int8 num_goals = 1;
  9454. if (task2.length() > 0)
  9455. num_goals++;
  9456. if (task3.length() > 0)
  9457. num_goals++;
  9458. if (task4.length() > 0)
  9459. num_goals++;
  9460. packet->setArrayLengthByName("num_goals", num_goals);
  9461. for (int8 i = 0; i < num_goals; i++) {
  9462. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9463. }
  9464. if (goal1.length() > 0)
  9465. packet->setArrayDataByName("goal_text", goal1.c_str());
  9466. if (goal2.length() > 0)
  9467. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9468. if (goal3.length() > 0)
  9469. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9470. if (goal4.length() > 0)
  9471. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9472. packet->setSubArrayDataByName("task_text", task1.c_str());
  9473. if (task2.length() > 0)
  9474. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9475. if (task3.length() > 0)
  9476. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9477. if (task4.length() > 0)
  9478. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9479. packet->setDataByName("complete_sound", "click");
  9480. packet->setDataByName("signal", signal.c_str());
  9481. packet->setDataByName("voice_key1", voice_key1);
  9482. packet->setDataByName("voice_key2", voice_key2);
  9483. client->QueuePacket(packet->serialize());
  9484. safe_delete(packet);
  9485. }
  9486. return 0;
  9487. }
  9488. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9489. if (!lua_interface)
  9490. return 0;
  9491. Client* client = 0;
  9492. Spawn* player = lua_interface->GetSpawn(state);
  9493. string window = lua_interface->GetStringValue(state, 2);
  9494. int8 show = lua_interface->GetInt8Value(state, 3);
  9495. if (!player) {
  9496. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9497. return 0;
  9498. }
  9499. if (!player->IsPlayer()) {
  9500. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9501. return 0;
  9502. }
  9503. else
  9504. client = ((Player*)player)->GetClient();
  9505. if (!client) {
  9506. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9507. return 0;
  9508. }
  9509. if (window.length() == 0) {
  9510. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9511. return 0;
  9512. }
  9513. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9514. if (packet) {
  9515. packet->setDataByName("window", window.c_str());
  9516. packet->setDataByName("show", show);
  9517. client->QueuePacket(packet->serialize());
  9518. safe_delete(packet);
  9519. }
  9520. return 0;
  9521. }
  9522. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9523. //See GameEvents.txt for options that can be used for this function
  9524. if (!lua_interface)
  9525. return 0;
  9526. Client* client = 0;
  9527. Spawn* player = lua_interface->GetSpawn(state);
  9528. string event_name = lua_interface->GetStringValue(state, 2);
  9529. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9530. if (!player || !player->IsPlayer()) {
  9531. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9532. return 0;
  9533. }
  9534. if (player->GetZone())
  9535. client = player->GetZone()->GetClientBySpawn(player);
  9536. if (!client) {
  9537. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9538. return 0;
  9539. }
  9540. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9541. if (packet) {
  9542. packet->setDataByName("event_name", event_name.c_str());
  9543. packet->setDataByName("enabled", enabled);
  9544. client->QueuePacket(packet->serialize());
  9545. safe_delete(packet);
  9546. }
  9547. return 0;
  9548. }
  9549. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9550. if (!lua_interface)
  9551. return 0;
  9552. Spawn* player = lua_interface->GetSpawn(state);
  9553. if (player && player->IsPlayer()) {
  9554. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9555. return 1;
  9556. }
  9557. return 0;
  9558. }
  9559. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9560. if (!lua_interface)
  9561. return 0;
  9562. Spawn* player = lua_interface->GetSpawn(state);
  9563. int8 step = lua_interface->GetInt8Value(state, 2);
  9564. if (player && player->IsPlayer() && step > 0) {
  9565. ((Player*)player)->SetTutorialStep(step);
  9566. }
  9567. return 0;
  9568. }
  9569. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9570. if (!lua_interface)
  9571. return 0;
  9572. Client* client = 0;
  9573. Spawn* player = lua_interface->GetSpawn(state);
  9574. string window = lua_interface->GetStringValue(state, 2);
  9575. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9576. if (!player) {
  9577. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9578. return 0;
  9579. }
  9580. if (!player->IsPlayer()) {
  9581. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9582. return 0;
  9583. }
  9584. else
  9585. client = ((Player*)player)->GetClient();
  9586. if (!client) {
  9587. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9588. return 0;
  9589. }
  9590. if (window.length() == 0) {
  9591. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9592. return 0;
  9593. }
  9594. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9595. if (packet) {
  9596. packet->setDataByName("window", window.c_str());
  9597. packet->setDataByName("flash_seconds", flash_seconds);
  9598. client->QueuePacket(packet->serialize());
  9599. safe_delete(packet);
  9600. }
  9601. return 0;
  9602. }
  9603. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9604. if (!lua_interface)
  9605. return 0;
  9606. Spawn* spawn = lua_interface->GetSpawn(state);
  9607. Spawn* target = lua_interface->GetSpawn(state, 2);
  9608. if (spawn && target)
  9609. return spawn->CheckLoS(target);
  9610. return 0;
  9611. }
  9612. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9613. if (!lua_interface)
  9614. return 0;
  9615. Spawn* spawn = lua_interface->GetSpawn(state);
  9616. float x = lua_interface->GetFloatValue(state, 2);
  9617. float y = lua_interface->GetFloatValue(state, 3);
  9618. float z = lua_interface->GetFloatValue(state, 4);
  9619. if (spawn)
  9620. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9621. return 0;
  9622. }
  9623. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9624. if (!lua_interface)
  9625. return 0;
  9626. ZoneServer* zone = lua_interface->GetZone(state);
  9627. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9628. if (zone)
  9629. zone->SetExpansionFlag(xpackFlag);
  9630. return 0;
  9631. }
  9632. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9633. if (!lua_interface)
  9634. return 0;
  9635. ZoneServer* zone = lua_interface->GetZone(state);
  9636. if (zone) {
  9637. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9638. return 1;
  9639. }
  9640. return 0;
  9641. }
  9642. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9643. if (!lua_interface)
  9644. return 0;
  9645. ZoneServer* zone = lua_interface->GetZone(state);
  9646. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9647. if (zone)
  9648. zone->SetHolidayFlag(holidayFlag);
  9649. return 0;
  9650. }
  9651. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9652. if (!lua_interface)
  9653. return 0;
  9654. ZoneServer* zone = lua_interface->GetZone(state);
  9655. if (zone) {
  9656. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9657. return 1;
  9658. }
  9659. return 0;
  9660. }
  9661. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9662. if (!lua_interface)
  9663. return 0;
  9664. Spawn* spawn = lua_interface->GetSpawn(state);
  9665. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9666. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9667. float distance = lua_interface->GetFloatValue(state, 4);
  9668. string in_range_function = lua_interface->GetStringValue(state, 5);
  9669. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9670. if (spawn && distance > 0 && in_range_function.length() > 0)
  9671. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9672. return 0;
  9673. }
  9674. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9675. if (!lua_interface)
  9676. return 0;
  9677. Spawn* spawn = lua_interface->GetSpawn(state);
  9678. Spawn* target = lua_interface->GetSpawn(state, 2);
  9679. if (spawn && target)
  9680. {
  9681. if (spawn->IsPlayer() && target->IsEntity())
  9682. {
  9683. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9684. return 1;
  9685. }
  9686. else if (spawn->IsEntity() && target->IsEntity())
  9687. {
  9688. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9689. return 1;
  9690. }
  9691. }
  9692. return 0;
  9693. }
  9694. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9695. if (!lua_interface)
  9696. return 0;
  9697. Spawn* spawn = lua_interface->GetSpawn(state);
  9698. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9699. if (spawn && spawn->IsEntity())
  9700. {
  9701. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9702. if (spawn->IsPlayer())
  9703. {
  9704. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9705. if (client)
  9706. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9707. }
  9708. }
  9709. return 0;
  9710. }
  9711. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9712. if (!lua_interface)
  9713. return 0;
  9714. Spawn* spawn = lua_interface->GetSpawn(state);
  9715. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9716. if (spawn && spawn->IsEntity())
  9717. {
  9718. ((Entity*)spawn)->SetSeeHideSpell(val);
  9719. if (spawn->IsPlayer())
  9720. {
  9721. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9722. if (client)
  9723. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9724. }
  9725. }
  9726. return 0;
  9727. }
  9728. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9729. {
  9730. if (!lua_interface)
  9731. return 0;
  9732. Spawn* player = lua_interface->GetSpawn(state);
  9733. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9734. string command = lua_interface->GetStringValue(state, 3);
  9735. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9736. lua_interface->ResetFunctionStack(state);
  9737. if (spawn && player && player->IsPlayer())
  9738. {
  9739. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9740. bool res = false;
  9741. if (cmd)
  9742. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9743. lua_interface->SetBooleanValue(state, res);
  9744. return 1;
  9745. }
  9746. return 0;
  9747. }
  9748. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9749. {
  9750. if (!lua_interface)
  9751. return 0;
  9752. Spawn* spawn = lua_interface->GetSpawn(state);
  9753. int32 charID = lua_interface->GetInt32Value(state, 2);
  9754. string command = lua_interface->GetStringValue(state, 3);
  9755. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9756. lua_interface->ResetFunctionStack(state);
  9757. if (spawn && charID)
  9758. {
  9759. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9760. bool res = false;
  9761. if (cmd)
  9762. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9763. lua_interface->SetBooleanValue(state, res);
  9764. return 1;
  9765. }
  9766. return 0;
  9767. }
  9768. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9769. {
  9770. if (!lua_interface)
  9771. return 0;
  9772. Spawn* spawn = lua_interface->GetSpawn(state);
  9773. string command = lua_interface->GetStringValue(state, 2);
  9774. lua_interface->ResetFunctionStack(state);
  9775. if (spawn && command.length() > 0)
  9776. spawn->RemovePrimaryEntityCommand(command.c_str());
  9777. return 0;
  9778. }
  9779. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9780. if (!lua_interface)
  9781. return 0;
  9782. Spawn* spawn = lua_interface->GetSpawn(state);
  9783. float distance = lua_interface->GetFloatValue(state, 2);
  9784. string command = lua_interface->GetStringValue(state, 3);
  9785. Spawn* player = lua_interface->GetSpawn(state, 4);
  9786. lua_interface->ResetFunctionStack(state);
  9787. if (spawn) {
  9788. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9789. }
  9790. return 0;
  9791. }
  9792. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9793. if (!lua_interface)
  9794. return 0;
  9795. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9796. Spawn* spawn = lua_interface->GetSpawn(state);
  9797. Spawn* player = lua_interface->GetSpawn(state, 2);
  9798. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9799. lua_interface->ResetFunctionStack(state);
  9800. if (spawn && player && transport_id && player->IsPlayer()) {
  9801. Client* client = 0;
  9802. if (player && player->IsPlayer())
  9803. client = player->GetZone()->GetClientBySpawn(player);
  9804. if (!client)
  9805. return 0;
  9806. vector<TransportDestination*> destinations;
  9807. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9808. if (destinations.size())
  9809. {
  9810. client->SetTemporaryTransportID(transport_id);
  9811. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9812. }
  9813. else
  9814. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9815. }
  9816. return 0;
  9817. }
  9818. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9819. if (!lua_interface)
  9820. return 0;
  9821. Spawn* player = lua_interface->GetSpawn(state);
  9822. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9823. lua_interface->ResetFunctionStack(state);
  9824. if (player && player->IsPlayer()) {
  9825. Client* client = 0;
  9826. if (player && player->IsPlayer())
  9827. client = player->GetZone()->GetClientBySpawn(player);
  9828. if (!client)
  9829. return 0;
  9830. client->SetTemporaryTransportID(transport_id);
  9831. }
  9832. return 0;
  9833. }
  9834. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9835. if (!lua_interface)
  9836. return 0;
  9837. Spawn* player = lua_interface->GetSpawn(state);
  9838. lua_interface->ResetFunctionStack(state);
  9839. if (player && player->IsPlayer()) {
  9840. Client* client = 0;
  9841. if (player && player->IsPlayer())
  9842. client = player->GetZone()->GetClientBySpawn(player);
  9843. if (!client)
  9844. return 0;
  9845. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9846. return 1;
  9847. }
  9848. return 0;
  9849. }
  9850. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9851. if (!lua_interface)
  9852. return 0;
  9853. Spawn* spawn = lua_interface->GetSpawn(state);
  9854. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9855. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9856. if (!spawn) {
  9857. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9858. return 0;
  9859. }
  9860. if (!spawn->IsEntity()) {
  9861. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9862. return 0;
  9863. }
  9864. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9865. {
  9866. 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);
  9867. return 0;
  9868. }
  9869. lua_interface->ResetFunctionStack(state);
  9870. if (spell && spell->targets.size() > 0) {
  9871. ZoneServer* zone = spell->caster->GetZone();
  9872. for (int8 i = 0; i < spell->targets.size(); i++) {
  9873. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9874. if (target && target->IsEntity()) {
  9875. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9876. if (target->IsPlayer())
  9877. ((Player*)target)->SetCharSheetChanged(true);
  9878. }
  9879. }
  9880. }
  9881. else {
  9882. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9883. if (spawn->IsPlayer())
  9884. ((Player*)spawn)->SetCharSheetChanged(true);
  9885. }
  9886. return 0;
  9887. }
  9888. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9889. if (!lua_interface)
  9890. return 0;
  9891. Spawn* spawn = lua_interface->GetSpawn(state);
  9892. lua_interface->ResetFunctionStack(state);
  9893. if (!spawn) {
  9894. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9895. return 0;
  9896. }
  9897. if (!spawn->IsEntity()) {
  9898. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9899. return 0;
  9900. }
  9901. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9902. return 1;
  9903. }
  9904. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9905. if (!lua_interface)
  9906. return 0;
  9907. int32 spell_id = lua_interface->GetInt32Value(state);
  9908. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9909. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9910. if (spell_id > 0) {
  9911. if (spell_tier == 0)
  9912. spell_tier = 1;
  9913. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9914. LuaSpell* lua_spell = 0;
  9915. if(custom_lua_script.size() > 0)
  9916. {
  9917. // attempt to load the custom script since it isn't already loaded
  9918. // we will re-obtain the lua_spell further below
  9919. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9920. {
  9921. 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());
  9922. lua_interface->LoadLuaSpell(custom_lua_script);
  9923. }
  9924. }
  9925. else
  9926. custom_lua_script = spell->GetSpellData()->lua_script;
  9927. if (!lua_spell && lua_interface)
  9928. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9929. if (!lua_spell)
  9930. {
  9931. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9932. return 0;
  9933. }
  9934. lua_spell->spell = new Spell(spell);
  9935. lua_interface->AddCustomSpell(lua_spell);
  9936. lua_interface->SetSpellValue(state, lua_spell);
  9937. return 1;
  9938. }
  9939. return 0;
  9940. }
  9941. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9942. if (!lua_interface)
  9943. return 0;
  9944. LuaSpell* spell = lua_interface->GetSpell(state);
  9945. string field = lua_interface->GetStringValue(state, 2);
  9946. if (!spell) {
  9947. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9948. return 0;
  9949. }
  9950. if (!spell->spell || !spell->spell->GetSpellData()) {
  9951. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9952. return 0;
  9953. }
  9954. boost::to_lower(field);
  9955. return spell->spell->GetSpellData(state, field);
  9956. }
  9957. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9958. if (!lua_interface)
  9959. return 0;
  9960. LuaSpell* spell = lua_interface->GetSpell(state);
  9961. string field = lua_interface->GetStringValue(state, 2);
  9962. int8 fieldArg = 3; // field value after the initial set
  9963. if (!spell) {
  9964. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9965. return 0;
  9966. }
  9967. if (!spell->spell || !spell->spell->GetSpellData()) {
  9968. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9969. return 0;
  9970. }
  9971. boost::to_lower(field);
  9972. bool valSet = false;
  9973. spell->spell->SetSpellData(state, field, fieldArg);
  9974. return valSet;
  9975. }
  9976. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9977. if (!lua_interface)
  9978. return 0;
  9979. LuaSpell* spell = lua_interface->GetSpell(state);
  9980. int8 idx = lua_interface->GetInt32Value(state, 2);
  9981. if (!spell) {
  9982. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9983. return 0;
  9984. }
  9985. if (!spell->spell || !spell->spell->GetSpellData()) {
  9986. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9987. return 0;
  9988. }
  9989. if (spell->spell->lua_data.size() <= idx)
  9990. {
  9991. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9992. return 0;
  9993. }
  9994. bool setVal = true;
  9995. LUAData* data = spell->spell->lua_data[idx];
  9996. switch (data->type)
  9997. {
  9998. case 0:
  9999. {
  10000. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10001. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10002. data->int_value = value;
  10003. data->int_value2 = value2;
  10004. break;
  10005. }
  10006. case 1:
  10007. {
  10008. float value = lua_interface->GetFloatValue(state, 3);
  10009. float value2 = lua_interface->GetFloatValue(state, 4);
  10010. data->float_value = value;
  10011. data->float_value2 = value2;
  10012. break;
  10013. }
  10014. case 2:
  10015. {
  10016. bool value = lua_interface->GetBooleanValue(state, 3);
  10017. data->bool_value = value;
  10018. break;
  10019. }
  10020. case 3:
  10021. {
  10022. string value = lua_interface->GetStringValue(state, 3);
  10023. string value2 = lua_interface->GetStringValue(state, 4);
  10024. data->string_value = value;
  10025. data->string_value2 = value2;
  10026. break;
  10027. }
  10028. default:
  10029. setVal = false;
  10030. }
  10031. return setVal;
  10032. }
  10033. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10034. if (!lua_interface)
  10035. return 0;
  10036. LuaSpell* spell = lua_interface->GetSpell(state);
  10037. int8 idx = lua_interface->GetInt32Value(state, 2);
  10038. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10039. if (!spell) {
  10040. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10041. return 0;
  10042. }
  10043. if (!spell->spell || !spell->spell->GetSpellData()) {
  10044. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10045. return 0;
  10046. }
  10047. if (spell->spell->lua_data.size() <= idx)
  10048. {
  10049. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10050. return 0;
  10051. }
  10052. bool setVal = true;
  10053. LUAData* data = spell->spell->lua_data[idx];
  10054. switch (data->type)
  10055. {
  10056. case 0:
  10057. {
  10058. if(!secondfield)
  10059. lua_interface->SetSInt32Value(state, data->int_value);
  10060. else
  10061. lua_interface->SetSInt32Value(state, data->int_value2);
  10062. break;
  10063. }
  10064. case 1:
  10065. {
  10066. if (!secondfield)
  10067. lua_interface->SetFloatValue(state, data->float_value);
  10068. else
  10069. lua_interface->SetFloatValue(state, data->float_value2);
  10070. break;
  10071. }
  10072. case 2:
  10073. {
  10074. lua_interface->SetBooleanValue(state, data->bool_value);
  10075. break;
  10076. }
  10077. case 3:
  10078. {
  10079. if (!secondfield)
  10080. lua_interface->SetStringValue(state, data->string_value.c_str());
  10081. else
  10082. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10083. break;
  10084. }
  10085. default:
  10086. setVal = false;
  10087. }
  10088. return setVal;
  10089. }
  10090. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10091. if (!lua_interface)
  10092. return 0;
  10093. LuaSpell* spell = lua_interface->GetSpell(state);
  10094. int8 idx = lua_interface->GetInt32Value(state, 2);
  10095. string field = lua_interface->GetStringValue(state, 3);
  10096. boost::to_lower(field);
  10097. if (!spell) {
  10098. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10099. return 0;
  10100. }
  10101. if (!spell->spell || !spell->spell->GetSpellData()) {
  10102. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10103. return 0;
  10104. }
  10105. if (spell->spell->effects.size() <= idx)
  10106. {
  10107. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10108. return 0;
  10109. }
  10110. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10111. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10112. if (field == "description")
  10113. effect->description = string(lua_interface->GetStringValue(state, 4));
  10114. else if (field == "bullet")
  10115. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10116. else if (field == "percentage")
  10117. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10118. else // no match
  10119. return 0;
  10120. return 1;
  10121. }
  10122. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10123. if (!lua_interface)
  10124. return 0;
  10125. LuaSpell* spell = lua_interface->GetSpell(state);
  10126. int8 idx = lua_interface->GetInt32Value(state, 2);
  10127. string field = lua_interface->GetStringValue(state, 3);
  10128. boost::to_lower(field);
  10129. if (!spell) {
  10130. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10131. return 0;
  10132. }
  10133. if (!spell->spell || !spell->spell->GetSpellData()) {
  10134. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10135. return 0;
  10136. }
  10137. if (spell->spell->effects.size() <= idx)
  10138. {
  10139. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10140. return 0;
  10141. }
  10142. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10143. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10144. if (field == "description")
  10145. lua_interface->SetStringValue(state, effect->description.c_str());
  10146. else if (field == "bullet")
  10147. lua_interface->SetInt32Value(state, effect->subbullet);
  10148. else if (field == "percentage")
  10149. lua_interface->SetInt32Value(state, effect->percentage);
  10150. else // no match
  10151. return 0;
  10152. return 1;
  10153. }
  10154. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10155. if (!lua_interface)
  10156. return 0;
  10157. LuaSpell* spell = lua_interface->GetSpell(state);
  10158. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10159. Spawn* target = lua_interface->GetSpawn(state, 3);
  10160. if (!target) {
  10161. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10162. return 0;
  10163. }
  10164. if (!target->IsEntity()) {
  10165. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10166. return 0;
  10167. }
  10168. if (!spell) {
  10169. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10170. return 0;
  10171. }
  10172. if (caster && !caster->IsEntity()) {
  10173. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10174. return 0;
  10175. }
  10176. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10177. return 0;
  10178. }
  10179. int EQ2Emu_lua_InWater(lua_State* state) {
  10180. if (!lua_interface)
  10181. return 0;
  10182. Spawn* spawn = lua_interface->GetSpawn(state);
  10183. lua_interface->ResetFunctionStack(state);
  10184. if (spawn) {
  10185. lua_interface->SetBooleanValue(state, spawn->InWater());
  10186. return 1;
  10187. }
  10188. return 0;
  10189. }
  10190. int EQ2Emu_lua_InLava(lua_State* state) {
  10191. if (!lua_interface)
  10192. return 0;
  10193. Spawn* spawn = lua_interface->GetSpawn(state);
  10194. lua_interface->ResetFunctionStack(state);
  10195. if (spawn) {
  10196. lua_interface->SetBooleanValue(state, spawn->InLava());
  10197. return 1;
  10198. }
  10199. return 0;
  10200. }
  10201. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10202. if (!lua_interface)
  10203. return 0;
  10204. Spawn* attacker = lua_interface->GetSpawn(state);
  10205. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10206. int8 type = lua_interface->GetInt8Value(state, 3);
  10207. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10208. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10209. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10210. string spell_name = lua_interface->GetStringValue(state, 7);
  10211. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10212. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10213. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10214. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10215. lua_interface->ResetFunctionStack(state);
  10216. if (!attacker) {
  10217. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10218. return 0;
  10219. }
  10220. if (!attacker->IsEntity()) {
  10221. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10222. return 0;
  10223. }
  10224. if (!victim) {
  10225. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10226. return 0;
  10227. }
  10228. if (!victim->IsEntity()) {
  10229. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10230. return 0;
  10231. }
  10232. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10233. return 0;
  10234. }
  10235. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10236. if (!lua_interface)
  10237. return 0;
  10238. Spawn* spawn = lua_interface->GetSpawn(state);
  10239. lua_interface->ResetFunctionStack(state);
  10240. if (spawn) {
  10241. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10242. return 1;
  10243. }
  10244. return 0;
  10245. }
  10246. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10247. if (!lua_interface)
  10248. return 0;
  10249. Spawn* spawn = lua_interface->GetSpawn(state);
  10250. bool invul = lua_interface->GetBooleanValue(state, 2);
  10251. lua_interface->ResetFunctionStack(state);
  10252. if (spawn) {
  10253. spawn->SetInvulnerable(invul);
  10254. }
  10255. return 0;
  10256. }
  10257. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10258. if (!lua_interface)
  10259. return 0;
  10260. string category = lua_interface->GetStringValue(state);
  10261. string name = lua_interface->GetStringValue(state, 2);
  10262. lua_interface->ResetFunctionStack(state);
  10263. Rule *ret = 0;
  10264. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10265. lua_interface->SetBooleanValue(state, ret->GetBool());
  10266. return 1;
  10267. }
  10268. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10269. return 0;
  10270. }
  10271. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10272. if (!lua_interface)
  10273. return 0;
  10274. string category = lua_interface->GetStringValue(state);
  10275. string name = lua_interface->GetStringValue(state, 2);
  10276. lua_interface->ResetFunctionStack(state);
  10277. Rule *ret = 0;
  10278. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10279. lua_interface->SetInt32Value(state, ret->GetInt32());
  10280. return 1;
  10281. }
  10282. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10283. return 0;
  10284. }
  10285. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10286. if (!lua_interface)
  10287. return 0;
  10288. string category = lua_interface->GetStringValue(state);
  10289. string name = lua_interface->GetStringValue(state, 2);
  10290. lua_interface->ResetFunctionStack(state);
  10291. Rule *ret = 0;
  10292. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10293. lua_interface->SetFloatValue(state, ret->GetFloat());
  10294. return 1;
  10295. }
  10296. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10297. return 0;
  10298. }
  10299. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10300. if (!lua_interface)
  10301. return 0;
  10302. Spawn* spawn = lua_interface->GetSpawn(state);
  10303. string type = lua_interface->GetStringValue(state, 2);
  10304. lua_interface->ResetFunctionStack(state);
  10305. if (spawn) {
  10306. int res = 1;
  10307. boost::to_lower(type);
  10308. if(type == "assigned_aa")
  10309. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10310. else if ( type == "unassigned_aa")
  10311. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10312. else if ( type == "assigned_tradeskill_aa")
  10313. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10314. else if ( type == "unassigned_tradeskill_aa")
  10315. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10316. else if ( type == "assigned_prestige_aa")
  10317. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10318. else if ( type == "unassigned_prestige_aa")
  10319. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10320. else if ( type == "assigned_tradeskill_prestige_aa")
  10321. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10322. else if ( type == "unassigned_tradeskill_prestige_aa")
  10323. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10324. else
  10325. res = 0;
  10326. return res;
  10327. }
  10328. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10329. return 0;
  10330. }
  10331. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10332. if (!lua_interface)
  10333. return 0;
  10334. Spawn* spawn = lua_interface->GetSpawn(state);
  10335. string type = lua_interface->GetStringValue(state, 2);
  10336. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10337. lua_interface->ResetFunctionStack(state);
  10338. if (spawn) {
  10339. boost::to_lower(type);
  10340. if(type == "assigned_aa")
  10341. spawn->SetAssignedAA((sint16)value);
  10342. else if ( type == "unassigned_aa")
  10343. spawn->SetUnassignedAA((sint16)value);
  10344. else if ( type == "assigned_tradeskill_aa")
  10345. spawn->SetTradeskillAA((sint16)value);
  10346. else if ( type == "unassigned_tradeskill_aa")
  10347. spawn->SetUnassignedTradeskillAA((sint16)value);
  10348. else if ( type == "assigned_prestige_aa")
  10349. spawn->SetPrestigeAA((sint16)value);
  10350. else if ( type == "unassigned_prestige_aa")
  10351. spawn->SetUnassignedPrestigeAA((sint16)value);
  10352. else if ( type == "assigned_tradeskill_prestige_aa")
  10353. spawn->SetTradeskillPrestigeAA((sint16)value);
  10354. else if ( type == "unassigned_tradeskill_prestige_aa")
  10355. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10356. if(spawn->IsPlayer())
  10357. ((Player*)spawn)->SetCharSheetChanged(true);
  10358. }
  10359. return 0;
  10360. }
  10361. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10362. if (!lua_interface)
  10363. return 0;
  10364. string titleName = lua_interface->GetStringValue(state);
  10365. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10366. lua_interface->ResetFunctionStack(state);
  10367. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10368. lua_interface->SetSInt32Value(state, index);
  10369. return 1;
  10370. }
  10371. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10372. if (!lua_interface)
  10373. return 0;
  10374. Spawn* spawn = lua_interface->GetSpawn(state);
  10375. string titleName = lua_interface->GetStringValue(state, 2);
  10376. lua_interface->ResetFunctionStack(state);
  10377. if(!spawn->IsPlayer())
  10378. {
  10379. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10380. lua_interface->SetSInt32Value(state, -1);
  10381. return 1;
  10382. }
  10383. Player* player = (Player*)spawn;
  10384. // check if player already has the title, don't need to add twice
  10385. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10386. if ( playerHasTitle)
  10387. {
  10388. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10389. return 1;
  10390. }
  10391. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10392. if(!title)
  10393. {
  10394. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10395. lua_interface->SetSInt32Value(state, -1);
  10396. return 1;
  10397. }
  10398. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10399. if(returnIdx < 0)
  10400. {
  10401. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10402. }
  10403. lua_interface->SetSInt32Value(state, returnIdx);
  10404. player->GetClient()->SendTitleUpdate();
  10405. return 1;
  10406. }
  10407. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10408. if (!lua_interface)
  10409. return 0;
  10410. Spawn* spawn = lua_interface->GetSpawn(state);
  10411. string titleName = lua_interface->GetStringValue(state, 2);
  10412. lua_interface->ResetFunctionStack(state);
  10413. if(!spawn->IsPlayer())
  10414. {
  10415. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10416. return 0;
  10417. }
  10418. Player* player = (Player*)spawn;
  10419. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10420. if(!title)
  10421. {
  10422. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10423. return 0;
  10424. }
  10425. if(title->GetPrefix())
  10426. {
  10427. 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());
  10428. return 0;
  10429. }
  10430. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10431. player->GetClient()->SendTitleUpdate();
  10432. return 1;
  10433. }
  10434. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10435. if (!lua_interface)
  10436. return 0;
  10437. Spawn* spawn = lua_interface->GetSpawn(state);
  10438. string titleName = lua_interface->GetStringValue(state, 2);
  10439. lua_interface->ResetFunctionStack(state);
  10440. if(!spawn->IsPlayer())
  10441. {
  10442. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10443. return 0;
  10444. }
  10445. Player* player = (Player*)spawn;
  10446. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10447. if(!title)
  10448. {
  10449. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10450. return 0;
  10451. }
  10452. if(!title->GetPrefix())
  10453. {
  10454. 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());
  10455. return 0;
  10456. }
  10457. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10458. player->GetClient()->SendTitleUpdate();
  10459. return 1;
  10460. }
  10461. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10462. if (!lua_interface)
  10463. return 0;
  10464. Spawn* spawn = lua_interface->GetSpawn(state);
  10465. lua_interface->ResetFunctionStack(state);
  10466. if(!spawn->IsPlayer())
  10467. {
  10468. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10469. return 0;
  10470. }
  10471. Player* player = (Player*)spawn;
  10472. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10473. player->GetClient()->SendTitleUpdate();
  10474. return 1;
  10475. }
  10476. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10477. if (!lua_interface)
  10478. return 0;
  10479. Spawn* spawn = lua_interface->GetSpawn(state);
  10480. lua_interface->ResetFunctionStack(state);
  10481. if(!spawn->IsPlayer())
  10482. {
  10483. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10484. return 0;
  10485. }
  10486. Player* player = (Player*)spawn;
  10487. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10488. player->GetClient()->SendTitleUpdate();
  10489. return 1;
  10490. }
  10491. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10492. if (!lua_interface)
  10493. return 0;
  10494. Spawn* spawn = lua_interface->GetSpawn(state);
  10495. string field = lua_interface->GetStringValue(state, 2);
  10496. lua_interface->ResetFunctionStack(state);
  10497. if(!spawn || !spawn->IsEntity())
  10498. {
  10499. 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));
  10500. return 0;
  10501. }
  10502. Entity* ent = (Entity*)spawn;
  10503. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10504. return 1;
  10505. }
  10506. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10507. if (!lua_interface)
  10508. return 0;
  10509. Spawn* spawn = lua_interface->GetSpawn(state);
  10510. string field = lua_interface->GetStringValue(state, 2);
  10511. lua_interface->ResetFunctionStack(state);
  10512. if(!spawn || !spawn->IsEntity())
  10513. {
  10514. 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));
  10515. return 0;
  10516. }
  10517. Entity* ent = (Entity*)spawn;
  10518. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10519. return 1;
  10520. }
  10521. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10522. if (!lua_interface)
  10523. return 0;
  10524. Spawn* spawn = lua_interface->GetSpawn(state);
  10525. string field = lua_interface->GetStringValue(state, 2);
  10526. lua_interface->ResetFunctionStack(state);
  10527. if(!spawn || !spawn->IsEntity())
  10528. {
  10529. 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));
  10530. return 0;
  10531. }
  10532. Entity* ent = (Entity*)spawn;
  10533. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10534. return 1;
  10535. }
  10536. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10537. if (!lua_interface)
  10538. return 0;
  10539. Spawn* spawn = lua_interface->GetSpawn(state);
  10540. string field = lua_interface->GetStringValue(state, 2);
  10541. lua_interface->ResetFunctionStack(state);
  10542. if(!spawn || !spawn->IsEntity())
  10543. {
  10544. 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));
  10545. return 0;
  10546. }
  10547. Entity* ent = (Entity*)spawn;
  10548. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10549. return 1;
  10550. }
  10551. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10552. if (!lua_interface)
  10553. return 0;
  10554. Spawn* spawn = lua_interface->GetSpawn(state);
  10555. string field = lua_interface->GetStringValue(state, 2);
  10556. string value = lua_interface->GetStringValue(state, 3);
  10557. lua_interface->ResetFunctionStack(state);
  10558. if(!spawn || !spawn->IsEntity())
  10559. {
  10560. 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));
  10561. return 0;
  10562. }
  10563. Entity* ent = (Entity*)spawn;
  10564. bool set_ = ent->SetInfoStructString(field, value);
  10565. lua_interface->SetBooleanValue(state, set_);
  10566. return 1;
  10567. }
  10568. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10569. if (!lua_interface)
  10570. return 0;
  10571. Spawn* spawn = lua_interface->GetSpawn(state);
  10572. string field = lua_interface->GetStringValue(state, 2);
  10573. int64 value = lua_interface->GetInt64Value(state, 3);
  10574. lua_interface->ResetFunctionStack(state);
  10575. if(!spawn || !spawn->IsEntity())
  10576. {
  10577. 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));
  10578. return 0;
  10579. }
  10580. Entity* ent = (Entity*)spawn;
  10581. bool set_ = ent->SetInfoStructUInt(field, value);
  10582. lua_interface->SetBooleanValue(state, set_);
  10583. return 1;
  10584. }
  10585. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10586. if (!lua_interface)
  10587. return 0;
  10588. Spawn* spawn = lua_interface->GetSpawn(state);
  10589. string field = lua_interface->GetStringValue(state, 2);
  10590. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10591. lua_interface->ResetFunctionStack(state);
  10592. if(!spawn || !spawn->IsEntity())
  10593. {
  10594. 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));
  10595. return 0;
  10596. }
  10597. Entity* ent = (Entity*)spawn;
  10598. bool set_ = ent->SetInfoStructSInt(field, value);
  10599. lua_interface->SetBooleanValue(state, set_);
  10600. return 1;
  10601. }
  10602. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10603. if (!lua_interface)
  10604. return 0;
  10605. Spawn* spawn = lua_interface->GetSpawn(state);
  10606. string field = lua_interface->GetStringValue(state, 2);
  10607. float value = lua_interface->GetFloatValue(state, 3);
  10608. lua_interface->ResetFunctionStack(state);
  10609. if(!spawn || !spawn->IsEntity())
  10610. {
  10611. 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));
  10612. return 0;
  10613. }
  10614. Entity* ent = (Entity*)spawn;
  10615. bool set_ = ent->SetInfoStructFloat(field, value);
  10616. lua_interface->SetBooleanValue(state, set_);
  10617. return 1;
  10618. }
  10619. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10620. if (!lua_interface)
  10621. return 0;
  10622. Spawn* spawn = lua_interface->GetSpawn(state);
  10623. bool value = lua_interface->GetBooleanValue(state, 2);
  10624. lua_interface->ResetFunctionStack(state);
  10625. if(!spawn || !spawn->IsPlayer())
  10626. {
  10627. 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));
  10628. return 0;
  10629. }
  10630. ((Player*)spawn)->SetCharSheetChanged(value);
  10631. return 0;
  10632. }
  10633. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10634. if (!lua_interface)
  10635. return 0;
  10636. Spawn* spawn = lua_interface->GetSpawn(state);
  10637. std::string fromName = lua_interface->GetStringValue(state, 2);
  10638. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10639. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10640. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10641. int32 copper = lua_interface->GetInt32Value(state, 6);
  10642. int32 silver = lua_interface->GetInt32Value(state, 7);
  10643. int32 gold = lua_interface->GetInt32Value(state, 8);
  10644. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10645. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10646. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10647. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10648. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10649. lua_interface->ResetFunctionStack(state);
  10650. if(!spawn || !spawn->IsPlayer())
  10651. {
  10652. 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));
  10653. lua_interface->SetBooleanValue(state, false);
  10654. return 1;
  10655. }
  10656. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10657. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10658. lua_interface->SetBooleanValue(state, true);
  10659. return 1;
  10660. }
  10661. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10662. if (!lua_interface)
  10663. return 0;
  10664. int32 char_id = lua_interface->GetInt32Value(state);
  10665. std::string fromName = lua_interface->GetStringValue(state, 2);
  10666. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10667. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10668. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10669. int32 copper = lua_interface->GetInt32Value(state, 6);
  10670. int32 silver = lua_interface->GetInt32Value(state, 7);
  10671. int32 gold = lua_interface->GetInt32Value(state, 8);
  10672. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10673. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10674. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10675. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10676. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10677. lua_interface->ResetFunctionStack(state);
  10678. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10679. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10680. lua_interface->SetBooleanValue(state, true);
  10681. return 1;
  10682. }
  10683. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10684. Spawn* widget;
  10685. if (lua_interface) {
  10686. widget = lua_interface->GetSpawn(state);
  10687. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10688. lua_interface->ResetFunctionStack(state);
  10689. if (widget && widget->IsWidget())
  10690. {
  10691. ((Widget*)widget)->OpenDoor();
  10692. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10693. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10694. }
  10695. else
  10696. 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));
  10697. }
  10698. return 0;
  10699. }
  10700. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10701. Spawn* widget;
  10702. if (lua_interface) {
  10703. widget = lua_interface->GetSpawn(state);
  10704. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10705. lua_interface->ResetFunctionStack(state);
  10706. if (widget && widget->IsWidget())
  10707. {
  10708. ((Widget*)widget)->CloseDoor();
  10709. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10710. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10711. }
  10712. else
  10713. 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));
  10714. }
  10715. return 0;
  10716. }
  10717. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10718. if (!lua_interface)
  10719. return 0;
  10720. Spawn* widget = lua_interface->GetSpawn(state);
  10721. lua_interface->ResetFunctionStack(state);
  10722. if (widget && widget->IsWidget())
  10723. {
  10724. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10725. return 1;
  10726. }
  10727. return 0;
  10728. }
  10729. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10730. if (!lua_interface)
  10731. return 0;
  10732. sint32 min = lua_interface->GetSInt32Value(state);
  10733. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10734. lua_interface->ResetFunctionStack(state);
  10735. sint32 result = MakeRandomInt(min, max);
  10736. lua_interface->SetSInt32Value(state, result);
  10737. return 1;
  10738. }
  10739. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10740. if (!lua_interface)
  10741. return 0;
  10742. float min = lua_interface->GetFloatValue(state);
  10743. float max = lua_interface->GetFloatValue(state, 2);
  10744. lua_interface->ResetFunctionStack(state);
  10745. float result = MakeRandomFloat(min, max);
  10746. lua_interface->SetFloatValue(state, result);
  10747. return 1;
  10748. }
  10749. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10750. if (!lua_interface)
  10751. return 0;
  10752. Spawn* spawn = lua_interface->GetSpawn(state);
  10753. int32 value = lua_interface->GetInt32Value(state, 2);
  10754. lua_interface->ResetFunctionStack(state);
  10755. if(!spawn)
  10756. {
  10757. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10758. lua_interface->SetBooleanValue(state, false);
  10759. return 1;
  10760. }
  10761. spawn->AddIconValue(value);
  10762. lua_interface->SetBooleanValue(state, true);
  10763. return 1;
  10764. }
  10765. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10766. if (!lua_interface)
  10767. return 0;
  10768. Spawn* spawn = lua_interface->GetSpawn(state);
  10769. int32 value = lua_interface->GetInt32Value(state, 2);
  10770. lua_interface->ResetFunctionStack(state);
  10771. if(!spawn)
  10772. {
  10773. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10774. lua_interface->SetBooleanValue(state, false);
  10775. return 1;
  10776. }
  10777. spawn->RemoveIconValue(value);
  10778. lua_interface->SetBooleanValue(state, true);
  10779. return 1;
  10780. }
  10781. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10782. Spawn* npc = lua_interface->GetSpawn(state);
  10783. lua_interface->ResetFunctionStack(state);
  10784. if (npc && npc->IsNPC()) {
  10785. NPC* shard = (NPC*)npc;
  10786. int32 shardid = shard->GetShardID();
  10787. lua_interface->SetInt32Value(state, shardid);
  10788. return 1;
  10789. }
  10790. lua_interface->SetInt32Value(state, 0);
  10791. return 1;
  10792. }
  10793. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10794. Spawn* npc = lua_interface->GetSpawn(state);
  10795. lua_interface->ResetFunctionStack(state);
  10796. if (npc && npc->IsNPC()) {
  10797. NPC* shard = (NPC*)npc;
  10798. int32 charid = shard->GetShardCharID();
  10799. lua_interface->SetInt32Value(state, charid);
  10800. return 1;
  10801. }
  10802. lua_interface->SetInt32Value(state, 0);
  10803. return 1;
  10804. }
  10805. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10806. Spawn* npc = lua_interface->GetSpawn(state);
  10807. lua_interface->ResetFunctionStack(state);
  10808. if (npc && npc->IsNPC()) {
  10809. NPC* shard = (NPC*)npc;
  10810. int64 timestamp = shard->GetShardCreatedTimestamp();
  10811. lua_interface->SetSInt64Value(state, timestamp);
  10812. return 1;
  10813. }
  10814. lua_interface->SetSInt64Value(state, 0);
  10815. return 1;
  10816. }
  10817. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10818. if (!lua_interface)
  10819. return 0;
  10820. int32 shardid = lua_interface->GetInt32Value(state);
  10821. lua_interface->ResetFunctionStack(state);
  10822. if(shardid < 1)
  10823. lua_interface->SetBooleanValue(state, false);
  10824. else
  10825. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10826. return 1;
  10827. }
  10828. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10829. if (!lua_interface)
  10830. return 0;
  10831. Spawn* spawn = lua_interface->GetSpawn(state);
  10832. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10833. if (spawn) {
  10834. spawn->PauseMovement(delay_in_ms);
  10835. }
  10836. lua_interface->ResetFunctionStack(state);
  10837. return 0;
  10838. }
  10839. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10840. if (!lua_interface)
  10841. return 0;
  10842. Spawn* spawn = lua_interface->GetSpawn(state);
  10843. if (spawn) {
  10844. spawn->StopMovement();
  10845. }
  10846. lua_interface->ResetFunctionStack(state);
  10847. return 0;
  10848. }
  10849. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10850. Player* player = (Player*)lua_interface->GetSpawn(state);
  10851. int8 level = lua_interface->GetInt8Value(state, 2);
  10852. lua_interface->ResetFunctionStack(state);
  10853. if (player && player->IsPlayer() && level > 0) {
  10854. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10855. return 1;
  10856. }
  10857. return 0;
  10858. }
  10859. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10860. Player* player = (Player*)lua_interface->GetSpawn(state);
  10861. int8 level = lua_interface->GetInt8Value(state, 2);
  10862. lua_interface->ResetFunctionStack(state);
  10863. if (player && player->IsPlayer() && level > 0) {
  10864. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10865. return 1;
  10866. }
  10867. return 0;
  10868. }
  10869. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10870. ZoneServer* zone = lua_interface->GetZone(state);
  10871. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10872. lua_interface->ResetFunctionStack(state);
  10873. if (zone) {
  10874. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10875. if (spawn) {
  10876. lua_interface->SetSpawnValue(state, spawn);
  10877. return 1;
  10878. }
  10879. }
  10880. return 0;
  10881. }
  10882. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10883. if (!lua_interface)
  10884. return 0;
  10885. Spawn* spawn = lua_interface->GetSpawn(state);
  10886. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10887. lua_interface->ResetFunctionStack(state);
  10888. bool res = false;
  10889. if(spawn && spawn->IsTransportSpawn())
  10890. {
  10891. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10892. spawn->SetRailID(rail_id);
  10893. res = true;
  10894. }
  10895. else if (!spawn) {
  10896. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10897. }
  10898. else if(!spawn->IsTransportSpawn()) {
  10899. 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());
  10900. }
  10901. lua_interface->SetBooleanValue(state, res);
  10902. return 1;
  10903. }
  10904. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10905. if (!lua_interface)
  10906. return 0;
  10907. ZoneServer* zone = lua_interface->GetZone(state);
  10908. lua_interface->ResetFunctionStack(state);
  10909. if (zone) {
  10910. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10911. return 1;
  10912. }
  10913. return 0;
  10914. }
  10915. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10916. if (!lua_interface)
  10917. return 0;
  10918. Spawn* spawn = lua_interface->GetSpawn(state);
  10919. lua_interface->ResetFunctionStack(state);
  10920. if (spawn) {
  10921. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10922. return 1;
  10923. }
  10924. return 0;
  10925. }
  10926. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  10927. if (!lua_interface)
  10928. return 0;
  10929. Spawn* player = lua_interface->GetSpawn(state);
  10930. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  10931. bool displayClient = lua_interface->GetInt32Value(state, 3);
  10932. lua_interface->ResetFunctionStack(state);
  10933. if (!player || !player->IsPlayer() || !player->GetClient()) {
  10934. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  10935. }
  10936. else if(!zoneID) {
  10937. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  10938. }
  10939. else
  10940. {
  10941. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  10942. return 1;
  10943. }
  10944. return 0;
  10945. }
  10946. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  10947. if (!lua_interface)
  10948. return 0;
  10949. int16 newYear = lua_interface->GetInt16Value(state, 1);
  10950. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  10951. int16 newHour = lua_interface->GetInt16Value(state, 3);
  10952. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  10953. lua_interface->ResetFunctionStack(state);
  10954. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  10955. world.GetWorldTimeStruct()->year = newYear;
  10956. world.GetWorldTimeStruct()->month = newMonth;
  10957. world.GetWorldTimeStruct()->hour = newHour;
  10958. world.GetWorldTimeStruct()->minute = newMinute;
  10959. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  10960. return 0;
  10961. }
  10962. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  10963. if (!lua_interface)
  10964. return 0;
  10965. lua_interface->ResetFunctionStack(state);
  10966. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10967. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  10968. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10969. return 1;
  10970. }
  10971. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  10972. if (!lua_interface)
  10973. return 0;
  10974. lua_interface->ResetFunctionStack(state);
  10975. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10976. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  10977. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10978. return 1;
  10979. }
  10980. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  10981. if (!lua_interface)
  10982. return 0;
  10983. lua_interface->ResetFunctionStack(state);
  10984. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10985. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  10986. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10987. return 1;
  10988. }
  10989. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  10990. if (!lua_interface)
  10991. return 0;
  10992. lua_interface->ResetFunctionStack(state);
  10993. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10994. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  10995. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10996. return 1;
  10997. }
  10998. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  10999. if (!lua_interface)
  11000. return 0;
  11001. lua_interface->ResetFunctionStack(state);
  11002. world.SendTimeUpdate();
  11003. return 0;
  11004. }