LuaFunctions.cpp 338 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046
  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 "../common/Log.h"
  29. #include <math.h>
  30. #include "HeroicOp/HeroicOp.h"
  31. #include "RaceTypes/RaceTypes.h"
  32. #include "ClientPacketFunctions.h"
  33. #include "Transmute.h"
  34. #include <boost/algorithm/string/predicate.hpp>
  35. #include <sstream>
  36. #include <boost/algorithm/string.hpp>
  37. extern MasterFactionList master_faction_list;
  38. extern WorldDatabase database;
  39. extern LuaInterface* lua_interface;
  40. extern ConfigReader configReader;
  41. extern MasterQuestList master_quest_list;
  42. extern MasterItemList master_item_list;
  43. extern MasterSpellList master_spell_list;
  44. extern World world;
  45. extern Commands commands;
  46. extern ZoneList zone_list;
  47. extern Races races;
  48. extern Classes classes;
  49. extern Variables variables;
  50. extern MasterSkillList master_skill_list;
  51. extern MasterHeroicOPList master_ho_list;
  52. extern MasterRaceTypeList race_types_list;
  53. extern MasterLanguagesList master_languages_list;
  54. vector<string> ParseString(string strVal, char delim) {
  55. stringstream ss(strVal);
  56. vector<string> ret;
  57. while (ss.good())
  58. {
  59. string substr;
  60. getline(ss, substr, delim);
  61. ret.push_back(substr);
  62. }
  63. return ret;
  64. }
  65. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  66. stringstream ss(strVal);
  67. vector<unsigned int> ret;
  68. while (ss.good())
  69. {
  70. string substr;
  71. getline(ss, substr, delim);
  72. stringstream valss(substr);
  73. unsigned int val = 0;
  74. valss >> val;
  75. ret.push_back(val);
  76. }
  77. return ret;
  78. }
  79. map<string, signed int> ParseStringMap(string strVal, char delim) {
  80. vector<string> pairs = ParseString(strVal, delim);
  81. vector<string>::iterator itr;
  82. map<string, signed int> ret;
  83. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  84. vector<string> keyvaluepair = ParseString(*itr, ':');
  85. if (keyvaluepair.size() == 2) {
  86. stringstream valss(keyvaluepair[1]);
  87. int32 val = 0;
  88. valss >> val;
  89. ret[keyvaluepair[0]] = val;
  90. }
  91. }
  92. return ret;
  93. }
  94. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  95. vector<string> pairs = ParseString(strVal, delim);
  96. vector<string>::iterator itr;
  97. map<unsigned int, unsigned short> ret;
  98. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  99. vector<string> keyvaluepair = ParseString(*itr, ':');
  100. int32 key = 0;
  101. if (keyvaluepair.size() > 0) {
  102. stringstream keyss(keyvaluepair[0]);
  103. keyss >> key;
  104. }
  105. if (keyvaluepair.size() == 1) {
  106. ret[key] = 1;
  107. }
  108. else if (keyvaluepair.size() == 2) {
  109. stringstream valss(keyvaluepair[1]);
  110. unsigned short val = 0;
  111. valss >> val;
  112. ret[key] = val;
  113. }
  114. }
  115. return ret;
  116. }
  117. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  118. vector<string> pairs = ParseString(strVal, delim);
  119. vector<string>::iterator itr;
  120. map<unsigned int, signed int> ret;
  121. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  122. vector<string> keyvaluepair = ParseString(*itr, ':');
  123. int32 key = 0;
  124. if (keyvaluepair.size() > 0) {
  125. stringstream keyss(keyvaluepair[0]);
  126. keyss >> key;
  127. }
  128. if (keyvaluepair.size() == 1) {
  129. ret[key] = 1;
  130. }
  131. else if (keyvaluepair.size() == 2) {
  132. stringstream valss(keyvaluepair[1]);
  133. signed int val = 0;
  134. valss >> val;
  135. ret[key] = val;
  136. }
  137. }
  138. return ret;
  139. }
  140. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  141. if (!lua_interface)
  142. return 0;
  143. Spawn* spawn = lua_interface->GetSpawn(state);
  144. string mp3_string = lua_interface->GetStringValue(state, 2);
  145. string text_string = lua_interface->GetStringValue(state, 3);
  146. string emote_string = lua_interface->GetStringValue(state, 4);
  147. int32 key1 = lua_interface->GetInt32Value(state, 5);
  148. int32 key2 = lua_interface->GetInt32Value(state, 6);
  149. Spawn* player = lua_interface->GetSpawn(state, 7);
  150. int8 language = lua_interface->GetInt8Value(state, 8);
  151. if (spawn) {
  152. const char* mp3 = 0;
  153. const char* text = 0;
  154. const char* emote = 0;
  155. if (mp3_string.length() > 0)
  156. mp3 = mp3_string.c_str();
  157. if (text_string.length() > 0)
  158. text = text_string.c_str();
  159. if (emote_string.length() > 0)
  160. emote = emote_string.c_str();
  161. Client* client = 0;
  162. if (player && player->IsPlayer())
  163. client = spawn->GetZone()->GetClientBySpawn(player);
  164. if (client) {
  165. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  166. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  167. }
  168. else
  169. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  170. }
  171. return 0;
  172. }
  173. int EQ2Emu_lua_PlaySound(lua_State* state) {
  174. if (!lua_interface)
  175. return 0;
  176. Spawn* spawn = lua_interface->GetSpawn(state);
  177. string sound_string = lua_interface->GetStringValue(state, 2);
  178. float x = lua_interface->GetFloatValue(state, 3);
  179. float y = lua_interface->GetFloatValue(state, 4);
  180. float z = lua_interface->GetFloatValue(state, 5);
  181. Spawn* player = lua_interface->GetSpawn(state, 6);
  182. if (spawn && sound_string.length() > 0) {
  183. Client* client = 0;
  184. if (player && player->IsPlayer())
  185. client = spawn->GetZone()->GetClientBySpawn(player);
  186. if (client)
  187. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  188. else
  189. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  190. }
  191. return 0;
  192. }
  193. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  194. if (!lua_interface)
  195. return 0;
  196. Spawn* spawn = lua_interface->GetSpawn(state);
  197. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  198. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  199. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  200. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  201. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  202. if (!spawn) {
  203. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  204. return 0;
  205. }
  206. if (quest_id > 0) {
  207. //Add this quest to the list of required quests for this spawn
  208. spawn->SetQuestsRequired(quest_id, quest_step);
  209. //If private spawn value set
  210. if (private_spawn) {
  211. //Set the spawn to be private when not granted access through this quest
  212. spawn->AddAllowAccessSpawn(spawn);
  213. spawn->SetPrivateQuestSpawn(true);
  214. }
  215. //This value allows access after a quest step, or the whole quest has been completed
  216. if (continued_access)
  217. spawn->SetQuestsRequiredContinuedAccess(true);
  218. //This value will override vis_flags in the vis packet
  219. if (flag_override > 0)
  220. spawn->SetQuestsRequiredOverride(flag_override);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. float max_distance = lua_interface->GetFloatValue(state, 2);
  229. string variable = lua_interface->GetStringValue(state, 3);
  230. string value = lua_interface->GetStringValue(state, 4);
  231. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  232. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  233. return 0;
  234. }
  235. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  236. if (!lua_interface)
  237. return 0;
  238. Client* client = 0;
  239. Spawn* player = lua_interface->GetSpawn(state);
  240. if (!player) {
  241. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  242. return 0;
  243. }
  244. if (!player->IsPlayer()) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  246. return 0;
  247. }
  248. if (player->GetZone())
  249. client = player->GetZone()->GetClientBySpawn(player);
  250. if (!client) {
  251. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  252. return 0;
  253. }
  254. float intensity = lua_interface->GetFloatValue(state, 2);
  255. int8 direction = lua_interface->GetInt8Value(state, 3);
  256. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  257. if (packet) {
  258. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  259. v1 = *(float *)(a1 + 4);
  260. if ( v1 > 0.0 )
  261. v2 = fminf(v1, 1.0);
  262. else
  263. v2 = 0.1;
  264. */
  265. packet->setDataByName("intensity", intensity);
  266. if ( client->GetVersion() > 546 )
  267. packet->setDataByName("direction", direction);
  268. client->QueuePacket(packet->serialize());
  269. safe_delete(packet);
  270. }
  271. return 0;
  272. }
  273. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  274. if (!lua_interface)
  275. return 0;
  276. Spawn* dead = lua_interface->GetSpawn(state);
  277. Spawn* killer = lua_interface->GetSpawn(state, 2);
  278. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  279. if (dead && dead->Alive() && dead->GetZone())
  280. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  281. return 0;
  282. }
  283. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  284. if (!lua_interface)
  285. return 0;
  286. Spawn* spawn = lua_interface->GetSpawn(state);
  287. float max_distance = lua_interface->GetFloatValue(state, 2);
  288. bool include_players = lua_interface->GetInt8Value(state, 3);
  289. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  290. if (max_distance > 0 && spawn && spawn->GetZone())
  291. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  292. return 0;
  293. }
  294. int EQ2Emu_lua_Despawn(lua_State* state) {
  295. if (!lua_interface)
  296. return 0;
  297. Spawn* spawn = lua_interface->GetSpawn(state);
  298. int32 delay = lua_interface->GetInt32Value(state, 2);
  299. if (spawn && spawn->GetZone())
  300. spawn->GetZone()->Despawn(spawn, delay);
  301. return 0;
  302. }
  303. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  304. if (!lua_interface)
  305. return 0;
  306. Spawn* spawn = lua_interface->GetSpawn(state);
  307. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  308. if (spawn) {
  309. spawn->info_changed = true;
  310. spawn->SetShowHandIcon(displayHandIcon);
  311. }
  312. return 0;
  313. }
  314. //this function is used to force an update packet to be sent.
  315. //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
  316. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  317. if (!lua_interface)
  318. return 0;
  319. Spawn* spawn = lua_interface->GetSpawn(state);
  320. if (spawn) {
  321. spawn->vis_changed = true;
  322. }
  323. return 0;
  324. }
  325. //this function is used to force an update packet to be sent.
  326. //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
  327. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  328. if (!lua_interface)
  329. return 0;
  330. Spawn* spawn = lua_interface->GetSpawn(state);
  331. if (spawn) {
  332. spawn->info_changed = true;
  333. }
  334. return 0;
  335. }
  336. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  337. if (!lua_interface)
  338. return 0;
  339. Spawn* spawn = lua_interface->GetSpawn(state);
  340. int32 new_state = lua_interface->GetInt32Value(state, 2);
  341. if (spawn) {
  342. spawn->GetZone()->SendStateCommand(spawn, new_state);
  343. }
  344. return 0;
  345. }
  346. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  347. if (!lua_interface)
  348. return 0;
  349. Spawn* spawn = lua_interface->GetSpawn(state);
  350. string variable = lua_interface->GetStringValue(state, 2);
  351. string value = lua_interface->GetStringValue(state, 3);
  352. 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.
  353. bool temporary_flag = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  354. int32 type = commands.GetSpawnSetType(variable);
  355. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  356. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  357. return 0;
  358. }
  359. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  360. if (!lua_interface)
  361. return 0;
  362. Spawn* spawn = lua_interface->GetSpawn(state);
  363. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  364. if (spawn && spawn_id > 0) {
  365. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  366. if (closest_spawn) {
  367. lua_interface->SetSpawnValue(state, closest_spawn);
  368. return 1;
  369. }
  370. }
  371. return 0;
  372. }
  373. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  374. if (!lua_interface)
  375. return 0;
  376. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  377. int32 position = lua_interface->GetInt32Value(state, 2);
  378. if (spawnList) {
  379. if (spawnList->size() > position) {
  380. lua_interface->SetSpawnValue(state, spawnList->at(position));
  381. return 1;
  382. }
  383. else {
  384. return 0;
  385. }
  386. return spawnList->size();
  387. }
  388. return 0;
  389. }
  390. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  391. if (!lua_interface)
  392. return 0;
  393. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  394. if (spawnList) {
  395. return spawnList->size();
  396. }
  397. return 0;
  398. }
  399. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  400. if (!lua_interface)
  401. return 0;
  402. vector<Spawn*>* spawnList = new vector<Spawn*>();
  403. lua_interface->SetSpawnListValue(state, spawnList);
  404. return 1;
  405. }
  406. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  407. if (!lua_interface)
  408. return 0;
  409. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  410. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  411. if (spawnList) {
  412. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  413. if (it == spawnList->end())
  414. spawnList->push_back(spawn);
  415. }
  416. return 0;
  417. }
  418. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  419. if (!lua_interface)
  420. return 0;
  421. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  422. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  423. if (spawnList) {
  424. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  425. if(it != spawnList->end())
  426. spawnList->erase(it);
  427. }
  428. return 0;
  429. }
  430. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  431. if (!lua_interface)
  432. return 0;
  433. Spawn* spawn = lua_interface->GetSpawn(state);
  434. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  435. if (spawn) {
  436. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  437. if (spawns.size() > 0) {
  438. vector<Spawn*>* spawnList = new vector<Spawn*>();
  439. vector<Spawn*>::iterator itr;
  440. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  441. spawnList->push_back(*itr);
  442. }
  443. lua_interface->SetSpawnListValue(state, spawnList);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. string variable_name = lua_interface->GetStringValue(state);
  453. Variable* var = variables.FindVariable(variable_name);
  454. if (var) {
  455. lua_interface->SetStringValue(state, var->GetValue());
  456. return 1;
  457. }
  458. return 0;
  459. }
  460. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  461. if (!lua_interface)
  462. return 0;
  463. int32 total_coins = lua_interface->GetInt32Value(state);
  464. if (total_coins == 0) {
  465. lua_interface->SetStringValue(state, "0 copper");
  466. return 1;
  467. }
  468. char tmp[64] = { 0 };
  469. string message = "";
  470. int32 val = 0;
  471. if (total_coins >= 1000000) {
  472. val = total_coins / 1000000;
  473. total_coins -= 1000000 * val;
  474. sprintf(tmp, " %u Platinum", val);
  475. message.append(tmp);
  476. memset(tmp, 0, 64);
  477. }
  478. if (total_coins >= 10000) {
  479. val = total_coins / 10000;
  480. total_coins -= 10000 * val;
  481. sprintf(tmp, " %u Gold", val);
  482. message.append(tmp);
  483. memset(tmp, 0, 64);
  484. }
  485. if (total_coins >= 100) {
  486. val = total_coins / 100;
  487. total_coins -= 100 * val;
  488. sprintf(tmp, " %u Silver", val);
  489. message.append(tmp);
  490. memset(tmp, 0, 64);
  491. }
  492. if (total_coins > 0) {
  493. sprintf(tmp, " %u Copper", (int32)total_coins);
  494. message.append(tmp);
  495. }
  496. lua_interface->SetStringValue(state, message.c_str());
  497. return 1;
  498. }
  499. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  500. ZoneServer* zone = lua_interface->GetZone(state);
  501. int32 group_id = lua_interface->GetInt32Value(state, 2);
  502. if (zone) {
  503. Spawn* spawn = zone->GetSpawnGroup(group_id);
  504. if (spawn) {
  505. lua_interface->SetSpawnValue(state, spawn);
  506. return 1;
  507. }
  508. }
  509. return 0;
  510. }
  511. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  512. ZoneServer* zone = lua_interface->GetZone(state);
  513. int32 location_id = lua_interface->GetInt32Value(state, 2);
  514. if (zone) {
  515. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  516. if (spawn) {
  517. lua_interface->SetSpawnValue(state, spawn);
  518. return 1;
  519. }
  520. }
  521. return 0;
  522. }
  523. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  524. Spawn* spawn = lua_interface->GetSpawn(state);
  525. if (spawn) {
  526. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  527. return 1;
  528. }
  529. return 0;
  530. }
  531. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  532. Spawn* spawn = lua_interface->GetSpawn(state);
  533. if (spawn) {
  534. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  535. return 1;
  536. }
  537. return 0;
  538. }
  539. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  540. Spawn* spawn = lua_interface->GetSpawn(state);
  541. if (spawn) {
  542. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  543. return 1;
  544. }
  545. return 0;
  546. }
  547. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  548. Spawn* spawn = lua_interface->GetSpawn(state);
  549. if (spawn) {
  550. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  551. return 1;
  552. }
  553. return 0;
  554. }
  555. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  556. Player* player = (Player*)lua_interface->GetSpawn(state);
  557. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  558. if (player && player->IsPlayer() && faction_id > 0) {
  559. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  560. return 1;
  561. }
  562. return 0;
  563. }
  564. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  565. if (!lua_interface)
  566. return 0;
  567. Spawn* spawn = lua_interface->GetSpawn(state);
  568. int32 value = lua_interface->GetInt32Value(state, 2);
  569. if (spawn) {
  570. spawn->SetFactionID(value);
  571. }
  572. return 0;
  573. }
  574. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  575. Spawn* spawn = lua_interface->GetSpawn(state);
  576. if (spawn) {
  577. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  578. return 1;
  579. }
  580. return 0;
  581. }
  582. int EQ2Emu_lua_GetGender(lua_State* state) {
  583. Spawn* spawn = lua_interface->GetSpawn(state);
  584. if (spawn) {
  585. lua_interface->SetInt32Value(state, spawn->GetGender());
  586. return 1;
  587. }
  588. return 0;
  589. }
  590. int EQ2Emu_lua_GetTarget(lua_State* state) {
  591. Spawn* spawn = lua_interface->GetSpawn(state);
  592. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  593. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  594. return 1;
  595. }
  596. return 0;
  597. }
  598. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  599. if (!lua_interface)
  600. return 0;
  601. Spawn* spawn = lua_interface->GetSpawn(state);
  602. string mp3_string = lua_interface->GetStringValue(state, 2);
  603. int32 key1 = lua_interface->GetInt32Value(state, 3);
  604. int32 key2 = lua_interface->GetInt32Value(state, 4);
  605. Spawn* player = lua_interface->GetSpawn(state, 5);
  606. if (spawn && mp3_string.length() > 0) {
  607. Client* client = 0;
  608. if (player && player->IsPlayer())
  609. client = spawn->GetZone()->GetClientBySpawn(player);
  610. if (client) {
  611. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  612. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  613. }
  614. else
  615. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  616. }
  617. return 0;
  618. }
  619. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  620. if (!lua_interface)
  621. return 0;
  622. Spawn* spawn = lua_interface->GetSpawn(state);
  623. if (spawn) {
  624. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  625. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  626. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  627. return 3;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  632. if (!lua_interface)
  633. return 0;
  634. Spawn* spawn = lua_interface->GetSpawn(state);
  635. if (spawn) {
  636. int32 item_id = lua_interface->GetInt32Value(state, 2);
  637. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  638. return 1;
  639. }
  640. return 0;
  641. }
  642. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  643. if (!lua_interface)
  644. return 0;
  645. Spawn* spawn = lua_interface->GetSpawn(state);
  646. if (spawn && spawn->IsEntity()) {
  647. int32 item_id = lua_interface->GetInt32Value(state, 2);
  648. int16 charges = lua_interface->GetInt16Value(state, 3);
  649. if (charges == 0)
  650. charges = 1;
  651. ((Entity*)spawn)->AddLootItem(item_id, charges);
  652. }
  653. return 0;
  654. }
  655. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  656. if (!lua_interface)
  657. return 0;
  658. Spawn* spawn = lua_interface->GetSpawn(state);
  659. if (spawn && spawn->IsEntity()) {
  660. int32 item_id = lua_interface->GetInt32Value(state, 2);
  661. spawn->LootItem(item_id);
  662. }
  663. return 0;
  664. }
  665. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  666. if (!lua_interface)
  667. return 0;
  668. Spawn* spawn = lua_interface->GetSpawn(state);
  669. if (spawn) {
  670. int32 val = lua_interface->GetInt32Value(state, 2);
  671. spawn->AddLootCoins(val);
  672. }
  673. return 0;
  674. }
  675. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  676. if (!lua_interface)
  677. return 0;
  678. Spawn* entity = lua_interface->GetSpawn(state);
  679. Spawn* player = lua_interface->GetSpawn(state, 2);
  680. if (entity && player && player->IsPlayer()) {
  681. int32 coins = lua_interface->GetInt32Value(state, 3);
  682. vector<Item*>* items = 0;
  683. int i = 0;
  684. int32 item_id = 0;
  685. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  686. if (items == 0)
  687. items = new vector<Item*>;
  688. if (master_item_list.GetItem(item_id))
  689. items->push_back(master_item_list.GetItem(item_id));
  690. i++;
  691. }
  692. Client* client = 0;
  693. client = player->GetZone()->GetClientBySpawn(player);
  694. if (client)
  695. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  696. if(coins > 0)
  697. entity->AddLootCoins(coins);
  698. safe_delete(items);
  699. }
  700. return 0;
  701. }
  702. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  703. if (!lua_interface)
  704. return 0;
  705. Spawn* entity = lua_interface->GetSpawn(state);
  706. Spawn* player = lua_interface->GetSpawn(state, 2);
  707. int32 item_id = lua_interface->GetInt32Value(state, 3);
  708. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  709. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  710. return 1;
  711. }
  712. return 0;
  713. }
  714. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  715. if (!lua_interface)
  716. return 0;
  717. Spawn* entity = lua_interface->GetSpawn(state);
  718. Spawn* player = lua_interface->GetSpawn(state, 2);
  719. if (entity && player && player->IsPlayer()) {
  720. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  726. if (!lua_interface)
  727. return 0;
  728. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  729. safe_delete(conversation);
  730. conversation = new vector<ConversationOption>();
  731. lua_interface->SetConversationValue(state, conversation);
  732. return 1;
  733. }
  734. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  738. if (conversation) {
  739. ConversationOption conv_option;
  740. conv_option.option = lua_interface->GetStringValue(state, 2);
  741. conv_option.function = lua_interface->GetStringValue(state, 3);
  742. if (conv_option.option.length() > 0)
  743. conversation->push_back(conv_option);
  744. }
  745. return 0;
  746. }
  747. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  748. if (!lua_interface)
  749. return 0;
  750. Spawn* npc = lua_interface->GetSpawn(state);
  751. Spawn* player = lua_interface->GetSpawn(state, 2);
  752. if (npc && player && player->IsPlayer() && player->GetZone()) {
  753. Client* client = player->GetZone()->GetClientBySpawn(player);
  754. if (client) {
  755. int32 conversation_id = client->GetConversationID(npc, 0);
  756. client->CloseDialog(conversation_id);
  757. }
  758. }
  759. return 0;
  760. }
  761. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  762. if (!lua_interface)
  763. return 0;
  764. Item* item = lua_interface->GetItem(state);
  765. Spawn* player = lua_interface->GetSpawn(state, 2);
  766. if (item && player && player->IsPlayer() && player->GetZone()) {
  767. Client* client = player->GetZone()->GetClientBySpawn(player);
  768. if (client) {
  769. int32 conversation_id = client->GetConversationID(0, item);
  770. client->CloseDialog(conversation_id);
  771. }
  772. }
  773. return 0;
  774. }
  775. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  776. if (!lua_interface)
  777. return 0;
  778. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  779. Spawn* spawn = 0;
  780. Item* item = 0;
  781. int8 type = lua_interface->GetInt8Value(state, 2);
  782. if (type == 1 || type == 3)
  783. spawn = lua_interface->GetSpawn(state, 3);
  784. else if (type == 2 || type == 4)
  785. item = lua_interface->GetItem(state, 3);
  786. Spawn* player = lua_interface->GetSpawn(state, 4);
  787. string text = lua_interface->GetStringValue(state, 5);
  788. string mp3 = lua_interface->GetStringValue(state, 6);
  789. int32 key1 = lua_interface->GetInt32Value(state, 7);
  790. int32 key2 = lua_interface->GetInt32Value(state, 8);
  791. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  792. Client* client = player->GetZone()->GetClientBySpawn(player);
  793. if (client) {
  794. if (spawn) {
  795. // Need to do this so the function works the same as it did before
  796. if (type == 1)
  797. type++;
  798. if (mp3.length() > 0)
  799. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  800. else
  801. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  802. }
  803. else {
  804. if (mp3.length() > 0)
  805. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  806. else
  807. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  808. }
  809. }
  810. }
  811. safe_delete(conversation);
  812. lua_interface->SetConversationValue(state, NULL);
  813. return 0;
  814. }
  815. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  816. if(!lua_interface)
  817. return 0;
  818. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  819. Item* item = lua_interface->GetItem(state, 2);
  820. Spawn* player = lua_interface->GetSpawn(state, 3);
  821. string text = lua_interface->GetStringValue(state, 4);
  822. string mp3 = lua_interface->GetStringValue(state, 5);
  823. int32 key1 = lua_interface->GetInt32Value(state, 6);
  824. int32 key2 = lua_interface->GetInt32Value(state, 7);
  825. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  826. Client* client = player->GetZone()->GetClientBySpawn(player);
  827. if(client){
  828. if(mp3.length() > 0)
  829. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  830. else
  831. client->DisplayConversation(item, conversation, (char*)text.c_str());
  832. }
  833. safe_delete(conversation);
  834. }
  835. return 0;
  836. }*/
  837. int EQ2Emu_lua_StartConversation(lua_State* state) {
  838. if (!lua_interface)
  839. return 0;
  840. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  841. Spawn* npc = lua_interface->GetSpawn(state, 2);
  842. Spawn* player = lua_interface->GetSpawn(state, 3);
  843. string text = lua_interface->GetStringValue(state, 4);
  844. string mp3 = lua_interface->GetStringValue(state, 5);
  845. int32 key1 = lua_interface->GetInt32Value(state, 6);
  846. int32 key2 = lua_interface->GetInt32Value(state, 7);
  847. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  848. Client* client = npc->GetZone()->GetClientBySpawn(player);
  849. if (mp3.length() > 0)
  850. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  851. else
  852. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  853. safe_delete(conversation);
  854. lua_interface->SetConversationValue(state, NULL);
  855. }
  856. else
  857. 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.", npc ? npc->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  858. return 0;
  859. }
  860. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* spawn = lua_interface->GetSpawn(state);
  864. float distance = lua_interface->GetFloatValue(state, 2);
  865. string in_range_function = lua_interface->GetStringValue(state, 3);
  866. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  867. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  868. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  872. ZoneServer* zone = lua_interface->GetZone(state);
  873. float x = lua_interface->GetFloatValue(state, 2);
  874. float y = lua_interface->GetFloatValue(state, 3);
  875. float z = lua_interface->GetFloatValue(state, 4);
  876. float max_variation = lua_interface->GetFloatValue(state, 5);
  877. string in_range_function = lua_interface->GetStringValue(state, 6);
  878. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  879. if (zone && in_range_function.length() > 0)
  880. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  881. return 0;
  882. }
  883. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  884. if (!lua_interface)
  885. return 0;
  886. Spawn* spawn = lua_interface->GetSpawn(state);
  887. if (spawn && spawn->IsEntity()) {
  888. int32 val = lua_interface->GetInt32Value(state, 2);
  889. ((Entity*)spawn)->SetLootCoins(val);
  890. }
  891. return 0;
  892. }
  893. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  894. if (!lua_interface)
  895. return 0;
  896. Spawn* spawn = lua_interface->GetSpawn(state);
  897. if (spawn && spawn->IsEntity()) {
  898. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  899. return 1;
  900. }
  901. return 0;
  902. }
  903. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  904. if (!lua_interface)
  905. return 0;
  906. Spawn* spawn = lua_interface->GetSpawn(state);
  907. float x = lua_interface->GetFloatValue(state, 2);
  908. float y = lua_interface->GetFloatValue(state, 3);
  909. float z = lua_interface->GetFloatValue(state, 4);
  910. float speed = lua_interface->GetFloatValue(state, 5);
  911. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  912. string function = lua_interface->GetStringValue(state, 7);
  913. if (spawn) {
  914. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  915. spawn->GetZone()->AddMovementNPC(spawn);
  916. }
  917. lua_interface->ResetFunctionStack(state);
  918. return 0;
  919. }
  920. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  921. if (!lua_interface)
  922. return 0;
  923. Spawn* spawn = lua_interface->GetSpawn(state);
  924. if (spawn) {
  925. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  926. return 1;
  927. }
  928. return 0;
  929. }
  930. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  931. if (!lua_interface)
  932. return 0;
  933. Spawn* spawn = lua_interface->GetSpawn(state);
  934. Spawn* target = lua_interface->GetSpawn(state, 2);
  935. if (spawn && target) {
  936. if (spawn->IsEntity())
  937. // ((Entity*)spawn)->FaceTarget(target);
  938. static_cast<Entity*>(spawn)->FaceTarget(target);
  939. }
  940. lua_interface->ResetFunctionStack(state);
  941. return 0;
  942. }
  943. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  944. if (!lua_interface)
  945. return 0;
  946. Spawn* spawn = lua_interface->GetSpawn(state);
  947. float x = lua_interface->GetFloatValue(state, 2);
  948. float y = lua_interface->GetFloatValue(state, 3);
  949. float z = lua_interface->GetFloatValue(state, 4);
  950. float speed = lua_interface->GetFloatValue(state, 5);
  951. string lua_function = lua_interface->GetStringValue(state, 6);
  952. bool more_points = lua_interface->GetBooleanValue(state, 7);
  953. if (spawn) {
  954. if (speed == 0)
  955. speed = spawn->GetSpeed();
  956. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  957. }
  958. lua_interface->ResetFunctionStack(state);
  959. return 0;
  960. }
  961. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  962. if (!lua_interface)
  963. return 0;
  964. Spawn* spawn = lua_interface->GetSpawn(state);
  965. if (spawn) {
  966. spawn->ClearRunningLocations();
  967. }
  968. return 0;
  969. }
  970. int EQ2Emu_lua_Say(lua_State* state) {
  971. if (!lua_interface)
  972. return 0;
  973. Spawn* spawn = lua_interface->GetSpawn(state);
  974. string message = lua_interface->GetStringValue(state, 2);
  975. Spawn* player = lua_interface->GetSpawn(state, 3);
  976. int32 language = lua_interface->GetInt32Value(state, 4);
  977. if (spawn && message.length() > 0) {
  978. Client* client = 0;
  979. if (player && player->IsPlayer())
  980. client = spawn->GetZone()->GetClientBySpawn(player);
  981. if (client)
  982. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  983. else
  984. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  985. }
  986. lua_interface->ResetFunctionStack(state);
  987. return 0;
  988. }
  989. int EQ2Emu_lua_Shout(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. Spawn* spawn = lua_interface->GetSpawn(state);
  993. string message = lua_interface->GetStringValue(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. if (spawn && message.length() > 0) {
  996. Client* client = 0;
  997. if (player && player->IsPlayer())
  998. client = spawn->GetZone()->GetClientBySpawn(player);
  999. if (client)
  1000. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1001. else
  1002. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1003. }
  1004. lua_interface->ResetFunctionStack(state);
  1005. return 0;
  1006. }
  1007. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1008. if (!lua_interface)
  1009. return 0;
  1010. Spawn* spawn = lua_interface->GetSpawn(state);
  1011. string message = lua_interface->GetStringValue(state, 2);
  1012. Spawn* player = lua_interface->GetSpawn(state, 3);
  1013. if (spawn && message.length() > 0) {
  1014. Client* client = 0;
  1015. if (player && player->IsPlayer())
  1016. client = spawn->GetZone()->GetClientBySpawn(player);
  1017. if (client)
  1018. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1019. else
  1020. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1021. }
  1022. lua_interface->ResetFunctionStack(state);
  1023. return 0;
  1024. }
  1025. int EQ2Emu_lua_Emote(lua_State* state) {
  1026. if (!lua_interface)
  1027. return 0;
  1028. Spawn* spawn = lua_interface->GetSpawn(state);
  1029. string message = lua_interface->GetStringValue(state, 2);
  1030. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1031. Spawn* player = lua_interface->GetSpawn(state, 4);
  1032. char* to = 0;
  1033. if (spawn2)
  1034. to = spawn2->GetName();
  1035. if (spawn && message.length() > 0) {
  1036. Client* client = 0;
  1037. if (player && player->IsPlayer())
  1038. client = spawn->GetZone()->GetClientBySpawn(player);
  1039. if (client)
  1040. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1041. else
  1042. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1043. }
  1044. lua_interface->ResetFunctionStack(state);
  1045. return 0;
  1046. }
  1047. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1048. if (!lua_interface)
  1049. return 0;
  1050. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1051. if (!luaspell)
  1052. return 0;
  1053. Spawn* caster = luaspell->caster;
  1054. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1055. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1056. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1057. Spawn* target = lua_interface->GetSpawn(state, 4);
  1058. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1059. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1060. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1061. lua_interface->ResetFunctionStack(state);
  1062. if (caster && caster->IsEntity()) {
  1063. bool success = false;
  1064. luaspell->resisted = false;
  1065. if (target) {
  1066. float distance = caster->GetDistance(target, true);
  1067. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1068. success = true;
  1069. }
  1070. if (luaspell->targets.size() > 0) {
  1071. Spawn* target = 0;
  1072. ZoneServer* zone = luaspell->caster->GetZone();
  1073. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1074. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1075. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1076. float distance = caster->GetDistance(target, true);
  1077. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1078. }
  1079. }
  1080. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1081. success = true;
  1082. }
  1083. if (success) {
  1084. if (caster->GetZone())
  1085. caster->GetZone()->TriggerCharSheetTimer();
  1086. }
  1087. }
  1088. return 0;
  1089. }
  1090. int EQ2Emu_lua_AddItem(lua_State* state) {
  1091. if (!lua_interface)
  1092. return 0;
  1093. Spawn* spawn = lua_interface->GetSpawn(state);
  1094. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1095. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1096. // default of 1 quantity to add
  1097. if (quantity == 0)
  1098. quantity = 1;
  1099. if (spawn && spawn->IsPlayer()) {
  1100. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1101. if (client && item_id > 0) {
  1102. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1103. return 1;
  1104. }
  1105. }
  1106. lua_interface->SetBooleanValue(state, false);
  1107. return 1;
  1108. }
  1109. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1110. if (!lua_interface)
  1111. return 0;
  1112. Spawn* spawn = lua_interface->GetSpawn(state);
  1113. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1114. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1115. string location = lua_interface->GetStringValue(state, 4);
  1116. if (spawn && spawn->IsPlayer()) {
  1117. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1118. if (client && item_id > 0) {
  1119. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1120. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1121. else
  1122. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1123. if (send_messages) {
  1124. Item* item = master_item_list.GetItem(item_id);
  1125. if (item) {
  1126. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1127. string popup_text = "You receive " + item->name;
  1128. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1129. }
  1130. }
  1131. return 1;
  1132. }
  1133. }
  1134. lua_interface->SetBooleanValue(state, false);
  1135. return 1;
  1136. }
  1137. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1138. Spawn* spawn = lua_interface->GetSpawn(state);
  1139. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1140. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1141. // default of 1 to remove
  1142. if (quantity == 0)
  1143. quantity = 1;
  1144. Client* client;
  1145. Item* item;
  1146. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1147. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1148. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1149. if (client->RemoveItem(item, quantity)) {
  1150. lua_interface->SetBooleanValue(state, true);
  1151. return 1;
  1152. }
  1153. }
  1154. }
  1155. }
  1156. lua_interface->SetBooleanValue(state, false);
  1157. return 1;
  1158. }
  1159. int EQ2Emu_lua_HasItem(lua_State* state) {
  1160. Spawn* player = lua_interface->GetSpawn(state);
  1161. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1162. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1163. if (player && player->IsPlayer()) {
  1164. bool hasItem = false;
  1165. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1166. if (!hasItem)
  1167. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1168. lua_interface->SetBooleanValue(state, hasItem);
  1169. return 1;
  1170. }
  1171. lua_interface->SetBooleanValue(state, false);
  1172. return 1;
  1173. }
  1174. int EQ2Emu_lua_Spawn(lua_State* state) {
  1175. if (!lua_interface)
  1176. return 0;
  1177. ZoneServer* zone = lua_interface->GetZone(state);
  1178. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1179. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1180. float x = lua_interface->GetFloatValue(state, 4);
  1181. float y = lua_interface->GetFloatValue(state, 5);
  1182. float z = lua_interface->GetFloatValue(state, 6);
  1183. float heading = lua_interface->GetFloatValue(state, 7);
  1184. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1185. Spawn* spawn = zone->GetSpawn(spawn_id);
  1186. if (!spawn)
  1187. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1188. else {
  1189. spawn->SetX(x);
  1190. spawn->SetZ(z);
  1191. spawn->SetY(y,true,true);
  1192. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1193. spawn->SetHeading(heading);
  1194. if (restricted_npc)
  1195. spawn->AddAllowAccessSpawn(spawn);
  1196. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1197. bool scriptActive = false;
  1198. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1199. scriptActive = true;
  1200. spawn->SetSpawnScript(string(spawn_script));
  1201. }
  1202. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1203. zone->AddSpawn(spawn);
  1204. if (scriptActive) {
  1205. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1206. }
  1207. lua_interface->SetSpawnValue(state, spawn);
  1208. return 1;
  1209. }
  1210. }
  1211. else {
  1212. string output = "Invalid paramaters to LUA Spawn command: \n";
  1213. if (!zone)
  1214. output = output.append("\t").append("Missing zone reference. \n");
  1215. if (spawn_id == 0)
  1216. output = output.append("\t").append("Missing spawn_id.");
  1217. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1218. }
  1219. return 0;
  1220. }
  1221. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1222. if (!lua_interface)
  1223. return 0;
  1224. ZoneServer* zone = lua_interface->GetZone(state);
  1225. if (zone) {
  1226. lua_interface->SetStringValue(state, zone->GetZoneName());
  1227. return 1;
  1228. }
  1229. return 0;
  1230. }
  1231. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1232. if (!lua_interface)
  1233. return 0;
  1234. ZoneServer* zone = lua_interface->GetZone(state);
  1235. if (zone) {
  1236. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1237. return 1;
  1238. }
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_GetZone(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. int32 zone_id = lua_interface->GetInt32Value(state);
  1245. ZoneServer* zone = 0;
  1246. if (zone_id > 0)
  1247. zone = zone_list.Get(zone_id);
  1248. else {
  1249. string zone_name = lua_interface->GetStringValue(state);
  1250. if (zone_name.length() > 0) {
  1251. zone = zone_list.Get(zone_name.c_str());
  1252. }
  1253. else {
  1254. Spawn* spawn = lua_interface->GetSpawn(state);
  1255. if (spawn)
  1256. zone = spawn->GetZone();
  1257. }
  1258. }
  1259. if (zone) {
  1260. lua_interface->SetZoneValue(state, zone);
  1261. return 1;
  1262. }
  1263. return 0;
  1264. }
  1265. int EQ2Emu_lua_AddHate(lua_State* state) {
  1266. Spawn* entity = lua_interface->GetSpawn(state);
  1267. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1268. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1269. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1270. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1271. if (entity && entity->IsEntity() && amount != 0) {
  1272. if (luaspell) {
  1273. ZoneServer* zone = luaspell->caster->GetZone();
  1274. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1275. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1276. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1277. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1278. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1279. if (send_packet)
  1280. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1281. }
  1282. }
  1283. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1284. }
  1285. else if (npc && npc->IsNPC() && npc->GetZone())
  1286. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1287. }
  1288. return 0;
  1289. }
  1290. int EQ2Emu_lua_Zone(lua_State* state) {
  1291. if (!lua_interface)
  1292. return 0;
  1293. ZoneServer* zone = lua_interface->GetZone(state);
  1294. Spawn* player = lua_interface->GetSpawn(state, 2);
  1295. Client* client = 0;
  1296. if (player && player->IsPlayer())
  1297. client = player->GetZone()->GetClientBySpawn(player);
  1298. float x = lua_interface->GetFloatValue(state, 3);
  1299. float y = lua_interface->GetFloatValue(state, 4);
  1300. float z = lua_interface->GetFloatValue(state, 5);
  1301. float heading = lua_interface->GetFloatValue(state, 6);
  1302. if (zone && client) {
  1303. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1304. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1305. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1306. {
  1307. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1308. return 0;
  1309. }
  1310. if (x != 0 || y != 0 || z != 0) {
  1311. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1312. player->SetX(x);
  1313. player->SetY(y);
  1314. player->SetZ(z);
  1315. player->SetHeading(heading);
  1316. client->Zone(zone->GetZoneName(), false);
  1317. }
  1318. else
  1319. client->Zone(zone->GetZoneName());
  1320. }
  1321. else
  1322. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1323. return 0;
  1324. }
  1325. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1326. if (!lua_interface)
  1327. return 0;
  1328. Spawn* spawn = lua_interface->GetSpawn(state);
  1329. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1330. if (spawn && spawn2)
  1331. spawn->AddAllowAccessSpawn(spawn2);
  1332. return 0;
  1333. }
  1334. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1335. if (!lua_interface)
  1336. return 0;
  1337. Spawn* target = lua_interface->GetSpawn(state);
  1338. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1339. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1340. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1341. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1342. if (!target) {
  1343. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1344. return 0;
  1345. }
  1346. if (!target->IsEntity()) {
  1347. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1348. return 0;
  1349. }
  1350. if (spell_id <= 0) {
  1351. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1352. return 0;
  1353. }
  1354. if (caster && !caster->IsEntity()) {
  1355. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1356. return 0;
  1357. }
  1358. if (spell_tier == 0)
  1359. spell_tier = 1;
  1360. if (!caster)
  1361. caster = target;
  1362. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1363. return 0;
  1364. }
  1365. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1366. if (!lua_interface)
  1367. return 0;
  1368. Spawn* target = lua_interface->GetSpawn(state);
  1369. int32 target_id = 0;
  1370. if (target)
  1371. target_id = target->GetID();
  1372. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1373. if (!luaspell)
  1374. return 0;
  1375. Spawn* caster = luaspell->caster;
  1376. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1377. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1378. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1379. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1380. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1381. //lua_interface->ResetFunctionStack(state);
  1382. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1383. vector<int16> faction_req;
  1384. vector<int16> race_req;
  1385. int32 class_req = 0;
  1386. int32 i = 0;
  1387. int8 f = 0;
  1388. int8 r = 0;
  1389. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1390. if (class_id < 100) {
  1391. class_req += pow(2.0, double(class_id - 1));
  1392. }
  1393. else if (class_id > 100 && class_id < 1000) {
  1394. race_req.push_back(class_id);
  1395. r++;
  1396. }
  1397. else {
  1398. faction_req.push_back(class_id);
  1399. f++;
  1400. }
  1401. i++;
  1402. }
  1403. if (caster && caster->IsEntity()) {
  1404. bool race_match = false;
  1405. bool success = false;
  1406. luaspell->resisted = false;
  1407. if (luaspell->initial_target == target_id) {
  1408. int xxx = 0;
  1409. }
  1410. if (luaspell->targets.size() > 0) {
  1411. ZoneServer* zone = luaspell->caster->GetZone();
  1412. Spawn* target = 0;
  1413. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1414. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1415. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1416. if (race_req.size() > 0) {
  1417. for (int8 i = 0; i < race_req.size(); i++) {
  1418. int32 xxx = target->GetLuaRaceId();
  1419. if (target->GetLuaRaceId() == race_req[i]) {
  1420. race_match = true;
  1421. }
  1422. }
  1423. }
  1424. else
  1425. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1426. if (race_match == true) {
  1427. float distance = caster->GetDistance(target, true);
  1428. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1429. }
  1430. }
  1431. }
  1432. success = true;
  1433. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1434. }
  1435. else if (target) {
  1436. //check class and race/faction here
  1437. if (race_req.size() > 0) {
  1438. for (int8 i = 0; i < race_req.size(); i++) {
  1439. if (target->GetLuaRaceId() == race_req[i]) {
  1440. race_match = true;
  1441. }
  1442. }
  1443. }
  1444. else
  1445. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1446. if (race_match == true) {
  1447. float distance = caster->GetDistance(target, true);
  1448. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1449. success = true;
  1450. }
  1451. }
  1452. if (success) {
  1453. Spell* spell = luaspell->spell;
  1454. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1455. ((Player*)caster)->InCombat(true);
  1456. if (caster->GetZone())
  1457. caster->GetZone()->TriggerCharSheetTimer();
  1458. }
  1459. }
  1460. }
  1461. return 0;
  1462. }
  1463. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1464. if (!lua_interface)
  1465. return 0;
  1466. Spawn* spawn = lua_interface->GetSpawn(state);
  1467. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1468. lua_interface->ResetFunctionStack(state);
  1469. if (spawn && value != 0) {
  1470. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1471. spawn->SetPower(spawn->GetTotalPower());
  1472. else
  1473. spawn->SetPower(spawn->GetPower() + value);
  1474. }
  1475. return 0;
  1476. }
  1477. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1478. if (!lua_interface)
  1479. return 0;
  1480. Spawn* spawn = lua_interface->GetSpawn(state);
  1481. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1482. lua_interface->ResetFunctionStack(state);
  1483. if (spawn && value != 0) {
  1484. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1485. spawn->SetHP(spawn->GetTotalHP());
  1486. else
  1487. spawn->SetHP(spawn->GetHP() + value);
  1488. }
  1489. return 0;
  1490. }
  1491. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1492. if (!lua_interface)
  1493. return 0;
  1494. Spawn* spawn = lua_interface->GetSpawn(state);
  1495. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1496. lua_interface->ResetFunctionStack(state);
  1497. if (spawn && value != 0) {
  1498. spawn->SetPower(spawn->GetPower() + value);
  1499. if (value > spawn->GetTotalHPBase())
  1500. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1501. }
  1502. return 0;
  1503. }
  1504. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1505. if (!lua_interface)
  1506. return 0;
  1507. Spawn* spawn = lua_interface->GetSpawn(state);
  1508. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1509. lua_interface->ResetFunctionStack(state);
  1510. if (spawn && value != 0) {
  1511. spawn->SetHP(spawn->GetHP() + value);
  1512. if (value > spawn->GetTotalHPBase())
  1513. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1514. }
  1515. return 0;
  1516. }
  1517. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1518. if (!lua_interface)
  1519. return 0;
  1520. Spawn* spawn = lua_interface->GetSpawn(state);
  1521. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1522. lua_interface->ResetFunctionStack(state);
  1523. if (spawn && value > 0) {
  1524. spawn->SetHP(value);
  1525. if (value > spawn->GetTotalHPBase())
  1526. spawn->SetTotalHP(value);
  1527. }
  1528. return 0;
  1529. }
  1530. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1531. if (!lua_interface)
  1532. return 0;
  1533. Spawn* spawn = lua_interface->GetSpawn(state);
  1534. float value = lua_interface->GetFloatValue(state, 2);
  1535. lua_interface->ResetFunctionStack(state);
  1536. if (spawn && spawn->IsEntity() && value > 0)
  1537. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1538. if (spawn->IsPlayer())
  1539. ((Player*)spawn)->SetCharSheetChanged(true);
  1540. return 0;
  1541. }
  1542. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1543. if (!lua_interface)
  1544. return 0;
  1545. Spawn* spawn = lua_interface->GetSpawn(state);
  1546. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1547. lua_interface->ResetFunctionStack(state);
  1548. if (spawn && spawn->IsEntity() && value > 0)
  1549. ((Entity*)spawn)->SetTotalHPBase(value);
  1550. return 0;
  1551. }
  1552. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1553. if (!lua_interface)
  1554. return 0;
  1555. Spawn* spawn = lua_interface->GetSpawn(state);
  1556. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1557. lua_interface->ResetFunctionStack(state);
  1558. if (spawn && value > 0) {
  1559. spawn->SetPower(value);
  1560. if (value > spawn->GetTotalPowerBase())
  1561. spawn->SetTotalPower(value);
  1562. }
  1563. return 0;
  1564. }
  1565. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1566. if (!lua_interface)
  1567. return 0;
  1568. Spawn* spawn = lua_interface->GetSpawn(state);
  1569. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1570. lua_interface->ResetFunctionStack(state);
  1571. if (spawn && spawn->IsEntity() && value > 0)
  1572. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1573. return 0;
  1574. }
  1575. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1576. if (!lua_interface)
  1577. return 0;
  1578. Spawn* spawn = lua_interface->GetSpawn(state);
  1579. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1580. lua_interface->ResetFunctionStack(state);
  1581. if (spawn && spawn->IsEntity() && value > 0)
  1582. ((Entity*)spawn)->SetTotalPowerBase(value);
  1583. return 0;
  1584. }
  1585. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1586. if (!lua_interface)
  1587. return 0;
  1588. Spawn* spawn = lua_interface->GetSpawn(state);
  1589. float x = lua_interface->GetFloatValue(state, 2);
  1590. float y = lua_interface->GetFloatValue(state, 3);
  1591. float z = lua_interface->GetFloatValue(state, 4);
  1592. float heading = lua_interface->GetFloatValue(state, 5);
  1593. lua_interface->ResetFunctionStack(state);
  1594. if (spawn) {
  1595. spawn->SetX(x);
  1596. spawn->SetY(y);
  1597. spawn->SetZ(z);
  1598. if (heading != 0)
  1599. spawn->SetHeading(heading);
  1600. spawn->SetSpawnOrigX(spawn->GetX());
  1601. spawn->SetSpawnOrigY(spawn->GetY());
  1602. spawn->SetSpawnOrigZ(spawn->GetZ());
  1603. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1604. if (spawn->IsPlayer()) {
  1605. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1606. if (client) {
  1607. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1608. client->QueuePacket(packet);
  1609. }
  1610. }
  1611. }
  1612. return 0;
  1613. }
  1614. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1615. if (!lua_interface)
  1616. return 0;
  1617. Spawn* spawn = lua_interface->GetSpawn(state);
  1618. float value = lua_interface->GetFloatValue(state, 2);
  1619. lua_interface->ResetFunctionStack(state);
  1620. if (spawn) {
  1621. spawn->SetHeading(value);
  1622. if (spawn->IsPlayer()) {
  1623. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1624. if (client) {
  1625. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1626. client->QueuePacket(packet);
  1627. }
  1628. }
  1629. }
  1630. return 0;
  1631. }
  1632. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1633. if (!lua_interface)
  1634. return 0;
  1635. Spawn* spawn = lua_interface->GetSpawn(state);
  1636. int16 value = lua_interface->GetInt16Value(state, 2);
  1637. lua_interface->ResetFunctionStack(state);
  1638. if (spawn)
  1639. spawn->SetModelType(value);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* spawn = lua_interface->GetSpawn(state);
  1646. int8 value = lua_interface->GetInt8Value(state, 2);
  1647. lua_interface->ResetFunctionStack(state);
  1648. if (spawn) {
  1649. if (spawn->IsPlayer())
  1650. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1651. else
  1652. spawn->SetAdventureClass(value);
  1653. }
  1654. return 0;
  1655. }
  1656. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1657. if (!lua_interface)
  1658. return 0;
  1659. Spawn* spawn = lua_interface->GetSpawn(state);
  1660. int8 value = lua_interface->GetInt8Value(state, 2);
  1661. lua_interface->ResetFunctionStack(state);
  1662. if (spawn) {
  1663. spawn->SetTradeskillClass(value);
  1664. if (spawn->IsEntity()) {
  1665. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1666. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1667. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1668. }
  1669. if (spawn->IsPlayer())
  1670. ((Player*)spawn)->SetCharSheetChanged(true);
  1671. }
  1672. return 0;
  1673. }
  1674. int EQ2Emu_lua_SetMount(lua_State* state) {
  1675. if (!lua_interface)
  1676. return 0;
  1677. Spawn* spawn = lua_interface->GetSpawn(state);
  1678. int16 value = lua_interface->GetInt16Value(state, 2);
  1679. if (spawn && spawn->IsEntity()) {
  1680. ((Entity*)spawn)->SetMount(value);
  1681. EQ2_Color color;
  1682. color.red = 255;
  1683. color.green = 255;
  1684. color.blue = 255;
  1685. ((Entity*)spawn)->SetMountColor(&color);
  1686. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1687. }
  1688. return 0;
  1689. }
  1690. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1691. if (!lua_interface)
  1692. return 0;
  1693. Spawn* spawn = lua_interface->GetSpawn(state);
  1694. EQ2_Color mount_color;
  1695. EQ2_Color saddle_color;
  1696. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1697. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1698. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1699. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1700. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1701. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1702. if (spawn && spawn->IsEntity()) {
  1703. ((Entity*)spawn)->SetMountColor(&mount_color);
  1704. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1705. }
  1706. return 0;
  1707. }
  1708. int EQ2Emu_lua_GetMount(lua_State* state) {
  1709. if (!lua_interface)
  1710. return 0;
  1711. Spawn* spawn = lua_interface->GetSpawn(state);
  1712. if (spawn && spawn->IsEntity()) {
  1713. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1714. return 1;
  1715. }
  1716. return 0;
  1717. }
  1718. int EQ2Emu_lua_GetRace(lua_State* state) {
  1719. if (!lua_interface)
  1720. return 0;
  1721. Spawn* spawn = lua_interface->GetSpawn(state);
  1722. if (spawn)
  1723. {
  1724. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1725. lua_interface->SetInt32Value(state, spawn->GetRace());
  1726. return 1;
  1727. }
  1728. return 0;
  1729. }
  1730. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1731. if (!lua_interface)
  1732. return 0;
  1733. Spawn* spawn = lua_interface->GetSpawn(state);
  1734. if (spawn) {
  1735. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1736. return 1;
  1737. }
  1738. return 0;
  1739. }
  1740. int EQ2Emu_lua_GetClass(lua_State* state) {
  1741. Spawn* spawn = lua_interface->GetSpawn(state);
  1742. if (spawn) {
  1743. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1744. return 1;
  1745. }
  1746. return 0;
  1747. }
  1748. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1749. Spawn* spawn = lua_interface->GetSpawn(state);
  1750. if (spawn) {
  1751. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1752. return 1;
  1753. }
  1754. return 0;
  1755. }
  1756. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1757. if (!lua_interface)
  1758. return 0;
  1759. Spawn* spawn = lua_interface->GetSpawn(state);
  1760. float value = lua_interface->GetFloatValue(state, 2);
  1761. lua_interface->ResetFunctionStack(state);
  1762. if (spawn) {
  1763. spawn->SetSpeed(value);
  1764. ((Entity*)spawn)->SetSpeed(value);
  1765. if (spawn->IsPlayer()) {
  1766. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1767. if (client) {
  1768. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1769. if (packet) {
  1770. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1771. packet->setDataByName("speed", value);
  1772. packet->setDataByName("size", 0.51);
  1773. EQ2Packet* app = packet->serialize();
  1774. client->QueuePacket(app);
  1775. safe_delete(packet);
  1776. }
  1777. }
  1778. }
  1779. }
  1780. return 0;
  1781. }
  1782. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1783. if (!lua_interface)
  1784. return 0;
  1785. Spawn* spawn = lua_interface->GetSpawn(state);
  1786. const int16 type = lua_interface->GetInt16Value(state, 2);
  1787. const float value = lua_interface->GetFloatValue(state, 3);
  1788. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1789. int64 class_req = 0;
  1790. int32 class_id = 0;
  1791. vector<int16> faction_req;
  1792. vector<int16> race_req;
  1793. int32 i = 0;
  1794. int8 f = 0;
  1795. int8 r = 0;
  1796. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1797. if (class_id < 100) {
  1798. class_req += pow(2.0, double(class_id - 1));
  1799. }
  1800. else if (class_id > 100 && class_id < 1000) {
  1801. race_req.push_back(class_id);
  1802. r++;
  1803. }
  1804. else {
  1805. faction_req.push_back(class_id);
  1806. f++;
  1807. }
  1808. i++;
  1809. }
  1810. if (value != 0 && type >= 0) {
  1811. if (luaspell && luaspell->spell && luaspell->caster) {
  1812. ZoneServer* zone = luaspell->caster->GetZone();
  1813. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1814. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1815. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1816. if (target) {
  1817. if (target->IsPlayer()) {
  1818. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1819. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1820. if (((Player*)target)->GetGroupMemberInfo())
  1821. ((Player*)target)->UpdateGroupMemberInfo();
  1822. ((Player*)target)->SetCharSheetChanged(true);
  1823. }
  1824. else if (target->IsNPC())
  1825. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1826. else
  1827. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1828. }
  1829. }
  1830. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1831. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1832. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1833. }
  1834. else if (spawn && spawn->IsEntity()) {
  1835. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1836. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1837. if (spawn->IsPlayer())
  1838. ((Player*)spawn)->SetCharSheetChanged(true);
  1839. }
  1840. else
  1841. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1842. }
  1843. else
  1844. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1845. return 0;
  1846. }
  1847. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1848. if (!lua_interface)
  1849. return 0;
  1850. Spawn* spawn = lua_interface->GetSpawn(state);
  1851. int16 type = lua_interface->GetInt16Value(state, 2);
  1852. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1853. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1854. if (!spawn) {
  1855. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1856. return 0;
  1857. }
  1858. if (!spawn->IsEntity()) {
  1859. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1860. return 0;
  1861. }
  1862. if (value == 0) {
  1863. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1864. return 0;
  1865. }
  1866. if (!luaspell || !luaspell->spell) {
  1867. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1868. return 0;
  1869. }
  1870. int32 class_req = 0;
  1871. vector<int16> faction_req;
  1872. vector<int16> race_req;
  1873. int32 class_id = 0;
  1874. int32 i = 0;
  1875. int8 f = 0;
  1876. int8 r = 0;
  1877. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1878. if (class_id < 100) {
  1879. class_req += pow(2.0, double(class_id - 1));
  1880. }
  1881. else if (class_id > 100 && class_id < 1000) {
  1882. race_req.push_back(class_id);
  1883. r++;
  1884. }
  1885. else {
  1886. faction_req.push_back(class_id);
  1887. f++;
  1888. }
  1889. i++;
  1890. }
  1891. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1892. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1893. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1894. if (spawn->IsPlayer())
  1895. ((Player*)spawn)->SetCharSheetChanged(true);
  1896. return 0;
  1897. }
  1898. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1899. if (!lua_interface)
  1900. return 0;
  1901. Spawn* spawn = lua_interface->GetSpawn(state);
  1902. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1903. if (luaspell && luaspell->spell) {
  1904. ZoneServer* zone = luaspell->caster->GetZone();
  1905. Spawn* target = 0;
  1906. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1907. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1908. target = zone->GetSpawnByID(luaspell->targets[i]);
  1909. if (target && target->IsEntity()) {
  1910. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1911. if (target->IsPlayer())
  1912. ((Player*)target)->SetCharSheetChanged(true);
  1913. }
  1914. }
  1915. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1916. }
  1917. else if (spawn && spawn->IsEntity()) {
  1918. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1919. if (spawn->IsPlayer())
  1920. ((Player*)spawn)->SetCharSheetChanged(true);
  1921. }
  1922. return 0;
  1923. }
  1924. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1925. if (!lua_interface)
  1926. return 0;
  1927. Spawn* spawn = lua_interface->GetSpawn(state);
  1928. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1929. float value = lua_interface->GetFloatValue(state, 3);
  1930. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1931. if (value != 0) {
  1932. int32 spell_id = 0;
  1933. if (luaspell && luaspell->spell && luaspell->caster) {
  1934. spell_id = luaspell->spell->GetSpellID();
  1935. ZoneServer* zone = luaspell->caster->GetZone();
  1936. Spawn* target = 0;
  1937. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1938. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1939. target = zone->GetSpawnByID(luaspell->targets[i]);
  1940. if (target && target->Alive()) {
  1941. if (target->IsPlayer()) {
  1942. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1943. Client* client = target->GetZone()->GetClientBySpawn(target);
  1944. if (client) {
  1945. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1946. if (packet)
  1947. client->QueuePacket(packet);
  1948. }
  1949. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1950. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1951. }
  1952. else if (target->IsNPC()) {
  1953. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1954. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1955. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1956. }
  1957. else
  1958. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1959. }
  1960. }
  1961. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1962. }
  1963. else if (spawn) {
  1964. if (spawn->IsPlayer()) {
  1965. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1966. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1967. if (client) {
  1968. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1969. if (packet)
  1970. client->QueuePacket(packet);
  1971. }
  1972. }
  1973. else if (spawn->IsNPC())
  1974. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1975. else
  1976. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1977. }
  1978. }
  1979. else
  1980. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1981. return 0;
  1982. }
  1983. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1984. if (!lua_interface)
  1985. return 0;
  1986. Spawn* spawn = lua_interface->GetSpawn(state);
  1987. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1988. if (spawn && spawn->IsPlayer()) {
  1989. int32 spell_id = 0;
  1990. if (luaspell && luaspell->spell) {
  1991. spell_id = luaspell->spell->GetSpellID();
  1992. ZoneServer* zone = luaspell->caster->GetZone();
  1993. Spawn* target = 0;
  1994. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1995. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1996. target = zone->GetSpawnByID(luaspell->targets[i]);
  1997. if (target) {
  1998. if (target->IsPlayer()) {
  1999. ((Player*)target)->RemoveSkillBonus(spell_id);
  2000. Client* client = target->GetZone()->GetClientBySpawn(target);
  2001. if (client) {
  2002. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2003. if (packet)
  2004. client->QueuePacket(packet);
  2005. }
  2006. }
  2007. else if (target->IsNPC())
  2008. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2009. else
  2010. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2011. }
  2012. }
  2013. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2014. }
  2015. else if (spawn) {
  2016. if (spawn->IsPlayer()) {
  2017. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2018. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2019. if (client) {
  2020. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2021. if (packet)
  2022. client->QueuePacket(packet);
  2023. }
  2024. }
  2025. else if (spawn->IsNPC())
  2026. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2027. else
  2028. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2029. }
  2030. }
  2031. return 0;
  2032. }
  2033. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2034. if (!lua_interface)
  2035. return 0;
  2036. Spawn* spawn = lua_interface->GetSpawn(state);
  2037. int8 type = lua_interface->GetInt32Value(state, 2);
  2038. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2039. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2040. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2041. ZoneServer* zone = luaspell->caster->GetZone();
  2042. Spawn* target = 0;
  2043. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2044. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2045. target = zone->GetSpawnByID(luaspell->targets[i]);
  2046. if (target && target->IsEntity()) {
  2047. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2048. ((Entity*)target)->AddMezSpell(luaspell);
  2049. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2050. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2051. if (target->IsNPC())
  2052. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2053. }
  2054. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2055. ((Entity*)target)->AddStifleSpell(luaspell);
  2056. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2057. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2058. if (target->IsNPC())
  2059. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2060. }
  2061. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2062. ((Entity*)target)->AddDazeSpell(luaspell);
  2063. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2064. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2065. if (target->IsNPC())
  2066. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2067. }
  2068. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2069. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2070. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2071. ((Entity*)target)->AddStunSpell(luaspell);
  2072. if (target->IsNPC())
  2073. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2074. }
  2075. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2076. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2077. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2078. ((Entity*)target)->AddRootSpell(luaspell);
  2079. if (target->IsNPC())
  2080. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2081. }
  2082. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2083. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2084. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2085. ((Entity*)target)->AddFearSpell(luaspell);
  2086. if (target->IsNPC())
  2087. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2088. }
  2089. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2090. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2091. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2092. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2093. }
  2094. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2095. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2096. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2097. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2098. }
  2099. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2100. ((Entity*)target)->AddSnareSpell(luaspell);
  2101. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2102. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2103. if (target->IsNPC())
  2104. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2105. }
  2106. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2107. ((Entity*)target)->AddFlightSpell(luaspell);
  2108. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2109. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2110. }
  2111. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2112. ((Entity*)target)->AddGlideSpell(luaspell);
  2113. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2114. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2115. }
  2116. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2117. ((Entity*)target)->AddSafefallSpell(luaspell);
  2118. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2119. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2120. }
  2121. else
  2122. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2123. }
  2124. else
  2125. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2126. }
  2127. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2128. }
  2129. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2130. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2131. ((Entity*)spawn)->AddMezSpell(luaspell);
  2132. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2133. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2134. }
  2135. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2136. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2137. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2138. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2139. }
  2140. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2141. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2142. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2143. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2144. }
  2145. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2146. ((Entity*)spawn)->AddStunSpell(luaspell);
  2147. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2148. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2149. }
  2150. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2151. ((Entity*)spawn)->AddRootSpell(luaspell);
  2152. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2153. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2154. }
  2155. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2156. ((Entity*)spawn)->AddFearSpell(luaspell);
  2157. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2158. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2159. }
  2160. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2161. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2162. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2163. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2164. }
  2165. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2166. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2167. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2168. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2169. }
  2170. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2171. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2172. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2173. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2174. }
  2175. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2176. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2177. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2178. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2179. }
  2180. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2181. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2182. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2183. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2184. }
  2185. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2186. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2187. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2188. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2189. }
  2190. else
  2191. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2192. }
  2193. else
  2194. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2195. return 0;
  2196. }
  2197. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2198. if (!lua_interface)
  2199. return 0;
  2200. Spawn* spawn = lua_interface->GetSpawn(state);
  2201. int8 type = lua_interface->GetInt8Value(state, 2);
  2202. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2203. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2204. if (spawn && spawn->IsEntity()) {
  2205. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2206. ZoneServer* zone = luaspell->caster->GetZone();
  2207. Spawn* target = 0;
  2208. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2209. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2210. target = zone->GetSpawnByID(luaspell->targets[i]);
  2211. if (target) {
  2212. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2213. ((Entity*)target)->RemoveMezSpell(luaspell);
  2214. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2215. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2216. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2217. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2218. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2219. ((Entity*)target)->RemoveStunSpell(luaspell);
  2220. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2221. ((Entity*)target)->RemoveRootSpell(luaspell);
  2222. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2223. ((Entity*)target)->RemoveFearSpell(luaspell);
  2224. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2225. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2226. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2227. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2228. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2229. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2230. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2231. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2232. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2233. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2234. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2235. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2236. else
  2237. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2238. }
  2239. }
  2240. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2241. }
  2242. else if (only_remove_spawn) {
  2243. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2244. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2245. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2246. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2247. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2248. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2249. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2250. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2251. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2252. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2253. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2254. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2255. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2256. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2257. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2258. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2259. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2260. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2261. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2262. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2263. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2264. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2265. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2266. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2267. else
  2268. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2269. }
  2270. }
  2271. return 0;
  2272. }
  2273. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2274. if (!lua_interface)
  2275. return 0;
  2276. Spawn* spawn = lua_interface->GetSpawn(state);
  2277. int8 type = lua_interface->GetInt8Value(state, 2);
  2278. bool hasEffect = false;
  2279. if (!spawn)
  2280. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2281. else if (!spawn->IsEntity())
  2282. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2283. else if (type < CONTROL_MAX_EFFECTS)
  2284. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2285. else
  2286. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2287. lua_interface->SetBooleanValue(state, hasEffect);
  2288. return 1;
  2289. }
  2290. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2291. if (!lua_interface)
  2292. return 0;
  2293. Spawn* spawn = lua_interface->GetSpawn(state);
  2294. float distance = 0.0f;
  2295. if (!spawn)
  2296. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2297. else if (!spawn->IsNPC())
  2298. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2299. else
  2300. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2301. lua_interface->SetFloatValue(state, distance);
  2302. return 1;
  2303. }
  2304. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2305. if (!lua_interface)
  2306. return 0;
  2307. Spawn* spawn = lua_interface->GetSpawn(state);
  2308. float distance = 0.0f;
  2309. if (!spawn)
  2310. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2311. else if (!spawn->IsNPC())
  2312. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2313. else
  2314. distance = ((NPC*)spawn)->GetAggroRadius();
  2315. lua_interface->SetFloatValue(state, distance);
  2316. return 1;
  2317. }
  2318. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2319. if (!lua_interface)
  2320. return 0;
  2321. Spawn* spawn = lua_interface->GetSpawn(state);
  2322. float distance = lua_interface->GetFloatValue(state, 2);
  2323. bool override = lua_interface->GetBooleanValue(state, 3);
  2324. bool result = false;
  2325. lua_interface->ResetFunctionStack(state);
  2326. if (!spawn)
  2327. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2328. else if (!spawn->IsNPC())
  2329. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2330. else
  2331. {
  2332. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2333. result = true;
  2334. }
  2335. lua_interface->SetBooleanValue(state, result);
  2336. return 1;
  2337. }
  2338. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2339. if (!lua_interface)
  2340. return 0;
  2341. Spawn* spawn = lua_interface->GetSpawn(state);
  2342. int16 value = lua_interface->GetInt16Value(state, 2);
  2343. if (spawn && spawn->IsEntity()) {
  2344. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2345. if (spawn->IsPlayer())
  2346. ((Player*)spawn)->SetCharSheetChanged(true);
  2347. }
  2348. return 0;
  2349. }
  2350. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2351. if (!lua_interface)
  2352. return 0;
  2353. Spawn* spawn = lua_interface->GetSpawn(state);
  2354. int16 value = lua_interface->GetInt16Value(state, 2);
  2355. if (spawn && spawn->IsEntity()) {
  2356. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2357. if (spawn->IsPlayer())
  2358. ((Player*)spawn)->SetCharSheetChanged(true);
  2359. }
  2360. return 0;
  2361. }
  2362. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2363. if (!lua_interface)
  2364. return 0;
  2365. Spawn* spawn = lua_interface->GetSpawn(state);
  2366. int16 value = lua_interface->GetInt16Value(state, 2);
  2367. if (spawn && spawn->IsEntity()) {
  2368. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2369. if (spawn->IsPlayer())
  2370. ((Player*)spawn)->SetCharSheetChanged(true);
  2371. }
  2372. return 0;
  2373. }
  2374. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2375. if (!lua_interface)
  2376. return 0;
  2377. Spawn* spawn = lua_interface->GetSpawn(state);
  2378. int16 value = lua_interface->GetInt16Value(state, 2);
  2379. if (spawn && spawn->IsEntity()) {
  2380. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2381. if (spawn->IsPlayer())
  2382. ((Player*)spawn)->SetCharSheetChanged(true);
  2383. }
  2384. return 0;
  2385. }
  2386. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2387. if (!lua_interface)
  2388. return 0;
  2389. Spawn* spawn = lua_interface->GetSpawn(state);
  2390. int16 value = lua_interface->GetInt16Value(state, 2);
  2391. if (spawn && spawn->IsEntity()) {
  2392. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2393. if (spawn->IsPlayer())
  2394. ((Player*)spawn)->SetCharSheetChanged(true);
  2395. }
  2396. return 0;
  2397. }
  2398. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2399. if (!lua_interface)
  2400. return 0;
  2401. Spawn* spawn = lua_interface->GetSpawn(state);
  2402. int8 value = lua_interface->GetInt8Value(state, 2);
  2403. if (spawn && spawn->IsEntity()) {
  2404. ((Entity*)spawn)->SetDeity(value);
  2405. if (spawn->IsPlayer())
  2406. ((Player*)spawn)->SetCharSheetChanged(true);
  2407. }
  2408. lua_interface->ResetFunctionStack(state);
  2409. return 0;
  2410. }
  2411. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2412. if (!lua_interface)
  2413. return 0;
  2414. Spawn* spawn = lua_interface->GetSpawn(state);
  2415. if (spawn && spawn->IsEntity()) {
  2416. int8 deity = ((Entity*)spawn)->GetDeity();
  2417. lua_interface->SetInt32Value(state, deity);
  2418. return 1;
  2419. }
  2420. return 0;
  2421. }
  2422. int EQ2Emu_lua_SetInt(lua_State* state) {
  2423. if (!lua_interface)
  2424. return 0;
  2425. Spawn* spawn = lua_interface->GetSpawn(state);
  2426. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2427. if (spawn && spawn->IsEntity()) {
  2428. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2429. if (spawn->IsPlayer())
  2430. ((Player*)spawn)->SetCharSheetChanged(true);
  2431. }
  2432. return 0;
  2433. }
  2434. int EQ2Emu_lua_SetWis(lua_State* state) {
  2435. if (!lua_interface)
  2436. return 0;
  2437. Spawn* spawn = lua_interface->GetSpawn(state);
  2438. float value = lua_interface->GetFloatValue(state, 2);
  2439. if (spawn && spawn->IsEntity()) {
  2440. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2441. if (spawn->IsPlayer())
  2442. ((Player*)spawn)->SetCharSheetChanged(true);
  2443. }
  2444. return 0;
  2445. }
  2446. int EQ2Emu_lua_SetSta(lua_State* state) {
  2447. if (!lua_interface)
  2448. return 0;
  2449. Spawn* spawn = lua_interface->GetSpawn(state);
  2450. float value = lua_interface->GetFloatValue(state, 2);
  2451. if (spawn && spawn->IsEntity()) {
  2452. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2453. if (spawn->IsPlayer())
  2454. ((Player*)spawn)->SetCharSheetChanged(true);
  2455. }
  2456. return 0;
  2457. }
  2458. int EQ2Emu_lua_SetStr(lua_State* state) {
  2459. if (!lua_interface)
  2460. return 0;
  2461. Spawn* spawn = lua_interface->GetSpawn(state);
  2462. float value = lua_interface->GetFloatValue(state, 2);
  2463. if (spawn && spawn->IsEntity()) {
  2464. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2465. if (spawn->IsPlayer())
  2466. ((Player*)spawn)->SetCharSheetChanged(true);
  2467. }
  2468. return 0;
  2469. }
  2470. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2471. if (!lua_interface)
  2472. return 0;
  2473. Spawn* spawn = lua_interface->GetSpawn(state);
  2474. float value = lua_interface->GetFloatValue(state, 2);
  2475. if (spawn && spawn->IsEntity()) {
  2476. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2477. if (spawn->IsPlayer())
  2478. ((Player*)spawn)->SetCharSheetChanged(true);
  2479. }
  2480. return 0;
  2481. }
  2482. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2483. if (!lua_interface)
  2484. return 0;
  2485. Spawn* spawn = lua_interface->GetSpawn(state);
  2486. if (spawn) {
  2487. lua_interface->SetInt32Value(state, spawn->GetHP());
  2488. return 1;
  2489. }
  2490. return 0;
  2491. }
  2492. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2493. if (!lua_interface)
  2494. return 0;
  2495. Spawn* spawn = lua_interface->GetSpawn(state);
  2496. if (spawn) {
  2497. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2498. return 1;
  2499. }
  2500. return 0;
  2501. }
  2502. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2503. if (!lua_interface)
  2504. return 0;
  2505. Spawn* spawn = lua_interface->GetSpawn(state);
  2506. if (spawn) {
  2507. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2508. return 1;
  2509. }
  2510. return 0;
  2511. }
  2512. int EQ2Emu_lua_GetName(lua_State* state) {
  2513. if (!lua_interface)
  2514. return 0;
  2515. Spawn* spawn = lua_interface->GetSpawn(state);
  2516. if (spawn) {
  2517. lua_interface->SetStringValue(state, spawn->GetName());
  2518. return 1;
  2519. }
  2520. return 0;
  2521. }
  2522. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2523. Spawn* spawn = lua_interface->GetSpawn(state);
  2524. if (spawn) {
  2525. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2526. return 1;
  2527. }
  2528. return 0;
  2529. }
  2530. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2531. if (!lua_interface)
  2532. return 0;
  2533. Spawn* spawn = lua_interface->GetSpawn(state);
  2534. if (spawn) {
  2535. lua_interface->SetInt32Value(state, spawn->GetPower());
  2536. return 1;
  2537. }
  2538. return 0;
  2539. }
  2540. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2541. if (!lua_interface)
  2542. return 0;
  2543. Spawn* spawn = lua_interface->GetSpawn(state);
  2544. if (spawn) {
  2545. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2546. return 1;
  2547. }
  2548. return 0;
  2549. }
  2550. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2551. if (!lua_interface)
  2552. return 0;
  2553. Spawn* spawn = lua_interface->GetSpawn(state);
  2554. if (spawn) {
  2555. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2556. return 1;
  2557. }
  2558. return 0;
  2559. }
  2560. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2561. if (!lua_interface)
  2562. return 0;
  2563. Spawn* spawn = lua_interface->GetSpawn(state);
  2564. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2565. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2566. if (spawn && spawn2) {
  2567. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2568. lua_interface->SetFloatValue(state, distance);
  2569. return 1;
  2570. }
  2571. return 0;
  2572. }
  2573. int EQ2Emu_lua_GetX(lua_State* state) {
  2574. if (!lua_interface)
  2575. return 0;
  2576. Spawn* spawn = lua_interface->GetSpawn(state);
  2577. if (spawn) {
  2578. lua_interface->SetFloatValue(state, spawn->GetX());
  2579. return 1;
  2580. }
  2581. return 0;
  2582. }
  2583. int EQ2Emu_lua_GetY(lua_State* state) {
  2584. if (!lua_interface)
  2585. return 0;
  2586. Spawn* spawn = lua_interface->GetSpawn(state);
  2587. if (spawn) {
  2588. lua_interface->SetFloatValue(state, spawn->GetY());
  2589. return 1;
  2590. }
  2591. return 0;
  2592. }
  2593. int EQ2Emu_lua_GetZ(lua_State* state) {
  2594. if (!lua_interface)
  2595. return 0;
  2596. Spawn* spawn = lua_interface->GetSpawn(state);
  2597. if (spawn) {
  2598. lua_interface->SetFloatValue(state, spawn->GetZ());
  2599. return 1;
  2600. }
  2601. return 0;
  2602. }
  2603. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2604. if (!lua_interface)
  2605. return 0;
  2606. Spawn* spawn = lua_interface->GetSpawn(state);
  2607. if (spawn) {
  2608. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2609. return 1;
  2610. }
  2611. return 0;
  2612. }
  2613. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2614. if (!lua_interface)
  2615. return 0;
  2616. Spawn* spawn = lua_interface->GetSpawn(state);
  2617. if (spawn) {
  2618. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2619. return 1;
  2620. }
  2621. return 0;
  2622. }
  2623. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2624. if (!lua_interface)
  2625. return 0;
  2626. Spawn* spawn = lua_interface->GetSpawn(state);
  2627. if (spawn) {
  2628. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2629. return 1;
  2630. }
  2631. return 0;
  2632. }
  2633. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2634. if (!lua_interface)
  2635. return 0;
  2636. Spawn* spawn = lua_interface->GetSpawn(state);
  2637. if (spawn && spawn->IsEntity()) {
  2638. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2639. return 1;
  2640. }
  2641. return 0;
  2642. }
  2643. int EQ2Emu_lua_GetInt(lua_State* state) {
  2644. if (!lua_interface)
  2645. return 0;
  2646. Spawn* spawn = lua_interface->GetSpawn(state);
  2647. if (spawn && spawn->IsEntity()) {
  2648. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2649. return 1;
  2650. }
  2651. return 0;
  2652. }
  2653. int EQ2Emu_lua_GetWis(lua_State* state) {
  2654. if (!lua_interface)
  2655. return 0;
  2656. Spawn* spawn = lua_interface->GetSpawn(state);
  2657. if (spawn && spawn->IsEntity()) {
  2658. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2659. return 1;
  2660. }
  2661. return 0;
  2662. }
  2663. int EQ2Emu_lua_GetSta(lua_State* state) {
  2664. if (!lua_interface)
  2665. return 0;
  2666. Spawn* spawn = lua_interface->GetSpawn(state);
  2667. if (spawn && spawn->IsEntity()) {
  2668. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2669. return 1;
  2670. }
  2671. return 0;
  2672. }
  2673. int EQ2Emu_lua_GetStr(lua_State* state) {
  2674. if (!lua_interface)
  2675. return 0;
  2676. Spawn* spawn = lua_interface->GetSpawn(state);
  2677. if (spawn && spawn->IsEntity()) {
  2678. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2679. return 1;
  2680. }
  2681. return 0;
  2682. }
  2683. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2684. if (!lua_interface)
  2685. return 0;
  2686. Spawn* spawn = lua_interface->GetSpawn(state);
  2687. if (spawn && spawn->IsEntity()) {
  2688. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2689. return 1;
  2690. }
  2691. return 0;
  2692. }
  2693. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2694. if (!lua_interface)
  2695. return 0;
  2696. Spawn* spawn = lua_interface->GetSpawn(state);
  2697. if (spawn && spawn->IsEntity()) {
  2698. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2699. return 1;
  2700. }
  2701. return 0;
  2702. }
  2703. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2704. if (!lua_interface)
  2705. return 0;
  2706. Spawn* spawn = lua_interface->GetSpawn(state);
  2707. if (spawn && spawn->IsEntity()) {
  2708. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2709. return 1;
  2710. }
  2711. return 0;
  2712. }
  2713. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2714. if (!lua_interface)
  2715. return 0;
  2716. Spawn* spawn = lua_interface->GetSpawn(state);
  2717. if (spawn && spawn->IsEntity()) {
  2718. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2719. return 1;
  2720. }
  2721. return 0;
  2722. }
  2723. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2724. if (!lua_interface)
  2725. return 0;
  2726. Spawn* spawn = lua_interface->GetSpawn(state);
  2727. if (spawn && spawn->IsEntity()) {
  2728. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2729. return 1;
  2730. }
  2731. return 0;
  2732. }
  2733. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2734. if (!lua_interface)
  2735. return 0;
  2736. Spawn* spawn = lua_interface->GetSpawn(state);
  2737. if (spawn && spawn->IsEntity()) {
  2738. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2739. return 1;
  2740. }
  2741. return 0;
  2742. }
  2743. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2744. if (!lua_interface)
  2745. return 0;
  2746. Spawn* player = lua_interface->GetSpawn(state);
  2747. if (!player || !player->IsPlayer()) {
  2748. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2749. return 0;
  2750. }
  2751. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2752. if (quest_id <= 0) {
  2753. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2754. return 0;
  2755. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2756. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2757. return 0;
  2758. }
  2759. int32 step = lua_interface->GetInt32Value(state, 3);
  2760. if (step > 0) {
  2761. Client* client = player->GetZone()->GetClientBySpawn(player);
  2762. if (client)
  2763. client->AddPendingQuestUpdate(quest_id, step);
  2764. } else {
  2765. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2766. }
  2767. return 0;
  2768. }
  2769. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2770. Spawn* player = lua_interface->GetSpawn(state);
  2771. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2772. int32 step = lua_interface->GetInt32Value(state, 3);
  2773. int32 progress = lua_interface->GetInt32Value(state, 4);
  2774. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2775. Client* client = player->GetZone()->GetClientBySpawn(player);
  2776. if (client)
  2777. client->AddPendingQuestUpdate(quest_id, step, progress);
  2778. }
  2779. return 0;
  2780. }
  2781. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2782. if (!lua_interface)
  2783. return 0;
  2784. Spawn* player = lua_interface->GetSpawn(state);
  2785. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2786. if (player && player->IsPlayer() && quest_id > 0) {
  2787. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2788. return 1;
  2789. }
  2790. return 0;
  2791. }
  2792. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2793. if (!lua_interface)
  2794. return 0;
  2795. Spawn* player = lua_interface->GetSpawn(state);
  2796. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2797. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2798. if (player && player->IsPlayer() && quest_id > 0) {
  2799. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2800. return 1;
  2801. }
  2802. return 0;
  2803. }
  2804. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2805. if (!lua_interface)
  2806. return 0;
  2807. Spawn* player = lua_interface->GetSpawn(state);
  2808. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2809. if (player && player->IsPlayer() && quest_id > 0) {
  2810. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2811. return 1;
  2812. }
  2813. return 0;
  2814. }
  2815. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2816. if (!lua_interface)
  2817. return 0;
  2818. Quest* quest = lua_interface->GetQuest(state);
  2819. string name = lua_interface->GetStringValue(state, 2);
  2820. string type = lua_interface->GetStringValue(state, 3);
  2821. string zone = lua_interface->GetStringValue(state, 4);
  2822. int16 level = lua_interface->GetInt16Value(state, 5);
  2823. string description = lua_interface->GetStringValue(state, 6);
  2824. bool load = true;
  2825. if (!quest) {
  2826. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2827. load = false;
  2828. }
  2829. if (load && name.length() == 0) {
  2830. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2831. load = false;
  2832. }
  2833. if (load && type.length() == 0) {
  2834. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2835. load = false;
  2836. }
  2837. if (load && zone.length() == 0) {
  2838. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2839. load = false;
  2840. }
  2841. if (load && description.length() == 0) {
  2842. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2843. load = false;
  2844. }
  2845. if (load && level == 0) {
  2846. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2847. load = false;
  2848. }
  2849. if (load)
  2850. quest->RegisterQuest(name, type, zone, level, description);
  2851. return 0;
  2852. }
  2853. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2854. if (!lua_interface)
  2855. return 0;
  2856. Quest* quest = lua_interface->GetQuest(state);
  2857. if (quest) {
  2858. int8 level = lua_interface->GetInt16Value(state, 2);
  2859. quest->SetPrereqLevel(level);
  2860. }
  2861. return 0;
  2862. }
  2863. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2864. if (!lua_interface)
  2865. return 0;
  2866. Quest* quest = lua_interface->GetQuest(state);
  2867. if (quest) {
  2868. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2869. quest->AddPrereqQuest(quest_id);
  2870. }
  2871. return 0;
  2872. }
  2873. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2874. if (!lua_interface)
  2875. return 0;
  2876. Quest* quest = lua_interface->GetQuest(state);
  2877. if (quest) {
  2878. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2879. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2880. if (quantity == 0)
  2881. quantity = 1;
  2882. Item* master_item = master_item_list.GetItem(item_id);
  2883. if (master_item) {
  2884. Item* item = new Item(master_item);
  2885. item->details.count = quantity;
  2886. quest->AddPrereqItem(item);
  2887. }
  2888. }
  2889. return 0;
  2890. }
  2891. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2892. if (!lua_interface)
  2893. return 0;
  2894. Spawn* player = lua_interface->GetSpawn(state);
  2895. if(!player || !player->IsPlayer()) {
  2896. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  2897. return 0;
  2898. }
  2899. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2900. if (quest_id > 0) {
  2901. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2902. return 1;
  2903. } else {
  2904. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2905. }
  2906. return 0;
  2907. }
  2908. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2909. if (!lua_interface)
  2910. return 0;
  2911. Quest* quest = lua_interface->GetQuest(state);
  2912. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2913. if (quest && spawn_id > 0)
  2914. quest->SetQuestReturnNPC(spawn_id);
  2915. return 0;
  2916. }
  2917. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2918. if (!lua_interface)
  2919. return 0;
  2920. Spawn* spawn = lua_interface->GetSpawn(state);
  2921. if (!spawn) {
  2922. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2923. return 0;
  2924. }
  2925. int32 time = lua_interface->GetInt32Value(state, 2);
  2926. if (time <= 0) {
  2927. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2928. return 0;
  2929. }
  2930. string function = lua_interface->GetStringValue(state, 3);
  2931. if (function.length() == 0) {
  2932. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2933. return 0;
  2934. }
  2935. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2936. Spawn* player = lua_interface->GetSpawn(state, 5);
  2937. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2938. timer->timer = Timer::GetCurrentTime2() + time;
  2939. timer->function = function;
  2940. timer->spawn = spawn->GetID();
  2941. timer->player = player ? player->GetID() : 0;
  2942. if (max_count == 0)
  2943. max_count = 1;
  2944. timer->max_count = max_count;
  2945. timer->current_count = 0;
  2946. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2947. return 0;
  2948. }
  2949. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2950. if (!lua_interface)
  2951. return 0;
  2952. Spawn* player = lua_interface->GetSpawn(state);
  2953. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2954. if (player && player->IsPlayer() && quest_id > 0) {
  2955. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2956. return 1;
  2957. }
  2958. return 0;
  2959. }
  2960. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2961. if (!lua_interface)
  2962. return 0;
  2963. Spawn* player = lua_interface->GetSpawn(state);
  2964. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2965. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2966. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2967. if (quest)
  2968. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2969. return 1;
  2970. }
  2971. return 0;
  2972. }
  2973. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2974. if (!lua_interface)
  2975. return 0;
  2976. Spawn* player = lua_interface->GetSpawn(state);
  2977. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2978. if (player && player->IsPlayer() && quest_id > 0) {
  2979. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2980. return 1;
  2981. }
  2982. return 0;
  2983. }
  2984. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2985. if (!lua_interface)
  2986. return 0;
  2987. Spawn* npc = lua_interface->GetSpawn(state);
  2988. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2989. if (npc && !npc->IsPlayer() && quest_id > 0)
  2990. npc->AddProvidedQuest(quest_id);
  2991. return 0;
  2992. }
  2993. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2994. if (!lua_interface)
  2995. return 0;
  2996. Spawn* npc = lua_interface->GetSpawn(state);
  2997. Spawn* player = lua_interface->GetSpawn(state, 2);
  2998. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2999. bool forced = lua_interface->GetBooleanValue(state, 4);
  3000. /* NPC is allowed to be null */
  3001. if (player && player->IsPlayer() && quest_id > 0) {
  3002. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  3003. if (master_quest) {
  3004. Client* client = player->GetZone()->GetClientBySpawn(player);
  3005. if (!client) {
  3006. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3007. }
  3008. Quest* quest = new Quest(master_quest);
  3009. if (!quest) {
  3010. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3011. }
  3012. if (client && quest) {
  3013. if (npc)
  3014. quest->SetQuestGiver(npc->GetDatabaseID());
  3015. else
  3016. quest->SetQuestGiver(0);
  3017. client->AddPendingQuest(quest, forced);
  3018. }
  3019. }
  3020. else {
  3021. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3022. }
  3023. }
  3024. else {
  3025. 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);
  3026. }
  3027. return 0;
  3028. }
  3029. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3030. if (!lua_interface)
  3031. return 0;
  3032. Quest* quest = lua_interface->GetQuest(state);
  3033. if (quest) {
  3034. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3035. quest->AddPrereqClass(class_id);
  3036. }
  3037. return 0;
  3038. }
  3039. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3040. if (!lua_interface)
  3041. return 0;
  3042. Quest* quest = lua_interface->GetQuest(state);
  3043. if (quest) {
  3044. int8 race = lua_interface->GetInt8Value(state, 2);
  3045. quest->AddPrereqRace(race);
  3046. }
  3047. return 0;
  3048. }
  3049. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3050. if (!lua_interface)
  3051. return 0;
  3052. Quest* quest = lua_interface->GetQuest(state);
  3053. if (quest) {
  3054. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3055. quest->AddPrereqModelType(model_type);
  3056. }
  3057. return 0;
  3058. }
  3059. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3060. if (!lua_interface)
  3061. return 0;
  3062. Quest* quest = lua_interface->GetQuest(state);
  3063. if (!quest) {
  3064. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3065. return 0;
  3066. }
  3067. int8 level = lua_interface->GetInt8Value(state, 2);
  3068. quest->SetPrereqTSLevel(level);
  3069. return 0;
  3070. }
  3071. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3072. if (!lua_interface)
  3073. return 0;
  3074. Quest* quest = lua_interface->GetQuest(state);
  3075. if (!quest) {
  3076. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3077. return 0;
  3078. }
  3079. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3080. quest->AddPrereqTradeskillClass(class_id);
  3081. return 0;
  3082. }
  3083. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3084. if (!lua_interface)
  3085. return 0;
  3086. Quest* quest = lua_interface->GetQuest(state);
  3087. if (quest) {
  3088. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3089. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3090. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3091. quest->AddPrereqFaction(faction_id, min, max);
  3092. }
  3093. return 0;
  3094. }
  3095. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3096. if (!lua_interface)
  3097. return 0;
  3098. Quest* quest = lua_interface->GetQuest(state);
  3099. if (quest) {
  3100. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3101. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3102. if (quantity == 0)
  3103. quantity = 1;
  3104. Item* master_item = master_item_list.GetItem(item_id);
  3105. if (master_item) {
  3106. Item* item = new Item(master_item);
  3107. item->details.count = quantity;
  3108. quest->AddSelectableRewardItem(item);
  3109. }
  3110. }
  3111. return 0;
  3112. }
  3113. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3114. if (!lua_interface)
  3115. return 0;
  3116. Quest* quest = lua_interface->GetQuest(state);
  3117. if (quest) {
  3118. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3119. vector<Item*>* items = quest->GetRewardItems();
  3120. if (items) {
  3121. vector<Item*>::iterator itr;
  3122. for (itr = items->begin(); itr != items->end(); itr++) {
  3123. if (*itr && (*itr)->details.item_id == item_id) {
  3124. lua_interface->SetBooleanValue(state, true);
  3125. return 1;
  3126. }
  3127. }
  3128. }
  3129. }
  3130. lua_interface->SetBooleanValue(state, false);
  3131. return 1;
  3132. }
  3133. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3134. if (!lua_interface)
  3135. return 0;
  3136. Quest* quest = lua_interface->GetQuest(state);
  3137. if (quest) {
  3138. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3139. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3140. if (quantity == 0)
  3141. quantity = 1;
  3142. Item* master_item = master_item_list.GetItem(item_id);
  3143. if (master_item) {
  3144. Item* item = new Item(master_item);
  3145. item->details.count = quantity;
  3146. quest->AddRewardItem(item);
  3147. }
  3148. }
  3149. return 0;
  3150. }
  3151. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3152. if (!lua_interface)
  3153. return 0;
  3154. Quest* quest = lua_interface->GetQuest(state);
  3155. if (quest) {
  3156. int32 copper = lua_interface->GetInt32Value(state, 2);
  3157. int32 silver = lua_interface->GetInt32Value(state, 3);
  3158. int32 gold = lua_interface->GetInt32Value(state, 4);
  3159. int32 plat = lua_interface->GetInt32Value(state, 5);
  3160. quest->AddRewardCoins(copper, silver, gold, plat);
  3161. }
  3162. return 0;
  3163. }
  3164. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3165. if (!lua_interface)
  3166. return 0;
  3167. Quest* quest = lua_interface->GetQuest(state);
  3168. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3169. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3170. if (quest && faction_id > 0 && amount != 0)
  3171. quest->AddRewardFaction(faction_id, amount);
  3172. return 0;
  3173. }
  3174. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3175. if (!lua_interface)
  3176. return 0;
  3177. Quest* quest = lua_interface->GetQuest(state);
  3178. if (quest) {
  3179. int32 status = lua_interface->GetInt32Value(state, 2);
  3180. quest->SetRewardStatus(status);
  3181. }
  3182. return 0;
  3183. }
  3184. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3185. if (!lua_interface)
  3186. return 0;
  3187. Quest* quest = lua_interface->GetQuest(state);
  3188. if (quest) {
  3189. string comment = lua_interface->GetStringValue(state, 2);
  3190. quest->SetRewardComment(comment);
  3191. }
  3192. return 0;
  3193. }
  3194. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3195. if (!lua_interface)
  3196. return 0;
  3197. Quest* quest = lua_interface->GetQuest(state);
  3198. if (quest) {
  3199. int32 exp = lua_interface->GetInt32Value(state, 2);
  3200. quest->SetRewardXP(exp);
  3201. }
  3202. return 0;
  3203. }
  3204. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3205. Quest* quest = lua_interface->GetQuest(state);
  3206. if (quest) {
  3207. int32 step = lua_interface->GetInt32Value(state, 2);
  3208. string description = lua_interface->GetStringValue(state, 3);
  3209. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3210. float percentage = lua_interface->GetFloatValue(state, 5);
  3211. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3212. int16 icon = lua_interface->GetInt16Value(state, 7);
  3213. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3214. const char* taskgroup = 0;
  3215. if (str_taskgroup.length() > 0)
  3216. taskgroup = str_taskgroup.c_str();
  3217. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3218. if (quest_step && icon && quantity > 0)
  3219. quest_step->SetIcon(icon);
  3220. }
  3221. return 0;
  3222. }
  3223. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3224. if (!lua_interface)
  3225. return 0;
  3226. Quest* quest = lua_interface->GetQuest(state);
  3227. if (quest) {
  3228. int32 step = lua_interface->GetInt32Value(state, 2);
  3229. string description = lua_interface->GetStringValue(state, 3);
  3230. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3231. float percentage = lua_interface->GetFloatValue(state, 5);
  3232. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3233. int16 icon = lua_interface->GetInt16Value(state, 7);
  3234. const char* taskgroup = 0;
  3235. if (str_taskgroup.length() > 0)
  3236. taskgroup = str_taskgroup.c_str();
  3237. int32 npc_id = 0;
  3238. vector<int32>* ids = 0;
  3239. Spawn* spawn = nullptr;
  3240. int i = 0;
  3241. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3242. if (ids == 0)
  3243. ids = new vector<int32>;
  3244. ids->push_back(npc_id);
  3245. i++;
  3246. }
  3247. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3248. if (quest_step && icon > 0 && quantity > 0)
  3249. quest_step->SetIcon(icon);
  3250. if (quest->GetPlayer()) {
  3251. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3252. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3253. }
  3254. }
  3255. return 0;
  3256. }
  3257. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3258. if (!lua_interface)
  3259. return 0;
  3260. Quest* quest = lua_interface->GetQuest(state);
  3261. if (quest) {
  3262. int32 step = lua_interface->GetInt32Value(state, 2);
  3263. string description = lua_interface->GetStringValue(state, 3);
  3264. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3265. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3266. int16 icon = lua_interface->GetInt16Value(state, 6);
  3267. const char* taskgroup = 0;
  3268. if (str_taskgroup.length() > 0)
  3269. taskgroup = str_taskgroup.c_str();
  3270. int32 npc_id = 0;
  3271. vector<int32>* ids = 0;
  3272. int i = 0;
  3273. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3274. if (ids == 0)
  3275. ids = new vector<int32>;
  3276. ids->push_back(npc_id);
  3277. i++;
  3278. }
  3279. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3280. if (quest_step && icon > 0)
  3281. quest_step->SetIcon(icon);
  3282. if (quest->GetPlayer()) {
  3283. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3284. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3285. }
  3286. }
  3287. return 0;
  3288. }
  3289. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3290. if (!lua_interface)
  3291. return 0;
  3292. Quest* quest = lua_interface->GetQuest(state);
  3293. if (quest) {
  3294. int32 step = lua_interface->GetInt32Value(state, 2);
  3295. string description = lua_interface->GetStringValue(state, 3);
  3296. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3297. float percentage = lua_interface->GetFloatValue(state, 5);
  3298. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3299. int16 icon = lua_interface->GetInt16Value(state, 7);
  3300. const char* taskgroup = 0;
  3301. if (str_taskgroup.length() > 0)
  3302. taskgroup = str_taskgroup.c_str();
  3303. int32 item_id = 0;
  3304. vector<int32>* ids = 0;
  3305. int i = 0;
  3306. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3307. if (ids == 0)
  3308. ids = new vector<int32>;
  3309. ids->push_back(item_id);
  3310. i++;
  3311. }
  3312. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3313. if (quest_step && icon > 0 && quantity > 0)
  3314. quest_step->SetIcon(icon);
  3315. if (quest->GetPlayer()) {
  3316. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3317. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3318. }
  3319. }
  3320. return 0;
  3321. }
  3322. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3323. if (!lua_interface)
  3324. return 0;
  3325. Quest* quest = lua_interface->GetQuest(state);
  3326. if (quest) {
  3327. int32 step = lua_interface->GetInt32Value(state, 2);
  3328. string description = lua_interface->GetStringValue(state, 3);
  3329. float max_variation = lua_interface->GetFloatValue(state, 4);
  3330. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3331. int16 icon = lua_interface->GetInt16Value(state, 6);
  3332. const char* taskgroup = 0;
  3333. if (str_taskgroup.length() > 0)
  3334. taskgroup = str_taskgroup.c_str();
  3335. vector<Location>* locations = 0;
  3336. int i = 7;
  3337. while (true) {
  3338. Location loc;
  3339. loc.x = lua_interface->GetFloatValue(state, i);
  3340. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3341. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3342. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3343. break;
  3344. if (locations == 0)
  3345. locations = new vector<Location>;
  3346. locations->push_back(loc);
  3347. i += 3;
  3348. }
  3349. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3350. if (quest_step && icon > 0)
  3351. quest_step->SetIcon(icon);
  3352. if (quest->GetPlayer()) {
  3353. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3354. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3355. }
  3356. }
  3357. return 0;
  3358. }
  3359. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3360. if (!lua_interface)
  3361. return 0;
  3362. Quest* quest = lua_interface->GetQuest(state);
  3363. if (quest) {
  3364. int32 step = lua_interface->GetInt32Value(state, 2);
  3365. string description = lua_interface->GetStringValue(state, 3);
  3366. float max_variation = lua_interface->GetFloatValue(state, 4);
  3367. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3368. int16 icon = lua_interface->GetInt16Value(state, 6);
  3369. const char* taskgroup = 0;
  3370. if (str_taskgroup.length() > 0)
  3371. taskgroup = str_taskgroup.c_str();
  3372. vector<Location>* locations = 0;
  3373. int i = 7;
  3374. while (true) {
  3375. Location loc;
  3376. loc.x = lua_interface->GetFloatValue(state, i);
  3377. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3378. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3379. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3380. break;
  3381. if (locations == 0)
  3382. locations = new vector<Location>;
  3383. locations->push_back(loc);
  3384. i += 3;
  3385. }
  3386. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3387. if (quest_step && icon > 0)
  3388. quest_step->SetIcon(icon);
  3389. if (quest->GetPlayer()) {
  3390. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3391. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3392. }
  3393. }
  3394. return 0;
  3395. }
  3396. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3397. Quest* quest = lua_interface->GetQuest(state);
  3398. if (quest) {
  3399. int32 step = lua_interface->GetInt32Value(state, 2);
  3400. string description = lua_interface->GetStringValue(state, 3);
  3401. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3402. float percentage = lua_interface->GetFloatValue(state, 5);
  3403. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3404. int16 icon = lua_interface->GetInt16Value(state, 7);
  3405. const char* taskgroup = 0;
  3406. if (str_taskgroup.length() > 0)
  3407. taskgroup = str_taskgroup.c_str();
  3408. int32 spell_id = 0;
  3409. vector<int32>* ids = 0;
  3410. int i = 0;
  3411. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3412. if (ids == 0)
  3413. ids = new vector<int32>;
  3414. ids->push_back(spell_id);
  3415. i++;
  3416. }
  3417. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3418. if (quest_step && icon > 0 && quantity > 0)
  3419. quest_step->SetIcon(icon);
  3420. if (quest->GetPlayer()) {
  3421. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3422. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3423. }
  3424. }
  3425. return 0;
  3426. }
  3427. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3428. if (!lua_interface)
  3429. return 0;
  3430. Quest* quest = lua_interface->GetQuest(state);
  3431. if (quest) {
  3432. int32 step = lua_interface->GetInt32Value(state, 2);
  3433. string description = lua_interface->GetStringValue(state, 3);
  3434. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3435. float percentage = lua_interface->GetFloatValue(state, 5);
  3436. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3437. int16 icon = lua_interface->GetInt16Value(state, 7);
  3438. const char* taskgroup = 0;
  3439. if (str_taskgroup.length() > 0)
  3440. taskgroup = str_taskgroup.c_str();
  3441. int32 item_id = 0;
  3442. vector<int32>* ids = 0;
  3443. int i = 0;
  3444. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3445. if (ids == 0)
  3446. ids = new vector<int32>;
  3447. ids->push_back(item_id);
  3448. i++;
  3449. }
  3450. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3451. if (quest_step && icon > 0 && quantity > 0)
  3452. quest_step->SetIcon(icon);
  3453. if (quest->GetPlayer()) {
  3454. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3455. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3456. }
  3457. }
  3458. return 0;
  3459. }
  3460. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3461. if (!lua_interface)
  3462. return 0;
  3463. Quest* quest = lua_interface->GetQuest(state);
  3464. if (quest) {
  3465. int32 step = lua_interface->GetInt32Value(state, 2);
  3466. string description = lua_interface->GetStringValue(state, 3);
  3467. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3468. float percentage = lua_interface->GetFloatValue(state, 5);
  3469. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3470. int16 icon = lua_interface->GetInt16Value(state, 7);
  3471. const char* taskgroup = 0;
  3472. if (str_taskgroup.length() > 0)
  3473. taskgroup = str_taskgroup.c_str();
  3474. int32 item_id = 0;
  3475. vector<int32>* ids = 0;
  3476. int i = 0;
  3477. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3478. if (ids == 0)
  3479. ids = new vector<int32>;
  3480. ids->push_back(item_id);
  3481. i++;
  3482. }
  3483. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3484. if (quest_step && icon > 0 && quantity > 0)
  3485. quest_step->SetIcon(icon);
  3486. if (quest->GetPlayer()) {
  3487. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3488. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3489. }
  3490. }
  3491. return 0;
  3492. }
  3493. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3494. if (!lua_interface)
  3495. return 0;
  3496. Quest* quest = lua_interface->GetQuest(state);
  3497. if (quest) {
  3498. string action = lua_interface->GetStringValue(state, 2);
  3499. if (action.length() > 0)
  3500. quest->SetCompleteAction(action);
  3501. }
  3502. return 0;
  3503. }
  3504. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3505. if (!lua_interface)
  3506. return 0;
  3507. Quest* quest = lua_interface->GetQuest(state);
  3508. if (quest) {
  3509. int32 step = lua_interface->GetInt32Value(state, 2);
  3510. string action = lua_interface->GetStringValue(state, 3);
  3511. if (step > 0 && action.length() > 0)
  3512. quest->AddCompleteAction(step, action);
  3513. }
  3514. return 0;
  3515. }
  3516. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Quest* quest = lua_interface->GetQuest(state);
  3520. if (quest) {
  3521. int32 step = lua_interface->GetInt32Value(state, 2);
  3522. string action = lua_interface->GetStringValue(state, 3);
  3523. if (step > 0 && action.length() > 0)
  3524. quest->AddProgressAction(step, action);
  3525. }
  3526. return 0;
  3527. }
  3528. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3529. if (!lua_interface)
  3530. return 0;
  3531. Quest* quest = lua_interface->GetQuest(state);
  3532. string description = lua_interface->GetStringValue(state, 2);
  3533. if (quest && description.length() > 0)
  3534. quest->SetDescription(description);
  3535. return 0;
  3536. }
  3537. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3538. if (!lua_interface)
  3539. return 0;
  3540. Quest* quest = lua_interface->GetQuest(state);
  3541. string description = lua_interface->GetStringValue(state, 2);
  3542. if (quest && description.length() > 0)
  3543. quest->SetCompletedDescription(description);
  3544. return 0;
  3545. }
  3546. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3547. if (!lua_interface)
  3548. return 0;
  3549. Quest* quest = lua_interface->GetQuest(state);
  3550. int32 step = lua_interface->GetInt32Value(state, 2);
  3551. string description = lua_interface->GetStringValue(state, 3);
  3552. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3553. if (quest && step > 0 && description.length() > 0) {
  3554. quest->SetTaskGroupDescription(step, description, display_bullets);
  3555. if (quest->GetPlayer()) {
  3556. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3557. if (client)
  3558. client->SendQuestUpdateStep(quest, step, false);
  3559. }
  3560. }
  3561. return 0;
  3562. }
  3563. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3564. if (!lua_interface)
  3565. return 0;
  3566. Quest* quest = lua_interface->GetQuest(state);
  3567. int32 step = lua_interface->GetInt32Value(state, 2);
  3568. string description = lua_interface->GetStringValue(state, 3);
  3569. if (quest && step > 0 && description.length() > 0) {
  3570. quest->SetStepDescription(step, description);
  3571. if (quest->GetPlayer()) {
  3572. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3573. if (client)
  3574. client->SendQuestUpdateStepImmediately(quest, step);
  3575. }
  3576. }
  3577. return 0;
  3578. }
  3579. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3580. Quest* quest = lua_interface->GetQuest(state);
  3581. string zone = lua_interface->GetStringValue(state, 2);
  3582. if (quest && zone.length() > 0)
  3583. quest->SetZone(zone);
  3584. return 0;
  3585. }
  3586. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3587. if (!lua_interface)
  3588. return 0;
  3589. Quest* quest = lua_interface->GetQuest(state);
  3590. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3591. int32 coin = lua_interface->GetInt32Value(state, 3);
  3592. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3593. string rewards_str = lua_interface->GetStringValue(state, 5);
  3594. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3595. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3596. string text = lua_interface->GetStringValue(state, 8);
  3597. int32 source_id = 0;
  3598. if (playerSpawn && playerSpawn->IsPlayer()) {
  3599. Player* player = (Player*)playerSpawn;
  3600. Client* client = player->GetZone()->GetClientBySpawn(player);
  3601. if (client) {
  3602. vector<Item*> reward_items;
  3603. vector<Item*> selectable_reward_items;
  3604. if (rewards_str.length() > 0) {
  3605. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3606. map<unsigned int, unsigned short>::iterator itr;
  3607. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3608. if (itr->first > 0) {
  3609. Item* item = new Item(master_item_list.GetItem(itr->first));
  3610. if (item) {
  3611. if (itr->second > 0)
  3612. item->details.count = itr->second;
  3613. reward_items.push_back(item);
  3614. }
  3615. }
  3616. }
  3617. }
  3618. if (select_rewards_str.length() > 0) {
  3619. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3620. map<unsigned int, unsigned short>::iterator itr;
  3621. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3622. if (itr->first > 0) {
  3623. Item* item = new Item(master_item_list.GetItem(itr->first));
  3624. if (item) {
  3625. if (itr->second > 0)
  3626. item->stack_count = itr->second;
  3627. selectable_reward_items.push_back(item);
  3628. }
  3629. }
  3630. }
  3631. }
  3632. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3633. const char* reward_type = "Quest Reward!";
  3634. if (!quest)
  3635. reward_type = "Reward!";
  3636. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3637. }
  3638. }
  3639. return 0;
  3640. }
  3641. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3642. if (!lua_interface)
  3643. return 0;
  3644. Quest* quest = lua_interface->GetQuest(state);
  3645. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3646. if (quest && spawn) {
  3647. if (spawn->IsPlayer()) {
  3648. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3649. if (client)
  3650. client->AddPendingQuestReward(quest);
  3651. }
  3652. }
  3653. return 0;
  3654. }
  3655. int EQ2Emu_lua_Harvest(lua_State* state) {
  3656. if (!lua_interface)
  3657. return 0;
  3658. Spawn* player = lua_interface->GetSpawn(state);
  3659. Spawn* node = lua_interface->GetSpawn(state, 2);
  3660. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3661. Client* client = player->GetZone()->GetClientBySpawn(player);
  3662. if (client) {
  3663. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3664. ((GroundSpawn*)node)->ProcessHarvest(client);
  3665. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3666. player->GetZone()->RemoveSpawn(true, node, true);
  3667. }
  3668. }
  3669. else if (player && player->IsPlayer()) {
  3670. Client* client = player->GetZone()->GetClientBySpawn(player);
  3671. if (client)
  3672. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3673. }
  3674. return 0;
  3675. }
  3676. int EQ2Emu_lua_Bind(lua_State* state) {
  3677. if (!lua_interface)
  3678. return 0;
  3679. Spawn* spawn = lua_interface->GetSpawn(state);
  3680. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3681. float x = lua_interface->GetFloatValue(state, 3);
  3682. float y = lua_interface->GetFloatValue(state, 4);
  3683. float z = lua_interface->GetFloatValue(state, 5);
  3684. float h = lua_interface->GetFloatValue(state, 6);
  3685. if (!spawn) {
  3686. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3687. return 0;
  3688. }
  3689. if (!spawn->IsPlayer()) {
  3690. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3691. return 0;
  3692. }
  3693. if (zone_id == 0) {
  3694. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3695. if (!client) {
  3696. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3697. return 0;
  3698. }
  3699. if (!client->Bind())
  3700. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3701. }
  3702. else {
  3703. Player* player = (Player*)spawn;
  3704. player->GetPlayerInfo()->SetBindZone(zone_id);
  3705. player->GetPlayerInfo()->SetBindX(x);
  3706. player->GetPlayerInfo()->SetBindY(y);
  3707. player->GetPlayerInfo()->SetBindZ(z);
  3708. player->GetPlayerInfo()->SetBindHeading(h);
  3709. }
  3710. return 0;
  3711. }
  3712. int EQ2Emu_lua_Gate(lua_State* state) {
  3713. if (!lua_interface)
  3714. return 0;
  3715. Spawn* spawn = lua_interface->GetSpawn(state);
  3716. if (spawn) {
  3717. if (spawn->IsPlayer()) {
  3718. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3719. if (client) {
  3720. if (!client->Gate())
  3721. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3722. }
  3723. }
  3724. }
  3725. return 0;
  3726. }
  3727. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3728. if (!lua_interface)
  3729. return 0;
  3730. bool ret = false;
  3731. Spawn* spawn = lua_interface->GetSpawn(state);
  3732. if (spawn) {
  3733. if (spawn->IsPlayer()) {
  3734. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3735. if (client)
  3736. ret = client->BindAllowed();
  3737. }
  3738. }
  3739. lua_interface->SetBooleanValue(state, ret);
  3740. return 1;
  3741. }
  3742. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3743. if (!lua_interface)
  3744. return 0;
  3745. bool ret = false;
  3746. Spawn* spawn = lua_interface->GetSpawn(state);
  3747. if (spawn) {
  3748. if (spawn->IsPlayer()) {
  3749. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3750. if (client)
  3751. ret = client->GateAllowed();
  3752. }
  3753. }
  3754. lua_interface->SetBooleanValue(state, ret);
  3755. return 1;
  3756. }
  3757. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3758. Spawn* spawn = lua_interface->GetSpawn(state);
  3759. if (spawn) {
  3760. lua_interface->SetBooleanValue(state, spawn->Alive());
  3761. return 1;
  3762. }
  3763. return 0;
  3764. }
  3765. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3766. if (!lua_interface)
  3767. return 0;
  3768. Spawn* spawn = lua_interface->GetSpawn(state);
  3769. if (spawn && spawn->IsEntity()) {
  3770. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3771. return 1;
  3772. }
  3773. return 0;
  3774. }
  3775. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3776. Spawn* spawn = lua_interface->GetSpawn(state);
  3777. string message = lua_interface->GetStringValue(state, 2);
  3778. string color_str = lua_interface->GetStringValue(state, 3);
  3779. int8 color = CHANNEL_NARRATIVE;
  3780. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3781. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3782. if (client) {
  3783. if (color_str.length() > 0) {
  3784. // leave for backwards compat, but all future should just use the number
  3785. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3786. color = CHANNEL_COLOR_RED;
  3787. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3788. color = CHANNEL_COLOR_YELLOW;
  3789. else
  3790. {
  3791. // use a number to specify the channel as per Commands/Commands.h defines
  3792. color = (int8)atoul(color_str.c_str());
  3793. }
  3794. }
  3795. client->SimpleMessage(color, message.c_str());
  3796. }
  3797. }
  3798. return 0;
  3799. }
  3800. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3801. Spawn* spawn = lua_interface->GetSpawn(state);
  3802. string message = lua_interface->GetStringValue(state, 2);
  3803. int8 red = lua_interface->GetInt8Value(state, 3);
  3804. int8 green = lua_interface->GetInt8Value(state, 4);
  3805. int8 blue = lua_interface->GetInt8Value(state, 5);
  3806. if (!spawn) {
  3807. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3808. return 0;
  3809. }
  3810. int32 words = ::CountWordsInString(message.c_str());
  3811. if (words < 5)
  3812. words = 5;
  3813. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3814. if (client)
  3815. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3816. return 0;
  3817. }
  3818. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3819. Spawn* spawn = lua_interface->GetSpawn(state);
  3820. int8 param = lua_interface->GetInt8Value(state, 2);
  3821. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3822. int8 value = lua_interface->GetInt8Value(state, 4);
  3823. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3824. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3825. if (client) {
  3826. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3827. switch (param) {
  3828. case 1: {
  3829. packet->setDataByName("parameter1", param_value);
  3830. break;
  3831. }
  3832. case 2: {
  3833. packet->setDataByName("parameter2", param_value);
  3834. break;
  3835. }
  3836. case 3: {
  3837. packet->setDataByName("parameter3", param_value);
  3838. break;
  3839. }
  3840. case 4: {
  3841. packet->setDataByName("parameter4", param_value);
  3842. break;
  3843. }
  3844. case 5: {
  3845. packet->setDataByName("parameter5", param_value);
  3846. break;
  3847. }
  3848. }
  3849. packet->setDataByName("value", value);
  3850. client->QueuePacket(packet->serialize());
  3851. safe_delete(packet);
  3852. }
  3853. }
  3854. return 0;
  3855. }
  3856. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3857. Spawn* spawn = lua_interface->GetSpawn(state);
  3858. if (spawn && spawn->IsPlayer()) {
  3859. if (((Player*)spawn)->GetIsTracking())
  3860. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3861. else
  3862. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3863. }
  3864. return 0;
  3865. }
  3866. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3867. Spawn* player = lua_interface->GetSpawn(state);
  3868. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3869. string name = lua_interface->GetStringValue(state, 3);
  3870. float distance = lua_interface->GetFloatValue(state, 4);
  3871. string command = lua_interface->GetStringValue(state, 5);
  3872. string error_text = lua_interface->GetStringValue(state, 6);
  3873. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3874. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3875. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3876. if (spawn) {
  3877. if (distance == 0)
  3878. distance = 10.0f;
  3879. if (command.length() == 0)
  3880. command = name;
  3881. if (command.length() < 1 && name.length() < 1)
  3882. {
  3883. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3884. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3885. spawn->RemovePrimaryCommands();
  3886. }
  3887. else
  3888. {
  3889. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3890. }
  3891. }
  3892. return 0;
  3893. }
  3894. int EQ2Emu_lua_HasSpell(lua_State* state) {
  3895. if (!lua_interface)
  3896. return 0;
  3897. Spawn* player = lua_interface->GetSpawn(state);
  3898. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3899. int16 tier = lua_interface->GetInt16Value(state, 3);
  3900. if (player && player->IsPlayer()) {
  3901. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  3902. return 1;
  3903. }
  3904. return 0;
  3905. }
  3906. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3907. if (!lua_interface)
  3908. return 0;
  3909. Spawn* player = lua_interface->GetSpawn(state);
  3910. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3911. int16 tier = lua_interface->GetInt16Value(state, 3);
  3912. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3913. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  3914. bool add_to_hotbar = true;
  3915. if (num_args > 4) {
  3916. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  3917. }
  3918. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3919. if (player && spell && player->IsPlayer()) {
  3920. Client* client = player->GetClient();
  3921. if (client) {
  3922. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3923. {
  3924. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3925. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3926. client->GetPlayer()->UnlockSpell(spell);
  3927. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3928. }
  3929. else
  3930. {
  3931. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3932. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3933. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3934. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3935. client->GetPlayer()->UnlockSpell(spell);
  3936. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3937. }
  3938. //if (client ) {
  3939. // ((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);
  3940. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3941. if (outapp)
  3942. client->QueuePacket(outapp);
  3943. }
  3944. }
  3945. return 0;
  3946. }
  3947. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3948. if (!lua_interface)
  3949. return 0;
  3950. Spawn* player = lua_interface->GetSpawn(state);
  3951. if (player && player->IsPlayer()) {
  3952. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3953. return 1;
  3954. }
  3955. return 0;
  3956. }
  3957. int EQ2Emu_lua_Attack(lua_State* state) {
  3958. if (lua_interface) {
  3959. Spawn* npc = lua_interface->GetSpawn(state);
  3960. Spawn* player = lua_interface->GetSpawn(state, 2);
  3961. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3962. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3963. }
  3964. return 0;
  3965. }
  3966. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3967. if (lua_interface) {
  3968. Spawn* target = lua_interface->GetSpawn(state);
  3969. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3970. if (target && target->GetZone())
  3971. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3972. }
  3973. return 0;
  3974. }
  3975. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3976. Spawn* player;
  3977. if (lua_interface) {
  3978. player = lua_interface->GetSpawn(state);
  3979. if (player && player->IsPlayer()) {
  3980. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3981. return 1;
  3982. }
  3983. }
  3984. return 0;
  3985. }
  3986. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3987. Spawn* player;
  3988. Client* client;
  3989. if (lua_interface) {
  3990. player = lua_interface->GetSpawn(state);
  3991. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3992. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3993. client->HandInCollections();
  3994. }
  3995. return 0;
  3996. }
  3997. int EQ2Emu_lua_UseWidget(lua_State* state) {
  3998. Spawn* widget;
  3999. if (lua_interface) {
  4000. widget = lua_interface->GetSpawn(state);
  4001. if (widget && widget->IsWidget())
  4002. ((Widget*)widget)->HandleUse(NULL, "");
  4003. }
  4004. return 0;
  4005. }
  4006. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4007. Spawn* spawn = 0;
  4008. int32 primary_list = 0;
  4009. int32 secondary_list = 0;
  4010. if (lua_interface) {
  4011. spawn = lua_interface->GetSpawn(state);
  4012. primary_list = lua_interface->GetInt32Value(state, 2);
  4013. secondary_list = lua_interface->GetInt32Value(state, 3);
  4014. if (!spawn->IsNPC()) {
  4015. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4016. return 0;
  4017. }
  4018. NPC* npc = (NPC*)spawn;
  4019. npc->SetPrimarySpellList(primary_list);
  4020. npc->SetSecondarySpellList(secondary_list);
  4021. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4022. }
  4023. return 0;
  4024. }
  4025. int EQ2Emu_lua_GetPet(lua_State* state) {
  4026. if (!lua_interface)
  4027. return 0;
  4028. Spawn* spawn = lua_interface->GetSpawn(state);
  4029. if (spawn) {
  4030. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4031. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4032. return 1;
  4033. }
  4034. }
  4035. return 0;
  4036. }
  4037. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4038. if (!lua_interface)
  4039. return 0;
  4040. Spawn* spawn = lua_interface->GetSpawn(state);
  4041. if (spawn) {
  4042. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4043. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4044. return 1;
  4045. }
  4046. }
  4047. return 0;
  4048. }
  4049. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4050. if (!lua_interface)
  4051. return 0;
  4052. Spawn* spawn = lua_interface->GetSpawn(state);
  4053. if (spawn) {
  4054. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4055. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4056. return 1;
  4057. }
  4058. }
  4059. return 0;
  4060. }
  4061. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4062. if (!lua_interface)
  4063. return 0;
  4064. Spawn* spawn = lua_interface->GetSpawn(state);
  4065. if (spawn) {
  4066. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4067. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4068. return 1;
  4069. }
  4070. }
  4071. return 0;
  4072. }
  4073. int EQ2Emu_lua_Charm(lua_State* state) {
  4074. if (!lua_interface)
  4075. return 0;
  4076. Spawn* owner = lua_interface->GetSpawn(state);
  4077. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4078. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4079. if (!luaspell) {
  4080. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4081. return 0;
  4082. }
  4083. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4084. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4085. pet->SetPet(true);
  4086. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4087. ((NPC*)pet)->SetOwner((Entity*)owner);
  4088. // If owner is player and player does not have a summoned pet set the players charsheet
  4089. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4090. Player* player = (Player*)owner;
  4091. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4092. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  4093. player->GetInfoStruct()->pet_movement = 2;
  4094. player->GetInfoStruct()->pet_behavior = 3;
  4095. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4096. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4097. // Make sure the values get sent to the client
  4098. player->SetCharSheetChanged(true);
  4099. }
  4100. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4101. pet->SetSpawnScript("");
  4102. // Set faction to the same as the owner
  4103. pet->SetFactionID(owner->GetFactionID());
  4104. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4105. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4106. // Clear hate list
  4107. ((NPC*)pet)->Brain()->ClearHate();
  4108. // Set the brain to a pet brain
  4109. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4110. }
  4111. return 0;
  4112. }
  4113. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4114. if (!lua_interface)
  4115. return 0;
  4116. Spawn* spawn = lua_interface->GetSpawn(state);
  4117. if (!spawn) {
  4118. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4119. return 0;
  4120. }
  4121. vector<Spawn*> groupMembers;
  4122. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4123. groupMembers = *spawn->GetSpawnGroup();
  4124. }
  4125. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4126. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4127. deque<GroupMemberInfo*>::iterator itr;
  4128. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4129. if (group)
  4130. {
  4131. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4132. deque<GroupMemberInfo*>* members = group->GetMembers();
  4133. GroupMemberInfo* info = 0;
  4134. for (itr = members->begin(); itr != members->end(); itr++) {
  4135. info = *itr;
  4136. if (info->client)
  4137. groupMembers.push_back(info->client->GetPlayer());
  4138. }
  4139. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4140. }
  4141. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4142. }
  4143. else
  4144. return 0;
  4145. lua_createtable(state, groupMembers.size(), 0);
  4146. int newTable = lua_gettop(state);
  4147. for (int32 i = 0; i < groupMembers.size(); i++) {
  4148. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4149. lua_rawseti(state, newTable, i + 1);
  4150. }
  4151. return 1;
  4152. }
  4153. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4154. if (!lua_interface)
  4155. return 0;
  4156. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4157. lua_interface->SetOptionWindowValue(state, option_window);
  4158. return 1;
  4159. }
  4160. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4161. if (!lua_interface)
  4162. return 0;
  4163. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4164. if (option_window) {
  4165. OptionWindowOption option_window_option;
  4166. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4167. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4168. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4169. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4170. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4171. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4172. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4173. option_window->push_back(option_window_option);
  4174. }
  4175. return 0;
  4176. }
  4177. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4178. if (!lua_interface)
  4179. return 0;
  4180. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4181. Spawn* player = lua_interface->GetSpawn(state, 2);
  4182. string window_title = lua_interface->GetStringValue(state, 3);
  4183. string cancel_command = lua_interface->GetStringValue(state, 4);
  4184. Client* client = player->GetZone()->GetClientBySpawn(player);
  4185. if (option_window && window_title.length() > 0 && client) {
  4186. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4187. if (!packet)
  4188. return 0;
  4189. packet->setDataByName("title_text", window_title.c_str());
  4190. if (cancel_command.length() > 0)
  4191. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4192. packet->setArrayLengthByName("num_selections", option_window->size());
  4193. vector<OptionWindowOption>::iterator itr;
  4194. int8 i = 0;
  4195. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4196. OptionWindowOption opt = *itr;
  4197. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4198. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4199. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4200. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4201. if (opt.optionCommand.length() > 0)
  4202. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4203. if (opt.optionConfirmTitle.length() > 0)
  4204. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4205. i++;
  4206. }
  4207. client->QueuePacket(packet->serialize());
  4208. safe_delete(option_window);
  4209. safe_delete(packet);
  4210. }
  4211. return 0;
  4212. }
  4213. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4214. if (!lua_interface)
  4215. return 0;
  4216. Spawn* spawn = lua_interface->GetSpawn(state);
  4217. if (spawn) {
  4218. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4219. return 1;
  4220. }
  4221. else
  4222. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4223. return 0;
  4224. }
  4225. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4226. if (!lua_interface)
  4227. return 0;
  4228. Spawn* spawn = lua_interface->GetSpawn(state);
  4229. if (spawn) {
  4230. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4231. return 1;
  4232. }
  4233. else
  4234. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4235. return 0;
  4236. }
  4237. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4238. if (!lua_interface)
  4239. return 0;
  4240. Spawn* spawn = lua_interface->GetSpawn(state);
  4241. if (spawn) {
  4242. int8 class_id = spawn->GetTradeskillClass();
  4243. // Need to add 42 for the offset in the array
  4244. class_id += 44;
  4245. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4246. return 1;
  4247. }
  4248. else
  4249. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4250. return 0;
  4251. }
  4252. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4253. if (!lua_interface)
  4254. return 0;
  4255. Spawn* spawn = lua_interface->GetSpawn(state);
  4256. int16 level = lua_interface->GetInt8Value(state, 2);
  4257. if (spawn) {
  4258. if (spawn->IsPlayer())
  4259. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4260. else
  4261. spawn->SetTSLevel(level);
  4262. }
  4263. else
  4264. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4265. return 0;
  4266. }
  4267. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4268. if (!lua_interface)
  4269. return 0;
  4270. Spawn* spawn = lua_interface->GetSpawn(state);
  4271. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4272. if (spawn) {
  4273. spawn->SetAttackable(attackable);
  4274. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4275. }
  4276. return 0;
  4277. }
  4278. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4279. // Check to see if we have a valid lua_interface
  4280. if (!lua_interface)
  4281. return 0;
  4282. // Get the spawn that is getting the pet
  4283. Spawn* spawn = lua_interface->GetSpawn(state);
  4284. // Get the DB ID of the pet
  4285. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4286. // The max level the pet can gain
  4287. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4288. // Get the spell that this command was called from
  4289. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4290. // Check to make sure the spawn pointer is valid
  4291. if (!spawn) {
  4292. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4293. return 0;
  4294. }
  4295. // Check to make sure the spawn is an entity
  4296. if (!spawn->IsEntity()) {
  4297. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4298. return 0;
  4299. }
  4300. // Check to make sure the spawn doesn't already have a pet of this type
  4301. if (((Entity*)spawn)->GetPet()) {
  4302. if (spawn->IsPlayer()) {
  4303. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4304. if (client)
  4305. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4306. }
  4307. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4308. return 0;
  4309. }
  4310. // Check to see if the DB ID for the pet is set
  4311. if (pet_id == 0) {
  4312. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4313. return 0;
  4314. }
  4315. // Check to see if the pointer to the spell is valid
  4316. if (!luaspell) {
  4317. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4318. return 0;
  4319. }
  4320. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4321. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4322. if (!pet) {
  4323. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4324. return 0;
  4325. }
  4326. // Check to make sure the pet is an npc
  4327. if (!pet->IsNPC()) {
  4328. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4329. return 0;
  4330. }
  4331. // Spawn the pet at the same location as the owner
  4332. pet->SetX(spawn->GetX());
  4333. pet->SetY(spawn->GetY());
  4334. pet->SetZ(spawn->GetZ());
  4335. pet->SetLocation(spawn->GetLocation());
  4336. pet->SetHeading(spawn->GetHeading());
  4337. spawn->GetZone()->AddSpawn(pet);
  4338. /*
  4339. const char* spawn_script = world.GetSpawnScript(pet_id);
  4340. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4341. spawn->SetSpawnScript(string(spawn_script));
  4342. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4343. }*/
  4344. // Get a random pet name
  4345. string random_pet_name;
  4346. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4347. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4348. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4349. // If player set various values for the char sheet (pet window)
  4350. if (spawn->IsPlayer()) {
  4351. Player* player = (Player*)spawn;
  4352. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4353. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  4354. player->GetInfoStruct()->pet_movement = 2;
  4355. player->GetInfoStruct()->pet_behavior = 3;
  4356. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4357. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4358. // Make sure the values get sent to the client
  4359. player->SetCharSheetChanged(true);
  4360. }
  4361. // Set the pets name
  4362. pet->SetName(random_pet_name.c_str());
  4363. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4364. if (max_level > 0)
  4365. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4366. else
  4367. pet->SetLevel(spawn->GetLevel());
  4368. // Set the max level this pet can reach
  4369. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4370. // Set the faction of the pet to the same faction as the owner
  4371. pet->SetFactionID(spawn->GetFactionID());
  4372. // Set the spawn as a pet
  4373. pet->SetPet(true);
  4374. // Give a pointer of the owner to the pet
  4375. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4376. // Give a pointer of the pet to the owner
  4377. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4378. // Set the pet type
  4379. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4380. // Set the spell id used to create this pet
  4381. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4382. // Set the spell tier used to create this pet
  4383. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4384. // Set the pets spawn type to 6
  4385. pet->SetSpawnType(6);
  4386. // Set the pets brain
  4387. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4388. // Check to see if the pet has a subtitle
  4389. if (strlen(pet->GetSubTitle()) > 0) {
  4390. // Add the players name to the front of the sub title
  4391. string pet_subtitle;
  4392. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4393. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4394. // Set the pets subtitle to the new one
  4395. pet->SetSubTitle(pet_subtitle.c_str());
  4396. }
  4397. // Add the "Pet Options" entity command to the pet
  4398. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4399. // Set the pet as the return value for this function
  4400. lua_interface->SetSpawnValue(state, pet);
  4401. return 1;
  4402. }
  4403. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4404. if (!lua_interface)
  4405. return 0;
  4406. Spawn* spawn = lua_interface->GetSpawn(state);
  4407. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4408. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4409. if (!spawn) {
  4410. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4411. return 0;
  4412. }
  4413. if (!spawn->IsEntity()) {
  4414. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4415. return 0;
  4416. }
  4417. if (((Entity*)spawn)->GetDeityPet()) {
  4418. if (spawn->IsPlayer()) {
  4419. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4420. if (client)
  4421. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4422. }
  4423. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4424. return 0;
  4425. }
  4426. if (pet_id == 0) {
  4427. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4428. return 0;
  4429. }
  4430. if (!luaspell) {
  4431. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4432. return 0;
  4433. }
  4434. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4435. if (!pet) {
  4436. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4437. return 0;
  4438. }
  4439. if (!pet->IsNPC()) {
  4440. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4441. return 0;
  4442. }
  4443. pet->SetX(spawn->GetX());
  4444. pet->SetY(spawn->GetY());
  4445. pet->SetZ(spawn->GetZ());
  4446. pet->SetLocation(spawn->GetLocation());
  4447. pet->SetHeading(spawn->GetHeading());
  4448. spawn->GetZone()->AddSpawn(pet);
  4449. string random_pet_name;
  4450. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4451. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4452. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4453. pet->SetName(random_pet_name.c_str());
  4454. pet->SetLevel(spawn->GetLevel());
  4455. pet->SetFactionID(spawn->GetFactionID());
  4456. pet->SetPet(true);
  4457. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4458. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4459. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4460. pet->SetSpawnType(6);
  4461. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4462. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4463. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4464. if (strlen(pet->GetSubTitle()) > 0) {
  4465. string pet_subtitle;
  4466. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4467. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4468. pet->SetSubTitle(pet_subtitle.c_str());
  4469. }
  4470. // deity and cosmetic pets are not attackable
  4471. pet->SetAttackable(false);
  4472. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4473. lua_interface->SetSpawnValue(state, pet);
  4474. return 1;
  4475. }
  4476. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4477. if (!lua_interface)
  4478. return 0;
  4479. Spawn* spawn = lua_interface->GetSpawn(state);
  4480. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4481. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4482. if (!spawn) {
  4483. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4484. return 0;
  4485. }
  4486. if (!spawn->IsEntity()) {
  4487. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4488. return 0;
  4489. }
  4490. if (((Entity*)spawn)->GetCosmeticPet()) {
  4491. if (spawn->IsPlayer()) {
  4492. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4493. if (client)
  4494. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4495. }
  4496. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4497. return 0;
  4498. }
  4499. if (pet_id == 0) {
  4500. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4501. return 0;
  4502. }
  4503. if (!luaspell) {
  4504. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4505. return 0;
  4506. }
  4507. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4508. if (!pet) {
  4509. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4510. return 0;
  4511. }
  4512. if (!pet->IsNPC()) {
  4513. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4514. return 0;
  4515. }
  4516. pet->SetX(spawn->GetX());
  4517. pet->SetY(spawn->GetY());
  4518. pet->SetZ(spawn->GetZ());
  4519. pet->SetLocation(spawn->GetLocation());
  4520. pet->SetHeading(spawn->GetHeading());
  4521. spawn->GetZone()->AddSpawn(pet);
  4522. string random_pet_name;
  4523. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4524. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4525. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4526. pet->SetName(random_pet_name.c_str());
  4527. pet->SetLevel(spawn->GetLevel());
  4528. pet->SetFactionID(spawn->GetFactionID());
  4529. pet->SetPet(true);
  4530. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4531. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4532. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4533. pet->SetSpawnType(6);
  4534. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4535. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4536. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4537. if (strlen(pet->GetSubTitle()) > 0) {
  4538. string pet_subtitle;
  4539. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4540. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4541. pet->SetSubTitle(pet_subtitle.c_str());
  4542. }
  4543. pet->SetAttackable(false);
  4544. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4545. lua_interface->SetSpawnValue(state, pet);
  4546. return 1;
  4547. }
  4548. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4549. if (!lua_interface)
  4550. return 0;
  4551. Spawn* spawn = lua_interface->GetSpawn(state);
  4552. if (!spawn) {
  4553. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4554. return 0;
  4555. }
  4556. if (!spawn->IsPet()) {
  4557. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4558. return 0;
  4559. }
  4560. if (!((NPC*)spawn)->IsDismissing())
  4561. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  4562. return 0;
  4563. }
  4564. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4565. if (!lua_interface)
  4566. return 0;
  4567. Quest* quest = lua_interface->GetQuest(state);
  4568. if (!quest) {
  4569. 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));
  4570. return 0;
  4571. }
  4572. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4573. if (feather_color > 0)
  4574. quest->SetFeatherColor(feather_color);
  4575. return 0;
  4576. }
  4577. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4578. if (!lua_interface)
  4579. return 0;
  4580. Spawn* spawn = lua_interface->GetSpawn(state);
  4581. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4582. if (!spawn) {
  4583. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4584. return 0;
  4585. }
  4586. if (!spawn2) {
  4587. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4588. return 0;
  4589. }
  4590. spawn->RemoveSpawnAccess(spawn2);
  4591. return 0;
  4592. }
  4593. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. ZoneServer* zone = lua_interface->GetZone(state);
  4597. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4598. if (!zone) {
  4599. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4600. return 0;
  4601. }
  4602. if (location_id == 0) {
  4603. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4604. return 0;
  4605. }
  4606. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4607. if (!location) {
  4608. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4609. return 0;
  4610. }
  4611. Spawn* spawn = 0;
  4612. if (location->entities[0]) {
  4613. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4614. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4615. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4616. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4617. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4618. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4619. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4620. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4621. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4622. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4623. if (spawn) {
  4624. const char* script = 0;
  4625. for (int x = 0; x < 3; x++) {
  4626. switch (x) {
  4627. case 0:
  4628. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4629. break;
  4630. case 1:
  4631. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4632. break;
  4633. case 2:
  4634. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4635. break;
  4636. }
  4637. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4638. spawn->SetSpawnScript(string(script));
  4639. break;
  4640. }
  4641. }
  4642. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4643. lua_interface->SetSpawnValue(state, spawn);
  4644. return 1;
  4645. }
  4646. else {
  4647. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4648. safe_delete(spawn);
  4649. }
  4650. }
  4651. return 0;
  4652. }
  4653. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4654. if (!lua_interface)
  4655. return 0;
  4656. Spawn* caster = lua_interface->GetSpawn(state);
  4657. Spawn* target = lua_interface->GetSpawn(state, 2);
  4658. int32 id = lua_interface->GetInt32Value(state, 3);
  4659. string command = lua_interface->GetStringValue(state, 4);
  4660. if (!caster) {
  4661. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4662. return 0;
  4663. }
  4664. if (!target) {
  4665. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4666. return 0;
  4667. }
  4668. if (!caster->IsPlayer()) {
  4669. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4670. return 0;
  4671. }
  4672. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4673. if (!entity_command) {
  4674. 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());
  4675. return 0;
  4676. }
  4677. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4678. if (!client) {
  4679. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4680. return 0;
  4681. }
  4682. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4683. return 0;
  4684. }
  4685. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4686. if (!lua_interface)
  4687. return 0;
  4688. Spawn* spawn = lua_interface->GetSpawn(state);
  4689. if (!spawn) {
  4690. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4691. return 0;
  4692. }
  4693. if (!spawn->IsNPC()) {
  4694. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4695. return 0;
  4696. }
  4697. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4698. return 0;
  4699. }
  4700. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4701. if (!lua_interface)
  4702. return 0;
  4703. Spawn* spawn = lua_interface->GetSpawn(state);
  4704. int16 tick = lua_interface->GetInt16Value(state, 2);
  4705. if (!spawn) {
  4706. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4707. return 0;
  4708. }
  4709. if (!spawn->IsNPC()) {
  4710. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4711. return 0;
  4712. }
  4713. if (tick < 20) {
  4714. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4715. return 0;
  4716. }
  4717. ((NPC*)spawn)->Brain()->SetTick(tick);
  4718. return 0;
  4719. }
  4720. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4721. if (!lua_interface)
  4722. return 0;
  4723. Spawn* spawn = lua_interface->GetSpawn(state);
  4724. Spawn* target = lua_interface->GetSpawn(state, 2);
  4725. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4726. if (!spawn) {
  4727. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4728. return 0;
  4729. }
  4730. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4731. spawn->SetFollowTarget(target, follow_distance);
  4732. return 0;
  4733. }
  4734. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4735. if (!lua_interface)
  4736. return 0;
  4737. Spawn* spawn = lua_interface->GetSpawn(state);
  4738. if (!spawn) {
  4739. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4740. return 0;
  4741. }
  4742. Spawn* target = spawn->GetFollowTarget();
  4743. if (target) {
  4744. lua_interface->SetSpawnValue(state, target);
  4745. return 1;
  4746. }
  4747. return 0;
  4748. }
  4749. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4750. if (!lua_interface)
  4751. return 0;
  4752. Spawn* spawn = lua_interface->GetSpawn(state);
  4753. if (!spawn) {
  4754. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4755. return 0;
  4756. }
  4757. if (spawn->following)
  4758. spawn->following = false;
  4759. else
  4760. spawn->following = true;
  4761. return 0;
  4762. }
  4763. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4764. if (!lua_interface)
  4765. return 0;
  4766. Spawn* spawn = lua_interface->GetSpawn(state);
  4767. if (!spawn) {
  4768. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4769. return 0;
  4770. }
  4771. lua_interface->SetBooleanValue(state, spawn->following);
  4772. return 1;
  4773. }
  4774. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4775. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4776. // I will attempt to explain how this function works for future refrence
  4777. // Fist lets make sure lua_interface is valid, if not return out
  4778. if (!lua_interface)
  4779. return 0;
  4780. // Next we grab the first 2 params same as we usually would
  4781. Spawn* spawn = lua_interface->GetSpawn(state);
  4782. string var = lua_interface->GetStringValue(state, 2);
  4783. // 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
  4784. // 1 = Spawn
  4785. // 2 = Zone
  4786. // 3 = Item
  4787. // 4 = Quest
  4788. // 5 = String
  4789. // 6 = nil (null)
  4790. int8 dataType = 0;
  4791. // Define pointers for each potential type
  4792. Spawn* spawnVal = 0;
  4793. ZoneServer* zone = 0;
  4794. Item* item = 0;
  4795. Quest* quest = 0;
  4796. string val;
  4797. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4798. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4799. // options window are also light user data be we do not handle those.
  4800. // We check with lua_islightuserdata(lua_State*, index)
  4801. if (lua_islightuserdata(state, 3)) {
  4802. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4803. // and convert it to LUAUserData*
  4804. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4805. // Check to make sure the data we got is valid, if not give an error
  4806. if (!data || !data->IsCorrectlyInitialized()) {
  4807. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4808. }
  4809. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4810. else if (data->IsSpawn()) {
  4811. spawnVal = data->spawn;
  4812. dataType = 1;
  4813. }
  4814. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4815. else if (data->IsZone()) {
  4816. zone = data->zone;
  4817. dataType = 2;
  4818. }
  4819. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4820. else if (data->IsItem()) {
  4821. item = data->item;
  4822. dataType = 3;
  4823. }
  4824. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4825. else if (data->IsQuest()) {
  4826. quest = data->quest;
  4827. dataType = 4;
  4828. }
  4829. }
  4830. // Wasn't light user data, check if it is nil(null)
  4831. else if (lua_isnil(state, 3)) {
  4832. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4833. dataType = 6;
  4834. }
  4835. // Wasn't light user data or nil (null), must be a string
  4836. else {
  4837. // Set the string and dataType variable
  4838. val = lua_interface->GetStringValue(state, 3);
  4839. dataType = 5;
  4840. }
  4841. // We now have all the params, lets check to make sure they are valid
  4842. if (!spawn) {
  4843. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4844. return 0;
  4845. }
  4846. if (var.length() == 0) {
  4847. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4848. return 0;
  4849. }
  4850. if (dataType == 0) {
  4851. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4852. return 0;
  4853. }
  4854. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4855. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4856. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4857. switch (dataType) {
  4858. case 1:
  4859. // 1 = Spawn
  4860. spawn->AddTempVariable(var, spawnVal);
  4861. break;
  4862. case 2:
  4863. // 2 = Zone
  4864. spawn->AddTempVariable(var, zone);
  4865. break;
  4866. case 3:
  4867. // 3 = Item
  4868. spawn->AddTempVariable(var, item);
  4869. break;
  4870. case 4:
  4871. // 4 = Quest
  4872. spawn->AddTempVariable(var, quest);
  4873. break;
  4874. case 5:
  4875. // 5 = String
  4876. spawn->AddTempVariable(var, val);
  4877. break;
  4878. case 6:
  4879. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4880. spawn->DeleteTempVariable(var);
  4881. break;
  4882. }
  4883. // And we are done so return out
  4884. return 0;
  4885. }
  4886. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4887. if (!lua_interface)
  4888. return 0;
  4889. Spawn* spawn = lua_interface->GetSpawn(state);
  4890. string var = lua_interface->GetStringValue(state, 2);
  4891. if (!spawn) {
  4892. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4893. return 0;
  4894. }
  4895. if (var.length() == 0) {
  4896. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4897. return 0;
  4898. }
  4899. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4900. int8 type = spawn->GetTempVariableType(var);
  4901. Spawn* spawn2 = 0;
  4902. ZoneServer* zone = 0;
  4903. Item* item = 0;
  4904. Quest* quest = 0;
  4905. // Set the lua function return value based on the type of data the variable contains
  4906. switch (type) {
  4907. case 1:
  4908. spawn2 = spawn->GetTempVariableSpawn(var);
  4909. if (!spawn2)
  4910. return 0;
  4911. lua_interface->SetSpawnValue(state, spawn2);
  4912. break;
  4913. case 2:
  4914. zone = spawn->GetTempVariableZone(var);
  4915. if (!zone)
  4916. return 0;
  4917. lua_interface->SetZoneValue(state, zone);
  4918. break;
  4919. case 3:
  4920. item = spawn->GetTempVariableItem(var);
  4921. if (!item)
  4922. return 0;
  4923. lua_interface->SetItemValue(state, item);
  4924. break;
  4925. case 4:
  4926. quest = spawn->GetTempVariableQuest(var);
  4927. if (!quest)
  4928. return 0;
  4929. lua_interface->SetQuestValue(state, quest);
  4930. break;
  4931. case 5:
  4932. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4933. break;
  4934. default:
  4935. // Not a valid type then the variable was not set so return out
  4936. return 0;
  4937. }
  4938. // Return value was set so return out
  4939. return 1;
  4940. }
  4941. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4942. {
  4943. if (!lua_interface)
  4944. return 0;
  4945. Quest* quest = lua_interface->GetQuest(state);
  4946. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4947. string description = lua_interface->GetStringValue(state, 3);
  4948. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4949. if (!quest) {
  4950. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4951. lua_interface->SetBooleanValue(state, false);
  4952. return 1;
  4953. }
  4954. if (!spawn) {
  4955. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4956. lua_interface->SetBooleanValue(state, false);
  4957. return 1;
  4958. }
  4959. if (!spawn->IsPlayer()) {
  4960. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4961. lua_interface->SetBooleanValue(state, false);
  4962. return 1;
  4963. }
  4964. if (item_id == 0) {
  4965. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4966. lua_interface->SetBooleanValue(state, false);
  4967. return 1;
  4968. }
  4969. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4970. if (!client) {
  4971. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4972. lua_interface->SetBooleanValue(state, false);
  4973. return 1;
  4974. }
  4975. Item* item = master_item_list.GetItem(item_id);
  4976. if (!item) {
  4977. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4978. lua_interface->SetBooleanValue(state, false);
  4979. return 1;
  4980. }
  4981. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4982. if (packet) {
  4983. packet->setDataByName("title", "Quest Reward!");
  4984. packet->setDataByName("name", quest->GetName());
  4985. packet->setDataByName("description", description.c_str());
  4986. packet->setDataByName("level", quest->GetLevel());
  4987. packet->setArrayLengthByName("num_rewards", 1);
  4988. packet->setArrayDataByName("reward_id", item->details.item_id);
  4989. if (client->GetVersion() < 860)
  4990. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4991. else if (client->GetVersion() < 1193)
  4992. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4993. else
  4994. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4995. client->QueuePacket(packet->serialize());
  4996. safe_delete(packet);
  4997. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  4998. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  4999. return 1;
  5000. }
  5001. lua_interface->SetBooleanValue(state, false);
  5002. return 1;
  5003. }
  5004. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5005. if (!lua_interface)
  5006. return 0;
  5007. Quest* quest = lua_interface->GetQuest(state);
  5008. if (!quest) {
  5009. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5010. return 0;
  5011. }
  5012. quest->SetRepeatable(true);
  5013. return 0;
  5014. }
  5015. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5016. if (!lua_interface)
  5017. return 0;
  5018. Spawn* spawn = lua_interface->GetSpawn(state);
  5019. if (!spawn) {
  5020. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5021. return 0;
  5022. }
  5023. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5024. string ret = classes.GetClassNameCase(base_class);
  5025. if (ret.length() > 0) {
  5026. lua_interface->SetStringValue(state, ret.c_str());
  5027. return 1;
  5028. }
  5029. return 0;
  5030. }
  5031. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5032. if (!lua_interface)
  5033. return 0;
  5034. Spawn* player = lua_interface->GetSpawn(state);
  5035. if (player && player->IsPlayer()) {
  5036. Client* client = player->GetClient();
  5037. if (client)
  5038. client->SendWaypoints();
  5039. }
  5040. return 0;
  5041. }
  5042. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5043. if (!lua_interface)
  5044. return 0;
  5045. Spawn* player = lua_interface->GetSpawn(state);
  5046. string name = lua_interface->GetStringValue(state, 2);
  5047. int32 type = lua_interface->GetInt32Value(state, 3);
  5048. if (type == 0)
  5049. type = 2;
  5050. if (name.length() > 0) {
  5051. if (player && player->IsPlayer()) {
  5052. Client* client = player->GetClient();
  5053. if (client)
  5054. client->AddWaypoint(name, type);
  5055. }
  5056. }
  5057. return 0;
  5058. }
  5059. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5060. if (!lua_interface)
  5061. return 0;
  5062. Spawn* player = lua_interface->GetSpawn(state);
  5063. string name = lua_interface->GetStringValue(state, 2);
  5064. if (name.length() > 0) {
  5065. if (player && player->IsPlayer()) {
  5066. Client* client = player->GetClient();
  5067. if (client)
  5068. client->RemoveWaypoint(name);
  5069. }
  5070. }
  5071. return 0;
  5072. }
  5073. int EQ2Emu_lua_AddWard(lua_State* state) {
  5074. if (!lua_interface)
  5075. return 0;
  5076. int32 damage = lua_interface->GetInt32Value(state);
  5077. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5078. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5079. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5080. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5081. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5082. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5083. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5084. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5085. bool ward_was_added = false;
  5086. ZoneServer* zone = spell->caster->GetZone();
  5087. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5088. for (int32 i = 0; i < spell->targets.size(); i++) {
  5089. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5090. if (!target)
  5091. continue;
  5092. if (target->IsEntity()) {
  5093. // If the ward is already active remove it
  5094. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5095. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5096. // Create new ward info
  5097. WardInfo* ward = new WardInfo;
  5098. ward->Spell = spell;
  5099. ward->BaseDamage = damage;
  5100. ward->DamageLeft = damage;
  5101. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5102. ward->keepWard = keepWard;
  5103. ward->WardType = wardType;
  5104. if (damageAbsorptionPercent > 100)
  5105. damageAbsorptionPercent = 100;
  5106. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5107. if (damageAbsorptionMaxHealthPercent > 100)
  5108. damageAbsorptionMaxHealthPercent = 100;
  5109. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5110. ward->RedirectDamagePercent = redirectDamagePercent;
  5111. ward->LastRedirectDamage = 0;
  5112. ward->LastAbsorbedDamage = 0;
  5113. ward->HitCount = 0;
  5114. spell->num_triggers = maxHitCount;
  5115. spell->had_triggers = true;
  5116. spell->cancel_after_all_triggers = false;
  5117. ward->MaxHitCount = maxHitCount;
  5118. if (wardType == WARD_TYPE_MAGICAL)
  5119. ward->DamageType = damageTypes;
  5120. // Add the ward to the entity
  5121. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5122. ward_was_added = true;
  5123. }
  5124. }
  5125. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5126. if (ward_was_added && spell->caster->IsPlayer()) {
  5127. spell->had_dmg_remaining = true;
  5128. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5129. }
  5130. return 0;
  5131. }
  5132. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5133. if (!lua_interface)
  5134. return 0;
  5135. int32 amount = lua_interface->GetInt32Value(state);
  5136. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5137. WardInfo* ward = 0;
  5138. ZoneServer* zone = spell->caster->GetZone();
  5139. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5140. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5141. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5142. ward = target->GetWard(spell->spell->GetSpellID());
  5143. if (ward) {
  5144. ward->DamageLeft += amount;
  5145. if (ward->DamageLeft > ward->BaseDamage)
  5146. ward->DamageLeft = ward->BaseDamage;
  5147. for (int32 i = 0; i < spell->targets.size(); i++) {
  5148. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5149. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5150. }
  5151. }
  5152. }
  5153. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5154. if (ward && spell->caster->IsPlayer())
  5155. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5156. return 0;
  5157. }
  5158. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5159. if (!lua_interface)
  5160. return 0;
  5161. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5162. if (!spell) {
  5163. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5164. return 0;
  5165. }
  5166. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5167. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5168. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5169. if (ward) {
  5170. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5171. return 1;
  5172. }
  5173. }
  5174. return 0;
  5175. }
  5176. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5177. if (!lua_interface)
  5178. return 0;
  5179. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5180. if (!spell) {
  5181. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5182. return 0;
  5183. }
  5184. string type = lua_interface->GetStringValue(state, 2);
  5185. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5186. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5187. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5188. if (ward) {
  5189. if (boost::iequals(type, "damageleft"))
  5190. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5191. else if (boost::iequals(type, "basedamage"))
  5192. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5193. else if (boost::iequals(type, "keepward"))
  5194. lua_interface->SetBooleanValue(state, ward->keepWard);
  5195. else if (boost::iequals(type, "wardtype"))
  5196. lua_interface->SetInt32Value(state, ward->WardType);
  5197. else if (boost::iequals(type, "dmgabsorptionpct"))
  5198. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5199. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5200. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5201. else if (boost::iequals(type, "redirectdamagepercent"))
  5202. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5203. else if (boost::iequals(type, "lastredirectdamage"))
  5204. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5205. else if (boost::iequals(type, "lastabsorbeddamage"))
  5206. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5207. else if (boost::iequals(type, "hitcount"))
  5208. lua_interface->SetInt32Value(state, ward->HitCount);
  5209. else if (boost::iequals(type, "maxhitcount"))
  5210. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5211. else
  5212. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5213. return 1;
  5214. }
  5215. }
  5216. return 0;
  5217. }
  5218. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5219. if (!lua_interface)
  5220. return 0;
  5221. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5222. ZoneServer* zone = spell->caster->GetZone();
  5223. Spawn* target = 0;
  5224. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5225. for (int32 i = 0; i < spell->targets.size(); i++) {
  5226. target = zone->GetSpawnByID(spell->targets.at(i));
  5227. if (target && target->IsEntity()) {
  5228. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5229. }
  5230. }
  5231. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5232. return 0;
  5233. }
  5234. int EQ2Emu_lua_Interrupt(lua_State* state)
  5235. {
  5236. if (!lua_interface)
  5237. return 0;
  5238. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5239. Spawn* target = lua_interface->GetSpawn(state, 2);
  5240. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5241. if (!caster)
  5242. {
  5243. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5244. return 0;
  5245. }
  5246. if (!target)
  5247. {
  5248. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5249. return 0;
  5250. }
  5251. if (!spell) {
  5252. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5253. return 0;
  5254. }
  5255. if (!target->IsEntity() && !spell)
  5256. {
  5257. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5258. return 0;
  5259. }
  5260. if (!target && spell) {
  5261. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5262. for (int8 i = 0; i < spell->targets.size(); i++) {
  5263. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5264. if (!target || !target->IsEntity())
  5265. continue;
  5266. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5267. }
  5268. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5269. }
  5270. else
  5271. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5272. return 0;
  5273. }
  5274. int EQ2Emu_lua_Stealth(lua_State* state) {
  5275. if (!lua_interface)
  5276. return 0;
  5277. int8 type = lua_interface->GetInt8Value(state);
  5278. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5279. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5280. if (!spell) {
  5281. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5282. return 0;
  5283. }
  5284. ZoneServer* zone = spell->caster->GetZone();
  5285. if (spawn) {
  5286. if (spawn->IsEntity()) {
  5287. if (type == 1) {
  5288. ((Entity*)spawn)->AddStealthSpell(spell);
  5289. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5290. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5291. }
  5292. else if (type == 2) {
  5293. ((Entity*)spawn)->AddInvisSpell(spell);
  5294. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5295. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5296. }
  5297. return 0;
  5298. }
  5299. else {
  5300. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5301. return 0;
  5302. }
  5303. }
  5304. else {
  5305. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5306. for (int32 i = 0; i < spell->targets.size(); i++) {
  5307. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5308. if (!spawn || !spawn->IsEntity())
  5309. continue;
  5310. if (type == 1) {
  5311. ((Entity*)spawn)->AddStealthSpell(spell);
  5312. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5313. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5314. }
  5315. else if (type == 2) {
  5316. ((Entity*)spawn)->AddInvisSpell(spell);
  5317. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5318. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5319. }
  5320. else {
  5321. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5322. break;
  5323. }
  5324. }
  5325. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5326. }
  5327. return 0;
  5328. }
  5329. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5330. if (!lua_interface)
  5331. return 0;
  5332. Spawn* spawn = lua_interface->GetSpawn(state);
  5333. if (!spawn) {
  5334. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5335. return 0;
  5336. }
  5337. if (spawn->IsEntity()) {
  5338. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5339. return 1;
  5340. }
  5341. else
  5342. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5343. return 0;
  5344. }
  5345. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5346. if (!lua_interface)
  5347. return 0;
  5348. Spawn* spawn = lua_interface->GetSpawn(state);
  5349. if (!spawn) {
  5350. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5351. return 0;
  5352. }
  5353. if (spawn->IsEntity()) {
  5354. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5355. return 1;
  5356. }
  5357. else
  5358. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5359. return 0;
  5360. }
  5361. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5362. if (!lua_interface)
  5363. return 0;
  5364. Spawn* player = lua_interface->GetSpawn(state);
  5365. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5366. if (!player->IsPlayer()) {
  5367. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5368. return 0;
  5369. }
  5370. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5371. return 1;
  5372. }
  5373. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5374. if (!lua_interface)
  5375. return 0;
  5376. Spawn* player = lua_interface->GetSpawn(state);
  5377. int8 slot = lua_interface->GetInt8Value(state, 2);
  5378. if (!player) {
  5379. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5380. return 0;
  5381. }
  5382. if (!player->IsPlayer()) {
  5383. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5384. return 0;
  5385. }
  5386. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5387. if (!item) {
  5388. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5389. return 0;
  5390. }
  5391. lua_interface->SetItemValue(state, item);
  5392. return 1;
  5393. }
  5394. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5395. if (!lua_interface)
  5396. return 0;
  5397. Spawn* player = lua_interface->GetSpawn(state);
  5398. int32 id = lua_interface->GetInt32Value(state, 2);
  5399. if (!player) {
  5400. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5401. return 0;
  5402. }
  5403. if (!player->IsPlayer()) {
  5404. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5405. return 0;
  5406. }
  5407. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5408. if (!item) {
  5409. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5410. return 0;
  5411. }
  5412. lua_interface->SetItemValue(state, item);
  5413. return 1;
  5414. }
  5415. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5416. if (!lua_interface)
  5417. return 0;
  5418. Spawn* player = lua_interface->GetSpawn(state);
  5419. int32 id = lua_interface->GetInt32Value(state, 2);
  5420. int8 count = lua_interface->GetInt8Value(state, 3);
  5421. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5422. if (!player) {
  5423. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5424. return 0;
  5425. }
  5426. if (!player->IsPlayer()) {
  5427. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5428. return 0;
  5429. }
  5430. if (!count)
  5431. count = 1;
  5432. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5433. if (!item) {
  5434. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5435. return 0;
  5436. }
  5437. lua_interface->SetItemValue(state, item);
  5438. return 1;
  5439. }
  5440. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5441. if (!lua_interface)
  5442. return 0;
  5443. Spawn* spawn = lua_interface->GetSpawn(state);
  5444. int32 anim = lua_interface->GetInt32Value(state, 2);
  5445. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5446. int8 type = lua_interface->GetInt8Value(state, 4);
  5447. if (!spawn) {
  5448. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5449. return 0;
  5450. }
  5451. if (spawn2) {
  5452. if (spawn2->IsPlayer()) {
  5453. if (type != 1 && type != 2)
  5454. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5455. else
  5456. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5457. return 0;
  5458. }
  5459. else {
  5460. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5461. return 0;
  5462. }
  5463. }
  5464. else
  5465. spawn->GetZone()->PlayAnimation(spawn, anim);
  5466. return 0;
  5467. }
  5468. int EQ2Emu_lua_IsPet(lua_State* state) {
  5469. if (!lua_interface)
  5470. return 0;
  5471. Spawn* spawn = lua_interface->GetSpawn(state);
  5472. if (!spawn) {
  5473. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5474. return 0;
  5475. }
  5476. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5477. return 1;
  5478. }
  5479. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5480. if (!lua_interface)
  5481. return 0;
  5482. Spawn* spawn = lua_interface->GetSpawn(state);
  5483. if (!spawn) {
  5484. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5485. return 0;
  5486. }
  5487. if (!spawn->IsNPC()) {
  5488. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. if (((NPC*)spawn)->GetOwner()) {
  5492. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5493. return 1;
  5494. }
  5495. return 0;
  5496. }
  5497. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5498. if (!lua_interface)
  5499. return 0;
  5500. Spawn* spawn = lua_interface->GetSpawn(state);
  5501. Spawn* target = lua_interface->GetSpawn(state, 2);
  5502. if (!spawn) {
  5503. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5504. return 0;
  5505. }
  5506. if (!spawn) {
  5507. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5508. return 0;
  5509. }
  5510. spawn->SetTarget(target);
  5511. return 0;
  5512. }
  5513. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5514. if (!lua_interface)
  5515. return 0;
  5516. Spawn* spawn = lua_interface->GetSpawn(state);
  5517. bool val = lua_interface->GetBooleanValue(state, 2);
  5518. if (!spawn) {
  5519. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5520. return 0;
  5521. }
  5522. if (!spawn->IsEntity()) {
  5523. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5524. return 0;
  5525. }
  5526. ((Entity*)spawn)->InCombat(val);
  5527. if (val) {
  5528. spawn->ClearRunningLocations();
  5529. spawn->CalculateRunningLocation(true);
  5530. }
  5531. return 0;
  5532. }
  5533. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5534. if (!lua_interface)
  5535. return 0;
  5536. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5537. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5538. if (!spawn1) {
  5539. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5540. return 0;
  5541. }
  5542. if (!spawn2) {
  5543. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5544. return 0;
  5545. }
  5546. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5547. return 1;
  5548. }
  5549. int EQ2Emu_lua_Runback(lua_State* state) {
  5550. if (!lua_interface)
  5551. return 0;
  5552. Spawn* spawn = lua_interface->GetSpawn(state);
  5553. if (!spawn) {
  5554. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5555. return 0;
  5556. }
  5557. if (!spawn->IsNPC()) {
  5558. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5559. return 0;
  5560. }
  5561. ((NPC*)spawn)->Runback();
  5562. return 0;
  5563. }
  5564. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5565. if (!lua_interface)
  5566. return 0;
  5567. Spawn* spawn = lua_interface->GetSpawn(state);
  5568. if (!spawn) {
  5569. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5570. return 0;
  5571. }
  5572. if (!spawn->IsNPC()) {
  5573. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5574. return 0;
  5575. }
  5576. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5577. return 1;
  5578. }
  5579. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5580. if (!lua_interface)
  5581. return 0;
  5582. Spawn* spawn = lua_interface->GetSpawn(state);
  5583. if (!spawn) {
  5584. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5585. return 0;
  5586. }
  5587. if (!spawn->IsEntity()) {
  5588. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5589. return 0;
  5590. }
  5591. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5592. return 1;
  5593. }
  5594. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5595. if (!lua_interface)
  5596. return 0;
  5597. Spawn* spawn = lua_interface->GetSpawn(state);
  5598. if (!spawn) {
  5599. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5600. return 0;
  5601. }
  5602. if (!spawn->IsEntity()) {
  5603. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5604. return 0;
  5605. }
  5606. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5607. return 1;
  5608. }
  5609. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5610. if (!lua_interface)
  5611. return 0;
  5612. Spawn* spawn = lua_interface->GetSpawn(state);
  5613. if (!spawn) {
  5614. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5615. return 0;
  5616. }
  5617. if (!spawn->IsEntity()) {
  5618. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5619. return 0;
  5620. }
  5621. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5622. return 1;
  5623. }
  5624. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5625. if (!lua_interface)
  5626. return 0;
  5627. Spawn* spawn = lua_interface->GetSpawn(state);
  5628. if (!spawn) {
  5629. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5630. return 0;
  5631. }
  5632. if (!spawn->IsEntity()) {
  5633. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5634. return 0;
  5635. }
  5636. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5637. return 1;
  5638. }
  5639. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5640. if (!lua_interface)
  5641. return 0;
  5642. Spawn* spawn = lua_interface->GetSpawn(state);
  5643. Spawn* target = lua_interface->GetSpawn(state, 2);
  5644. float distance = lua_interface->GetFloatValue(state, 3);
  5645. if (!spawn) {
  5646. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5647. return 0;
  5648. }
  5649. if (!target) {
  5650. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5651. return 0;
  5652. }
  5653. if (!spawn->IsNPC()) {
  5654. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5655. return 0;
  5656. }
  5657. if (!target->IsEntity()) {
  5658. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5659. return 0;
  5660. }
  5661. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5662. return 1;
  5663. }
  5664. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5665. if (!lua_interface)
  5666. return 0;
  5667. Spawn* spawn = lua_interface->GetSpawn(state);
  5668. Spawn* target = lua_interface->GetSpawn(state, 2);
  5669. float distance = lua_interface->GetFloatValue(state, 3);
  5670. if (!spawn) {
  5671. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5672. return 0;
  5673. }
  5674. if (!target) {
  5675. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5676. return 0;
  5677. }
  5678. if (!spawn->IsNPC()) {
  5679. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5680. return 0;
  5681. }
  5682. if (!target->IsEntity()) {
  5683. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5684. return 0;
  5685. }
  5686. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5687. return 0;
  5688. }
  5689. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5690. if (!lua_interface)
  5691. return 0;
  5692. Spawn* spawn = lua_interface->GetSpawn(state);
  5693. if (!spawn) {
  5694. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5695. return 0;
  5696. }
  5697. if (!spawn->IsNPC()) {
  5698. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5699. return 0;
  5700. }
  5701. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5702. return 1;
  5703. }
  5704. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5705. if (!lua_interface)
  5706. return 0;
  5707. Spawn* spawn = lua_interface->GetSpawn(state);
  5708. if (!spawn) {
  5709. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5710. return 0;
  5711. }
  5712. if (!spawn->IsNPC()) {
  5713. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5714. return 0;
  5715. }
  5716. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5717. return 1;
  5718. }
  5719. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5720. if (!lua_interface)
  5721. return 0;
  5722. Spawn* spawn = lua_interface->GetSpawn(state);
  5723. if (!spawn) {
  5724. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5725. return 0;
  5726. }
  5727. if (!spawn->IsNPC()) {
  5728. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5729. return 0;
  5730. }
  5731. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5732. if (hated) {
  5733. lua_interface->SetSpawnValue(state, hated);
  5734. return 1;
  5735. }
  5736. return 0;
  5737. }
  5738. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5739. if (!lua_interface)
  5740. return 0;
  5741. Spawn* spawn = lua_interface->GetSpawn(state);
  5742. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5743. if (!spawn) {
  5744. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5745. return 0;
  5746. }
  5747. if (!spawn->IsNPC()) {
  5748. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5749. return 0;
  5750. }
  5751. if (!hated) {
  5752. ((NPC*)spawn)->Brain()->ClearHate();
  5753. return 0;
  5754. }
  5755. else
  5756. {
  5757. if (!hated->IsEntity()) {
  5758. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5759. return 0;
  5760. }
  5761. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5762. return 0;
  5763. }
  5764. return 0;
  5765. }
  5766. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5767. if (!lua_interface)
  5768. return 0;
  5769. Spawn* spawn = lua_interface->GetSpawn(state);
  5770. if (!spawn) {
  5771. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5772. return 0;
  5773. }
  5774. if (!spawn->IsNPC()) {
  5775. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5776. return 0;
  5777. }
  5778. ((NPC*)spawn)->Brain()->ClearEncounter();
  5779. return 0;
  5780. }
  5781. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5782. if (!lua_interface)
  5783. return 0;
  5784. Spawn* spawn = lua_interface->GetSpawn(state);
  5785. if (!spawn) {
  5786. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5787. return 0;
  5788. }
  5789. if (!spawn->IsNPC()) {
  5790. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5791. return 0;
  5792. }
  5793. // Temp list to store hate list
  5794. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5795. if (encounterList->size() == 0) {
  5796. safe_delete(encounterList);
  5797. return 0;
  5798. }
  5799. lua_createtable(state, encounterList->size(), 0);
  5800. int newTable = lua_gettop(state);
  5801. for (int32 i = 0; i < encounterList->size(); i++) {
  5802. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5803. if (temp)
  5804. lua_interface->SetSpawnValue(state, temp);
  5805. lua_rawseti(state, newTable, i + 1);
  5806. }
  5807. safe_delete(encounterList);
  5808. return 1;
  5809. }
  5810. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5811. if (!lua_interface)
  5812. return 0;
  5813. Spawn* spawn = lua_interface->GetSpawn(state);
  5814. if (!spawn) {
  5815. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5816. return 0;
  5817. }
  5818. if (!spawn->IsNPC()) {
  5819. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5820. return 0;
  5821. }
  5822. // Temp list to store hate list
  5823. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5824. if (hateList->size() == 0) {
  5825. safe_delete(hateList);
  5826. return 0;
  5827. }
  5828. lua_createtable(state, hateList->size(), 0);
  5829. int newTable = lua_gettop(state);
  5830. for (int32 i = 0; i < hateList->size(); i++) {
  5831. lua_interface->SetSpawnValue(state, hateList->at(i));
  5832. lua_rawseti(state, newTable, i + 1);
  5833. }
  5834. safe_delete(hateList);
  5835. return 1;
  5836. }
  5837. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5838. if (!lua_interface)
  5839. return 0;
  5840. Spawn* spawn = lua_interface->GetSpawn(state);
  5841. if (!spawn) {
  5842. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5843. return 0;
  5844. }
  5845. if (spawn->IsPlayer()) {
  5846. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5847. lua_interface->SetBooleanValue(state, true);
  5848. else
  5849. lua_interface->SetBooleanValue(state, false);
  5850. return 1;
  5851. }
  5852. else {
  5853. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5854. return 1;
  5855. }
  5856. }
  5857. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5858. if (!lua_interface)
  5859. return 0;
  5860. Quest* quest = lua_interface->GetQuest(state);
  5861. if (!quest) {
  5862. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. quest->SetCompletedFlag(true);
  5866. return 0;
  5867. }
  5868. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5869. if (!lua_interface)
  5870. return 0;
  5871. Spawn* spawn = lua_interface->GetSpawn(state);
  5872. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5873. int8 tier = lua_interface->GetInt8Value(state, 3);
  5874. if (!spawn) {
  5875. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5876. return 0;
  5877. }
  5878. if (!spawn->IsEntity()) {
  5879. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5880. return 0;
  5881. }
  5882. if (spellID == 0) {
  5883. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5887. if (effect) {
  5888. if (tier > 0) {
  5889. // If a tier was passed chec to see if it is the same as the effect
  5890. if (tier == effect->tier)
  5891. lua_interface->SetBooleanValue(state, true);
  5892. else
  5893. lua_interface->SetBooleanValue(state, false);
  5894. return 1;
  5895. }
  5896. else {
  5897. // Have an effect but no tier was passed so return true
  5898. lua_interface->SetBooleanValue(state, true);
  5899. }
  5900. return 1;
  5901. }
  5902. // no effect so return false
  5903. lua_interface->SetBooleanValue(state, false);
  5904. return 1;
  5905. }
  5906. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5907. if (!lua_interface)
  5908. return 0;
  5909. Spawn* spawn = lua_interface->GetSpawn(state);
  5910. int32 id = lua_interface->GetInt32Value(state, 2);
  5911. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5912. Spawn* spawn2 = 0;
  5913. vector<Spawn*> list;
  5914. if (!spawn) {
  5915. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5916. return 0;
  5917. }
  5918. //If zone not provided, use spawn's zone
  5919. if (!zone)
  5920. zone = spawn->GetZone();
  5921. list = zone->GetSpawnsByID(id);
  5922. if (list.size() == 0) {
  5923. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5924. return 0;
  5925. }
  5926. vector<Spawn*>::iterator itr = list.begin();
  5927. for (int8 i = 0; i < list.size(); i++) {
  5928. spawn2 = itr[i];
  5929. if (spawn2)
  5930. spawn2->AddAllowAccessSpawn(spawn);
  5931. }
  5932. return 0;
  5933. }
  5934. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5935. if (!lua_interface)
  5936. return 0;
  5937. Spawn* spawn = lua_interface->GetSpawn(state);
  5938. int32 id = lua_interface->GetInt32Value(state, 2);
  5939. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5940. Spawn* spawn2 = 0;
  5941. if (!spawn) {
  5942. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5943. return 0;
  5944. }
  5945. //If zone not provided, use spawn's zone
  5946. if (!zone)
  5947. zone = spawn->GetZone();
  5948. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5949. vector<Spawn*>::iterator itr = list.begin();
  5950. if (list.size() == 0) {
  5951. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5952. return 0;
  5953. }
  5954. for (int8 i = 0; i < list.size(); i++) {
  5955. spawn2 = itr[i];
  5956. if (spawn2)
  5957. spawn2->RemoveSpawnAccess(spawn);
  5958. }
  5959. return 0;
  5960. }
  5961. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5962. if (!lua_interface)
  5963. return 0;
  5964. Quest* quest = lua_interface->GetQuest(state);
  5965. if (!quest) {
  5966. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5967. return 0;
  5968. }
  5969. quest->SetYellowName(true);
  5970. return 0;
  5971. }
  5972. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5973. if (!lua_interface)
  5974. return 0;
  5975. Spawn* spawn = lua_interface->GetSpawn(state);
  5976. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5977. if (!spawn) {
  5978. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5979. return 0;
  5980. }
  5981. if (!spawn->IsPlayer()) {
  5982. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5983. return 0;
  5984. }
  5985. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5986. return 1;
  5987. }
  5988. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5989. if (!lua_interface)
  5990. return 0;
  5991. Spawn* spawn = lua_interface->GetSpawn(state);
  5992. if (!spawn) {
  5993. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5994. return 0;
  5995. }
  5996. if (!spawn->IsPlayer()) {
  5997. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5998. return 0;
  5999. }
  6000. ZoneServer* zone = spawn->GetZone();
  6001. if (!zone) {
  6002. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6003. return 0;
  6004. }
  6005. Instance_Type iType = zone->GetInstanceType();
  6006. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6007. iType == GROUP_LOCKOUT_INSTANCE ||
  6008. iType == RAID_LOCKOUT_INSTANCE ||
  6009. iType == SOLO_PERSIST_INSTANCE ||
  6010. iType == GROUP_PERSIST_INSTANCE ||
  6011. iType == RAID_PERSIST_INSTANCE) {
  6012. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6013. if (data) {
  6014. // Check to see if the timer has already been set, if it has return out.
  6015. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6016. return 0;
  6017. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6018. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6019. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6020. if (client) {
  6021. string time_msg = "";
  6022. int32 time = data->success_lockout_time;
  6023. int16 hour;
  6024. int8 min;
  6025. int8 sec;
  6026. hour = time / 3600;
  6027. time = time % 3600;
  6028. min = time / 60;
  6029. time = time % 60;
  6030. sec = time;
  6031. if (hour > 0) {
  6032. char temp[10];
  6033. sprintf(temp, " %i", hour);
  6034. time_msg.append(temp);
  6035. time_msg.append(" hour");
  6036. time_msg.append((hour > 1) ? "s" : "");
  6037. }
  6038. if (min > 0) {
  6039. char temp[5];
  6040. sprintf(temp, " %i", min);
  6041. time_msg.append(temp);
  6042. time_msg.append(" minute");
  6043. time_msg.append((min > 1) ? "s" : "");
  6044. }
  6045. // Only add seconds if minutes and hours are 0
  6046. if (hour == 0 && min == 0 && sec > 0) {
  6047. char temp[5];
  6048. sprintf(temp, " %i", sec);
  6049. time_msg.append(temp);
  6050. time_msg.append(" second");
  6051. time_msg.append((sec > 1) ? "s" : "");
  6052. }
  6053. 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());
  6054. }
  6055. }
  6056. else
  6057. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6058. }
  6059. else
  6060. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6061. return 0;
  6062. }
  6063. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6064. if (!lua_interface)
  6065. return 0;
  6066. Spawn* spawn = lua_interface->GetSpawn(state);
  6067. if (!spawn) {
  6068. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6069. return 0;
  6070. }
  6071. if (!spawn->IsPlayer()) {
  6072. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6073. return 0;
  6074. }
  6075. ZoneServer* zone = spawn->GetZone();
  6076. if (!zone) {
  6077. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6078. return 0;
  6079. }
  6080. Instance_Type iType = zone->GetInstanceType();
  6081. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6082. iType == GROUP_LOCKOUT_INSTANCE ||
  6083. iType == RAID_LOCKOUT_INSTANCE ||
  6084. iType == SOLO_PERSIST_INSTANCE ||
  6085. iType == GROUP_PERSIST_INSTANCE ||
  6086. iType == RAID_PERSIST_INSTANCE) {
  6087. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6088. if (data) {
  6089. // Check to see if the timer has already been set, if it has return out.
  6090. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6091. return 0;
  6092. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6093. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6094. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6095. if (client) {
  6096. string time_msg = "";
  6097. int32 time = data->failure_lockout_time;
  6098. int16 hour;
  6099. int8 min;
  6100. int8 sec;
  6101. hour = time / 3600;
  6102. time = time % 3600;
  6103. min = time / 60;
  6104. time = time % 60;
  6105. sec = time;
  6106. if (hour > 0) {
  6107. char temp[10];
  6108. sprintf(temp, " %i", hour);
  6109. time_msg.append(temp);
  6110. time_msg.append(" hour");
  6111. time_msg.append((hour > 1) ? "s" : "");
  6112. }
  6113. if (min > 0) {
  6114. char temp[5];
  6115. sprintf(temp, " %i", min);
  6116. time_msg.append(temp);
  6117. time_msg.append(" minute");
  6118. time_msg.append((min > 1) ? "s" : "");
  6119. }
  6120. // Only add seconds if minutes and hours are 0
  6121. if (hour == 0 && min == 0 && sec > 0) {
  6122. char temp[5];
  6123. sprintf(temp, " %i", sec);
  6124. time_msg.append(temp);
  6125. time_msg.append(" second");
  6126. time_msg.append((sec > 1) ? "s" : "");
  6127. }
  6128. 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());
  6129. }
  6130. }
  6131. else
  6132. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6133. }
  6134. else
  6135. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6139. if (!lua_interface)
  6140. return 0;
  6141. Spawn* spawn = lua_interface->GetSpawn(state);
  6142. if (!spawn) {
  6143. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6147. return 1;
  6148. }
  6149. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6150. if (!lua_interface)
  6151. return 0;
  6152. Spawn* player = lua_interface->GetSpawn(state);
  6153. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6154. if (!player) {
  6155. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6156. return 0;
  6157. }
  6158. if (!player->IsPlayer()) {
  6159. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6160. return 0;
  6161. }
  6162. if (!ground) {
  6163. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6164. return 0;
  6165. }
  6166. if (!ground->IsGroundSpawn()) {
  6167. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6168. return 0;
  6169. }
  6170. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6171. if (!groundspawn_entries) {
  6172. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6173. return 0;
  6174. }
  6175. Skill* skill = 0;
  6176. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6177. if (collection_skill == "Collecting")
  6178. skill = ((Player*)player)->GetSkillByName("Gathering");
  6179. else
  6180. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6181. if (!skill) {
  6182. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6183. return 0;
  6184. }
  6185. vector<GroundSpawnEntry*>::iterator itr;
  6186. GroundSpawnEntry* entry = 0;
  6187. bool can_harvest = false;
  6188. sint32 min_skill = -1;
  6189. // first, iterate through groundspawn_entries, discard tables player cannot use
  6190. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6191. {
  6192. entry = *itr;
  6193. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6194. min_skill = entry->min_skill_level;
  6195. // if player lacks skill, skip table
  6196. if (entry->min_skill_level > skill->current_val)
  6197. continue;
  6198. // if bonus, but player lacks level, skip table
  6199. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6200. continue;
  6201. can_harvest = true;
  6202. break;
  6203. }
  6204. lua_interface->SetBooleanValue(state, can_harvest);
  6205. // If false, send the message to the client
  6206. if (!can_harvest) {
  6207. Client* client = player->GetZone()->GetClientBySpawn(player);
  6208. if (client) {
  6209. string msg = "You do not have enough skill to ";
  6210. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6211. msg.append("gather");
  6212. else if (collection_skill == "Mining")
  6213. msg.append("mine");
  6214. else if (collection_skill == "Trapping")
  6215. msg.append("trap");
  6216. else if (collection_skill == "Foresting")
  6217. msg.append("forest");
  6218. else if (collection_skill == "Fishing")
  6219. msg.append("catch");
  6220. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6221. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  6222. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6223. }
  6224. }
  6225. return 1;
  6226. }
  6227. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6228. if (!lua_interface)
  6229. return 0;
  6230. Spawn* player = lua_interface->GetSpawn(state);
  6231. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6232. if (!player) {
  6233. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6234. return 0;
  6235. }
  6236. if (!player->IsPlayer()) {
  6237. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6241. lua_interface->SetBooleanValue(state, ret);
  6242. return 1;
  6243. }
  6244. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6245. // Check to see if we have a valid lua_interface
  6246. if (!lua_interface)
  6247. return 0;
  6248. // Get the spawn that is getting the pet
  6249. Spawn* spawn = lua_interface->GetSpawn(state);
  6250. Spawn* target = lua_interface->GetSpawn(state, 2);
  6251. // Get the DB ID of the pet
  6252. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6253. float x = lua_interface->GetFloatValue(state, 4);
  6254. float y = lua_interface->GetFloatValue(state, 5);
  6255. float z = lua_interface->GetFloatValue(state, 6);
  6256. // Get the spell that this command was called from
  6257. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6258. // Check to make sure the spawn pointer is valid
  6259. if (!spawn) {
  6260. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6261. return 0;
  6262. }
  6263. // Check to make sure the spawn is an entity
  6264. if (!spawn->IsEntity()) {
  6265. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6266. return 0;
  6267. }
  6268. if (!target) {
  6269. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. if (!target->IsEntity()) {
  6273. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6274. return 0;
  6275. }
  6276. // Check to see if the DB ID for the pet is set
  6277. if (pet_id == 0) {
  6278. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6279. return 0;
  6280. }
  6281. // Check to see if the pointer to the spell is valid
  6282. if (!luaspell) {
  6283. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6284. return 0;
  6285. }
  6286. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6287. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6288. if (!pet) {
  6289. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6290. return 0;
  6291. }
  6292. // Check to make sure the pet is an npc
  6293. if (!pet->IsNPC()) {
  6294. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6295. return 0;
  6296. }
  6297. if (x == 0)
  6298. x = spawn->GetX();
  6299. if (y == 0)
  6300. y = spawn->GetY();
  6301. if (z == 0)
  6302. z = spawn->GetZ();
  6303. // Spawn the pet at the same location as the owner
  6304. pet->SetX(x);
  6305. pet->SetY(y);
  6306. pet->SetZ(z);
  6307. pet->SetLocation(spawn->GetLocation());
  6308. pet->SetHeading(spawn->GetHeading());
  6309. spawn->GetZone()->AddSpawn(pet);
  6310. /*
  6311. const char* spawn_script = world.GetSpawnScript(pet_id);
  6312. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6313. spawn->SetSpawnScript(string(spawn_script));
  6314. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6315. }*/
  6316. // Get a random pet name
  6317. string random_pet_name;
  6318. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6319. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6320. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6321. // Set the pets name
  6322. pet->SetName(random_pet_name.c_str());
  6323. // Set the level of the pet to the owners level
  6324. pet->SetLevel(spawn->GetLevel());
  6325. // Set the faction of the pet to the same faction as the owner
  6326. pet->SetFactionID(spawn->GetFactionID());
  6327. // Set the spawn as a pet
  6328. pet->SetPet(true);
  6329. // Give a pointer of the owner to the pet
  6330. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6331. // Set the pet type
  6332. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6333. // Set the spell id used to create this pet
  6334. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6335. // Set the spell tier used to create this pet
  6336. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6337. // Set the pets spawn type to 6
  6338. pet->SetSpawnType(6);
  6339. // Set the pets brain
  6340. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6341. // Check to see if the pet has a subtitle
  6342. if (strlen(pet->GetSubTitle()) > 0) {
  6343. // Add the players name to the front of the sub title
  6344. string pet_subtitle;
  6345. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6346. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6347. // Set the pets subtitle to the new one
  6348. pet->SetSubTitle(pet_subtitle.c_str());
  6349. }
  6350. // Set the pet as the return value for this function
  6351. lua_interface->SetSpawnValue(state, pet);
  6352. return 1;
  6353. }
  6354. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6355. if (!lua_interface)
  6356. return 0;
  6357. Spawn* spawn = lua_interface->GetSpawn(state);
  6358. Spawn* player = lua_interface->GetSpawn(state, 2);
  6359. float max_distance = lua_interface->GetFloatValue(state, 3);
  6360. string type = lua_interface->GetStringValue(state, 4);
  6361. if (!spawn || (spawn && spawn->IsPlayer())) {
  6362. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6363. return 0;
  6364. }
  6365. if (!player || (player && !player->IsPlayer())) {
  6366. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6367. return 0;
  6368. }
  6369. Client* client = 0;
  6370. if (player->GetZone())
  6371. client = player->GetZone()->GetClientBySpawn(player);
  6372. if (!client) {
  6373. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6374. return 0;
  6375. }
  6376. //Set max_distance to default if not set or not proper value
  6377. if (max_distance <= 0)
  6378. max_distance = 500;
  6379. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6380. if (packet) {
  6381. float unknown2_3 = 0;
  6382. int8 placement_mode = 0;
  6383. if (type == "wall") {
  6384. placement_mode = 2;
  6385. unknown2_3 = 150;
  6386. }
  6387. else if (type == "ceiling")
  6388. placement_mode = 1;
  6389. packet->setDataByName("placement_mode", placement_mode);
  6390. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6391. packet->setDataByName("model_type", spawn->GetModelType());
  6392. packet->setDataByName("unknown", 1); //size
  6393. packet->setDataByName("unknown2", 1); //size 2
  6394. packet->setDataByName("unknown2", .5, 1); //size 3
  6395. packet->setDataByName("unknown2", 3, 2);
  6396. packet->setDataByName("unknown2", unknown2_3, 3);
  6397. packet->setDataByName("max_distance", max_distance);
  6398. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6399. client->QueuePacket(packet->serialize());
  6400. safe_delete(packet);
  6401. }
  6402. return 0;
  6403. }
  6404. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6405. if (!lua_interface)
  6406. return 0;
  6407. Item* item = lua_interface->GetItem(state);
  6408. if (!item) {
  6409. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6410. return 0;
  6411. }
  6412. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6413. return 1;
  6414. }
  6415. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6416. if (!lua_interface)
  6417. return 0;
  6418. Spawn* spawn = lua_interface->GetSpawn(state);
  6419. if (!spawn) {
  6420. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6421. return 0;
  6422. }
  6423. if (spawn->GetZone())
  6424. spawn->GetZone()->AddTransportSpawn(spawn);
  6425. return 0;
  6426. }
  6427. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6428. if (!lua_interface)
  6429. return 0;
  6430. Skill* skill = lua_interface->GetSkill(state);
  6431. if (!skill) {
  6432. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6433. return 0;
  6434. }
  6435. lua_interface->SetInt32Value(state, skill->current_val);
  6436. return 1;
  6437. }
  6438. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6439. if (!lua_interface)
  6440. return 0;
  6441. Skill* skill = lua_interface->GetSkill(state);
  6442. if (!skill) {
  6443. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6444. return 0;
  6445. }
  6446. lua_interface->SetInt32Value(state, skill->max_val);
  6447. return 1;
  6448. }
  6449. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6450. if (!lua_interface)
  6451. return 0;
  6452. Skill* skill = lua_interface->GetSkill(state);
  6453. if (!skill) {
  6454. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6455. return 0;
  6456. }
  6457. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6458. return 1;
  6459. }
  6460. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6461. if (!lua_interface)
  6462. return 0;
  6463. Skill* skill = lua_interface->GetSkill(state);
  6464. int16 value = lua_interface->GetInt16Value(state, 2);
  6465. if (!skill) {
  6466. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6467. return 0;
  6468. }
  6469. skill->max_val = value;
  6470. if (skill->max_val < skill->current_val)
  6471. skill->current_val = skill->max_val;
  6472. return 0;
  6473. }
  6474. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6475. if (!lua_interface)
  6476. return 0;
  6477. Skill* skill = lua_interface->GetSkill(state);
  6478. int16 value = lua_interface->GetInt16Value(state, 2);
  6479. if (!skill) {
  6480. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6481. return 0;
  6482. }
  6483. if (value > skill->max_val)
  6484. skill->current_val = skill->max_val;
  6485. else
  6486. skill->current_val = value;
  6487. return 0;
  6488. }
  6489. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6490. if (!lua_interface)
  6491. return 0;
  6492. Spawn* player = lua_interface->GetSpawn(state);
  6493. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6494. if (skill_id > 0 && player && player->IsPlayer()) {
  6495. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6496. return 1;
  6497. }
  6498. return 0;
  6499. }
  6500. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6501. if (!lua_interface)
  6502. return 0;
  6503. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6504. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6505. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6506. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6507. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6508. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6509. if (player_spawn && player_spawn->IsPlayer()) {
  6510. Player* player = (Player*)player_spawn;
  6511. bool added = false;
  6512. if (!player->skill_list.HasSkill(skill_id)) {
  6513. player->AddSkill(skill_id, current_val, max_val, true);
  6514. added = true;
  6515. }
  6516. 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
  6517. Client* client = player->GetClient();
  6518. if (client) {
  6519. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6520. if (packet)
  6521. client->QueuePacket(packet);
  6522. }
  6523. }
  6524. if (added) {
  6525. lua_interface->SetBooleanValue(state, true);
  6526. return 1;
  6527. }
  6528. }
  6529. else {
  6530. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6531. }
  6532. }
  6533. else {
  6534. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6535. }
  6536. lua_interface->SetBooleanValue(state, false);
  6537. return 1;
  6538. }
  6539. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6540. if (!lua_interface)
  6541. return 0;
  6542. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6543. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6544. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6545. if (skill_id > 0) {
  6546. if (player_spawn && player_spawn->IsPlayer()) {
  6547. Player* player = (Player*)player_spawn;
  6548. if (player->skill_list.HasSkill(skill_id)) {
  6549. player->RemovePlayerSkill(skill_id);
  6550. if (!more_to_remove) {
  6551. Client* client = player->GetClient();
  6552. if (client) {
  6553. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6554. if (packet)
  6555. client->QueuePacket(packet);
  6556. }
  6557. }
  6558. }
  6559. }
  6560. else {
  6561. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6562. }
  6563. }
  6564. else {
  6565. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6566. }
  6567. return 0;
  6568. }
  6569. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6570. if (!lua_interface)
  6571. return 0;
  6572. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6573. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6574. int16 amount = lua_interface->GetInt8Value(state, 3);
  6575. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6576. if (amount > 0 && skill_type < 100) {
  6577. if (player_spawn && player_spawn->IsPlayer()) {
  6578. Player* player = (Player*)player_spawn;
  6579. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6580. if (!more_to_increase) {
  6581. Client* client = player->GetClient();
  6582. if (client) {
  6583. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6584. if (packet)
  6585. client->QueuePacket(packet);
  6586. }
  6587. }
  6588. }
  6589. else {
  6590. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6591. }
  6592. }
  6593. else {
  6594. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6595. }
  6596. return 0;
  6597. }
  6598. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6599. if (!lua_interface)
  6600. return 0;
  6601. Spawn* spawn = lua_interface->GetSpawn(state);
  6602. string name = lua_interface->GetStringValue(state, 2);
  6603. if (!spawn) {
  6604. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6605. return 0;
  6606. }
  6607. if (!spawn->IsEntity()) {
  6608. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6609. return 0;
  6610. }
  6611. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6612. if (skill) {
  6613. lua_interface->SetSkillValue(state, skill);
  6614. return 1;
  6615. }
  6616. return 0;
  6617. }
  6618. int EQ2Emu_lua_AddProc(lua_State* state) {
  6619. if (!lua_interface)
  6620. return 0;
  6621. Spawn* spawn = lua_interface->GetSpawn(state);
  6622. int8 type = lua_interface->GetInt8Value(state, 2);
  6623. float chance = lua_interface->GetFloatValue(state, 3);
  6624. Item* item = lua_interface->GetItem(state, 4);
  6625. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6626. LuaSpell* spell = 0;
  6627. if (!spawn && (!spell || !use_all_spelltargets)) {
  6628. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6629. return 0;
  6630. }
  6631. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6632. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6633. return 0;
  6634. }
  6635. if (!item)
  6636. spell = lua_interface->GetCurrentSpell(state);
  6637. if (!item && !spell) {
  6638. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6639. return 0;
  6640. }
  6641. if (spell && use_all_spelltargets) {
  6642. Spawn* target;
  6643. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6644. for (int8 i = 0; i < spell->targets.size(); i++) {
  6645. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6646. if (!target || !target->IsEntity())
  6647. continue;
  6648. ((Entity*)target)->AddProc(type, chance, item, spell);
  6649. }
  6650. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6651. }
  6652. else
  6653. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6654. return 0;
  6655. }
  6656. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6657. if (!lua_interface)
  6658. return 0;
  6659. Spawn* spawn = lua_interface->GetSpawn(state);
  6660. Item* item = lua_interface->GetItem(state, 2);
  6661. LuaSpell* spell = 0;
  6662. if (!spawn) {
  6663. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6664. return 0;
  6665. }
  6666. if (!spawn->IsEntity()) {
  6667. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. if (!item)
  6671. spell = lua_interface->GetCurrentSpell(state);
  6672. if (!item && !spell) {
  6673. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6674. return 0;
  6675. }
  6676. if (spell) {
  6677. Spawn* target;
  6678. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6679. for (int8 i = 0; i < spell->targets.size(); i++) {
  6680. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6681. if (!target || !target->IsEntity())
  6682. continue;
  6683. ((Entity*)target)->RemoveProc(item, spell);
  6684. }
  6685. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6686. spell->caster->RemoveProc(item, spell);
  6687. }
  6688. else
  6689. ((Entity*)spawn)->RemoveProc(item, spell);
  6690. return 0;
  6691. }
  6692. int EQ2Emu_lua_Knockback(lua_State* state) {
  6693. if (!lua_interface)
  6694. return 0;
  6695. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6696. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6697. int32 duration = lua_interface->GetInt32Value(state, 3);
  6698. float vertical = lua_interface->GetFloatValue(state, 4);
  6699. float horizontal = lua_interface->GetFloatValue(state, 5);
  6700. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6701. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6702. if (!target_spawn) {
  6703. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6704. return 0;
  6705. }
  6706. if (!spawn) {
  6707. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6708. return 0;
  6709. }
  6710. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6711. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6712. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6713. if (packet) {
  6714. packet->setDataByName("target_x", target_spawn->GetX());
  6715. packet->setDataByName("target_y", target_spawn->GetY());
  6716. packet->setDataByName("target_z", target_spawn->GetZ());
  6717. packet->setDataByName("vertical_movement", vertical);
  6718. packet->setDataByName("horizontal_movement", horizontal);
  6719. if (use_heading)
  6720. packet->setDataByName("use_player_heading", 1);
  6721. client->QueuePacket(packet->serialize());
  6722. }
  6723. safe_delete(packet);
  6724. }
  6725. return 0;
  6726. }
  6727. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6728. if (!lua_interface)
  6729. return 0;
  6730. Spawn* spawn = lua_interface->GetSpawn(state);
  6731. if (!spawn) {
  6732. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6733. return 0;
  6734. }
  6735. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6736. return 1;
  6737. }
  6738. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6739. if (!lua_interface)
  6740. return 0;
  6741. Spawn* caster = lua_interface->GetSpawn(state);
  6742. Spawn* target = lua_interface->GetSpawn(state, 2);
  6743. string name = lua_interface->GetStringValue(state, 3);
  6744. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6745. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6746. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6747. string success_msg = lua_interface->GetStringValue(state, 7);
  6748. string effect_msg = lua_interface->GetStringValue(state, 8);
  6749. if (!caster) {
  6750. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6751. return 0;
  6752. }
  6753. if (!caster->IsEntity()) {
  6754. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6755. return 0;
  6756. }
  6757. if (!target) {
  6758. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6759. return 0;
  6760. }
  6761. if (!target->IsEntity()) {
  6762. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6763. return 0;
  6764. }
  6765. if (name.length() == 0) {
  6766. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6767. return 0;
  6768. }
  6769. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6770. return 0;
  6771. }
  6772. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6773. if (!lua_interface)
  6774. return 0;
  6775. string name = lua_interface->GetStringValue(state);
  6776. if (name.length() == 0) {
  6777. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6778. return 0;
  6779. }
  6780. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6781. if (!skill) {
  6782. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6783. return 0;
  6784. }
  6785. lua_interface->SetInt32Value(state, skill->skill_id);
  6786. return 1;
  6787. }
  6788. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6789. if (!lua_interface)
  6790. return 0;
  6791. Spawn* spawn = lua_interface->GetSpawn(state);
  6792. if (!spawn) {
  6793. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6794. return 0;
  6795. }
  6796. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6797. return 1;
  6798. }
  6799. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6800. if (!lua_interface)
  6801. return 0;
  6802. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6803. if (!luaspell) {
  6804. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6805. return 0;
  6806. }
  6807. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6808. return 1;
  6809. }
  6810. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6811. if (!lua_interface)
  6812. return 0;
  6813. Spawn* spawn = lua_interface->GetSpawn(state);
  6814. Spawn* target = lua_interface->GetSpawn(state, 2);
  6815. if (!spawn) {
  6816. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6817. return 0;
  6818. }
  6819. if (!spawn->IsEntity()) {
  6820. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6821. return 0;
  6822. }
  6823. if (!target) {
  6824. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6825. return 0;
  6826. }
  6827. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6828. return 1;
  6829. }
  6830. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6831. if (!lua_interface)
  6832. return 0;
  6833. Spawn* spawn = lua_interface->GetSpawn(state);
  6834. Spawn* target = lua_interface->GetSpawn(state, 2);
  6835. if (!spawn) {
  6836. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6837. return 0;
  6838. }
  6839. if (!spawn->IsEntity()) {
  6840. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6841. return 0;
  6842. }
  6843. if (!target) {
  6844. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6845. return 0;
  6846. }
  6847. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6848. return 1;
  6849. }
  6850. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6851. if (!lua_interface)
  6852. return 0;
  6853. Item* item = lua_interface->GetItem(state);
  6854. if (!item) {
  6855. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6856. return 0;
  6857. }
  6858. lua_interface->SetInt32Value(state, item->details.count);
  6859. return 1;
  6860. }
  6861. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6862. if (!lua_interface)
  6863. return 0;
  6864. Item* item = lua_interface->GetItem(state);
  6865. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6866. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6867. if (!item) {
  6868. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6869. return 0;
  6870. }
  6871. if (!owner) {
  6872. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6873. return 0;
  6874. }
  6875. if (!owner->IsPlayer()) {
  6876. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6877. return 0;
  6878. }
  6879. if (item->stack_count < new_count) {
  6880. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6881. return 0;
  6882. }
  6883. if (new_count > 0) {
  6884. item->details.count = new_count;
  6885. item->save_needed = true;
  6886. }
  6887. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6888. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6889. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6890. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6891. else
  6892. {
  6893. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6894. return 0;
  6895. }
  6896. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6897. if (!client)
  6898. return 0;
  6899. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6900. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6901. if (app)
  6902. client->QueuePacket(app);
  6903. return 0;
  6904. }
  6905. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6906. if (!lua_interface)
  6907. return 0;
  6908. int32 time = lua_interface->GetInt32Value(state);
  6909. string function = lua_interface->GetStringValue(state, 2);
  6910. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6911. Spawn* target = lua_interface->GetSpawn(state, 4);
  6912. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6913. if (time == 0) {
  6914. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6915. return 0;
  6916. }
  6917. if (function.length() == 0) {
  6918. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6919. return 0;
  6920. }
  6921. if (!spell) {
  6922. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6923. return 0;
  6924. }
  6925. SpellScriptTimer* timer = new SpellScriptTimer;
  6926. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6927. #ifdef WIN32
  6928. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6929. #else
  6930. bzero(timer, sizeof(SpellScriptTimer));
  6931. #endif*/
  6932. timer->caster = 0;
  6933. timer->deleteWhenDone = false;
  6934. timer->target = 0;
  6935. timer->time = Timer::GetCurrentTime2() + time;
  6936. timer->customFunction = function;
  6937. timer->spell = spell;
  6938. if (caster)
  6939. timer->caster = caster->GetID();
  6940. if (target)
  6941. timer->target = target->GetID();
  6942. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6943. return 0;
  6944. }
  6945. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6946. if (!lua_interface)
  6947. return 0;
  6948. float hp_perc = lua_interface->GetFloatValue(state);
  6949. float power_perc = lua_interface->GetFloatValue(state, 2);
  6950. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6951. Spawn* target = lua_interface->GetSpawn(state, 4);
  6952. string heal_name = lua_interface->GetStringValue(state, 5);
  6953. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6954. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6955. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6956. if (!spell) {
  6957. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6958. return 0;
  6959. }
  6960. Entity* caster = spell->caster;
  6961. if (!caster) {
  6962. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6963. return 0;
  6964. }
  6965. Client* client = 0;
  6966. PendingResurrection* rez = 0;
  6967. ZoneServer* zone = spell->caster->GetZone();
  6968. if (!target) {
  6969. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6970. if (spell->targets.size() > 0) {
  6971. vector<int32> spell_targets = spell->targets;
  6972. for (int8 i = 0; i < spell_targets.size(); i++) {
  6973. target = zone->GetSpawnByID(spell_targets.at(i));
  6974. if (!target)
  6975. continue;
  6976. if (!target->IsPlayer())
  6977. continue;
  6978. client = target->GetZone()->GetClientBySpawn(target);
  6979. if (!client)
  6980. continue;
  6981. rez = client->GetCurrentRez();
  6982. if (rez->active)
  6983. continue;
  6984. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6985. rez->active = true;
  6986. rez->caster = caster;
  6987. rez->expire_timer = new Timer;
  6988. int32 duration = spell->spell->GetSpellDuration();
  6989. rez->expire_timer->Start(duration * 100);
  6990. rez->hp_perc = hp_perc;
  6991. rez->mp_perc = power_perc;
  6992. rez->range = spell->spell->GetSpellData()->range;
  6993. rez->spell_name = spell->spell->GetName();
  6994. if (heal_name.length() > 0)
  6995. rez->heal_name = heal_name;
  6996. else
  6997. rez->heal_name = rez->spell_name;
  6998. rez->no_calcs = no_calcs;
  6999. rez->crit_mod = crit_mod;
  7000. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7001. if (send_window)
  7002. client->SendResurrectionWindow();
  7003. else {
  7004. target->GetZone()->ResurrectSpawn(target, client);
  7005. rez->should_delete = true;
  7006. }
  7007. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7008. }
  7009. }
  7010. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7011. }
  7012. else {
  7013. client = target->GetZone()->GetClientBySpawn(target);
  7014. if (!client)
  7015. return 0;
  7016. rez = client->GetCurrentRez();
  7017. if (rez->active)
  7018. return 0;
  7019. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7020. rez->active = true;
  7021. rez->caster = caster;
  7022. rez->expire_timer = new Timer;
  7023. int32 duration = spell->spell->GetSpellDuration();
  7024. rez->expire_timer->Start(duration * 100);
  7025. rez->hp_perc = hp_perc;
  7026. rez->mp_perc = power_perc;
  7027. rez->range = spell->spell->GetSpellData()->range;
  7028. rez->spell_name = spell->spell->GetName();
  7029. if (heal_name.length() > 0)
  7030. rez->heal_name = heal_name;
  7031. else
  7032. rez->heal_name = rez->spell_name;
  7033. rez->no_calcs = no_calcs;
  7034. rez->crit_mod = crit_mod;
  7035. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7036. if (send_window)
  7037. client->SendResurrectionWindow();
  7038. else {
  7039. target->GetZone()->ResurrectSpawn(target, client);
  7040. rez->should_delete = true;
  7041. }
  7042. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7043. }
  7044. return 0;
  7045. }
  7046. int EQ2Emu_lua_SetVision(lua_State* state) {
  7047. if (!lua_interface)
  7048. return 0;
  7049. Spawn* spawn = lua_interface->GetSpawn(state);
  7050. int8 vision = lua_interface->GetInt8Value(state, 2);
  7051. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7052. if (!spawn) {
  7053. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7054. return 0;
  7055. }
  7056. if (!spawn->IsEntity()) {
  7057. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7058. return 0;
  7059. }
  7060. if (spell && spell->targets.size() > 0) {
  7061. ZoneServer* zone = spell->caster->GetZone();
  7062. for (int8 i = 0; i < spell->targets.size(); i++) {
  7063. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7064. if (target->IsEntity()) {
  7065. ((Entity*)target)->GetInfoStruct()->vision = vision;
  7066. if (target->IsPlayer())
  7067. ((Player*)target)->SetCharSheetChanged(true);
  7068. }
  7069. }
  7070. }
  7071. else {
  7072. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  7073. if (spawn->IsPlayer())
  7074. ((Player*)spawn)->SetCharSheetChanged(true);
  7075. }
  7076. return 0;
  7077. }
  7078. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7079. if (!lua_interface)
  7080. return 0;
  7081. Spawn* spawn = lua_interface->GetSpawn(state);
  7082. float intensity = lua_interface->GetFloatValue(state, 2);
  7083. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7084. if (!spawn) {
  7085. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7086. return 0;
  7087. }
  7088. if (!spawn->IsEntity()) {
  7089. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7090. return 0;
  7091. }
  7092. if (spell && spell->targets.size() > 0) {
  7093. ZoneServer* zone = spell->caster->GetZone();
  7094. for (int8 i = 0; i < spell->targets.size(); i++) {
  7095. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7096. if (target && target->IsEntity()) {
  7097. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  7098. if (target->IsPlayer())
  7099. ((Player*)target)->SetCharSheetChanged(true);
  7100. }
  7101. }
  7102. }
  7103. else {
  7104. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  7105. if (spawn->IsPlayer())
  7106. ((Player*)spawn)->SetCharSheetChanged(true);
  7107. }
  7108. return 0;
  7109. }
  7110. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7111. if (!lua_interface)
  7112. return 0;
  7113. Spawn* spawn = lua_interface->GetSpawn(state);
  7114. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7115. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7116. if (!spawn) {
  7117. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7118. return 0;
  7119. }
  7120. if (!spawn->IsEntity()) {
  7121. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7122. return 0;
  7123. }
  7124. if (spell && spell->targets.size() > 0) {
  7125. ZoneServer* zone = spell->caster->GetZone();
  7126. for (int8 i = 0; i < spell->targets.size(); i++) {
  7127. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7128. if (target->IsEntity()) {
  7129. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7130. if (target->IsPlayer())
  7131. ((Player*)target)->SetCharSheetChanged(true);
  7132. }
  7133. }
  7134. }
  7135. else {
  7136. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7137. if (spawn->IsPlayer())
  7138. ((Player*)spawn)->SetCharSheetChanged(true);
  7139. }
  7140. return 0;
  7141. }
  7142. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7143. if (!lua_interface)
  7144. return 0;
  7145. Item* item = lua_interface->GetItem(state);
  7146. int8 type = lua_interface->GetInt32Value(state, 2);
  7147. if (!item) {
  7148. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7149. return 0;
  7150. }
  7151. if (type == 1)
  7152. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7153. else if (type == 2)
  7154. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7155. return 1;
  7156. }
  7157. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7158. if (!lua_interface)
  7159. return 0;
  7160. Spawn* target = lua_interface->GetSpawn(state);
  7161. float val = lua_interface->GetFloatValue(state, 2);
  7162. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7163. // Added from Gangrenous post
  7164. if (spell && spell->resisted)
  7165. return 0;
  7166. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7167. if (val > 1.0f)
  7168. val = 1.0f - (val / 100.0f);
  7169. if (spell && spell->spell && spell->targets.size() > 0) {
  7170. ZoneServer* zone = spell->caster->GetZone();
  7171. for (int32 i = 0; i != spell->targets.size(); i++) {
  7172. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7173. if (spawn && spawn->IsEntity()) {
  7174. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7175. if (spawn->IsPlayer())
  7176. ((Player*)spawn)->SetCharSheetChanged(true);
  7177. }
  7178. }
  7179. }
  7180. else {
  7181. if (target && target->IsEntity()) {
  7182. ((Entity*)target)->SetSpeedMultiplier(val);
  7183. if (target->IsPlayer())
  7184. ((Player*)target)->SetCharSheetChanged(true);
  7185. }
  7186. }
  7187. return 0;
  7188. }
  7189. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7190. if (!lua_interface)
  7191. return 0;
  7192. Spawn* spawn = lua_interface->GetSpawn(state);
  7193. int16 model = lua_interface->GetInt16Value(state, 2);
  7194. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7195. if (spell && spell->spell && spell->targets.size() > 0) {
  7196. ZoneServer* zone = spell->caster->GetZone();
  7197. for (int32 i = 0; i < spell->targets.size(); i++) {
  7198. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7199. if (target)
  7200. target->SetIllusionModel(model);
  7201. }
  7202. }
  7203. else {
  7204. if (!spawn) {
  7205. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7206. return 0;
  7207. }
  7208. spawn->SetIllusionModel(model);
  7209. }
  7210. return 0;
  7211. }
  7212. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7213. if (!lua_interface)
  7214. return 0;
  7215. Spawn* spawn = lua_interface->GetSpawn(state);
  7216. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7217. if (spell && spell->spell && spell->targets.size() > 0) {
  7218. ZoneServer* zone = spell->caster->GetZone();
  7219. for (int32 i = 0; i < spell->targets.size(); i++) {
  7220. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7221. if (target)
  7222. target->SetIllusionModel(0);
  7223. }
  7224. }
  7225. else {
  7226. if (!spawn) {
  7227. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7228. return 0;
  7229. }
  7230. spawn->SetIllusionModel(0);
  7231. }
  7232. return 0;
  7233. }
  7234. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7235. if (!lua_interface)
  7236. return 0;
  7237. Spawn* caster = lua_interface->GetSpawn(state);
  7238. Spawn* target = lua_interface->GetSpawn(state, 2);
  7239. float chance = lua_interface->GetFloatValue(state, 3);
  7240. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7241. if (!caster) {
  7242. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7243. return 0;
  7244. }
  7245. if (!caster->IsEntity()) {
  7246. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7247. return 0;
  7248. }
  7249. if (!target) {
  7250. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7251. return 0;
  7252. }
  7253. if (!target->IsEntity()) {
  7254. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7255. return 0;
  7256. }
  7257. if (chance <= 0) {
  7258. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7259. return 0;
  7260. }
  7261. if (!spell) {
  7262. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7263. return 0;
  7264. }
  7265. if (((Entity*)caster)->GetThreatTransfer()) {
  7266. return 0;
  7267. }
  7268. ThreatTransfer* transfer = new ThreatTransfer;
  7269. transfer->Target = target->GetID();
  7270. transfer->Amount = chance;
  7271. transfer->Spell = spell;
  7272. ((Entity*)caster)->SetThreatTransfer(transfer);
  7273. return 0;
  7274. }
  7275. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7276. if (!lua_interface)
  7277. return 0;
  7278. Spawn* spawn = lua_interface->GetSpawn(state);
  7279. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7280. if (!spawn) {
  7281. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7282. return 0;
  7283. }
  7284. if (!spell) {
  7285. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7286. return 0;
  7287. }
  7288. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7289. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7290. ((Entity*)spawn)->SetThreatTransfer(0);
  7291. safe_delete(transfer);
  7292. }
  7293. return 0;
  7294. }
  7295. int EQ2Emu_lua_CureByType(lua_State* state) {
  7296. if (!lua_interface)
  7297. return 0;
  7298. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7299. if (!spell) {
  7300. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7301. return 0;
  7302. }
  7303. int8 cure_count = lua_interface->GetInt8Value(state);
  7304. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7305. string cure_name = lua_interface->GetStringValue(state, 3);
  7306. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7307. Spawn* target = lua_interface->GetSpawn(state, 5);
  7308. if (target) {
  7309. if (!target->IsEntity()) {
  7310. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7311. return 0;
  7312. }
  7313. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7314. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7315. }
  7316. else {
  7317. ZoneServer* zone = spell->caster->GetZone();
  7318. vector<int32> targets = spell->targets;
  7319. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7320. for (int8 i = 0; i < targets.size(); i++) {
  7321. target = zone->GetSpawnByID(targets.at(i));
  7322. if (!target || !target->IsEntity())
  7323. continue;
  7324. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7325. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7326. }
  7327. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7328. }
  7329. return 0;
  7330. }
  7331. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7332. if (!lua_interface)
  7333. return 0;
  7334. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7335. if (!spell) {
  7336. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7337. return 0;
  7338. }
  7339. int8 cure_count = lua_interface->GetInt8Value(state);
  7340. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7341. string cure_name = lua_interface->GetStringValue(state, 3);
  7342. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7343. Spawn* target = lua_interface->GetSpawn(state, 5);
  7344. if (target) {
  7345. if (!target->IsEntity()) {
  7346. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7347. return 0;
  7348. }
  7349. if (((Entity*)target)->GetDetCount() > 0)
  7350. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7351. }
  7352. else {
  7353. ZoneServer* zone = spell->caster->GetZone();
  7354. vector<int32> targets = spell->targets;
  7355. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7356. for (int8 i = 0; i < targets.size(); i++) {
  7357. target = zone->GetSpawnByID(targets.at(i));
  7358. if (!target || !target->IsEntity())
  7359. continue;
  7360. if (((Entity*)target)->GetDetCount() > 0)
  7361. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7362. }
  7363. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7364. }
  7365. return 0;
  7366. }
  7367. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7368. if (!lua_interface)
  7369. return 0;
  7370. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7371. if (!spell) {
  7372. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7373. return 0;
  7374. }
  7375. if (!spell->caster) {
  7376. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7377. return 0;
  7378. }
  7379. if (!spell->caster->GetZone()) {
  7380. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7381. return 0;
  7382. }
  7383. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7384. return 0;
  7385. }
  7386. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7387. if (!lua_interface)
  7388. return 0;
  7389. Spawn* spawn = lua_interface->GetSpawn(state);
  7390. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7391. if (!spell) {
  7392. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7393. return 0;
  7394. }
  7395. if (spawn && spawn->IsEntity())
  7396. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7397. else {
  7398. ZoneServer* zone = spell->caster->GetZone();
  7399. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7400. for (int32 i = 0; i < spell->targets.size(); i++) {
  7401. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7402. if (!spawn || !spawn->IsEntity())
  7403. continue;
  7404. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7405. }
  7406. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7407. }
  7408. return 0;
  7409. }
  7410. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7411. if (!lua_interface)
  7412. return 0;
  7413. Spawn* spawn = lua_interface->GetSpawn(state);
  7414. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7415. if (!spell) {
  7416. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7417. return 0;
  7418. }
  7419. if (spawn && spawn->IsEntity())
  7420. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7421. else {
  7422. ZoneServer* zone = spell->caster->GetZone();
  7423. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7424. for (int32 i = 0; i < spell->targets.size(); i++) {
  7425. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7426. if (!spawn || !spawn->IsEntity())
  7427. continue;
  7428. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7429. }
  7430. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7431. }
  7432. return 0;
  7433. }
  7434. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7435. if (!lua_interface)
  7436. return 0;
  7437. Spawn* caster = lua_interface->GetSpawn(state);
  7438. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7439. if (!caster) {
  7440. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7441. return 0;
  7442. }
  7443. if (!caster->IsPlayer()) {
  7444. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7445. return 0;
  7446. }
  7447. Spawn* target = caster->GetTarget();
  7448. if (!target) {
  7449. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7450. return 0;
  7451. }
  7452. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7453. if (!client) {
  7454. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7455. return 0;
  7456. }
  7457. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7458. if (ho) {
  7459. ho->SetTarget(target->GetID());
  7460. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7461. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7462. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7463. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7464. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7465. deque<GroupMemberInfo*>::iterator itr;
  7466. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7467. if (group)
  7468. {
  7469. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7470. deque<GroupMemberInfo*>* members = group->GetMembers();
  7471. for (itr = members->begin(); itr != members->end(); itr++) {
  7472. if ((*itr)->client)
  7473. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7474. }
  7475. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7476. }
  7477. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7478. }
  7479. else
  7480. safe_delete(ho);
  7481. }
  7482. else {
  7483. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7484. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7485. }
  7486. else
  7487. safe_delete(ho);
  7488. }
  7489. }
  7490. return 0;
  7491. }
  7492. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7493. if (!lua_interface)
  7494. return 0;
  7495. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7496. if (!spell) {
  7497. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7498. return 0;
  7499. }
  7500. int16 triggerCount = lua_interface->GetInt16Value(state);
  7501. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7502. if (!triggerCount) {
  7503. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7504. return 0;
  7505. }
  7506. spell->num_triggers = triggerCount;
  7507. spell->had_triggers = true;
  7508. spell->cancel_after_all_triggers = cancel_after_triggers;
  7509. return 0;
  7510. }
  7511. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7512. if (!lua_interface)
  7513. return 0;
  7514. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7515. if (!spell) {
  7516. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7517. return 0;
  7518. }
  7519. lua_interface->SetInt32Value(state, spell->num_triggers);
  7520. return 1;
  7521. }
  7522. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7523. if (!lua_interface)
  7524. return 0;
  7525. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7526. if (!spell) {
  7527. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7528. return 0;
  7529. }
  7530. int16 remove_count = lua_interface->GetInt16Value(state);
  7531. if (!remove_count)
  7532. remove_count = 1;
  7533. if (remove_count >= spell->num_triggers) {
  7534. spell->num_triggers = 0;
  7535. if (spell->cancel_after_all_triggers)
  7536. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7537. }
  7538. else {
  7539. spell->num_triggers -= remove_count;
  7540. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7541. }
  7542. return 0;
  7543. }
  7544. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7545. if (!lua_interface)
  7546. return 0;
  7547. Spawn* spawn = lua_interface->GetSpawn(state);
  7548. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7549. if (!spawn) {
  7550. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7551. return 0;
  7552. }
  7553. if (!copy_spawn) {
  7554. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7555. return 0;
  7556. }
  7557. spawn->CopySpawnAppearance(copy_spawn);
  7558. return 0;
  7559. }
  7560. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7561. if (!lua_interface)
  7562. return 0;
  7563. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7564. int8 type = lua_interface->GetInt8Value(state);
  7565. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7566. if (!spell) {
  7567. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7568. return 0;
  7569. }
  7570. if (spawn) {
  7571. if (!spawn->IsEntity()) {
  7572. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7573. return 0;
  7574. }
  7575. Entity* entity = ((Entity*)spawn);
  7576. switch (type) {
  7577. case IMMUNITY_TYPE_AOE:
  7578. entity->AddAOEImmunity(spell);
  7579. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7580. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7581. break;
  7582. case IMMUNITY_TYPE_STUN:
  7583. entity->AddStunImmunity(spell);
  7584. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7585. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7586. break;
  7587. case IMMUNITY_TYPE_ROOT:
  7588. entity->AddRootImmunity(spell);
  7589. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7590. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7591. break;
  7592. case IMMUNITY_TYPE_DAZE:
  7593. entity->AddDazeImmunity(spell);
  7594. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7595. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7596. break;
  7597. case IMMUNITY_TYPE_FEAR:
  7598. entity->AddFearImmunity(spell);
  7599. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7600. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7601. break;
  7602. case IMMUNITY_TYPE_MEZ:
  7603. entity->AddMezImmunity(spell);
  7604. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7605. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7606. break;
  7607. case IMMUNITY_TYPE_STIFLE:
  7608. entity->AddStifleImmunity(spell);
  7609. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7610. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7611. break;
  7612. default:
  7613. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7614. }
  7615. }
  7616. else {
  7617. bool should_break = false;
  7618. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7619. for (int8 i = 0; i < spell->targets.size(); i++) {
  7620. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7621. if (!spawn || !spawn->IsEntity())
  7622. continue;
  7623. Entity* entity = ((Entity*)spawn);
  7624. switch (type) {
  7625. case IMMUNITY_TYPE_AOE:
  7626. entity->AddAOEImmunity(spell);
  7627. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7628. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7629. break;
  7630. case IMMUNITY_TYPE_STUN:
  7631. entity->AddStunImmunity(spell);
  7632. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7633. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7634. break;
  7635. case IMMUNITY_TYPE_ROOT:
  7636. entity->AddRootImmunity(spell);
  7637. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7638. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7639. break;
  7640. case IMMUNITY_TYPE_DAZE:
  7641. entity->AddDazeImmunity(spell);
  7642. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7643. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7644. break;
  7645. case IMMUNITY_TYPE_FEAR:
  7646. entity->AddFearImmunity(spell);
  7647. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7648. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7649. break;
  7650. case IMMUNITY_TYPE_MEZ:
  7651. entity->AddMezImmunity(spell);
  7652. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7653. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7654. break;
  7655. case IMMUNITY_TYPE_STIFLE:
  7656. entity->AddStifleImmunity(spell);
  7657. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7658. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7659. break;
  7660. default:
  7661. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7662. should_break = true;
  7663. }
  7664. if (should_break)
  7665. break;
  7666. }
  7667. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7668. }
  7669. return 0;
  7670. }
  7671. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7672. if (!lua_interface)
  7673. return 0;
  7674. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7675. int8 type = lua_interface->GetInt8Value(state);
  7676. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7677. if (!spell) {
  7678. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7679. return 0;
  7680. }
  7681. if (spawn) {
  7682. if (!spawn->IsEntity()) {
  7683. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7684. return 0;
  7685. }
  7686. Entity* entity = ((Entity*)spawn);
  7687. switch (type) {
  7688. case IMMUNITY_TYPE_AOE:
  7689. entity->RemoveAOEImmunity(spell);
  7690. break;
  7691. case IMMUNITY_TYPE_STUN:
  7692. entity->RemoveStunImmunity(spell);
  7693. break;
  7694. case IMMUNITY_TYPE_ROOT:
  7695. entity->RemoveRootImmunity(spell);
  7696. break;
  7697. case IMMUNITY_TYPE_DAZE:
  7698. entity->RemoveDazeImmunity(spell);
  7699. break;
  7700. case IMMUNITY_TYPE_FEAR:
  7701. entity->RemoveFearImmunity(spell);
  7702. break;
  7703. case IMMUNITY_TYPE_MEZ:
  7704. entity->RemoveMezImmunity(spell);
  7705. break;
  7706. case IMMUNITY_TYPE_STIFLE:
  7707. entity->RemoveStifleImmunity(spell);
  7708. break;
  7709. default:
  7710. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7711. }
  7712. }
  7713. else {
  7714. bool should_break = false;
  7715. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7716. for (int8 i = 0; i < spell->targets.size(); i++) {
  7717. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7718. if (!spawn || !spawn->IsEntity())
  7719. continue;
  7720. Entity* entity = ((Entity*)spawn);
  7721. switch (type) {
  7722. case IMMUNITY_TYPE_AOE:
  7723. entity->RemoveAOEImmunity(spell);
  7724. break;
  7725. case IMMUNITY_TYPE_STUN:
  7726. entity->RemoveStunImmunity(spell);
  7727. break;
  7728. case IMMUNITY_TYPE_ROOT:
  7729. entity->RemoveRootImmunity(spell);
  7730. break;
  7731. case IMMUNITY_TYPE_DAZE:
  7732. entity->RemoveDazeImmunity(spell);
  7733. break;
  7734. case IMMUNITY_TYPE_FEAR:
  7735. entity->RemoveFearImmunity(spell);
  7736. break;
  7737. case IMMUNITY_TYPE_MEZ:
  7738. entity->RemoveMezImmunity(spell);
  7739. break;
  7740. case IMMUNITY_TYPE_STIFLE:
  7741. entity->RemoveStifleImmunity(spell);
  7742. break;
  7743. default:
  7744. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7745. should_break = true;
  7746. }
  7747. if (should_break)
  7748. break;
  7749. }
  7750. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7751. }
  7752. return 0;
  7753. }
  7754. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7755. if (!lua_interface)
  7756. return 0;
  7757. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7758. if (!spell) {
  7759. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7760. return 0;
  7761. }
  7762. float snare = lua_interface->GetFloatValue(state);
  7763. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7764. // convert the val to the speed multipler value (100 - val)
  7765. float val = 100.0 - snare;
  7766. val /= 100.0;
  7767. if (spawn) {
  7768. if (!spawn->IsEntity()) {
  7769. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7770. return 0;
  7771. }
  7772. ((Entity*)spawn)->SetSnareValue(spell, val);
  7773. }
  7774. else {
  7775. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7776. for (int8 i = 0; i < spell->targets.size(); i++) {
  7777. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7778. if (!spawn || !spawn->IsEntity())
  7779. continue;
  7780. ((Entity*)spawn)->SetSnareValue(spell, val);
  7781. }
  7782. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7783. }
  7784. return 0;
  7785. }
  7786. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7787. if (!lua_interface)
  7788. return 0;
  7789. Spawn* spawn = lua_interface->GetSpawn(state);
  7790. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7791. if (!spawn) {
  7792. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7793. return 0;
  7794. }
  7795. if (race_id == 0) {
  7796. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7800. return 1;
  7801. }
  7802. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7803. if (!lua_interface)
  7804. return 0;
  7805. Spawn* spawn = lua_interface->GetSpawn(state);
  7806. if (!spawn) {
  7807. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7808. return 0;
  7809. }
  7810. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7811. return 1;
  7812. }
  7813. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7814. if (!lua_interface)
  7815. return 0;
  7816. Spawn* spawn = lua_interface->GetSpawn(state);
  7817. if (!spawn) {
  7818. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7819. return 0;
  7820. }
  7821. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7822. return 1;
  7823. }
  7824. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7825. if (!lua_interface)
  7826. return 0;
  7827. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7828. if (!spell) {
  7829. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7830. return 0;
  7831. }
  7832. lua_interface->SetStringValue(state, spell->spell->GetName());
  7833. return 1;
  7834. }
  7835. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7836. if (!lua_interface)
  7837. return 0;
  7838. Quest* quest = lua_interface->GetQuest(state);
  7839. if (!quest) {
  7840. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7841. return 0;
  7842. }
  7843. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7844. return 1;
  7845. }
  7846. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7847. if (!lua_interface)
  7848. return 0;
  7849. Quest* quest = lua_interface->GetQuest(state);
  7850. int32 flags = lua_interface->GetInt32Value(state, 2);
  7851. if (!quest) {
  7852. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7853. return 0;
  7854. }
  7855. quest->SetQuestFlags(flags);
  7856. return 0;
  7857. }
  7858. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7859. if (!lua_interface)
  7860. return 0;
  7861. Quest* quest = lua_interface->GetQuest(state);
  7862. Spawn* player = lua_interface->GetSpawn(state, 2);
  7863. int32 step = lua_interface->GetInt32Value(state, 3);
  7864. int32 duration = lua_interface->GetInt32Value(state, 4);
  7865. string action = lua_interface->GetStringValue(state, 5);
  7866. if (!quest) {
  7867. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7868. return 0;
  7869. }
  7870. if (!player) {
  7871. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7872. return 0;
  7873. }
  7874. if (!player->IsPlayer()) {
  7875. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7876. return 0;
  7877. }
  7878. if (step == 0) {
  7879. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7880. return 0;
  7881. }
  7882. if (duration == 0) {
  7883. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7884. return 0;
  7885. }
  7886. if (action.length() == 0) {
  7887. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7888. return 0;
  7889. }
  7890. Client* client = player->GetZone()->GetClientBySpawn(player);
  7891. if (!client) {
  7892. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7893. return 0;
  7894. }
  7895. quest->SetTimerStep(step);
  7896. quest->AddFailedAction(step, action);
  7897. quest->SetStepTimer(duration);
  7898. client->AddQuestTimer(quest->GetQuestID());
  7899. return 0;
  7900. }
  7901. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7902. if (!lua_interface)
  7903. return 0;
  7904. Quest* quest = lua_interface->GetQuest(state);
  7905. Spawn* player = lua_interface->GetSpawn(state, 2);
  7906. if (!quest) {
  7907. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7908. return 0;
  7909. }
  7910. if (!player) {
  7911. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7912. return 0;
  7913. }
  7914. if (!player->IsPlayer()) {
  7915. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7916. return 0;
  7917. }
  7918. Client* client = player->GetZone()->GetClientBySpawn(player);
  7919. if (!client) {
  7920. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7921. return 0;
  7922. }
  7923. quest->SetTimerStep(0);
  7924. quest->SetStepTimer(0);
  7925. client->RemoveQuestTimer(quest->GetQuestID());
  7926. return 0;
  7927. }
  7928. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7929. if (!lua_interface)
  7930. return 0;
  7931. Spawn* player = lua_interface->GetSpawn(state);
  7932. Quest* quest = lua_interface->GetQuest(state, 2);
  7933. int32 step = lua_interface->GetInt32Value(state, 3);
  7934. if (!player) {
  7935. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7936. return 0;
  7937. }
  7938. if (!player->IsPlayer()) {
  7939. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7940. return 0;
  7941. }
  7942. if (!quest) {
  7943. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7944. return 0;
  7945. }
  7946. if (step == 0) {
  7947. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7948. return 0;
  7949. }
  7950. Client* client = player->GetZone()->GetClientBySpawn(player);
  7951. if (!client) {
  7952. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7953. return 0;
  7954. }
  7955. if (quest->RemoveQuestStep(step, client)) {
  7956. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7957. client->GetCurrentZone()->SendQuestUpdates(client);
  7958. }
  7959. else
  7960. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7961. return 0;
  7962. }
  7963. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7964. if (!lua_interface)
  7965. return 0;
  7966. Quest* quest = lua_interface->GetQuest(state, 1);
  7967. int32 step = lua_interface->GetInt32Value(state, 2);
  7968. string desc = lua_interface->GetStringValue(state, 3);
  7969. string task_group = lua_interface->GetStringValue(state, 4);
  7970. if (!quest) {
  7971. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7972. return 0;
  7973. }
  7974. if (step == 0) {
  7975. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7976. return 0;
  7977. }
  7978. QuestStep* quest_step = quest->GetQuestStep(step);
  7979. if (!quest_step) {
  7980. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7981. return 0;
  7982. }
  7983. quest_step->SetStepProgress(0);
  7984. quest_step->SetTaskGroup(task_group);
  7985. quest_step->SetDescription(desc);
  7986. return 0;
  7987. }
  7988. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7989. if (!lua_interface)
  7990. return 0;
  7991. Quest* quest = lua_interface->GetQuest(state);
  7992. int32 step = lua_interface->GetInt32Value(state, 2);
  7993. string action = lua_interface->GetStringValue(state, 3);
  7994. if (!quest) {
  7995. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7996. return 0;
  7997. }
  7998. if (step == 0) {
  7999. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8000. return 0;
  8001. }
  8002. if (action.length() == 0) {
  8003. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8004. return 0;
  8005. }
  8006. quest->AddFailedAction(step, action);
  8007. return 0;
  8008. }
  8009. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8010. if (!lua_interface)
  8011. return 0;
  8012. Spawn* player = lua_interface->GetSpawn(state);
  8013. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8014. int32 step = lua_interface->GetInt32Value(state, 3);
  8015. if (!player) {
  8016. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8017. return 0;
  8018. }
  8019. if (!player->IsPlayer()) {
  8020. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8021. return 0;
  8022. }
  8023. if (quest_id == 0) {
  8024. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8025. return 0;
  8026. }
  8027. if (step == 0) {
  8028. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8029. return 0;
  8030. }
  8031. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8032. if (!quest) {
  8033. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8034. return 0;
  8035. }
  8036. quest->StepFailed(step);
  8037. return 0;
  8038. }
  8039. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8040. if (!lua_interface)
  8041. return 0;
  8042. Spawn* player = lua_interface->GetSpawn(state);
  8043. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8044. if (!player) {
  8045. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8046. return 0;
  8047. }
  8048. if (!player->IsPlayer()) {
  8049. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8050. return 0;
  8051. }
  8052. if (quest_id == 0) {
  8053. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8054. return 0;
  8055. }
  8056. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8057. if (!quest) {
  8058. lua_interface->SetInt32Value(state, 0);
  8059. return 1;
  8060. }
  8061. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8062. return 1;
  8063. }
  8064. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8065. if (!lua_interface)
  8066. return 0;
  8067. string name = lua_interface->GetStringValue(state);
  8068. string value = lua_interface->GetStringValue(state, 2);
  8069. string comment = lua_interface->GetStringValue(state, 3);
  8070. if (name.length() == 0) {
  8071. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8072. return 0;
  8073. }
  8074. if (value.length() == 0) {
  8075. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. string varname = string("lua_").append(name);
  8079. Variable* var = variables.FindVariable(varname);
  8080. if (var)
  8081. var->SetValue(value.c_str());
  8082. else {
  8083. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8084. variables.AddVariable(var);
  8085. }
  8086. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8087. return 0;
  8088. }
  8089. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8090. if (!lua_interface)
  8091. return 0;
  8092. string name = lua_interface->GetStringValue(state);
  8093. if (name.length() == 0) {
  8094. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8095. return 0;
  8096. }
  8097. string varname = string("lua_").append(name);
  8098. Variable* var = variables.FindVariable(varname);
  8099. if (var)
  8100. lua_interface->SetStringValue(state, var->GetValue());
  8101. else
  8102. lua_interface->SetStringValue(state, "NULL");
  8103. return 1;
  8104. }
  8105. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8106. if (!lua_interface)
  8107. return 0;
  8108. Spawn* player = lua_interface->GetSpawn(state);
  8109. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8110. if (!player) {
  8111. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8112. return 0;
  8113. }
  8114. if (!player->IsPlayer()) {
  8115. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8116. return 0;
  8117. }
  8118. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8119. return 1;
  8120. }
  8121. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8122. if (!lua_interface)
  8123. return 0;
  8124. Spawn* player = lua_interface->GetSpawn(state);
  8125. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8126. if (!player) {
  8127. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8128. return 0;
  8129. }
  8130. if (!player->IsPlayer()) {
  8131. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8132. return 0;
  8133. }
  8134. Language* language = master_languages_list.GetLanguage(language_id);
  8135. if (language)
  8136. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8137. return 0;
  8138. }
  8139. int EQ2Emu_lua_IsNight(lua_State* state) {
  8140. if (!lua_interface)
  8141. return 0;
  8142. ZoneServer* zone = lua_interface->GetZone(state);
  8143. if (!zone) {
  8144. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8145. return 0;
  8146. }
  8147. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8148. return 1;
  8149. }
  8150. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8151. if (!lua_interface)
  8152. return 0;
  8153. Spawn* spawn = lua_interface->GetSpawn(state);
  8154. if (!spawn) {
  8155. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8156. return 0;
  8157. }
  8158. if (!spawn->IsWidget()) {
  8159. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8160. return 0;
  8161. }
  8162. ((Widget*)spawn)->SetMultiFloorLift(true);
  8163. if (spawn->GetZone())
  8164. spawn->GetZone()->AddTransportSpawn(spawn);
  8165. return 0;
  8166. }
  8167. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8168. if (!lua_interface)
  8169. return 0;
  8170. Spawn* player = lua_interface->GetSpawn(state);
  8171. int32 path = lua_interface->GetInt32Value(state, 2);
  8172. if (!player) {
  8173. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8174. return 0;
  8175. }
  8176. if (!player->IsPlayer()) {
  8177. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8178. return 0;
  8179. }
  8180. if (path == 0) {
  8181. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8182. return 0;
  8183. }
  8184. Client* client = player->GetZone()->GetClientBySpawn(player);
  8185. if (!client) {
  8186. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8187. return 0;
  8188. }
  8189. client->SendFlightAutoMount(path);
  8190. return 0;
  8191. }
  8192. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8193. if (!lua_interface)
  8194. return 0;
  8195. Spawn* player = lua_interface->GetSpawn(state);
  8196. if (!player) {
  8197. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8198. return 0;
  8199. }
  8200. if (!player->IsPlayer()) {
  8201. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8202. return 0;
  8203. }
  8204. Client* client = player->GetZone()->GetClientBySpawn(player);
  8205. if (!client) {
  8206. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8207. return 0;
  8208. }
  8209. client->EndAutoMount();
  8210. return 0;
  8211. }
  8212. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8213. if (!lua_interface)
  8214. return 0;
  8215. Spawn* player = lua_interface->GetSpawn(state);
  8216. if (!player) {
  8217. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8218. return 0;
  8219. }
  8220. if (!player->IsPlayer()) {
  8221. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8222. return 0;
  8223. }
  8224. Client* client = player->GetZone()->GetClientBySpawn(player);
  8225. if (!client) {
  8226. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8227. return 0;
  8228. }
  8229. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8230. return 1;
  8231. }
  8232. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8233. if (!lua_interface)
  8234. return 0;
  8235. Spawn* player = lua_interface->GetSpawn(state);
  8236. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8237. int32 value = lua_interface->GetInt32Value(state, 3);
  8238. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8239. if (!player) {
  8240. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8241. return 0;
  8242. }
  8243. if (!player->IsPlayer()) {
  8244. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8248. return 0;
  8249. }
  8250. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8251. if (!lua_interface)
  8252. return 0;
  8253. Spawn* player = lua_interface->GetSpawn(state);
  8254. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8255. if (!player) {
  8256. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8257. return 0;
  8258. }
  8259. if (!player->IsPlayer()) {
  8260. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8261. return 0;
  8262. }
  8263. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8264. if (!hd)
  8265. return 0;
  8266. lua_interface->SetInt32Value(state, hd->Value);
  8267. lua_interface->SetInt32Value(state, hd->Value2);
  8268. return 2;
  8269. }
  8270. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8271. if (!lua_interface)
  8272. return 0;
  8273. Spawn* spawn = lua_interface->GetSpawn(state);
  8274. int32 grid = lua_interface->GetInt32Value(state, 2);
  8275. if (!spawn) {
  8276. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8277. return 0;
  8278. }
  8279. if (grid == 0) {
  8280. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8281. return 0;
  8282. }
  8283. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8284. return 0;
  8285. }
  8286. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8287. if (!lua_interface)
  8288. return 0;
  8289. Spawn* spawn = lua_interface->GetSpawn(state);
  8290. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8291. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8292. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8293. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8294. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8295. if (!spawn) {
  8296. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8297. return 0;
  8298. }
  8299. //Add this quest to the list of required quests for this spawn
  8300. spawn->SetRequiredHistory(event_id, value1, value2);
  8301. //If private spawn value set
  8302. if (private_spawn) {
  8303. //Set the spawn to be private when not granted access via history
  8304. spawn->AddAllowAccessSpawn(spawn);
  8305. spawn->SetPrivateQuestSpawn(true);
  8306. }
  8307. //This value will override vis_flags in the vis packet
  8308. if (flag_override > 0)
  8309. spawn->SetQuestsRequiredOverride(flag_override);
  8310. return 0;
  8311. }
  8312. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8313. if (!lua_interface)
  8314. return 0;
  8315. Spawn* player = lua_interface->GetSpawn(state);
  8316. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8317. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8318. if (!player) {
  8319. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8320. return 0;
  8321. }
  8322. if (!player->IsPlayer()) {
  8323. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8324. return 0;
  8325. }
  8326. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8327. return 1;
  8328. }
  8329. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8330. if (!lua_interface)
  8331. return 0;
  8332. Spawn* player = lua_interface->GetSpawn(state);
  8333. int8 level = lua_interface->GetInt8Value(state, 2);
  8334. if (!player) {
  8335. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8336. return 0;
  8337. }
  8338. if (!player->IsPlayer()) {
  8339. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8340. return 0;
  8341. }
  8342. if (level == 0) {
  8343. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8344. return 0;
  8345. }
  8346. Client* client = player->GetZone()->GetClientBySpawn(player);
  8347. if (!client) {
  8348. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8349. return 0;
  8350. }
  8351. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8352. return 0;
  8353. }
  8354. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8355. if (!lua_interface)
  8356. return 0;
  8357. Spawn* player = lua_interface->GetSpawn(state);
  8358. int32 amount = lua_interface->GetInt32Value(state, 2);
  8359. if (!player) {
  8360. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8361. return 0;
  8362. }
  8363. if (!player->IsPlayer()) {
  8364. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8365. return 0;
  8366. }
  8367. if (amount == 0) {
  8368. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8369. return 0;
  8370. }
  8371. ((Player*)player)->AddCoins(amount);
  8372. return 0;
  8373. }
  8374. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8375. if (!lua_interface)
  8376. return 0;
  8377. Spawn* player = lua_interface->GetSpawn(state);
  8378. int32 amount = lua_interface->GetInt32Value(state, 2);
  8379. if (!player) {
  8380. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8381. return 0;
  8382. }
  8383. if (!player->IsPlayer()) {
  8384. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8385. return 0;
  8386. }
  8387. if (amount == 0) {
  8388. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8389. return 0;
  8390. }
  8391. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8392. return 1;
  8393. }
  8394. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8395. if (!lua_interface)
  8396. return 0;
  8397. ZoneServer* zone = lua_interface->GetZone(state);
  8398. if (!zone) {
  8399. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8400. return 0;
  8401. }
  8402. vector<Entity*> players = zone->GetPlayers();
  8403. if (players.size() == 0)
  8404. return 0;
  8405. lua_createtable(state, players.size(), 0);
  8406. int newTable = lua_gettop(state);
  8407. for (int32 i = 0; i < players.size(); i++) {
  8408. lua_interface->SetSpawnValue(state, players.at(i));
  8409. lua_rawseti(state, newTable, i + 1);
  8410. }
  8411. return 1;
  8412. }
  8413. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8414. if (!lua_interface)
  8415. return 0;
  8416. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8417. if (!zone) {
  8418. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8419. return 0;
  8420. }
  8421. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8422. //Map of <placement_id, location_id>
  8423. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8424. map<int32, int32>::iterator itr;
  8425. vector<Spawn*> group;
  8426. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8427. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8428. if (!location) {
  8429. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8430. return 0;
  8431. }
  8432. Spawn* spawn = 0;
  8433. if (location->entities[0]) {
  8434. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8435. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8436. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8437. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8438. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8439. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8440. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8441. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8442. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8443. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8444. if (spawn) {
  8445. const char* script = 0;
  8446. for (int x = 0; x < 3; x++) {
  8447. switch (x) {
  8448. case 0:
  8449. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8450. break;
  8451. case 1:
  8452. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8453. break;
  8454. case 2:
  8455. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8456. break;
  8457. }
  8458. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8459. spawn->SetSpawnScript(string(script));
  8460. break;
  8461. }
  8462. }
  8463. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8464. lua_interface->SetSpawnValue(state, spawn);
  8465. group.push_back(spawn);
  8466. }
  8467. else {
  8468. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8469. safe_delete(spawn);
  8470. }
  8471. }
  8472. }
  8473. if (!group.empty()) {
  8474. lua_createtable(state, group.size(), 0);
  8475. int newTable = lua_gettop(state);
  8476. for (int32 i = 0; i < group.size(); i++) {
  8477. lua_interface->SetSpawnValue(state, group[i]);
  8478. lua_rawseti(state, newTable, i + 1);
  8479. }
  8480. }
  8481. else
  8482. lua_pushnil(state);
  8483. return 1;
  8484. }
  8485. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8486. if (!lua_interface)
  8487. return 0;
  8488. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8489. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8490. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8491. if (!spawn) {
  8492. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8493. return 0;
  8494. }
  8495. if (anim_id == 0) {
  8496. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8497. return 0;
  8498. }
  8499. if (leeway == 0)
  8500. leeway = 5000;
  8501. spawn->SetSpawnAnim(anim_id);
  8502. spawn->SetSpawnAnimLeeway(leeway);
  8503. return 0;
  8504. }
  8505. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8506. if (!lua_interface)
  8507. return 0;
  8508. Spawn* player = lua_interface->GetSpawn(state);
  8509. if (!player) {
  8510. return 0;
  8511. }
  8512. Client* client = player->GetZone()->GetClientBySpawn(player);
  8513. if (!client) {
  8514. return 0;
  8515. }
  8516. lua_interface->SetInt32Value(state, client->GetVersion());
  8517. return 1;
  8518. }
  8519. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8520. if (!lua_interface)
  8521. return 0;
  8522. Item* item = lua_interface->GetItem(state);
  8523. if (!item) {
  8524. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8525. return 0;
  8526. }
  8527. lua_interface->SetInt32Value(state, item->details.item_id);
  8528. return 1;
  8529. }
  8530. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8531. if (!lua_interface)
  8532. return 0;
  8533. Spawn* spawn = lua_interface->GetSpawn(state);
  8534. if (!spawn) {
  8535. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8539. return 1;
  8540. }
  8541. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8542. if (!lua_interface)
  8543. return 0;
  8544. Spawn* spawn = lua_interface->GetSpawn(state);
  8545. if (!spawn) {
  8546. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8547. return 0;
  8548. }
  8549. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8550. return 1;
  8551. }
  8552. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8553. if (!lua_interface)
  8554. return 0;
  8555. Spawn* spawn = lua_interface->GetSpawn(state);
  8556. if (!spawn) {
  8557. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8558. return 0;
  8559. }
  8560. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8561. return 1;
  8562. }
  8563. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8564. if (!lua_interface)
  8565. return 0;
  8566. Spawn* spawn = lua_interface->GetSpawn(state);
  8567. if (!spawn) {
  8568. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8569. return 0;
  8570. }
  8571. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8572. return 1;
  8573. }
  8574. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8575. if (!lua_interface)
  8576. return 0;
  8577. Spawn* spawn = lua_interface->GetSpawn(state);
  8578. float pct = lua_interface->GetFloatValue(state, 2);
  8579. if (!spawn) {
  8580. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8581. return 0;
  8582. }
  8583. if (pct == 0) {
  8584. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8585. return 0;
  8586. }
  8587. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8588. lua_interface->SetInt32Value(state, amount);
  8589. return 1;
  8590. }
  8591. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8592. if (!lua_interface)
  8593. return 0;
  8594. Spawn* spawn = lua_interface->GetSpawn(state);
  8595. float pct = lua_interface->GetFloatValue(state, 2);
  8596. if (!spawn) {
  8597. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8598. return 0;
  8599. }
  8600. if (pct == 0) {
  8601. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8602. return 0;
  8603. }
  8604. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8605. lua_interface->SetInt32Value(state, amount);
  8606. return 1;
  8607. }
  8608. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8609. if (!lua_interface)
  8610. return 0;
  8611. Spawn* spawn = lua_interface->GetSpawn(state);
  8612. if (!spawn) {
  8613. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8614. return 0;
  8615. }
  8616. if (!spawn->IsPlayer()) {
  8617. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8618. return 0;
  8619. }
  8620. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8621. return 1;
  8622. }
  8623. int EQ2Emu_lua_Evac(lua_State* state) {
  8624. if (!lua_interface)
  8625. return 0;
  8626. Spawn* target = lua_interface->GetSpawn(state);
  8627. if (target) {
  8628. float x = target->GetZone()->GetSafeX();
  8629. float y = target->GetZone()->GetSafeY();
  8630. float z = target->GetZone()->GetSafeZ();
  8631. float h = target->GetZone()->GetSafeHeading();
  8632. target->SetX(x);
  8633. target->SetY(y);
  8634. target->SetZ(z);
  8635. target->SetHeading(h);
  8636. target->SetSpawnOrigX(target->GetX());
  8637. target->SetSpawnOrigY(target->GetY());
  8638. target->SetSpawnOrigZ(target->GetZ());
  8639. target->SetSpawnOrigHeading(target->GetHeading());
  8640. if (target->IsPlayer()) {
  8641. Client* client = target->GetZone()->GetClientBySpawn(target);
  8642. if (client) {
  8643. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8644. if (packet)
  8645. {
  8646. packet->setDataByName("x", x);
  8647. packet->setDataByName("y", y);
  8648. packet->setDataByName("z", z);
  8649. client->QueuePacket(packet->serialize());
  8650. safe_delete(packet);
  8651. }
  8652. }
  8653. }
  8654. }
  8655. else {
  8656. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8657. ZoneServer* zone = spell->caster->GetZone();
  8658. float x = spell->caster->GetZone()->GetSafeX();
  8659. float y = spell->caster->GetZone()->GetSafeY();
  8660. float z = spell->caster->GetZone()->GetSafeZ();
  8661. float h = spell->caster->GetZone()->GetSafeHeading();
  8662. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8663. for (int32 i = 0; i < spell->targets.size(); i++) {
  8664. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8665. if (!target2)
  8666. continue;
  8667. target2->SetX(x);
  8668. target2->SetY(y);
  8669. target2->SetZ(z);
  8670. target2->SetHeading(h);
  8671. target2->SetSpawnOrigX(target2->GetX());
  8672. target2->SetSpawnOrigY(target2->GetY());
  8673. target2->SetSpawnOrigZ(target2->GetZ());
  8674. target2->SetSpawnOrigHeading(target2->GetHeading());
  8675. if (target2->IsPlayer()) {
  8676. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8677. if (client) {
  8678. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8679. if (packet)
  8680. {
  8681. packet->setDataByName("x", x);
  8682. packet->setDataByName("y", y);
  8683. packet->setDataByName("z", z);
  8684. client->QueuePacket(packet->serialize());
  8685. safe_delete(packet);
  8686. }
  8687. }
  8688. }
  8689. }
  8690. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8691. }
  8692. return 0;
  8693. }
  8694. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8695. if (!lua_interface)
  8696. return 0;
  8697. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8698. if (!luaspell) {
  8699. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8700. return 0;
  8701. }
  8702. int8 tier = luaspell->spell->GetSpellTier();
  8703. lua_interface->SetInt32Value(state, tier);
  8704. return 1;
  8705. }
  8706. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8707. if (!lua_interface)
  8708. return 0;
  8709. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8710. if (!luaspell) {
  8711. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8712. return 0;
  8713. }
  8714. int32 spell_id = luaspell->spell->GetSpellID();
  8715. lua_interface->SetInt32Value(state, spell_id);
  8716. return 1;
  8717. }
  8718. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8719. if (!lua_interface)
  8720. return 0;
  8721. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8722. if (!spawn) {
  8723. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8724. return 0;
  8725. }
  8726. if (!spawn->IsPlayer()) {
  8727. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8728. return 0;
  8729. }
  8730. ZoneServer* zone = spawn->GetZone();
  8731. if (!zone) {
  8732. return 0;
  8733. }
  8734. Client* client = zone->GetClientBySpawn(spawn);
  8735. if (!client) {
  8736. return 0;
  8737. }
  8738. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8739. return 0;
  8740. }
  8741. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8742. if (!lua_interface)
  8743. return 0;
  8744. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8745. if (!spawn) {
  8746. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8747. return 0;
  8748. }
  8749. if (!spawn->IsPlayer()) {
  8750. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8751. return 0;
  8752. }
  8753. ZoneServer* zone = spawn->GetZone();
  8754. if (!zone) {
  8755. return 0;
  8756. }
  8757. Client* client = zone->GetClientBySpawn(spawn);
  8758. if (!client) {
  8759. return 0;
  8760. }
  8761. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8762. return 0;
  8763. }
  8764. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8765. if (!lua_interface)
  8766. return 0;
  8767. Spawn* caster = lua_interface->GetSpawn(state);
  8768. Spawn* target = lua_interface->GetSpawn(state, 2);
  8769. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8770. string spell_name = lua_interface->GetStringValue(state, 4);
  8771. if (!caster) {
  8772. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8773. return 0;
  8774. }
  8775. if (!caster->IsEntity()) {
  8776. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8777. return 0;
  8778. }
  8779. if (!target) {
  8780. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8781. return 0;
  8782. }
  8783. if (!target->IsEntity()) {
  8784. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8785. return 0;
  8786. }
  8787. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8788. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8789. return 0;
  8790. }
  8791. int EQ2Emu_lua_AddLootToObject(lua_State* state) {
  8792. if (!lua_interface)
  8793. return 0;
  8794. Spawn* object = lua_interface->GetSpawn(state);
  8795. Spawn* player = lua_interface->GetSpawn(state, 2);
  8796. if (object && player && player->IsPlayer()) {
  8797. int32 coins = lua_interface->GetInt32Value(state, 3);
  8798. vector<Item*>* items = 0;
  8799. int i = 0;
  8800. int32 item_id = 0;
  8801. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  8802. if (items == 0)
  8803. items = new vector<Item*>;
  8804. if (master_item_list.GetItem(item_id))
  8805. items->push_back(master_item_list.GetItem(item_id));
  8806. i++;
  8807. }
  8808. Client* client = 0;
  8809. client = object->GetZone()->GetClientBySpawn(player);
  8810. if (client) {
  8811. ((Player*)player)->AddPendingLootItems(object->GetID(), items);
  8812. }
  8813. safe_delete(items);
  8814. }
  8815. return 0;
  8816. }
  8817. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8818. if (!lua_interface)
  8819. return 0;
  8820. Spawn* player = lua_interface->GetSpawn(state);
  8821. int32 amount = lua_interface->GetInt32Value(state, 2);
  8822. if (player && player->IsPlayer() && amount > 0) {
  8823. ((Player*)player)->AddXP(amount);
  8824. ((Player*)player)->SetCharSheetChanged(true);
  8825. Client* client = player->GetZone()->GetClientBySpawn(player);
  8826. if (client) {
  8827. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8828. }
  8829. }
  8830. return 0;
  8831. }
  8832. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8833. if (!lua_interface)
  8834. return 0;
  8835. Spawn* player = lua_interface->GetSpawn(state);
  8836. int8 type = lua_interface->GetInt8Value(state, 2);
  8837. string text = lua_interface->GetStringValue(state, 3);
  8838. Client* client = 0;
  8839. if (player && player->IsPlayer())
  8840. client = player->GetZone()->GetClientBySpawn(player);
  8841. if (!client || text.length() == 0) {
  8842. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8843. return 0;
  8844. }
  8845. client->SimpleMessage(type, text.c_str());
  8846. return 0;
  8847. }
  8848. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8849. if (!lua_interface)
  8850. return 0;
  8851. Spawn* player = lua_interface->GetSpawn(state);
  8852. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8853. Client* client = 0;
  8854. if (player && player->IsPlayer())
  8855. client = player->GetZone()->GetClientBySpawn(player);
  8856. if (!client || !spawn) {
  8857. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8858. return 0;
  8859. }
  8860. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8861. if (!items) {
  8862. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8863. return 0;
  8864. }
  8865. client->Loot(spawn->GetLootCoins(), items, spawn);
  8866. return 0;
  8867. }
  8868. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8869. if (!lua_interface)
  8870. return 0;
  8871. Spawn* spawnref = lua_interface->GetSpawn(state);
  8872. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8873. if (spawn_id > 0 && spawnref) {
  8874. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8875. if (spawns.size() == 0) {
  8876. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8877. return 0;
  8878. }
  8879. Spawn* spawn = 0;
  8880. int16 index = MakeRandomInt(0, spawns.size());
  8881. if (index >= spawns.size() || index < 0)
  8882. index = 0;
  8883. spawn = spawns[index];
  8884. lua_interface->SetSpawnValue(state, spawn);
  8885. return 1;
  8886. }
  8887. else {
  8888. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8889. }
  8890. return 0;
  8891. }
  8892. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8893. Spawn* player = lua_interface->GetSpawn(state);
  8894. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8895. string name = lua_interface->GetStringValue(state, 3);
  8896. float distance = lua_interface->GetFloatValue(state, 4);
  8897. string command = lua_interface->GetStringValue(state, 5);
  8898. string error_text = lua_interface->GetStringValue(state, 6);
  8899. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8900. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8901. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8902. if (distance == 0)
  8903. distance = 10.0f;
  8904. if (command.length() == 0)
  8905. command = name;
  8906. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8907. if (spawns.size() == 0) {
  8908. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8909. return 0;
  8910. }
  8911. Spawn* spawn = 0;
  8912. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  8913. spawn = *itr;
  8914. if (spawn) {
  8915. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  8916. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  8917. }
  8918. }
  8919. }
  8920. return 0;
  8921. }
  8922. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  8923. if (!lua_interface)
  8924. return 0;
  8925. Client* client = 0;
  8926. Spawn* player = lua_interface->GetSpawn(state);
  8927. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  8928. if (player && player->IsPlayer() && player->GetZone())
  8929. client = player->GetZone()->GetClientBySpawn(player);
  8930. else{
  8931. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  8932. return 0;
  8933. }
  8934. if (client) {
  8935. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8936. if (packet) {
  8937. packet->setDataByName("goal_num", goal_num);
  8938. client->QueuePacket(packet->serialize());
  8939. safe_delete(packet);
  8940. }
  8941. }
  8942. return 0;
  8943. }
  8944. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  8945. if (!lua_interface)
  8946. return 0;
  8947. Client* client = 0;
  8948. Spawn* player = lua_interface->GetSpawn(state);
  8949. if (player && player->IsPlayer() && player->GetZone())
  8950. client = player->GetZone()->GetClientBySpawn(player);
  8951. else {
  8952. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  8953. return 0;
  8954. }
  8955. if (client) {
  8956. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  8957. }
  8958. return 0;
  8959. }
  8960. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  8961. if (!lua_interface)
  8962. return 0;
  8963. Client* client = 0;
  8964. Spawn* player = lua_interface->GetSpawn(state);
  8965. float duration = lua_interface->GetFloatValue(state, 2);
  8966. string text = lua_interface->GetStringValue(state, 3);
  8967. string voice = lua_interface->GetStringValue(state, 4);
  8968. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  8969. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  8970. string signal = lua_interface->GetStringValue(state, 7);
  8971. string goal1 = lua_interface->GetStringValue(state, 8);
  8972. string task1 = lua_interface->GetStringValue(state, 9);
  8973. string goal2 = lua_interface->GetStringValue(state, 10);
  8974. string task2 = lua_interface->GetStringValue(state, 11);
  8975. string goal3 = lua_interface->GetStringValue(state, 12);
  8976. string task3 = lua_interface->GetStringValue(state, 13);
  8977. string goal4 = lua_interface->GetStringValue(state, 14);
  8978. string task4 = lua_interface->GetStringValue(state, 15);
  8979. if (!player) {
  8980. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  8981. return 0;
  8982. }
  8983. if (!player->IsPlayer()) {
  8984. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  8985. return 0;
  8986. }
  8987. else
  8988. client = ((Player*)player)->GetClient();
  8989. if (!client) {
  8990. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  8991. return 0;
  8992. }
  8993. if (text.length() == 0) {
  8994. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  8995. return 0;
  8996. }
  8997. if (duration >= 0 && duration < 2)
  8998. duration = 2;
  8999. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9000. if (packet) {
  9001. packet->setDataByName("open_seconds_max", duration);
  9002. packet->setDataByName("text", text.c_str());
  9003. packet->setDataByName("voice", voice.c_str());
  9004. int8 num_goals = 1;
  9005. if (task2.length() > 0)
  9006. num_goals++;
  9007. if (task3.length() > 0)
  9008. num_goals++;
  9009. if (task4.length() > 0)
  9010. num_goals++;
  9011. packet->setArrayLengthByName("num_goals", num_goals);
  9012. for (int8 i = 0; i < num_goals; i++) {
  9013. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9014. }
  9015. if (goal1.length() > 0)
  9016. packet->setArrayDataByName("goal_text", goal1.c_str());
  9017. if (goal2.length() > 0)
  9018. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9019. if (goal3.length() > 0)
  9020. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9021. if (goal4.length() > 0)
  9022. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9023. packet->setSubArrayDataByName("task_text", task1.c_str());
  9024. if (task2.length() > 0)
  9025. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9026. if (task3.length() > 0)
  9027. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9028. if (task4.length() > 0)
  9029. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9030. packet->setDataByName("complete_sound", "click");
  9031. packet->setDataByName("signal", signal.c_str());
  9032. packet->setDataByName("voice_key1", voice_key1);
  9033. packet->setDataByName("voice_key2", voice_key2);
  9034. client->QueuePacket(packet->serialize());
  9035. safe_delete(packet);
  9036. }
  9037. return 0;
  9038. }
  9039. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9040. if (!lua_interface)
  9041. return 0;
  9042. Client* client = 0;
  9043. Spawn* player = lua_interface->GetSpawn(state);
  9044. string window = lua_interface->GetStringValue(state, 2);
  9045. int8 show = lua_interface->GetInt8Value(state, 3);
  9046. if (!player) {
  9047. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9048. return 0;
  9049. }
  9050. if (!player->IsPlayer()) {
  9051. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9052. return 0;
  9053. }
  9054. else
  9055. client = ((Player*)player)->GetClient();
  9056. if (!client) {
  9057. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9058. return 0;
  9059. }
  9060. if (window.length() == 0) {
  9061. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9062. return 0;
  9063. }
  9064. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9065. if (packet) {
  9066. packet->setDataByName("window", window.c_str());
  9067. packet->setDataByName("show", show);
  9068. client->QueuePacket(packet->serialize());
  9069. safe_delete(packet);
  9070. }
  9071. return 0;
  9072. }
  9073. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9074. //See GameEvents.txt for options that can be used for this function
  9075. if (!lua_interface)
  9076. return 0;
  9077. Client* client = 0;
  9078. Spawn* player = lua_interface->GetSpawn(state);
  9079. string event_name = lua_interface->GetStringValue(state, 2);
  9080. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9081. if (!player || !player->IsPlayer()) {
  9082. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9083. return 0;
  9084. }
  9085. if (player->GetZone())
  9086. client = player->GetZone()->GetClientBySpawn(player);
  9087. if (!client) {
  9088. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9089. return 0;
  9090. }
  9091. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9092. if (packet) {
  9093. packet->setDataByName("event_name", event_name.c_str());
  9094. packet->setDataByName("enabled", enabled);
  9095. client->QueuePacket(packet->serialize());
  9096. safe_delete(packet);
  9097. }
  9098. return 0;
  9099. }
  9100. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9101. if (!lua_interface)
  9102. return 0;
  9103. Spawn* player = lua_interface->GetSpawn(state);
  9104. if (player && player->IsPlayer()) {
  9105. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9106. return 1;
  9107. }
  9108. return 0;
  9109. }
  9110. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9111. if (!lua_interface)
  9112. return 0;
  9113. Spawn* player = lua_interface->GetSpawn(state);
  9114. int8 step = lua_interface->GetInt8Value(state, 2);
  9115. if (player && player->IsPlayer() && step > 0) {
  9116. ((Player*)player)->SetTutorialStep(step);
  9117. }
  9118. return 0;
  9119. }
  9120. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9121. if (!lua_interface)
  9122. return 0;
  9123. Client* client = 0;
  9124. Spawn* player = lua_interface->GetSpawn(state);
  9125. string window = lua_interface->GetStringValue(state, 2);
  9126. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9127. if (!player) {
  9128. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9129. return 0;
  9130. }
  9131. if (!player->IsPlayer()) {
  9132. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9133. return 0;
  9134. }
  9135. else
  9136. client = ((Player*)player)->GetClient();
  9137. if (!client) {
  9138. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9139. return 0;
  9140. }
  9141. if (window.length() == 0) {
  9142. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9143. return 0;
  9144. }
  9145. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9146. if (packet) {
  9147. packet->setDataByName("window", window.c_str());
  9148. packet->setDataByName("flash_seconds", flash_seconds);
  9149. client->QueuePacket(packet->serialize());
  9150. safe_delete(packet);
  9151. }
  9152. return 0;
  9153. }
  9154. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9155. if (!lua_interface)
  9156. return 0;
  9157. Spawn* spawn = lua_interface->GetSpawn(state);
  9158. Spawn* target = lua_interface->GetSpawn(state, 2);
  9159. if (spawn && target)
  9160. return spawn->CheckLoS(target);
  9161. return 0;
  9162. }
  9163. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9164. if (!lua_interface)
  9165. return 0;
  9166. Spawn* spawn = lua_interface->GetSpawn(state);
  9167. float x = lua_interface->GetFloatValue(state, 2);
  9168. float y = lua_interface->GetFloatValue(state, 3);
  9169. float z = lua_interface->GetFloatValue(state, 4);
  9170. if (spawn)
  9171. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9172. return 0;
  9173. }
  9174. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9175. if (!lua_interface)
  9176. return 0;
  9177. ZoneServer* zone = lua_interface->GetZone(state);
  9178. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9179. if (zone)
  9180. zone->SetExpansionFlag(xpackFlag);
  9181. return 0;
  9182. }
  9183. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9184. if (!lua_interface)
  9185. return 0;
  9186. ZoneServer* zone = lua_interface->GetZone(state);
  9187. if (zone) {
  9188. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9189. return 1;
  9190. }
  9191. return 0;
  9192. }
  9193. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9194. if (!lua_interface)
  9195. return 0;
  9196. ZoneServer* zone = lua_interface->GetZone(state);
  9197. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9198. if (zone)
  9199. zone->SetHolidayFlag(holidayFlag);
  9200. return 0;
  9201. }
  9202. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9203. if (!lua_interface)
  9204. return 0;
  9205. ZoneServer* zone = lua_interface->GetZone(state);
  9206. if (zone) {
  9207. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9208. return 1;
  9209. }
  9210. return 0;
  9211. }
  9212. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9213. if (!lua_interface)
  9214. return 0;
  9215. Spawn* spawn = lua_interface->GetSpawn(state);
  9216. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9217. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9218. float distance = lua_interface->GetFloatValue(state, 4);
  9219. string in_range_function = lua_interface->GetStringValue(state, 5);
  9220. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9221. if (spawn && distance > 0 && in_range_function.length() > 0)
  9222. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9223. return 0;
  9224. }
  9225. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9226. if (!lua_interface)
  9227. return 0;
  9228. Spawn* spawn = lua_interface->GetSpawn(state);
  9229. Spawn* target = lua_interface->GetSpawn(state, 2);
  9230. if (spawn && target)
  9231. {
  9232. if (spawn->IsPlayer() && target->IsEntity())
  9233. {
  9234. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9235. return 1;
  9236. }
  9237. else if (spawn->IsEntity() && target->IsEntity())
  9238. {
  9239. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9240. return 1;
  9241. }
  9242. }
  9243. return 0;
  9244. }
  9245. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9246. if (!lua_interface)
  9247. return 0;
  9248. Spawn* spawn = lua_interface->GetSpawn(state);
  9249. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9250. if (spawn && spawn->IsEntity())
  9251. {
  9252. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9253. if (spawn->IsPlayer())
  9254. {
  9255. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9256. if (client)
  9257. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9258. }
  9259. }
  9260. return 0;
  9261. }
  9262. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9263. if (!lua_interface)
  9264. return 0;
  9265. Spawn* spawn = lua_interface->GetSpawn(state);
  9266. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9267. if (spawn && spawn->IsEntity())
  9268. {
  9269. ((Entity*)spawn)->SetSeeHideSpell(val);
  9270. if (spawn->IsPlayer())
  9271. {
  9272. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9273. if (client)
  9274. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9275. }
  9276. }
  9277. return 0;
  9278. }
  9279. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9280. {
  9281. if (!lua_interface)
  9282. return 0;
  9283. Spawn* player = lua_interface->GetSpawn(state);
  9284. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9285. string command = lua_interface->GetStringValue(state, 3);
  9286. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9287. if (spawn && player && player->IsPlayer())
  9288. {
  9289. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9290. bool res = false;
  9291. if (cmd)
  9292. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9293. lua_interface->SetBooleanValue(state, res);
  9294. return 1;
  9295. }
  9296. return 0;
  9297. }
  9298. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9299. {
  9300. if (!lua_interface)
  9301. return 0;
  9302. Spawn* spawn = lua_interface->GetSpawn(state);
  9303. string command = lua_interface->GetStringValue(state, 2);
  9304. if (spawn && command.length() > 0)
  9305. spawn->RemovePrimaryEntityCommand(command.c_str());
  9306. return 0;
  9307. }
  9308. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9309. if (!lua_interface)
  9310. return 0;
  9311. Spawn* spawn = lua_interface->GetSpawn(state);
  9312. float distance = lua_interface->GetFloatValue(state, 2);
  9313. string command = lua_interface->GetStringValue(state, 3);
  9314. Spawn* player = lua_interface->GetSpawn(state, 4);
  9315. if (spawn) {
  9316. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9317. }
  9318. return 0;
  9319. }
  9320. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9321. if (!lua_interface)
  9322. return 0;
  9323. Spawn* spawn = lua_interface->GetSpawn(state);
  9324. Spawn* player = lua_interface->GetSpawn(state, 2);
  9325. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9326. if (spawn && player && transport_id && player->IsPlayer()) {
  9327. Client* client = 0;
  9328. if (player && player->IsPlayer())
  9329. client = player->GetZone()->GetClientBySpawn(player);
  9330. if (!client)
  9331. return 0;
  9332. vector<TransportDestination*> destinations;
  9333. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9334. if (destinations.size())
  9335. {
  9336. client->SetTemporaryTransportID(transport_id);
  9337. client->ProcessTeleport(spawn, &destinations, transport_id);
  9338. }
  9339. else
  9340. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9341. }
  9342. return 0;
  9343. }
  9344. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9345. if (!lua_interface)
  9346. return 0;
  9347. Spawn* player = lua_interface->GetSpawn(state);
  9348. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9349. if (player && player->IsPlayer()) {
  9350. Client* client = 0;
  9351. if (player && player->IsPlayer())
  9352. client = player->GetZone()->GetClientBySpawn(player);
  9353. if (!client)
  9354. return 0;
  9355. client->SetTemporaryTransportID(transport_id);
  9356. }
  9357. return 0;
  9358. }
  9359. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9360. if (!lua_interface)
  9361. return 0;
  9362. Spawn* player = lua_interface->GetSpawn(state);
  9363. if (player && player->IsPlayer()) {
  9364. Client* client = 0;
  9365. if (player && player->IsPlayer())
  9366. client = player->GetZone()->GetClientBySpawn(player);
  9367. if (!client)
  9368. return 0;
  9369. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9370. return 1;
  9371. }
  9372. return 0;
  9373. }
  9374. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9375. if (!lua_interface)
  9376. return 0;
  9377. Spawn* spawn = lua_interface->GetSpawn(state);
  9378. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9379. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9380. if (!spawn) {
  9381. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9382. return 0;
  9383. }
  9384. if (!spawn->IsEntity()) {
  9385. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9386. return 0;
  9387. }
  9388. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9389. {
  9390. 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);
  9391. return 0;
  9392. }
  9393. if (spell && spell->targets.size() > 0) {
  9394. ZoneServer* zone = spell->caster->GetZone();
  9395. for (int8 i = 0; i < spell->targets.size(); i++) {
  9396. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9397. if (target->IsEntity()) {
  9398. ((Entity*)target)->GetInfoStruct()->alignment = (sint8)alignment;
  9399. if (target->IsPlayer())
  9400. ((Player*)target)->SetCharSheetChanged(true);
  9401. }
  9402. }
  9403. }
  9404. else {
  9405. ((Entity*)spawn)->GetInfoStruct()->alignment = (sint8)alignment;
  9406. if (spawn->IsPlayer())
  9407. ((Player*)spawn)->SetCharSheetChanged(true);
  9408. }
  9409. return 0;
  9410. }
  9411. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9412. if (!lua_interface)
  9413. return 0;
  9414. Spawn* spawn = lua_interface->GetSpawn(state);
  9415. if (!spawn) {
  9416. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9417. return 0;
  9418. }
  9419. if (!spawn->IsEntity()) {
  9420. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9421. return 0;
  9422. }
  9423. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9424. return 1;
  9425. }
  9426. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9427. if (!lua_interface)
  9428. return 0;
  9429. int32 spell_id = lua_interface->GetInt32Value(state);
  9430. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9431. if (spell_id > 0) {
  9432. if (spell_tier == 0)
  9433. spell_tier = 1;
  9434. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9435. LuaSpell* lua_spell = 0;
  9436. if (lua_interface)
  9437. lua_spell = lua_interface->GetSpell(spell->GetSpellData()->lua_script.c_str());
  9438. if (!lua_spell)
  9439. return 0;
  9440. lua_spell->spell = new Spell(spell);
  9441. lua_interface->AddCustomSpell(lua_spell);
  9442. lua_interface->SetSpellValue(state, lua_spell);
  9443. return 1;
  9444. }
  9445. return 0;
  9446. }
  9447. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9448. if (!lua_interface)
  9449. return 0;
  9450. LuaSpell* spell = lua_interface->GetSpell(state);
  9451. string field = lua_interface->GetStringValue(state, 2);
  9452. if (!spell) {
  9453. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9454. return 0;
  9455. }
  9456. if (!spell->spell || !spell->spell->GetSpellData()) {
  9457. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9458. return 0;
  9459. }
  9460. boost::to_lower(field);
  9461. return spell->spell->GetSpellData(state, field);
  9462. }
  9463. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9464. if (!lua_interface)
  9465. return 0;
  9466. LuaSpell* spell = lua_interface->GetSpell(state);
  9467. string field = lua_interface->GetStringValue(state, 2);
  9468. int8 fieldArg = 3; // field value after the initial set
  9469. if (!spell) {
  9470. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9471. return 0;
  9472. }
  9473. if (!spell->spell || !spell->spell->GetSpellData()) {
  9474. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9475. return 0;
  9476. }
  9477. boost::to_lower(field);
  9478. bool valSet = false;
  9479. spell->spell->SetSpellData(state, field, fieldArg);
  9480. return valSet;
  9481. }
  9482. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9483. if (!lua_interface)
  9484. return 0;
  9485. LuaSpell* spell = lua_interface->GetSpell(state);
  9486. int8 idx = lua_interface->GetInt32Value(state, 2);
  9487. if (!spell) {
  9488. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9489. return 0;
  9490. }
  9491. if (!spell->spell || !spell->spell->GetSpellData()) {
  9492. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9493. return 0;
  9494. }
  9495. if (spell->spell->lua_data.size() <= idx)
  9496. {
  9497. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9498. return 0;
  9499. }
  9500. bool setVal = true;
  9501. LUAData* data = spell->spell->lua_data[idx];
  9502. switch (data->type)
  9503. {
  9504. case 0:
  9505. {
  9506. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9507. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9508. data->int_value = value;
  9509. data->int_value2 = value2;
  9510. break;
  9511. }
  9512. case 1:
  9513. {
  9514. float value = lua_interface->GetFloatValue(state, 3);
  9515. float value2 = lua_interface->GetFloatValue(state, 4);
  9516. data->float_value = value;
  9517. data->float_value2 = value2;
  9518. break;
  9519. }
  9520. case 2:
  9521. {
  9522. bool value = lua_interface->GetBooleanValue(state, 3);
  9523. data->bool_value = value;
  9524. break;
  9525. }
  9526. case 3:
  9527. {
  9528. string value = lua_interface->GetStringValue(state, 3);
  9529. string value2 = lua_interface->GetStringValue(state, 4);
  9530. data->string_value = value;
  9531. data->string_value2 = value2;
  9532. break;
  9533. }
  9534. default:
  9535. setVal = false;
  9536. }
  9537. return setVal;
  9538. }
  9539. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9540. if (!lua_interface)
  9541. return 0;
  9542. LuaSpell* spell = lua_interface->GetSpell(state);
  9543. int8 idx = lua_interface->GetInt32Value(state, 2);
  9544. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9545. if (!spell) {
  9546. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9547. return 0;
  9548. }
  9549. if (!spell->spell || !spell->spell->GetSpellData()) {
  9550. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9551. return 0;
  9552. }
  9553. if (spell->spell->lua_data.size() <= idx)
  9554. {
  9555. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9556. return 0;
  9557. }
  9558. bool setVal = true;
  9559. LUAData* data = spell->spell->lua_data[idx];
  9560. switch (data->type)
  9561. {
  9562. case 0:
  9563. {
  9564. if(!secondfield)
  9565. lua_interface->SetSInt32Value(state, data->int_value);
  9566. else
  9567. lua_interface->SetSInt32Value(state, data->int_value2);
  9568. break;
  9569. }
  9570. case 1:
  9571. {
  9572. if (!secondfield)
  9573. lua_interface->SetFloatValue(state, data->float_value);
  9574. else
  9575. lua_interface->SetFloatValue(state, data->float_value2);
  9576. break;
  9577. }
  9578. case 2:
  9579. {
  9580. lua_interface->SetBooleanValue(state, data->bool_value);
  9581. break;
  9582. }
  9583. case 3:
  9584. {
  9585. if (!secondfield)
  9586. lua_interface->SetStringValue(state, data->string_value.c_str());
  9587. else
  9588. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9589. break;
  9590. }
  9591. default:
  9592. setVal = false;
  9593. }
  9594. return setVal;
  9595. }
  9596. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9597. if (!lua_interface)
  9598. return 0;
  9599. LuaSpell* spell = lua_interface->GetSpell(state);
  9600. int8 idx = lua_interface->GetInt32Value(state, 2);
  9601. string field = lua_interface->GetStringValue(state, 3);
  9602. boost::to_lower(field);
  9603. if (!spell) {
  9604. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9605. return 0;
  9606. }
  9607. if (!spell->spell || !spell->spell->GetSpellData()) {
  9608. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9609. return 0;
  9610. }
  9611. if (spell->spell->effects.size() <= idx)
  9612. {
  9613. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9614. return 0;
  9615. }
  9616. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9617. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9618. if (field == "description")
  9619. effect->description = string(lua_interface->GetStringValue(state, 4));
  9620. else if (field == "bullet")
  9621. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9622. else if (field == "percentage")
  9623. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9624. else // no match
  9625. return 0;
  9626. return 1;
  9627. }
  9628. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9629. if (!lua_interface)
  9630. return 0;
  9631. LuaSpell* spell = lua_interface->GetSpell(state);
  9632. int8 idx = lua_interface->GetInt32Value(state, 2);
  9633. string field = lua_interface->GetStringValue(state, 3);
  9634. boost::to_lower(field);
  9635. if (!spell) {
  9636. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9637. return 0;
  9638. }
  9639. if (!spell->spell || !spell->spell->GetSpellData()) {
  9640. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9641. return 0;
  9642. }
  9643. if (spell->spell->effects.size() <= idx)
  9644. {
  9645. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9646. return 0;
  9647. }
  9648. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9649. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9650. if (field == "description")
  9651. lua_interface->SetStringValue(state, effect->description.c_str());
  9652. else if (field == "bullet")
  9653. lua_interface->SetInt32Value(state, effect->subbullet);
  9654. else if (field == "percentage")
  9655. lua_interface->SetInt32Value(state, effect->percentage);
  9656. else // no match
  9657. return 0;
  9658. return 1;
  9659. }
  9660. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9661. if (!lua_interface)
  9662. return 0;
  9663. LuaSpell* spell = lua_interface->GetSpell(state);
  9664. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9665. Spawn* target = lua_interface->GetSpawn(state, 3);
  9666. if (!target) {
  9667. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9668. return 0;
  9669. }
  9670. if (!target->IsEntity()) {
  9671. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9672. return 0;
  9673. }
  9674. if (!spell) {
  9675. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9676. return 0;
  9677. }
  9678. if (caster && !caster->IsEntity()) {
  9679. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9680. return 0;
  9681. }
  9682. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9683. return 0;
  9684. }
  9685. int EQ2Emu_lua_InWater(lua_State* state) {
  9686. if (!lua_interface)
  9687. return 0;
  9688. Spawn* spawn = lua_interface->GetSpawn(state);
  9689. if (spawn) {
  9690. lua_interface->SetBooleanValue(state, spawn->InWater());
  9691. return 1;
  9692. }
  9693. return 0;
  9694. }