LuaFunctions.cpp 384 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. if (spawn) {
  156. const char* mp3 = 0;
  157. const char* text = 0;
  158. const char* emote = 0;
  159. if (mp3_string.length() > 0)
  160. mp3 = mp3_string.c_str();
  161. if (text_string.length() > 0)
  162. text = text_string.c_str();
  163. if (emote_string.length() > 0)
  164. emote = emote_string.c_str();
  165. Client* client = 0;
  166. if (player && player->IsPlayer())
  167. client = spawn->GetZone()->GetClientBySpawn(player);
  168. if (client) {
  169. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  170. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  171. }
  172. else
  173. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  174. }
  175. return 0;
  176. }
  177. int EQ2Emu_lua_PlaySound(lua_State* state) {
  178. if (!lua_interface)
  179. return 0;
  180. Spawn* spawn = lua_interface->GetSpawn(state);
  181. string sound_string = lua_interface->GetStringValue(state, 2);
  182. float x = lua_interface->GetFloatValue(state, 3);
  183. float y = lua_interface->GetFloatValue(state, 4);
  184. float z = lua_interface->GetFloatValue(state, 5);
  185. Spawn* player = lua_interface->GetSpawn(state, 6);
  186. if (spawn && sound_string.length() > 0) {
  187. Client* client = 0;
  188. if (player && player->IsPlayer())
  189. client = spawn->GetZone()->GetClientBySpawn(player);
  190. if (client)
  191. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  192. else
  193. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  194. }
  195. return 0;
  196. }
  197. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  202. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  203. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  204. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  205. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  206. if (!spawn) {
  207. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  208. return 0;
  209. }
  210. if (quest_id > 0) {
  211. //Add this quest to the list of required quests for this spawn
  212. spawn->SetQuestsRequired(quest_id, quest_step);
  213. //If private spawn value set
  214. if (private_spawn) {
  215. //Set the spawn to be private when not granted access through this quest
  216. spawn->AddAllowAccessSpawn(spawn);
  217. spawn->SetPrivateQuestSpawn(true);
  218. }
  219. //This value allows access after a quest step, or the whole quest has been completed
  220. if (continued_access)
  221. spawn->SetQuestsRequiredContinuedAccess(true);
  222. //This value will override vis_flags in the vis packet
  223. if (flag_override > 0)
  224. spawn->SetQuestsRequiredOverride(flag_override);
  225. }
  226. return 0;
  227. }
  228. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  229. if (!lua_interface)
  230. return 0;
  231. Spawn* spawn = lua_interface->GetSpawn(state);
  232. float max_distance = lua_interface->GetFloatValue(state, 2);
  233. string variable = lua_interface->GetStringValue(state, 3);
  234. string value = lua_interface->GetStringValue(state, 4);
  235. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  236. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  237. return 0;
  238. }
  239. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  240. if (!lua_interface)
  241. return 0;
  242. Client* client = 0;
  243. Spawn* player = lua_interface->GetSpawn(state);
  244. if (!player) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  246. return 0;
  247. }
  248. if (!player->IsPlayer()) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  250. return 0;
  251. }
  252. if (player->GetZone())
  253. client = player->GetZone()->GetClientBySpawn(player);
  254. if (!client) {
  255. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  256. return 0;
  257. }
  258. float intensity = lua_interface->GetFloatValue(state, 2);
  259. int8 direction = lua_interface->GetInt8Value(state, 3);
  260. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  261. if (packet) {
  262. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  263. v1 = *(float *)(a1 + 4);
  264. if ( v1 > 0.0 )
  265. v2 = fminf(v1, 1.0);
  266. else
  267. v2 = 0.1;
  268. */
  269. packet->setDataByName("intensity", intensity);
  270. if ( client->GetVersion() > 546 )
  271. packet->setDataByName("direction", direction);
  272. client->QueuePacket(packet->serialize());
  273. safe_delete(packet);
  274. }
  275. return 0;
  276. }
  277. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  278. if (!lua_interface)
  279. return 0;
  280. Spawn* dead = lua_interface->GetSpawn(state);
  281. Spawn* killer = lua_interface->GetSpawn(state, 2);
  282. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  283. if (dead && dead->Alive() && dead->GetZone())
  284. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  285. return 0;
  286. }
  287. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  288. if (!lua_interface)
  289. return 0;
  290. Spawn* spawn = lua_interface->GetSpawn(state);
  291. float max_distance = lua_interface->GetFloatValue(state, 2);
  292. bool include_players = lua_interface->GetInt8Value(state, 3);
  293. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  294. if (max_distance > 0 && spawn && spawn->GetZone())
  295. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  296. return 0;
  297. }
  298. int EQ2Emu_lua_Despawn(lua_State* state) {
  299. if (!lua_interface)
  300. return 0;
  301. Spawn* spawn = lua_interface->GetSpawn(state);
  302. int32 delay = lua_interface->GetInt32Value(state, 2);
  303. if (spawn && spawn->GetZone())
  304. spawn->GetZone()->Despawn(spawn, delay);
  305. return 0;
  306. }
  307. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* spawn = lua_interface->GetSpawn(state);
  311. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  312. if (spawn) {
  313. spawn->info_changed = true;
  314. spawn->SetShowHandIcon(displayHandIcon);
  315. }
  316. return 0;
  317. }
  318. //this function is used to force an update packet to be sent.
  319. //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
  320. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  321. if (!lua_interface)
  322. return 0;
  323. Spawn* spawn = lua_interface->GetSpawn(state);
  324. if (spawn) {
  325. spawn->vis_changed = true;
  326. spawn->GetZone()->AddChangedSpawn(spawn);
  327. }
  328. return 0;
  329. }
  330. //this function is used to force an update packet to be sent.
  331. //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
  332. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  333. if (!lua_interface)
  334. return 0;
  335. Spawn* spawn = lua_interface->GetSpawn(state);
  336. if (spawn) {
  337. spawn->info_changed = true;
  338. spawn->GetZone()->AddChangedSpawn(spawn);
  339. }
  340. return 0;
  341. }
  342. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. int32 new_state = lua_interface->GetInt32Value(state, 2);
  347. Spawn* player = lua_interface->GetSpawn(state, 3);
  348. lua_interface->ResetFunctionStack(state);
  349. if (spawn) {
  350. if(player)
  351. {
  352. if(player->IsPlayer())
  353. {
  354. Client* client = ((Player*)player)->GetClient();
  355. if(client)
  356. {
  357. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  358. lua_interface->SetBooleanValue(state, true);
  359. return 1;
  360. }
  361. else
  362. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  363. }
  364. else
  365. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  366. }
  367. else
  368. {
  369. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  370. lua_interface->SetBooleanValue(state, true);
  371. return 1;
  372. }
  373. }
  374. lua_interface->SetBooleanValue(state, false);
  375. return 1;
  376. }
  377. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. Spawn* spawn = lua_interface->GetSpawn(state);
  381. string variable = lua_interface->GetStringValue(state, 2);
  382. string value = lua_interface->GetStringValue(state, 3);
  383. 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.
  384. bool temporary_flag = true;
  385. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  386. int8 index = 0;
  387. if(num_args >= 5)
  388. {
  389. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  390. index = lua_interface->GetInt8Value(state, 6);
  391. }
  392. int32 type = commands.GetSpawnSetType(variable);
  393. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  394. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  395. return 0;
  396. }
  397. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  398. if (!lua_interface)
  399. return 0;
  400. Spawn* spawn = lua_interface->GetSpawn(state);
  401. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  402. if (spawn && spawn_id > 0) {
  403. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  404. if (closest_spawn) {
  405. lua_interface->SetSpawnValue(state, closest_spawn);
  406. return 1;
  407. }
  408. }
  409. return 0;
  410. }
  411. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  412. if (!lua_interface)
  413. return 0;
  414. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  415. int32 position = lua_interface->GetInt32Value(state, 2);
  416. if (spawnList) {
  417. if (spawnList->size() > position) {
  418. lua_interface->SetSpawnValue(state, spawnList->at(position));
  419. return 1;
  420. }
  421. else {
  422. return 0;
  423. }
  424. return spawnList->size();
  425. }
  426. return 0;
  427. }
  428. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  429. if (!lua_interface)
  430. return 0;
  431. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  432. if (spawnList) {
  433. return spawnList->size();
  434. }
  435. return 0;
  436. }
  437. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  438. if (!lua_interface)
  439. return 0;
  440. vector<Spawn*>* spawnList = new vector<Spawn*>();
  441. lua_interface->SetSpawnListValue(state, spawnList);
  442. return 1;
  443. }
  444. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  445. if (!lua_interface)
  446. return 0;
  447. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  448. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  449. if (spawnList) {
  450. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  451. if (it == spawnList->end())
  452. spawnList->push_back(spawn);
  453. }
  454. return 0;
  455. }
  456. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  457. if (!lua_interface)
  458. return 0;
  459. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  460. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  461. if (spawnList) {
  462. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  463. if(it != spawnList->end())
  464. spawnList->erase(it);
  465. }
  466. return 0;
  467. }
  468. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  469. if (!lua_interface)
  470. return 0;
  471. Spawn* spawn = lua_interface->GetSpawn(state);
  472. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  473. if (spawn) {
  474. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  475. if (spawns.size() > 0) {
  476. vector<Spawn*>* spawnList = new vector<Spawn*>();
  477. vector<Spawn*>::iterator itr;
  478. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  479. spawnList->push_back(*itr);
  480. }
  481. lua_interface->SetSpawnListValue(state, spawnList);
  482. return 1;
  483. }
  484. }
  485. return 0;
  486. }
  487. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  488. if (!lua_interface)
  489. return 0;
  490. Spawn* spawn = lua_interface->GetSpawn(state);
  491. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  492. if (spawn) {
  493. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  494. if (spawns.size() > 0) {
  495. vector<Spawn*>* spawnList = new vector<Spawn*>();
  496. vector<Spawn*>::iterator itr;
  497. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  498. spawnList->push_back(*itr);
  499. }
  500. lua_interface->SetSpawnListValue(state, spawnList);
  501. return 1;
  502. }
  503. }
  504. return 0;
  505. }
  506. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  507. if (!lua_interface)
  508. return 0;
  509. Spawn* spawn = lua_interface->GetSpawn(state);
  510. if (spawn) {
  511. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  512. if (spawns.size() > 0) {
  513. lua_createtable(state, spawns.size(), 0);
  514. int newTable = lua_gettop(state);
  515. for (int32 i = 0; i < spawns.size(); i++) {
  516. lua_interface->SetSpawnValue(state, spawns.at(i));
  517. lua_rawseti(state, newTable, i + 1);
  518. }
  519. return 1;
  520. }
  521. }
  522. return 0;
  523. }
  524. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  525. if (!lua_interface)
  526. return 0;
  527. string variable_name = lua_interface->GetStringValue(state);
  528. Variable* var = variables.FindVariable(variable_name);
  529. if (var) {
  530. lua_interface->SetStringValue(state, var->GetValue());
  531. return 1;
  532. }
  533. return 0;
  534. }
  535. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  536. if (!lua_interface)
  537. return 0;
  538. int32 total_coins = lua_interface->GetInt32Value(state);
  539. if (total_coins == 0) {
  540. lua_interface->SetStringValue(state, "0 copper");
  541. return 1;
  542. }
  543. char tmp[64] = { 0 };
  544. string message = "";
  545. int32 val = 0;
  546. if (total_coins >= 1000000) {
  547. val = total_coins / 1000000;
  548. total_coins -= 1000000 * val;
  549. sprintf(tmp, " %u Platinum", val);
  550. message.append(tmp);
  551. memset(tmp, 0, 64);
  552. }
  553. if (total_coins >= 10000) {
  554. val = total_coins / 10000;
  555. total_coins -= 10000 * val;
  556. sprintf(tmp, " %u Gold", val);
  557. message.append(tmp);
  558. memset(tmp, 0, 64);
  559. }
  560. if (total_coins >= 100) {
  561. val = total_coins / 100;
  562. total_coins -= 100 * val;
  563. sprintf(tmp, " %u Silver", val);
  564. message.append(tmp);
  565. memset(tmp, 0, 64);
  566. }
  567. if (total_coins > 0) {
  568. sprintf(tmp, " %u Copper", (int32)total_coins);
  569. message.append(tmp);
  570. }
  571. lua_interface->SetStringValue(state, message.c_str());
  572. return 1;
  573. }
  574. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  575. ZoneServer* zone = lua_interface->GetZone(state);
  576. int32 group_id = lua_interface->GetInt32Value(state, 2);
  577. if (zone) {
  578. Spawn* spawn = zone->GetSpawnGroup(group_id);
  579. if (spawn) {
  580. lua_interface->SetSpawnValue(state, spawn);
  581. return 1;
  582. }
  583. }
  584. return 0;
  585. }
  586. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  587. ZoneServer* zone = lua_interface->GetZone(state);
  588. int32 location_id = lua_interface->GetInt32Value(state, 2);
  589. if (zone) {
  590. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  591. if (spawn) {
  592. lua_interface->SetSpawnValue(state, spawn);
  593. return 1;
  594. }
  595. }
  596. return 0;
  597. }
  598. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  599. Spawn* spawn = lua_interface->GetSpawn(state);
  600. if (spawn) {
  601. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  602. return 1;
  603. }
  604. return 0;
  605. }
  606. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  607. Spawn* spawn = lua_interface->GetSpawn(state);
  608. if (spawn) {
  609. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  610. return 1;
  611. }
  612. return 0;
  613. }
  614. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  615. if (!lua_interface)
  616. return 0;
  617. Spawn* spawn = lua_interface->GetSpawn(state);
  618. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  619. lua_interface->ResetFunctionStack(state);
  620. if (spawn) {
  621. spawn->SetSpawnGroupID(new_group_id);
  622. lua_interface->SetBooleanValue(state, true);
  623. return 1;
  624. }
  625. lua_interface->SetBooleanValue(state, false);
  626. return 1;
  627. }
  628. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  629. if (!lua_interface)
  630. return 0;
  631. Spawn* spawn = lua_interface->GetSpawn(state);
  632. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  636. lua_interface->SetBooleanValue(state, true);
  637. return 1;
  638. }
  639. lua_interface->SetBooleanValue(state, false);
  640. return 1;
  641. }
  642. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. if (spawn) {
  645. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  646. return 1;
  647. }
  648. return 0;
  649. }
  650. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  651. Spawn* spawn = lua_interface->GetSpawn(state);
  652. if (spawn) {
  653. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  654. return 1;
  655. }
  656. return 0;
  657. }
  658. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  659. Player* player = (Player*)lua_interface->GetSpawn(state);
  660. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  661. if (player && player->IsPlayer() && faction_id > 0) {
  662. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  663. return 1;
  664. }
  665. return 0;
  666. }
  667. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  668. if (!lua_interface)
  669. return 0;
  670. Spawn* spawn = lua_interface->GetSpawn(state);
  671. int32 value = lua_interface->GetInt32Value(state, 2);
  672. if (spawn) {
  673. spawn->SetFactionID(value);
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. if (spawn) {
  680. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  681. return 1;
  682. }
  683. return 0;
  684. }
  685. int EQ2Emu_lua_GetGender(lua_State* state) {
  686. Spawn* spawn = lua_interface->GetSpawn(state);
  687. if (spawn) {
  688. lua_interface->SetInt32Value(state, spawn->GetGender());
  689. return 1;
  690. }
  691. return 0;
  692. }
  693. int EQ2Emu_lua_GetTarget(lua_State* state) {
  694. Spawn* spawn = lua_interface->GetSpawn(state);
  695. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  696. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  697. return 1;
  698. }
  699. return 0;
  700. }
  701. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  702. if (!lua_interface)
  703. return 0;
  704. Spawn* spawn = lua_interface->GetSpawn(state);
  705. string mp3_string = lua_interface->GetStringValue(state, 2);
  706. int32 key1 = lua_interface->GetInt32Value(state, 3);
  707. int32 key2 = lua_interface->GetInt32Value(state, 4);
  708. Spawn* player = lua_interface->GetSpawn(state, 5);
  709. if (spawn && mp3_string.length() > 0) {
  710. Client* client = 0;
  711. if (player && player->IsPlayer())
  712. client = spawn->GetZone()->GetClientBySpawn(player);
  713. if (client) {
  714. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  715. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  716. }
  717. else
  718. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  719. }
  720. return 0;
  721. }
  722. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  723. if (!lua_interface)
  724. return 0;
  725. Spawn* spawn = lua_interface->GetSpawn(state);
  726. if (spawn) {
  727. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  728. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  729. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  730. return 3;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. if (spawn) {
  739. int32 item_id = lua_interface->GetInt32Value(state, 2);
  740. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  741. return 1;
  742. }
  743. return 0;
  744. }
  745. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  746. if (!lua_interface)
  747. return 0;
  748. Spawn* spawn = lua_interface->GetSpawn(state);
  749. if (spawn && spawn->IsEntity()) {
  750. int32 item_id = lua_interface->GetInt32Value(state, 2);
  751. int16 charges = lua_interface->GetInt16Value(state, 3);
  752. if (charges == 0)
  753. charges = 1;
  754. ((Entity*)spawn)->AddLootItem(item_id, charges);
  755. }
  756. return 0;
  757. }
  758. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  759. if (!lua_interface)
  760. return 0;
  761. Spawn* spawn = lua_interface->GetSpawn(state);
  762. if (spawn && spawn->IsEntity()) {
  763. int32 item_id = lua_interface->GetInt32Value(state, 2);
  764. Item* item = spawn->LootItem(item_id);
  765. safe_delete(item);
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 val = lua_interface->GetInt32Value(state, 2);
  775. spawn->AddLootCoins(val);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* entity = lua_interface->GetSpawn(state);
  783. Spawn* player = lua_interface->GetSpawn(state, 2);
  784. if (entity && player && player->IsPlayer()) {
  785. int32 coins = lua_interface->GetInt32Value(state, 3);
  786. vector<Item*>* items = 0;
  787. int i = 0;
  788. int32 item_id = 0;
  789. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  790. if (items == 0)
  791. items = new vector<Item*>;
  792. if (master_item_list.GetItem(item_id))
  793. items->push_back(master_item_list.GetItem(item_id));
  794. i++;
  795. }
  796. Client* client = 0;
  797. client = player->GetZone()->GetClientBySpawn(player);
  798. if (client)
  799. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  800. if(coins > 0)
  801. entity->AddLootCoins(coins);
  802. safe_delete(items);
  803. }
  804. return 0;
  805. }
  806. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  807. if (!lua_interface)
  808. return 0;
  809. Spawn* entity = lua_interface->GetSpawn(state);
  810. Spawn* player = lua_interface->GetSpawn(state, 2);
  811. int32 item_id = lua_interface->GetInt32Value(state, 3);
  812. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  813. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  814. return 1;
  815. }
  816. return 0;
  817. }
  818. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  819. if (!lua_interface)
  820. return 0;
  821. Spawn* entity = lua_interface->GetSpawn(state);
  822. Spawn* player = lua_interface->GetSpawn(state, 2);
  823. if (entity && player && player->IsPlayer()) {
  824. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  825. return 1;
  826. }
  827. return 0;
  828. }
  829. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  830. if (!lua_interface)
  831. return 0;
  832. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  833. safe_delete(conversation);
  834. conversation = new vector<ConversationOption>();
  835. lua_interface->SetConversationValue(state, conversation);
  836. return 1;
  837. }
  838. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  839. if (!lua_interface)
  840. return 0;
  841. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  842. if (conversation) {
  843. ConversationOption conv_option;
  844. conv_option.option = lua_interface->GetStringValue(state, 2);
  845. conv_option.function = lua_interface->GetStringValue(state, 3);
  846. if (conv_option.option.length() > 0)
  847. conversation->push_back(conv_option);
  848. }
  849. return 0;
  850. }
  851. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  852. if (!lua_interface)
  853. return 0;
  854. Spawn* npc = lua_interface->GetSpawn(state);
  855. Spawn* player = lua_interface->GetSpawn(state, 2);
  856. if (npc && player && player->IsPlayer() && player->GetZone()) {
  857. Client* client = player->GetZone()->GetClientBySpawn(player);
  858. if (client) {
  859. int32 conversation_id = client->GetConversationID(npc, 0);
  860. client->CloseDialog(conversation_id);
  861. }
  862. }
  863. return 0;
  864. }
  865. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  866. if (!lua_interface)
  867. return 0;
  868. Item* item = lua_interface->GetItem(state);
  869. Spawn* player = lua_interface->GetSpawn(state, 2);
  870. if (item && player && player->IsPlayer() && player->GetZone()) {
  871. Client* client = player->GetZone()->GetClientBySpawn(player);
  872. if (client) {
  873. int32 conversation_id = client->GetConversationID(0, item);
  874. client->CloseDialog(conversation_id);
  875. }
  876. }
  877. return 0;
  878. }
  879. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  880. if (!lua_interface)
  881. return 0;
  882. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  883. Spawn* spawn = 0;
  884. Item* item = 0;
  885. int8 type = lua_interface->GetInt8Value(state, 2);
  886. if (type == 1 || type == 3)
  887. spawn = lua_interface->GetSpawn(state, 3);
  888. else if (type == 2 || type == 4)
  889. item = lua_interface->GetItem(state, 3);
  890. Spawn* player = lua_interface->GetSpawn(state, 4);
  891. string text = lua_interface->GetStringValue(state, 5);
  892. string mp3 = lua_interface->GetStringValue(state, 6);
  893. int32 key1 = lua_interface->GetInt32Value(state, 7);
  894. int32 key2 = lua_interface->GetInt32Value(state, 8);
  895. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  896. Client* client = player->GetZone()->GetClientBySpawn(player);
  897. if (client) {
  898. if (spawn) {
  899. // Need to do this so the function works the same as it did before
  900. if (type == 1)
  901. type++;
  902. if (mp3.length() > 0)
  903. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  904. else
  905. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  906. }
  907. else {
  908. if (mp3.length() > 0)
  909. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  910. else
  911. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  912. }
  913. }
  914. }
  915. safe_delete(conversation);
  916. lua_interface->SetConversationValue(state, NULL);
  917. return 0;
  918. }
  919. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  920. if(!lua_interface)
  921. return 0;
  922. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  923. Item* item = lua_interface->GetItem(state, 2);
  924. Spawn* player = lua_interface->GetSpawn(state, 3);
  925. string text = lua_interface->GetStringValue(state, 4);
  926. string mp3 = lua_interface->GetStringValue(state, 5);
  927. int32 key1 = lua_interface->GetInt32Value(state, 6);
  928. int32 key2 = lua_interface->GetInt32Value(state, 7);
  929. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  930. Client* client = player->GetZone()->GetClientBySpawn(player);
  931. if(client){
  932. if(mp3.length() > 0)
  933. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  934. else
  935. client->DisplayConversation(item, conversation, (char*)text.c_str());
  936. }
  937. safe_delete(conversation);
  938. }
  939. return 0;
  940. }*/
  941. int EQ2Emu_lua_StartConversation(lua_State* state) {
  942. if (!lua_interface)
  943. return 0;
  944. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  945. Spawn* source = lua_interface->GetSpawn(state, 2);
  946. Spawn* player = lua_interface->GetSpawn(state, 3);
  947. string text = lua_interface->GetStringValue(state, 4);
  948. string mp3 = lua_interface->GetStringValue(state, 5);
  949. int32 key1 = lua_interface->GetInt32Value(state, 6);
  950. int32 key2 = lua_interface->GetInt32Value(state, 7);
  951. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  952. Client* client = source->GetZone()->GetClientBySpawn(player);
  953. if (mp3.length() > 0)
  954. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  955. else
  956. client->DisplayConversation(source, 1, conversation, text.c_str());
  957. safe_delete(conversation);
  958. lua_interface->SetConversationValue(state, NULL);
  959. }
  960. else
  961. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  962. return 0;
  963. }
  964. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  965. if (!lua_interface)
  966. return 0;
  967. Spawn* spawn = lua_interface->GetSpawn(state);
  968. float distance = lua_interface->GetFloatValue(state, 2);
  969. string in_range_function = lua_interface->GetStringValue(state, 3);
  970. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  971. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  972. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  973. return 0;
  974. }
  975. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  976. ZoneServer* zone = lua_interface->GetZone(state);
  977. float x = lua_interface->GetFloatValue(state, 2);
  978. float y = lua_interface->GetFloatValue(state, 3);
  979. float z = lua_interface->GetFloatValue(state, 4);
  980. float max_variation = lua_interface->GetFloatValue(state, 5);
  981. string in_range_function = lua_interface->GetStringValue(state, 6);
  982. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  983. if (zone && in_range_function.length() > 0)
  984. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  985. return 0;
  986. }
  987. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  988. if (!lua_interface)
  989. return 0;
  990. Spawn* spawn = lua_interface->GetSpawn(state);
  991. if (spawn && spawn->IsEntity()) {
  992. int32 val = lua_interface->GetInt32Value(state, 2);
  993. ((Entity*)spawn)->SetLootCoins(val);
  994. }
  995. return 0;
  996. }
  997. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. Spawn* spawn = lua_interface->GetSpawn(state);
  1001. if (spawn && spawn->IsEntity()) {
  1002. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1003. return 1;
  1004. }
  1005. return 0;
  1006. }
  1007. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1008. if (!lua_interface)
  1009. return 0;
  1010. Spawn* spawn = lua_interface->GetSpawn(state);
  1011. float x = lua_interface->GetFloatValue(state, 2);
  1012. float y = lua_interface->GetFloatValue(state, 3);
  1013. float z = lua_interface->GetFloatValue(state, 4);
  1014. float speed = lua_interface->GetFloatValue(state, 5);
  1015. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1016. string function = lua_interface->GetStringValue(state, 7);
  1017. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1018. float heading = lua_interface->GetFloatValue(state, 8);
  1019. if (spawn) {
  1020. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1021. spawn->GetZone()->AddMovementNPC(spawn);
  1022. }
  1023. lua_interface->ResetFunctionStack(state);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. if (spawn) {
  1031. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1032. return 1;
  1033. }
  1034. return 0;
  1035. }
  1036. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1037. if (!lua_interface)
  1038. return 0;
  1039. Spawn* spawn = lua_interface->GetSpawn(state);
  1040. if (spawn && spawn->IsPlayer()) {
  1041. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1042. return 1;
  1043. }
  1044. lua_interface->SetInt32Value(state, 0);
  1045. return 1;
  1046. }
  1047. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1048. if (!lua_interface)
  1049. return 0;
  1050. Spawn* spawn = lua_interface->GetSpawn(state);
  1051. Spawn* target = lua_interface->GetSpawn(state, 2);
  1052. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1053. bool reset_action_state = true;
  1054. if(num_args > 2)
  1055. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1056. if (spawn && target) {
  1057. if (spawn->IsEntity())
  1058. // ((Entity*)spawn)->FaceTarget(target);
  1059. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1060. }
  1061. lua_interface->ResetFunctionStack(state);
  1062. return 0;
  1063. }
  1064. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1065. if (!lua_interface)
  1066. return 0;
  1067. Spawn* spawn = lua_interface->GetSpawn(state);
  1068. float x = lua_interface->GetFloatValue(state, 2);
  1069. float y = lua_interface->GetFloatValue(state, 3);
  1070. float z = lua_interface->GetFloatValue(state, 4);
  1071. float speed = lua_interface->GetFloatValue(state, 5);
  1072. string lua_function = lua_interface->GetStringValue(state, 6);
  1073. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1074. if (spawn) {
  1075. if (speed == 0)
  1076. speed = spawn->GetSpeed();
  1077. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1078. }
  1079. lua_interface->ResetFunctionStack(state);
  1080. return 0;
  1081. }
  1082. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1083. if (!lua_interface)
  1084. return 0;
  1085. Spawn* spawn = lua_interface->GetSpawn(state);
  1086. if (spawn) {
  1087. spawn->ClearRunningLocations();
  1088. }
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_Say(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. string message = lua_interface->GetStringValue(state, 2);
  1096. Spawn* player = lua_interface->GetSpawn(state, 3);
  1097. int32 language = lua_interface->GetInt32Value(state, 4);
  1098. if (spawn && message.length() > 0) {
  1099. Client* client = 0;
  1100. if (player && player->IsPlayer())
  1101. client = spawn->GetZone()->GetClientBySpawn(player);
  1102. if (client)
  1103. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1104. else
  1105. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1106. }
  1107. lua_interface->ResetFunctionStack(state);
  1108. return 0;
  1109. }
  1110. int EQ2Emu_lua_Shout(lua_State* state) {
  1111. if (!lua_interface)
  1112. return 0;
  1113. Spawn* spawn = lua_interface->GetSpawn(state);
  1114. string message = lua_interface->GetStringValue(state, 2);
  1115. Spawn* player = lua_interface->GetSpawn(state, 3);
  1116. float dist = lua_interface->GetFloatValue(state, 4);
  1117. if (spawn && message.length() > 0) {
  1118. Client* client = 0;
  1119. if (player && player->IsPlayer())
  1120. client = spawn->GetZone()->GetClientBySpawn(player);
  1121. if (client)
  1122. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1123. else
  1124. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1125. }
  1126. lua_interface->ResetFunctionStack(state);
  1127. return 0;
  1128. }
  1129. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1130. if (!lua_interface)
  1131. return 0;
  1132. Spawn* spawn = lua_interface->GetSpawn(state);
  1133. string message = lua_interface->GetStringValue(state, 2);
  1134. Spawn* player = lua_interface->GetSpawn(state, 3);
  1135. if (spawn && message.length() > 0) {
  1136. Client* client = 0;
  1137. if (player && player->IsPlayer())
  1138. client = spawn->GetZone()->GetClientBySpawn(player);
  1139. if (client)
  1140. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1141. else
  1142. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1143. }
  1144. lua_interface->ResetFunctionStack(state);
  1145. return 0;
  1146. }
  1147. int EQ2Emu_lua_Emote(lua_State* state) {
  1148. if (!lua_interface)
  1149. return 0;
  1150. Spawn* spawn = lua_interface->GetSpawn(state);
  1151. string message = lua_interface->GetStringValue(state, 2);
  1152. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1153. Spawn* player = lua_interface->GetSpawn(state, 4);
  1154. char* to = 0;
  1155. if (spawn2)
  1156. to = spawn2->GetName();
  1157. if (spawn && message.length() > 0) {
  1158. Client* client = 0;
  1159. if (player && player->IsPlayer())
  1160. client = spawn->GetZone()->GetClientBySpawn(player);
  1161. if (client)
  1162. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1163. else
  1164. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1165. }
  1166. lua_interface->ResetFunctionStack(state);
  1167. return 0;
  1168. }
  1169. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1170. if (!lua_interface)
  1171. return 0;
  1172. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1173. if (!luaspell)
  1174. return 0;
  1175. Spawn* caster = luaspell->caster;
  1176. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1177. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1178. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1179. Spawn* target = lua_interface->GetSpawn(state, 4);
  1180. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1181. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1182. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1183. lua_interface->ResetFunctionStack(state);
  1184. boost::to_lower(heal_type);
  1185. if (caster && caster->IsEntity()) {
  1186. bool success = false;
  1187. luaspell->resisted = false;
  1188. if (target) {
  1189. float distance = caster->GetDistance(target, true);
  1190. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1191. success = true;
  1192. }
  1193. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1194. Spawn* target = 0;
  1195. ZoneServer* zone = luaspell->caster->GetZone();
  1196. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1197. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1198. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1199. float distance = caster->GetDistance(target, true);
  1200. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1201. }
  1202. }
  1203. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1204. success = true;
  1205. }
  1206. if (success) {
  1207. if (caster->GetZone())
  1208. caster->GetZone()->TriggerCharSheetTimer();
  1209. }
  1210. }
  1211. return 0;
  1212. }
  1213. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1214. if (!lua_interface)
  1215. return 0;
  1216. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1217. if (!luaspell)
  1218. return 0;
  1219. Spawn* caster = luaspell->caster;
  1220. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1221. float percentage = lua_interface->GetFloatValue(state, 2);
  1222. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1223. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1224. Spawn* target = lua_interface->GetSpawn(state, 5);
  1225. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1226. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1227. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1228. lua_interface->ResetFunctionStack(state);
  1229. boost::to_lower(heal_type);
  1230. int32 min_heal = 0, max_heal = 0;
  1231. if (caster && caster->IsEntity() && target) {
  1232. if(percentage <= 0.0f)
  1233. {
  1234. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1235. return 0;
  1236. }
  1237. if(heal_type == "power")
  1238. {
  1239. if(current_value)
  1240. {
  1241. if(caster_value)
  1242. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1243. else
  1244. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1245. }
  1246. else
  1247. {
  1248. if(caster_value)
  1249. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1250. else
  1251. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1252. }
  1253. }
  1254. else
  1255. {
  1256. if(current_value)
  1257. {
  1258. if(caster_value)
  1259. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1260. else
  1261. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1262. }
  1263. else
  1264. {
  1265. if(caster_value)
  1266. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1267. else
  1268. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1269. }
  1270. }
  1271. bool success = false;
  1272. luaspell->resisted = false;
  1273. if (target) {
  1274. float distance = caster->GetDistance(target, true);
  1275. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1276. success = true;
  1277. }
  1278. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1279. Spawn* target = 0;
  1280. ZoneServer* zone = luaspell->caster->GetZone();
  1281. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1282. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1283. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1284. float distance = caster->GetDistance(target, true);
  1285. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1286. }
  1287. }
  1288. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1289. success = true;
  1290. }
  1291. if (success) {
  1292. if (caster->GetZone())
  1293. caster->GetZone()->TriggerCharSheetTimer();
  1294. }
  1295. }
  1296. return 0;
  1297. }
  1298. int EQ2Emu_lua_AddItem(lua_State* state) {
  1299. if (!lua_interface)
  1300. return 0;
  1301. Spawn* spawn = lua_interface->GetSpawn(state);
  1302. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1303. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1304. // default of 1 quantity to add
  1305. if (quantity == 0)
  1306. quantity = 1;
  1307. if (spawn && spawn->IsPlayer()) {
  1308. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1309. if (client && item_id > 0) {
  1310. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1311. return 1;
  1312. }
  1313. }
  1314. lua_interface->SetBooleanValue(state, false);
  1315. return 1;
  1316. }
  1317. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1318. if (!lua_interface)
  1319. return 0;
  1320. Spawn* spawn = lua_interface->GetSpawn(state);
  1321. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1322. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1323. string location = lua_interface->GetStringValue(state, 4);
  1324. if (spawn && spawn->IsPlayer()) {
  1325. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1326. if (client && item_id > 0) {
  1327. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1328. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1329. else
  1330. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1331. if (send_messages) {
  1332. Item* item = master_item_list.GetItem(item_id);
  1333. if (item) {
  1334. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1335. string popup_text = "You receive " + item->name;
  1336. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1337. }
  1338. }
  1339. return 1;
  1340. }
  1341. }
  1342. lua_interface->SetBooleanValue(state, false);
  1343. return 1;
  1344. }
  1345. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1346. Spawn* spawn = lua_interface->GetSpawn(state);
  1347. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1348. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1349. // default of 1 to remove
  1350. if (quantity == 0)
  1351. quantity = 1;
  1352. Client* client;
  1353. Item* item;
  1354. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1355. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1356. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1357. if (client->RemoveItem(item, quantity)) {
  1358. lua_interface->SetBooleanValue(state, true);
  1359. return 1;
  1360. }
  1361. }
  1362. }
  1363. }
  1364. lua_interface->SetBooleanValue(state, false);
  1365. return 1;
  1366. }
  1367. int EQ2Emu_lua_HasItem(lua_State* state) {
  1368. Spawn* player = lua_interface->GetSpawn(state);
  1369. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1370. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1371. if (player && player->IsPlayer()) {
  1372. bool hasItem = false;
  1373. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1374. if (!hasItem)
  1375. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1376. lua_interface->SetBooleanValue(state, hasItem);
  1377. return 1;
  1378. }
  1379. lua_interface->SetBooleanValue(state, false);
  1380. return 1;
  1381. }
  1382. int EQ2Emu_lua_Spawn(lua_State* state) {
  1383. if (!lua_interface)
  1384. return 0;
  1385. ZoneServer* zone = lua_interface->GetZone(state);
  1386. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1387. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1388. float x = lua_interface->GetFloatValue(state, 4);
  1389. float y = lua_interface->GetFloatValue(state, 5);
  1390. float z = lua_interface->GetFloatValue(state, 6);
  1391. float heading = lua_interface->GetFloatValue(state, 7);
  1392. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1393. Spawn* spawn = zone->GetSpawn(spawn_id);
  1394. if (!spawn)
  1395. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1396. else {
  1397. spawn->SetX(x);
  1398. spawn->SetZ(z);
  1399. spawn->SetY(y,true,true);
  1400. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1401. spawn->SetHeading(heading);
  1402. if (restricted_npc)
  1403. spawn->AddAllowAccessSpawn(spawn);
  1404. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1405. bool scriptActive = false;
  1406. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1407. scriptActive = true;
  1408. spawn->SetSpawnScript(string(spawn_script));
  1409. }
  1410. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1411. zone->AddSpawn(spawn);
  1412. if (scriptActive) {
  1413. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1414. }
  1415. lua_interface->SetSpawnValue(state, spawn);
  1416. return 1;
  1417. }
  1418. }
  1419. else {
  1420. string output = "Invalid paramaters to LUA Spawn command: \n";
  1421. if (!zone)
  1422. output = output.append("\t").append("Missing zone reference. \n");
  1423. if (spawn_id == 0)
  1424. output = output.append("\t").append("Missing spawn_id.");
  1425. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1426. }
  1427. return 0;
  1428. }
  1429. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1430. if (!lua_interface)
  1431. return 0;
  1432. ZoneServer* zone = lua_interface->GetZone(state);
  1433. if (zone) {
  1434. lua_interface->SetStringValue(state, zone->GetZoneName());
  1435. return 1;
  1436. }
  1437. return 0;
  1438. }
  1439. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1440. if (!lua_interface)
  1441. return 0;
  1442. ZoneServer* zone = lua_interface->GetZone(state);
  1443. if (zone) {
  1444. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1445. return 1;
  1446. }
  1447. return 0;
  1448. }
  1449. int EQ2Emu_lua_GetZone(lua_State* state) {
  1450. if (!lua_interface)
  1451. return 0;
  1452. int32 zone_id = lua_interface->GetInt32Value(state);
  1453. ZoneServer* zone = 0;
  1454. if (zone_id > 0)
  1455. zone = zone_list.Get(zone_id);
  1456. else {
  1457. string zone_name = lua_interface->GetStringValue(state);
  1458. if (zone_name.length() > 0) {
  1459. zone = zone_list.Get(zone_name.c_str());
  1460. }
  1461. else {
  1462. Spawn* spawn = lua_interface->GetSpawn(state);
  1463. if (spawn)
  1464. zone = spawn->GetZone();
  1465. }
  1466. }
  1467. if (zone) {
  1468. lua_interface->SetZoneValue(state, zone);
  1469. return 1;
  1470. }
  1471. return 0;
  1472. }
  1473. int EQ2Emu_lua_AddHate(lua_State* state) {
  1474. Spawn* entity = lua_interface->GetSpawn(state);
  1475. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1476. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1477. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1478. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1479. if (entity && entity->IsEntity() && amount != 0) {
  1480. if (luaspell) {
  1481. ZoneServer* zone = luaspell->caster->GetZone();
  1482. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1483. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1484. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1485. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1486. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1487. if (send_packet)
  1488. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1489. }
  1490. }
  1491. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1492. }
  1493. else if (npc && npc->IsNPC() && npc->GetZone())
  1494. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1495. }
  1496. return 0;
  1497. }
  1498. int EQ2Emu_lua_Zone(lua_State* state) {
  1499. if (!lua_interface)
  1500. return 0;
  1501. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1502. ZoneServer* zone = lua_interface->GetZone(state);
  1503. Spawn* player = lua_interface->GetSpawn(state, 2);
  1504. Client* client = 0;
  1505. if (player && player->IsPlayer())
  1506. client = player->GetZone()->GetClientBySpawn(player);
  1507. float x = lua_interface->GetFloatValue(state, 3);
  1508. float y = lua_interface->GetFloatValue(state, 4);
  1509. float z = lua_interface->GetFloatValue(state, 5);
  1510. float heading = lua_interface->GetFloatValue(state, 6);
  1511. if (zone && client) {
  1512. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1513. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1514. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1515. {
  1516. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1517. return 0;
  1518. }
  1519. if (x != 0 || y != 0 || z != 0) {
  1520. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1521. player->SetX(x);
  1522. player->SetY(y);
  1523. player->SetZ(z);
  1524. player->SetHeading(heading);
  1525. client->Zone(zone->GetZoneName(), false);
  1526. }
  1527. else
  1528. client->Zone(zone->GetZoneName());
  1529. }
  1530. else
  1531. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1532. return 0;
  1533. }
  1534. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1535. if (!lua_interface)
  1536. return 0;
  1537. Spawn* spawn = lua_interface->GetSpawn(state);
  1538. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1539. if (spawn && spawn2)
  1540. spawn->AddAllowAccessSpawn(spawn2);
  1541. return 0;
  1542. }
  1543. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1544. if (!lua_interface)
  1545. return 0;
  1546. Spawn* target = lua_interface->GetSpawn(state);
  1547. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1548. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1549. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1550. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1551. if (!target) {
  1552. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1553. return 0;
  1554. }
  1555. if (!target->IsEntity()) {
  1556. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1557. return 0;
  1558. }
  1559. if (spell_id <= 0) {
  1560. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1561. return 0;
  1562. }
  1563. if (caster && !caster->IsEntity()) {
  1564. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1565. return 0;
  1566. }
  1567. if (spell_tier == 0)
  1568. spell_tier = 1;
  1569. if (!caster)
  1570. caster = target;
  1571. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1572. return 0;
  1573. }
  1574. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1575. if (!lua_interface)
  1576. return 0;
  1577. Spawn* target = lua_interface->GetSpawn(state);
  1578. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1579. if (!luaspell)
  1580. return 0;
  1581. Spawn* caster = luaspell->caster;
  1582. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1583. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1584. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1585. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1586. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1587. //lua_interface->ResetFunctionStack(state);
  1588. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1589. vector<int16> faction_req;
  1590. vector<int16> race_req;
  1591. int32 class_req = 0;
  1592. int32 i = 0;
  1593. int8 f = 0;
  1594. int8 r = 0;
  1595. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1596. if (class_id < 100) {
  1597. class_req += pow(2.0, double(class_id - 1));
  1598. }
  1599. else if (class_id > 100 && class_id < 1000) {
  1600. race_req.push_back(class_id);
  1601. r++;
  1602. }
  1603. else {
  1604. faction_req.push_back(class_id);
  1605. f++;
  1606. }
  1607. i++;
  1608. }
  1609. if (caster && caster->IsEntity()) {
  1610. bool race_match = false;
  1611. bool success = false;
  1612. luaspell->resisted = false;
  1613. if (luaspell->targets.size() > 0) {
  1614. ZoneServer* zone = luaspell->caster->GetZone();
  1615. Spawn* target = 0;
  1616. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1617. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1618. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1619. if (race_req.size() > 0) {
  1620. for (int8 i = 0; i < race_req.size(); i++) {
  1621. if (target->GetLuaRaceId() == race_req[i]) {
  1622. race_match = true;
  1623. }
  1624. }
  1625. }
  1626. else
  1627. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1628. if (race_match == true) {
  1629. float distance = caster->GetDistance(target, true);
  1630. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1631. }
  1632. }
  1633. }
  1634. success = true;
  1635. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1636. }
  1637. else if (target) {
  1638. //check class and race/faction here
  1639. if (race_req.size() > 0) {
  1640. for (int8 i = 0; i < race_req.size(); i++) {
  1641. if (target->GetLuaRaceId() == race_req[i]) {
  1642. race_match = true;
  1643. }
  1644. }
  1645. }
  1646. else
  1647. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1648. if (race_match == true) {
  1649. float distance = caster->GetDistance(target, true);
  1650. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1651. success = true;
  1652. }
  1653. }
  1654. if (success) {
  1655. Spell* spell = luaspell->spell;
  1656. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1657. ((Player*)caster)->InCombat(true);
  1658. if (caster->GetZone())
  1659. caster->GetZone()->TriggerCharSheetTimer();
  1660. }
  1661. }
  1662. }
  1663. return 0;
  1664. }
  1665. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1666. if (!lua_interface)
  1667. return 0;
  1668. Spawn* spawn = lua_interface->GetSpawn(state);
  1669. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1670. lua_interface->ResetFunctionStack(state);
  1671. if (spawn && value != 0) {
  1672. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1673. spawn->SetPower(spawn->GetTotalPower());
  1674. else
  1675. spawn->SetPower(spawn->GetPower() + value);
  1676. }
  1677. return 0;
  1678. }
  1679. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1680. if (!lua_interface)
  1681. return 0;
  1682. Spawn* spawn = lua_interface->GetSpawn(state);
  1683. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1684. lua_interface->ResetFunctionStack(state);
  1685. if (spawn && value != 0) {
  1686. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1687. spawn->SetHP(spawn->GetTotalHP());
  1688. else
  1689. spawn->SetHP(spawn->GetHP() + value);
  1690. }
  1691. return 0;
  1692. }
  1693. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1694. if (!lua_interface)
  1695. return 0;
  1696. Spawn* spawn = lua_interface->GetSpawn(state);
  1697. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1698. lua_interface->ResetFunctionStack(state);
  1699. if (spawn && value != 0) {
  1700. spawn->SetPower(spawn->GetPower() + value);
  1701. if (value > spawn->GetTotalHPBase())
  1702. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1703. }
  1704. return 0;
  1705. }
  1706. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1707. if (!lua_interface)
  1708. return 0;
  1709. Spawn* spawn = lua_interface->GetSpawn(state);
  1710. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1711. lua_interface->ResetFunctionStack(state);
  1712. if (spawn && value != 0) {
  1713. spawn->SetHP(spawn->GetHP() + value);
  1714. if (value > spawn->GetTotalHPBase())
  1715. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1716. }
  1717. return 0;
  1718. }
  1719. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1720. if (!lua_interface)
  1721. return 0;
  1722. Spawn* spawn = lua_interface->GetSpawn(state);
  1723. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1724. lua_interface->ResetFunctionStack(state);
  1725. if (spawn) {
  1726. spawn->SetHP(value);
  1727. if (value > spawn->GetTotalHPBase())
  1728. spawn->SetTotalHP(value);
  1729. }
  1730. return 0;
  1731. }
  1732. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1733. if (!lua_interface)
  1734. return 0;
  1735. Spawn* spawn = lua_interface->GetSpawn(state);
  1736. float value = lua_interface->GetFloatValue(state, 2);
  1737. lua_interface->ResetFunctionStack(state);
  1738. if (spawn && spawn->IsEntity() && value > 0)
  1739. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1740. if (spawn->IsPlayer())
  1741. ((Player*)spawn)->SetCharSheetChanged(true);
  1742. return 0;
  1743. }
  1744. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1745. if (!lua_interface)
  1746. return 0;
  1747. Spawn* spawn = lua_interface->GetSpawn(state);
  1748. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1749. lua_interface->ResetFunctionStack(state);
  1750. if (spawn && spawn->IsEntity() && value > 0)
  1751. ((Entity*)spawn)->SetTotalHPBase(value);
  1752. return 0;
  1753. }
  1754. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1755. if (!lua_interface)
  1756. return 0;
  1757. Spawn* spawn = lua_interface->GetSpawn(state);
  1758. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1759. lua_interface->ResetFunctionStack(state);
  1760. if (spawn && value > 0) {
  1761. spawn->SetPower(value);
  1762. if (value > spawn->GetTotalPowerBase())
  1763. spawn->SetTotalPower(value);
  1764. }
  1765. return 0;
  1766. }
  1767. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1768. if (!lua_interface)
  1769. return 0;
  1770. Spawn* spawn = lua_interface->GetSpawn(state);
  1771. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1772. lua_interface->ResetFunctionStack(state);
  1773. if (spawn && spawn->IsEntity() && value > 0)
  1774. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1775. return 0;
  1776. }
  1777. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1778. if (!lua_interface)
  1779. return 0;
  1780. Spawn* spawn = lua_interface->GetSpawn(state);
  1781. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1782. lua_interface->ResetFunctionStack(state);
  1783. if (spawn && spawn->IsEntity() && value > 0)
  1784. ((Entity*)spawn)->SetTotalPowerBase(value);
  1785. return 0;
  1786. }
  1787. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1788. if (!lua_interface)
  1789. return 0;
  1790. Spawn* spawn = lua_interface->GetSpawn(state);
  1791. float x = lua_interface->GetFloatValue(state, 2);
  1792. float y = lua_interface->GetFloatValue(state, 3);
  1793. float z = lua_interface->GetFloatValue(state, 4);
  1794. float heading = lua_interface->GetFloatValue(state, 5);
  1795. lua_interface->ResetFunctionStack(state);
  1796. if (spawn) {
  1797. spawn->SetX(x);
  1798. spawn->SetY(y);
  1799. spawn->SetZ(z);
  1800. if (heading != 0)
  1801. spawn->SetHeading(heading);
  1802. spawn->SetSpawnOrigX(spawn->GetX());
  1803. spawn->SetSpawnOrigY(spawn->GetY());
  1804. spawn->SetSpawnOrigZ(spawn->GetZ());
  1805. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1806. if (spawn->IsPlayer()) {
  1807. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1808. if (client) {
  1809. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1810. client->QueuePacket(packet);
  1811. }
  1812. }
  1813. }
  1814. return 0;
  1815. }
  1816. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1817. if (!lua_interface)
  1818. return 0;
  1819. Spawn* spawn = lua_interface->GetSpawn(state);
  1820. float value = lua_interface->GetFloatValue(state, 2);
  1821. lua_interface->ResetFunctionStack(state);
  1822. if (spawn) {
  1823. spawn->SetHeading(value);
  1824. if (spawn->IsPlayer()) {
  1825. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1826. if (client) {
  1827. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1828. client->QueuePacket(packet);
  1829. }
  1830. }
  1831. }
  1832. return 0;
  1833. }
  1834. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1835. if (!lua_interface)
  1836. return 0;
  1837. Spawn* spawn = lua_interface->GetSpawn(state);
  1838. int16 value = lua_interface->GetInt16Value(state, 2);
  1839. lua_interface->ResetFunctionStack(state);
  1840. if (spawn)
  1841. spawn->SetModelType(value);
  1842. return 0;
  1843. }
  1844. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1845. if (!lua_interface)
  1846. return 0;
  1847. Spawn* spawn = lua_interface->GetSpawn(state);
  1848. int8 value = lua_interface->GetInt8Value(state, 2);
  1849. lua_interface->ResetFunctionStack(state);
  1850. if (spawn) {
  1851. if (spawn->IsPlayer())
  1852. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1853. else
  1854. spawn->SetAdventureClass(value);
  1855. }
  1856. return 0;
  1857. }
  1858. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1859. if (!lua_interface)
  1860. return 0;
  1861. Spawn* spawn = lua_interface->GetSpawn(state);
  1862. int8 value = lua_interface->GetInt8Value(state, 2);
  1863. lua_interface->ResetFunctionStack(state);
  1864. if (spawn) {
  1865. spawn->SetTradeskillClass(value);
  1866. if (spawn->IsEntity()) {
  1867. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1868. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1869. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1870. }
  1871. if (spawn->IsPlayer())
  1872. ((Player*)spawn)->SetCharSheetChanged(true);
  1873. }
  1874. return 0;
  1875. }
  1876. int EQ2Emu_lua_SetMount(lua_State* state) {
  1877. if (!lua_interface)
  1878. return 0;
  1879. Spawn* spawn = lua_interface->GetSpawn(state);
  1880. int16 value = lua_interface->GetInt16Value(state, 2);
  1881. if (spawn && spawn->IsEntity()) {
  1882. ((Entity*)spawn)->SetMount(value);
  1883. EQ2_Color color;
  1884. color.red = 255;
  1885. color.green = 255;
  1886. color.blue = 255;
  1887. ((Entity*)spawn)->SetMountColor(&color);
  1888. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1889. }
  1890. return 0;
  1891. }
  1892. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1893. if (!lua_interface)
  1894. return 0;
  1895. Spawn* spawn = lua_interface->GetSpawn(state);
  1896. EQ2_Color mount_color;
  1897. EQ2_Color saddle_color;
  1898. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1899. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1900. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1901. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1902. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1903. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1904. if (spawn && spawn->IsEntity()) {
  1905. ((Entity*)spawn)->SetMountColor(&mount_color);
  1906. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1907. }
  1908. return 0;
  1909. }
  1910. int EQ2Emu_lua_GetMount(lua_State* state) {
  1911. if (!lua_interface)
  1912. return 0;
  1913. Spawn* spawn = lua_interface->GetSpawn(state);
  1914. if (spawn && spawn->IsEntity()) {
  1915. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1916. return 1;
  1917. }
  1918. return 0;
  1919. }
  1920. int EQ2Emu_lua_GetRace(lua_State* state) {
  1921. if (!lua_interface)
  1922. return 0;
  1923. Spawn* spawn = lua_interface->GetSpawn(state);
  1924. if (spawn)
  1925. {
  1926. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1927. lua_interface->SetInt32Value(state, spawn->GetRace());
  1928. return 1;
  1929. }
  1930. return 0;
  1931. }
  1932. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1933. if (!lua_interface)
  1934. return 0;
  1935. Spawn* spawn = lua_interface->GetSpawn(state);
  1936. if (spawn) {
  1937. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1938. return 1;
  1939. }
  1940. return 0;
  1941. }
  1942. int EQ2Emu_lua_GetClass(lua_State* state) {
  1943. Spawn* spawn = lua_interface->GetSpawn(state);
  1944. if (spawn) {
  1945. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1946. return 1;
  1947. }
  1948. return 0;
  1949. }
  1950. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1951. Spawn* spawn = lua_interface->GetSpawn(state);
  1952. if (spawn) {
  1953. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1954. return 1;
  1955. }
  1956. return 0;
  1957. }
  1958. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1959. if (!lua_interface)
  1960. return 0;
  1961. Spawn* spawn = lua_interface->GetSpawn(state);
  1962. float value = lua_interface->GetFloatValue(state, 2);
  1963. lua_interface->ResetFunctionStack(state);
  1964. if (spawn) {
  1965. spawn->SetSpeed(value);
  1966. if(spawn->IsEntity())
  1967. ((Entity*)spawn)->SetSpeed(value);
  1968. if (spawn->IsPlayer()) {
  1969. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1970. if (client) {
  1971. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1972. if (packet) {
  1973. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1974. packet->setDataByName("speed", value);
  1975. packet->setDataByName("size", 0.51);
  1976. EQ2Packet* app = packet->serialize();
  1977. client->QueuePacket(app);
  1978. safe_delete(packet);
  1979. }
  1980. }
  1981. }
  1982. }
  1983. return 0;
  1984. }
  1985. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1986. if (!lua_interface)
  1987. return 0;
  1988. Spawn* spawn = lua_interface->GetSpawn(state);
  1989. const int16 type = lua_interface->GetInt16Value(state, 2);
  1990. const float value = lua_interface->GetFloatValue(state, 3);
  1991. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1992. int64 class_req = 0;
  1993. int32 class_id = 0;
  1994. vector<int16> faction_req;
  1995. vector<int16> race_req;
  1996. int32 i = 0;
  1997. int8 f = 0;
  1998. int8 r = 0;
  1999. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2000. if (class_id < 100) {
  2001. class_req += pow(2.0, double(class_id - 1));
  2002. }
  2003. else if (class_id > 100 && class_id < 1000) {
  2004. race_req.push_back(class_id);
  2005. r++;
  2006. }
  2007. else {
  2008. faction_req.push_back(class_id);
  2009. f++;
  2010. }
  2011. i++;
  2012. }
  2013. if (value != 0 && type >= 0) {
  2014. if (luaspell && luaspell->spell && luaspell->caster) {
  2015. ZoneServer* zone = luaspell->caster->GetZone();
  2016. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2017. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2018. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2019. if (target) {
  2020. if (target->IsPlayer()) {
  2021. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2022. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2023. if (((Player*)target)->GetGroupMemberInfo())
  2024. ((Player*)target)->UpdateGroupMemberInfo();
  2025. ((Player*)target)->SetCharSheetChanged(true);
  2026. }
  2027. else if (target->IsNPC())
  2028. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2029. else
  2030. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2031. }
  2032. }
  2033. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2034. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2035. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2036. }
  2037. else if (spawn && spawn->IsEntity()) {
  2038. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2039. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2040. if (spawn->IsPlayer())
  2041. ((Player*)spawn)->SetCharSheetChanged(true);
  2042. }
  2043. else
  2044. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2045. }
  2046. else
  2047. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2048. return 0;
  2049. }
  2050. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2051. if (!lua_interface)
  2052. return 0;
  2053. Spawn* spawn = lua_interface->GetSpawn(state);
  2054. int16 type = lua_interface->GetInt16Value(state, 2);
  2055. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2056. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2057. if (!spawn) {
  2058. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2059. return 0;
  2060. }
  2061. if (!spawn->IsEntity()) {
  2062. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2063. return 0;
  2064. }
  2065. if (value == 0) {
  2066. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2067. return 0;
  2068. }
  2069. if (!luaspell || !luaspell->spell) {
  2070. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2071. return 0;
  2072. }
  2073. int32 class_req = 0;
  2074. vector<int16> faction_req;
  2075. vector<int16> race_req;
  2076. int32 class_id = 0;
  2077. int32 i = 0;
  2078. int8 f = 0;
  2079. int8 r = 0;
  2080. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2081. if (class_id < 100) {
  2082. class_req += pow(2.0, double(class_id - 1));
  2083. }
  2084. else if (class_id > 100 && class_id < 1000) {
  2085. race_req.push_back(class_id);
  2086. r++;
  2087. }
  2088. else {
  2089. faction_req.push_back(class_id);
  2090. f++;
  2091. }
  2092. i++;
  2093. }
  2094. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2095. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2096. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2097. if (spawn->IsPlayer())
  2098. ((Player*)spawn)->SetCharSheetChanged(true);
  2099. return 0;
  2100. }
  2101. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2102. if (!lua_interface)
  2103. return 0;
  2104. Spawn* spawn = lua_interface->GetSpawn(state);
  2105. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2106. if (!spawn) {
  2107. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2108. return 0;
  2109. }
  2110. if (!spawn->IsEntity()) {
  2111. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2112. return 0;
  2113. }
  2114. if (!luaspell || !luaspell->spell) {
  2115. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2116. return 0;
  2117. }
  2118. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2119. if (spawn->IsPlayer())
  2120. ((Player*)spawn)->SetCharSheetChanged(true);
  2121. return 0;
  2122. }
  2123. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2124. if (!lua_interface)
  2125. return 0;
  2126. Spawn* spawn = lua_interface->GetSpawn(state);
  2127. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2128. if (luaspell && luaspell->spell) {
  2129. ZoneServer* zone = luaspell->caster->GetZone();
  2130. Spawn* target = 0;
  2131. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2132. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2133. target = zone->GetSpawnByID(luaspell->targets[i]);
  2134. if (target && target->IsEntity()) {
  2135. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2136. if (target->IsPlayer())
  2137. ((Player*)target)->SetCharSheetChanged(true);
  2138. }
  2139. }
  2140. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2141. }
  2142. else if (spawn && spawn->IsEntity()) {
  2143. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2144. if (spawn->IsPlayer())
  2145. ((Player*)spawn)->SetCharSheetChanged(true);
  2146. }
  2147. return 0;
  2148. }
  2149. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2150. if (!lua_interface)
  2151. return 0;
  2152. Spawn* spawn = lua_interface->GetSpawn(state);
  2153. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2154. float value = lua_interface->GetFloatValue(state, 3);
  2155. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2156. if (value != 0) {
  2157. int32 spell_id = 0;
  2158. if (luaspell && luaspell->spell && luaspell->caster) {
  2159. spell_id = luaspell->spell->GetSpellID();
  2160. ZoneServer* zone = luaspell->caster->GetZone();
  2161. Spawn* target = 0;
  2162. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2163. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2164. target = zone->GetSpawnByID(luaspell->targets[i]);
  2165. if (target && target->Alive()) {
  2166. if (target->IsPlayer()) {
  2167. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2168. Client* client = target->GetZone()->GetClientBySpawn(target);
  2169. if (client) {
  2170. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2171. if (packet)
  2172. client->QueuePacket(packet);
  2173. }
  2174. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2175. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2176. }
  2177. else if (target->IsNPC()) {
  2178. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2179. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2180. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2181. }
  2182. else
  2183. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2184. }
  2185. }
  2186. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2187. }
  2188. else if (spawn) {
  2189. if (spawn->IsPlayer()) {
  2190. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2191. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2192. if (client) {
  2193. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2194. if (packet)
  2195. client->QueuePacket(packet);
  2196. }
  2197. }
  2198. else if (spawn->IsNPC())
  2199. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2200. else
  2201. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2202. }
  2203. }
  2204. else
  2205. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2206. return 0;
  2207. }
  2208. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2209. if (!lua_interface)
  2210. return 0;
  2211. Spawn* spawn = lua_interface->GetSpawn(state);
  2212. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2213. if (spawn && spawn->IsPlayer()) {
  2214. int32 spell_id = 0;
  2215. if (luaspell && luaspell->spell) {
  2216. spell_id = luaspell->spell->GetSpellID();
  2217. ZoneServer* zone = luaspell->caster->GetZone();
  2218. Spawn* target = 0;
  2219. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2220. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2221. target = zone->GetSpawnByID(luaspell->targets[i]);
  2222. if (target) {
  2223. if (target->IsPlayer()) {
  2224. ((Player*)target)->RemoveSkillBonus(spell_id);
  2225. Client* client = target->GetZone()->GetClientBySpawn(target);
  2226. if (client) {
  2227. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2228. if (packet)
  2229. client->QueuePacket(packet);
  2230. }
  2231. }
  2232. else if (target->IsNPC())
  2233. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2234. else
  2235. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2236. }
  2237. }
  2238. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2239. }
  2240. else if (spawn) {
  2241. if (spawn->IsPlayer()) {
  2242. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2243. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2244. if (client) {
  2245. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2246. if (packet)
  2247. client->QueuePacket(packet);
  2248. }
  2249. }
  2250. else if (spawn->IsNPC())
  2251. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2252. else
  2253. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2254. }
  2255. }
  2256. return 0;
  2257. }
  2258. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2259. if (!lua_interface)
  2260. return 0;
  2261. Spawn* spawn = lua_interface->GetSpawn(state);
  2262. int8 type = lua_interface->GetInt32Value(state, 2);
  2263. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2264. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2265. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2266. ZoneServer* zone = luaspell->caster->GetZone();
  2267. Spawn* target = 0;
  2268. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2269. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2270. target = zone->GetSpawnByID(luaspell->targets[i]);
  2271. if (target && target->IsEntity()) {
  2272. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2273. ((Entity*)target)->AddMezSpell(luaspell);
  2274. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2275. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2276. if (target->IsNPC())
  2277. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2278. }
  2279. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2280. ((Entity*)target)->AddStifleSpell(luaspell);
  2281. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2282. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2283. if (target->IsNPC())
  2284. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2285. }
  2286. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2287. ((Entity*)target)->AddDazeSpell(luaspell);
  2288. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2289. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2290. if (target->IsNPC())
  2291. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2292. }
  2293. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2294. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2295. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2296. ((Entity*)target)->AddStunSpell(luaspell);
  2297. if (target->IsNPC())
  2298. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2299. }
  2300. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2301. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2302. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2303. ((Entity*)target)->AddRootSpell(luaspell);
  2304. if (target->IsNPC())
  2305. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2306. }
  2307. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2308. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2309. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2310. ((Entity*)target)->AddFearSpell(luaspell);
  2311. if (target->IsNPC())
  2312. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2313. }
  2314. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2315. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2316. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2317. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2318. }
  2319. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2320. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2321. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2322. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2323. }
  2324. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2325. ((Entity*)target)->AddSnareSpell(luaspell);
  2326. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2327. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2328. if (target->IsNPC())
  2329. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2330. }
  2331. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2332. ((Entity*)target)->AddFlightSpell(luaspell);
  2333. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2334. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2335. }
  2336. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2337. ((Entity*)target)->AddGlideSpell(luaspell);
  2338. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2339. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2340. }
  2341. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2342. ((Entity*)target)->AddSafefallSpell(luaspell);
  2343. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2344. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2345. }
  2346. else
  2347. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2348. }
  2349. else
  2350. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2351. }
  2352. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2353. }
  2354. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2355. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2356. ((Entity*)spawn)->AddMezSpell(luaspell);
  2357. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2358. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2359. }
  2360. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2361. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2362. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2363. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2364. }
  2365. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2366. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2367. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2368. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2369. }
  2370. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2371. ((Entity*)spawn)->AddStunSpell(luaspell);
  2372. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2373. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2374. }
  2375. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2376. ((Entity*)spawn)->AddRootSpell(luaspell);
  2377. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2378. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2379. }
  2380. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2381. ((Entity*)spawn)->AddFearSpell(luaspell);
  2382. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2383. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2384. }
  2385. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2386. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2387. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2388. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2389. }
  2390. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2391. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2392. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2393. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2394. }
  2395. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2396. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2397. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2398. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2399. }
  2400. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2401. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2402. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2403. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2404. }
  2405. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2406. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2407. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2408. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2409. }
  2410. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2411. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2412. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2413. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2414. }
  2415. else
  2416. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2417. }
  2418. else
  2419. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2420. return 0;
  2421. }
  2422. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2423. if (!lua_interface)
  2424. return 0;
  2425. Spawn* spawn = lua_interface->GetSpawn(state);
  2426. int8 type = lua_interface->GetInt8Value(state, 2);
  2427. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2428. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2429. if (spawn && spawn->IsEntity()) {
  2430. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2431. ZoneServer* zone = luaspell->caster->GetZone();
  2432. Spawn* target = 0;
  2433. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2434. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2435. target = zone->GetSpawnByID(luaspell->targets[i]);
  2436. if (target) {
  2437. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2438. ((Entity*)target)->RemoveMezSpell(luaspell);
  2439. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2440. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2441. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2442. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2443. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2444. ((Entity*)target)->RemoveStunSpell(luaspell);
  2445. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2446. ((Entity*)target)->RemoveRootSpell(luaspell);
  2447. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2448. ((Entity*)target)->RemoveFearSpell(luaspell);
  2449. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2450. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2451. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2452. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2453. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2454. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2455. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2456. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2457. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2458. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2459. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2460. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2461. else
  2462. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2463. }
  2464. }
  2465. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2466. }
  2467. else if (only_remove_spawn) {
  2468. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2469. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2470. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2471. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2472. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2473. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2474. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2475. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2476. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2477. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2478. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2479. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2480. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2481. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2482. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2483. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2484. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2485. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2486. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2487. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2488. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2489. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2490. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2491. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2492. else
  2493. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2494. }
  2495. }
  2496. return 0;
  2497. }
  2498. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2499. if (!lua_interface)
  2500. return 0;
  2501. Spawn* spawn = lua_interface->GetSpawn(state);
  2502. int8 type = lua_interface->GetInt8Value(state, 2);
  2503. bool hasEffect = false;
  2504. if (!spawn)
  2505. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2506. else if (!spawn->IsEntity())
  2507. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2508. else if (type < CONTROL_MAX_EFFECTS)
  2509. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2510. else
  2511. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2512. lua_interface->SetBooleanValue(state, hasEffect);
  2513. return 1;
  2514. }
  2515. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2516. if (!lua_interface)
  2517. return 0;
  2518. Spawn* spawn = lua_interface->GetSpawn(state);
  2519. float distance = 0.0f;
  2520. if (!spawn)
  2521. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2522. else if (!spawn->IsNPC())
  2523. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2524. else
  2525. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2526. lua_interface->SetFloatValue(state, distance);
  2527. return 1;
  2528. }
  2529. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2530. if (!lua_interface)
  2531. return 0;
  2532. Spawn* spawn = lua_interface->GetSpawn(state);
  2533. float distance = 0.0f;
  2534. if (!spawn)
  2535. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2536. else if (!spawn->IsNPC())
  2537. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2538. else
  2539. distance = ((NPC*)spawn)->GetAggroRadius();
  2540. lua_interface->SetFloatValue(state, distance);
  2541. return 1;
  2542. }
  2543. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2544. if (!lua_interface)
  2545. return 0;
  2546. Spawn* spawn = lua_interface->GetSpawn(state);
  2547. float distance = lua_interface->GetFloatValue(state, 2);
  2548. bool override = lua_interface->GetBooleanValue(state, 3);
  2549. bool result = false;
  2550. lua_interface->ResetFunctionStack(state);
  2551. if (!spawn)
  2552. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2553. else if (!spawn->IsNPC())
  2554. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2555. else
  2556. {
  2557. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2558. result = true;
  2559. }
  2560. lua_interface->SetBooleanValue(state, result);
  2561. return 1;
  2562. }
  2563. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2564. if (!lua_interface)
  2565. return 0;
  2566. Spawn* spawn = lua_interface->GetSpawn(state);
  2567. int16 value = lua_interface->GetInt16Value(state, 2);
  2568. if (spawn && spawn->IsEntity()) {
  2569. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2570. if (spawn->IsPlayer())
  2571. ((Player*)spawn)->SetCharSheetChanged(true);
  2572. }
  2573. return 0;
  2574. }
  2575. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2576. if (!lua_interface)
  2577. return 0;
  2578. Spawn* spawn = lua_interface->GetSpawn(state);
  2579. int16 value = lua_interface->GetInt16Value(state, 2);
  2580. if (spawn && spawn->IsEntity()) {
  2581. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2582. if (spawn->IsPlayer())
  2583. ((Player*)spawn)->SetCharSheetChanged(true);
  2584. }
  2585. return 0;
  2586. }
  2587. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2588. if (!lua_interface)
  2589. return 0;
  2590. Spawn* spawn = lua_interface->GetSpawn(state);
  2591. int16 value = lua_interface->GetInt16Value(state, 2);
  2592. if (spawn && spawn->IsEntity()) {
  2593. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2594. if (spawn->IsPlayer())
  2595. ((Player*)spawn)->SetCharSheetChanged(true);
  2596. }
  2597. return 0;
  2598. }
  2599. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2600. if (!lua_interface)
  2601. return 0;
  2602. Spawn* spawn = lua_interface->GetSpawn(state);
  2603. int16 value = lua_interface->GetInt16Value(state, 2);
  2604. if (spawn && spawn->IsEntity()) {
  2605. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2606. if (spawn->IsPlayer())
  2607. ((Player*)spawn)->SetCharSheetChanged(true);
  2608. }
  2609. return 0;
  2610. }
  2611. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2612. if (!lua_interface)
  2613. return 0;
  2614. Spawn* spawn = lua_interface->GetSpawn(state);
  2615. int16 value = lua_interface->GetInt16Value(state, 2);
  2616. if (spawn && spawn->IsEntity()) {
  2617. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2618. if (spawn->IsPlayer())
  2619. ((Player*)spawn)->SetCharSheetChanged(true);
  2620. }
  2621. return 0;
  2622. }
  2623. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2624. if (!lua_interface)
  2625. return 0;
  2626. Spawn* spawn = lua_interface->GetSpawn(state);
  2627. int8 value = lua_interface->GetInt8Value(state, 2);
  2628. if (spawn && spawn->IsEntity()) {
  2629. ((Entity*)spawn)->SetDeity(value);
  2630. if (spawn->IsPlayer())
  2631. ((Player*)spawn)->SetCharSheetChanged(true);
  2632. }
  2633. lua_interface->ResetFunctionStack(state);
  2634. return 0;
  2635. }
  2636. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2637. if (!lua_interface)
  2638. return 0;
  2639. Spawn* spawn = lua_interface->GetSpawn(state);
  2640. if (spawn && spawn->IsEntity()) {
  2641. int8 deity = ((Entity*)spawn)->GetDeity();
  2642. lua_interface->SetInt32Value(state, deity);
  2643. return 1;
  2644. }
  2645. return 0;
  2646. }
  2647. int EQ2Emu_lua_SetInt(lua_State* state) {
  2648. if (!lua_interface)
  2649. return 0;
  2650. Spawn* spawn = lua_interface->GetSpawn(state);
  2651. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2652. if (spawn && spawn->IsEntity()) {
  2653. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2654. if (spawn->IsPlayer())
  2655. ((Player*)spawn)->SetCharSheetChanged(true);
  2656. }
  2657. return 0;
  2658. }
  2659. int EQ2Emu_lua_SetWis(lua_State* state) {
  2660. if (!lua_interface)
  2661. return 0;
  2662. Spawn* spawn = lua_interface->GetSpawn(state);
  2663. float value = lua_interface->GetFloatValue(state, 2);
  2664. if (spawn && spawn->IsEntity()) {
  2665. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2666. if (spawn->IsPlayer())
  2667. ((Player*)spawn)->SetCharSheetChanged(true);
  2668. }
  2669. return 0;
  2670. }
  2671. int EQ2Emu_lua_SetSta(lua_State* state) {
  2672. if (!lua_interface)
  2673. return 0;
  2674. Spawn* spawn = lua_interface->GetSpawn(state);
  2675. float value = lua_interface->GetFloatValue(state, 2);
  2676. if (spawn && spawn->IsEntity()) {
  2677. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2678. if (spawn->IsPlayer())
  2679. ((Player*)spawn)->SetCharSheetChanged(true);
  2680. }
  2681. return 0;
  2682. }
  2683. int EQ2Emu_lua_SetStr(lua_State* state) {
  2684. if (!lua_interface)
  2685. return 0;
  2686. Spawn* spawn = lua_interface->GetSpawn(state);
  2687. float value = lua_interface->GetFloatValue(state, 2);
  2688. if (spawn && spawn->IsEntity()) {
  2689. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2690. if (spawn->IsPlayer())
  2691. ((Player*)spawn)->SetCharSheetChanged(true);
  2692. }
  2693. return 0;
  2694. }
  2695. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2696. if (!lua_interface)
  2697. return 0;
  2698. Spawn* spawn = lua_interface->GetSpawn(state);
  2699. float value = lua_interface->GetFloatValue(state, 2);
  2700. if (spawn && spawn->IsEntity()) {
  2701. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2702. if (spawn->IsPlayer())
  2703. ((Player*)spawn)->SetCharSheetChanged(true);
  2704. }
  2705. return 0;
  2706. }
  2707. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2708. if (!lua_interface)
  2709. return 0;
  2710. Spawn* spawn = lua_interface->GetSpawn(state);
  2711. if (spawn) {
  2712. lua_interface->SetInt32Value(state, spawn->GetHP());
  2713. return 1;
  2714. }
  2715. return 0;
  2716. }
  2717. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2718. if (!lua_interface)
  2719. return 0;
  2720. Spawn* spawn = lua_interface->GetSpawn(state);
  2721. if (spawn) {
  2722. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2723. return 1;
  2724. }
  2725. return 0;
  2726. }
  2727. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2728. if (!lua_interface)
  2729. return 0;
  2730. Spawn* spawn = lua_interface->GetSpawn(state);
  2731. if (spawn) {
  2732. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2733. return 1;
  2734. }
  2735. return 0;
  2736. }
  2737. int EQ2Emu_lua_GetName(lua_State* state) {
  2738. if (!lua_interface)
  2739. return 0;
  2740. Spawn* spawn = lua_interface->GetSpawn(state);
  2741. if (spawn) {
  2742. lua_interface->SetStringValue(state, spawn->GetName());
  2743. return 1;
  2744. }
  2745. return 0;
  2746. }
  2747. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2748. Spawn* spawn = lua_interface->GetSpawn(state);
  2749. if (spawn) {
  2750. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2751. return 1;
  2752. }
  2753. return 0;
  2754. }
  2755. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2756. if (!lua_interface)
  2757. return 0;
  2758. Spawn* spawn = lua_interface->GetSpawn(state);
  2759. if (spawn) {
  2760. lua_interface->SetInt32Value(state, spawn->GetPower());
  2761. return 1;
  2762. }
  2763. return 0;
  2764. }
  2765. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2766. if (!lua_interface)
  2767. return 0;
  2768. Spawn* spawn = lua_interface->GetSpawn(state);
  2769. if (spawn) {
  2770. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2771. return 1;
  2772. }
  2773. return 0;
  2774. }
  2775. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. if (spawn) {
  2780. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2781. return 1;
  2782. }
  2783. return 0;
  2784. }
  2785. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2786. if (!lua_interface)
  2787. return 0;
  2788. Spawn* spawn = lua_interface->GetSpawn(state);
  2789. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2790. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2791. if (spawn && spawn2) {
  2792. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2793. lua_interface->SetFloatValue(state, distance);
  2794. return 1;
  2795. }
  2796. return 0;
  2797. }
  2798. int EQ2Emu_lua_GetX(lua_State* state) {
  2799. if (!lua_interface)
  2800. return 0;
  2801. Spawn* spawn = lua_interface->GetSpawn(state);
  2802. if (spawn) {
  2803. lua_interface->SetFloatValue(state, spawn->GetX());
  2804. return 1;
  2805. }
  2806. return 0;
  2807. }
  2808. int EQ2Emu_lua_GetY(lua_State* state) {
  2809. if (!lua_interface)
  2810. return 0;
  2811. Spawn* spawn = lua_interface->GetSpawn(state);
  2812. if (spawn) {
  2813. lua_interface->SetFloatValue(state, spawn->GetY());
  2814. return 1;
  2815. }
  2816. return 0;
  2817. }
  2818. int EQ2Emu_lua_GetZ(lua_State* state) {
  2819. if (!lua_interface)
  2820. return 0;
  2821. Spawn* spawn = lua_interface->GetSpawn(state);
  2822. if (spawn) {
  2823. lua_interface->SetFloatValue(state, spawn->GetZ());
  2824. return 1;
  2825. }
  2826. return 0;
  2827. }
  2828. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2829. if (!lua_interface)
  2830. return 0;
  2831. Spawn* spawn = lua_interface->GetSpawn(state);
  2832. if (spawn) {
  2833. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2834. return 1;
  2835. }
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* spawn = lua_interface->GetSpawn(state);
  2842. if (spawn) {
  2843. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2844. return 1;
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Spawn* spawn = lua_interface->GetSpawn(state);
  2852. if (spawn) {
  2853. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2854. return 1;
  2855. }
  2856. return 0;
  2857. }
  2858. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2859. if (!lua_interface)
  2860. return 0;
  2861. Spawn* spawn = lua_interface->GetSpawn(state);
  2862. if (spawn && spawn->IsEntity()) {
  2863. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2864. return 1;
  2865. }
  2866. return 0;
  2867. }
  2868. int EQ2Emu_lua_GetInt(lua_State* state) {
  2869. if (!lua_interface)
  2870. return 0;
  2871. Spawn* spawn = lua_interface->GetSpawn(state);
  2872. if (spawn && spawn->IsEntity()) {
  2873. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2874. return 1;
  2875. }
  2876. return 0;
  2877. }
  2878. int EQ2Emu_lua_GetWis(lua_State* state) {
  2879. if (!lua_interface)
  2880. return 0;
  2881. Spawn* spawn = lua_interface->GetSpawn(state);
  2882. if (spawn && spawn->IsEntity()) {
  2883. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2884. return 1;
  2885. }
  2886. return 0;
  2887. }
  2888. int EQ2Emu_lua_GetSta(lua_State* state) {
  2889. if (!lua_interface)
  2890. return 0;
  2891. Spawn* spawn = lua_interface->GetSpawn(state);
  2892. if (spawn && spawn->IsEntity()) {
  2893. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2894. return 1;
  2895. }
  2896. return 0;
  2897. }
  2898. int EQ2Emu_lua_GetStr(lua_State* state) {
  2899. if (!lua_interface)
  2900. return 0;
  2901. Spawn* spawn = lua_interface->GetSpawn(state);
  2902. if (spawn && spawn->IsEntity()) {
  2903. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2904. return 1;
  2905. }
  2906. return 0;
  2907. }
  2908. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2909. if (!lua_interface)
  2910. return 0;
  2911. Spawn* spawn = lua_interface->GetSpawn(state);
  2912. if (spawn && spawn->IsEntity()) {
  2913. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2914. return 1;
  2915. }
  2916. return 0;
  2917. }
  2918. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2919. if (!lua_interface)
  2920. return 0;
  2921. Spawn* spawn = lua_interface->GetSpawn(state);
  2922. if (spawn && spawn->IsEntity()) {
  2923. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2924. return 1;
  2925. }
  2926. return 0;
  2927. }
  2928. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2929. if (!lua_interface)
  2930. return 0;
  2931. Spawn* spawn = lua_interface->GetSpawn(state);
  2932. if (spawn && spawn->IsEntity()) {
  2933. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2934. return 1;
  2935. }
  2936. return 0;
  2937. }
  2938. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2939. if (!lua_interface)
  2940. return 0;
  2941. Spawn* spawn = lua_interface->GetSpawn(state);
  2942. if (spawn && spawn->IsEntity()) {
  2943. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2944. return 1;
  2945. }
  2946. return 0;
  2947. }
  2948. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2949. if (!lua_interface)
  2950. return 0;
  2951. Spawn* spawn = lua_interface->GetSpawn(state);
  2952. if (spawn && spawn->IsEntity()) {
  2953. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2954. return 1;
  2955. }
  2956. return 0;
  2957. }
  2958. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2959. if (!lua_interface)
  2960. return 0;
  2961. Spawn* spawn = lua_interface->GetSpawn(state);
  2962. if (spawn && spawn->IsEntity()) {
  2963. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2964. return 1;
  2965. }
  2966. return 0;
  2967. }
  2968. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2969. if (!lua_interface)
  2970. return 0;
  2971. Spawn* player = lua_interface->GetSpawn(state);
  2972. if (!player || !player->IsPlayer()) {
  2973. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2974. return 0;
  2975. }
  2976. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2977. if (quest_id <= 0) {
  2978. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2979. return 0;
  2980. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2981. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2982. return 0;
  2983. }
  2984. int32 step = lua_interface->GetInt32Value(state, 3);
  2985. if (step > 0) {
  2986. Client* client = player->GetZone()->GetClientBySpawn(player);
  2987. if (client)
  2988. client->AddPendingQuestUpdate(quest_id, step);
  2989. } else {
  2990. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2991. }
  2992. return 0;
  2993. }
  2994. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2995. Spawn* player = lua_interface->GetSpawn(state);
  2996. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2997. int32 step = lua_interface->GetInt32Value(state, 3);
  2998. int32 progress = lua_interface->GetInt32Value(state, 4);
  2999. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3000. Client* client = player->GetZone()->GetClientBySpawn(player);
  3001. if (client)
  3002. client->AddPendingQuestUpdate(quest_id, step, progress);
  3003. }
  3004. return 0;
  3005. }
  3006. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3007. if (!lua_interface)
  3008. return 0;
  3009. Spawn* player = lua_interface->GetSpawn(state);
  3010. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3011. if (player && player->IsPlayer() && quest_id > 0) {
  3012. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3013. return 1;
  3014. }
  3015. return 0;
  3016. }
  3017. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3018. if (!lua_interface)
  3019. return 0;
  3020. Spawn* player = lua_interface->GetSpawn(state);
  3021. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3022. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3023. if (player && player->IsPlayer() && quest_id > 0) {
  3024. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3025. return 1;
  3026. }
  3027. return 0;
  3028. }
  3029. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3030. if (!lua_interface)
  3031. return 0;
  3032. Spawn* player = lua_interface->GetSpawn(state);
  3033. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3034. if (player && player->IsPlayer() && quest_id > 0) {
  3035. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3036. return 1;
  3037. }
  3038. return 0;
  3039. }
  3040. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3041. if (!lua_interface)
  3042. return 0;
  3043. Quest* quest = lua_interface->GetQuest(state);
  3044. string name = lua_interface->GetStringValue(state, 2);
  3045. string type = lua_interface->GetStringValue(state, 3);
  3046. string zone = lua_interface->GetStringValue(state, 4);
  3047. int16 level = lua_interface->GetInt16Value(state, 5);
  3048. string description = lua_interface->GetStringValue(state, 6);
  3049. bool load = true;
  3050. if (!quest) {
  3051. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3052. load = false;
  3053. }
  3054. if (load && name.length() == 0) {
  3055. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3056. load = false;
  3057. }
  3058. if (load && type.length() == 0) {
  3059. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3060. load = false;
  3061. }
  3062. if (load && zone.length() == 0) {
  3063. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3064. load = false;
  3065. }
  3066. if (load && description.length() == 0) {
  3067. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3068. load = false;
  3069. }
  3070. if (load && level == 0) {
  3071. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3072. load = false;
  3073. }
  3074. if (load)
  3075. quest->RegisterQuest(name, type, zone, level, description);
  3076. return 0;
  3077. }
  3078. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3079. if (!lua_interface)
  3080. return 0;
  3081. Quest* quest = lua_interface->GetQuest(state);
  3082. if (quest) {
  3083. int8 level = lua_interface->GetInt16Value(state, 2);
  3084. quest->SetPrereqLevel(level);
  3085. }
  3086. return 0;
  3087. }
  3088. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3089. if (!lua_interface)
  3090. return 0;
  3091. Quest* quest = lua_interface->GetQuest(state);
  3092. if (quest) {
  3093. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3094. quest->AddPrereqQuest(quest_id);
  3095. }
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3099. if (!lua_interface)
  3100. return 0;
  3101. Quest* quest = lua_interface->GetQuest(state);
  3102. if (quest) {
  3103. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3104. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3105. if (quantity == 0)
  3106. quantity = 1;
  3107. Item* master_item = master_item_list.GetItem(item_id);
  3108. if (master_item) {
  3109. Item* item = new Item(master_item);
  3110. item->details.count = quantity;
  3111. quest->AddPrereqItem(item);
  3112. }
  3113. }
  3114. return 0;
  3115. }
  3116. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3117. if (!lua_interface)
  3118. return 0;
  3119. Spawn* player = lua_interface->GetSpawn(state);
  3120. if(!player || !player->IsPlayer()) {
  3121. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3122. return 0;
  3123. }
  3124. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3125. if (quest_id > 0) {
  3126. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3127. return 1;
  3128. } else {
  3129. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3130. }
  3131. return 0;
  3132. }
  3133. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3134. if (!lua_interface)
  3135. return 0;
  3136. Quest* quest = lua_interface->GetQuest(state);
  3137. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3138. lua_interface->ResetFunctionStack(state);
  3139. if (quest && spawn_id > 0)
  3140. quest->SetQuestReturnNPC(spawn_id);
  3141. return 0;
  3142. }
  3143. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3144. if (!lua_interface)
  3145. return 0;
  3146. Spawn* spawn = lua_interface->GetSpawn(state);
  3147. int32 time = lua_interface->GetInt32Value(state, 2);
  3148. string function = lua_interface->GetStringValue(state, 3);
  3149. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3150. Spawn* player = lua_interface->GetSpawn(state, 5);
  3151. lua_interface->ResetFunctionStack(state);
  3152. if (!spawn) {
  3153. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3154. return 0;
  3155. }
  3156. if (time <= 0) {
  3157. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3158. return 0;
  3159. }
  3160. if (function.length() == 0) {
  3161. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3162. return 0;
  3163. }
  3164. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3165. if ( time < 10)
  3166. time = 10;
  3167. timer->timer = Timer::GetCurrentTime2() + time;
  3168. timer->function = function;
  3169. timer->spawn = spawn->GetID();
  3170. timer->player = player ? player->GetID() : 0;
  3171. if (max_count == 0)
  3172. max_count = 1;
  3173. timer->max_count = max_count;
  3174. timer->current_count = 0;
  3175. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3176. return 0;
  3177. }
  3178. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3179. if (!lua_interface)
  3180. return 0;
  3181. Spawn* spawn = lua_interface->GetSpawn(state);
  3182. string function = lua_interface->GetStringValue(state, 2);
  3183. lua_interface->ResetFunctionStack(state);
  3184. if (!spawn) {
  3185. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3186. return 0;
  3187. }
  3188. if(!spawn->GetZone()) {
  3189. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3190. return 0;
  3191. }
  3192. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3193. return 0;
  3194. }
  3195. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3196. if (!lua_interface)
  3197. return 0;
  3198. Spawn* player = lua_interface->GetSpawn(state);
  3199. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3200. lua_interface->ResetFunctionStack(state);
  3201. if (player && player->IsPlayer() && quest_id > 0) {
  3202. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3203. return 1;
  3204. }
  3205. return 0;
  3206. }
  3207. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3208. if (!lua_interface)
  3209. return 0;
  3210. Spawn* player = lua_interface->GetSpawn(state);
  3211. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3212. lua_interface->ResetFunctionStack(state);
  3213. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3214. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3215. if (quest)
  3216. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3217. return 1;
  3218. }
  3219. return 0;
  3220. }
  3221. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3222. if (!lua_interface)
  3223. return 0;
  3224. Spawn* player = lua_interface->GetSpawn(state);
  3225. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3226. lua_interface->ResetFunctionStack(state);
  3227. if (player && player->IsPlayer() && quest_id > 0) {
  3228. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3229. return 1;
  3230. }
  3231. return 0;
  3232. }
  3233. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3234. if (!lua_interface)
  3235. return 0;
  3236. Spawn* npc = lua_interface->GetSpawn(state);
  3237. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3238. lua_interface->ResetFunctionStack(state);
  3239. if (npc && !npc->IsPlayer() && quest_id > 0)
  3240. npc->AddProvidedQuest(quest_id);
  3241. return 0;
  3242. }
  3243. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3244. if (!lua_interface)
  3245. return 0;
  3246. Spawn* npc = lua_interface->GetSpawn(state);
  3247. Spawn* player = lua_interface->GetSpawn(state, 2);
  3248. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3249. bool forced = lua_interface->GetBooleanValue(state, 4);
  3250. lua_interface->ResetFunctionStack(state);
  3251. /* NPC is allowed to be null */
  3252. if (player && player->IsPlayer() && quest_id > 0) {
  3253. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3254. if (master_quest) {
  3255. Client* client = player->GetZone()->GetClientBySpawn(player);
  3256. if (!client) {
  3257. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3258. }
  3259. Quest* quest = new Quest(master_quest);
  3260. if (!quest) {
  3261. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3262. }
  3263. if (client && quest) {
  3264. if (npc)
  3265. quest->SetQuestGiver(npc->GetDatabaseID());
  3266. else
  3267. quest->SetQuestGiver(0);
  3268. client->AddPendingQuest(quest, forced);
  3269. }
  3270. }
  3271. else {
  3272. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3273. }
  3274. }
  3275. else {
  3276. 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);
  3277. }
  3278. return 0;
  3279. }
  3280. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3281. if (!lua_interface)
  3282. return 0;
  3283. Quest* quest = lua_interface->GetQuest(state);
  3284. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3285. lua_interface->ResetFunctionStack(state);
  3286. if (quest) {
  3287. quest->AddPrereqClass(class_id);
  3288. }
  3289. return 0;
  3290. }
  3291. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3292. if (!lua_interface)
  3293. return 0;
  3294. Quest* quest = lua_interface->GetQuest(state);
  3295. int8 race = lua_interface->GetInt8Value(state, 2);
  3296. lua_interface->ResetFunctionStack(state);
  3297. if (quest) {
  3298. quest->AddPrereqRace(race);
  3299. }
  3300. return 0;
  3301. }
  3302. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3303. if (!lua_interface)
  3304. return 0;
  3305. Quest* quest = lua_interface->GetQuest(state);
  3306. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3307. lua_interface->ResetFunctionStack(state);
  3308. if (quest) {
  3309. quest->AddPrereqModelType(model_type);
  3310. }
  3311. return 0;
  3312. }
  3313. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3314. if (!lua_interface)
  3315. return 0;
  3316. Quest* quest = lua_interface->GetQuest(state);
  3317. int8 level = lua_interface->GetInt8Value(state, 2);
  3318. lua_interface->ResetFunctionStack(state);
  3319. if (!quest) {
  3320. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3321. return 0;
  3322. }
  3323. quest->SetPrereqTSLevel(level);
  3324. return 0;
  3325. }
  3326. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3327. if (!lua_interface)
  3328. return 0;
  3329. Quest* quest = lua_interface->GetQuest(state);
  3330. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3331. lua_interface->ResetFunctionStack(state);
  3332. if (!quest) {
  3333. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3334. return 0;
  3335. }
  3336. quest->AddPrereqTradeskillClass(class_id);
  3337. return 0;
  3338. }
  3339. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3340. if (!lua_interface)
  3341. return 0;
  3342. Quest* quest = lua_interface->GetQuest(state);
  3343. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3344. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3345. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3346. lua_interface->ResetFunctionStack(state);
  3347. if (quest) {
  3348. quest->AddPrereqFaction(faction_id, min, max);
  3349. }
  3350. return 0;
  3351. }
  3352. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3353. if (!lua_interface)
  3354. return 0;
  3355. Quest* quest = lua_interface->GetQuest(state);
  3356. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3357. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3358. lua_interface->ResetFunctionStack(state);
  3359. if (quest) {
  3360. if (quantity == 0)
  3361. quantity = 1;
  3362. Item* master_item = master_item_list.GetItem(item_id);
  3363. if (master_item) {
  3364. Item* item = new Item(master_item);
  3365. item->details.count = quantity;
  3366. quest->AddSelectableRewardItem(item);
  3367. }
  3368. }
  3369. return 0;
  3370. }
  3371. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3372. if (!lua_interface)
  3373. return 0;
  3374. Quest* quest = lua_interface->GetQuest(state);
  3375. if (quest) {
  3376. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3377. vector<Item*>* items = quest->GetRewardItems();
  3378. if (items) {
  3379. vector<Item*>::iterator itr;
  3380. for (itr = items->begin(); itr != items->end(); itr++) {
  3381. if (*itr && (*itr)->details.item_id == item_id) {
  3382. lua_interface->SetBooleanValue(state, true);
  3383. return 1;
  3384. }
  3385. }
  3386. }
  3387. }
  3388. lua_interface->SetBooleanValue(state, false);
  3389. return 1;
  3390. }
  3391. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3392. if (!lua_interface)
  3393. return 0;
  3394. Quest* quest = lua_interface->GetQuest(state);
  3395. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3396. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3397. lua_interface->ResetFunctionStack(state);
  3398. if (quest) {
  3399. if (quantity == 0)
  3400. quantity = 1;
  3401. Item* master_item = master_item_list.GetItem(item_id);
  3402. if (master_item) {
  3403. Item* item = new Item(master_item);
  3404. item->details.count = quantity;
  3405. quest->AddRewardItem(item);
  3406. }
  3407. }
  3408. return 0;
  3409. }
  3410. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3411. if (!lua_interface)
  3412. return 0;
  3413. Quest* quest = lua_interface->GetQuest(state);
  3414. int32 copper = lua_interface->GetInt32Value(state, 2);
  3415. int32 silver = lua_interface->GetInt32Value(state, 3);
  3416. int32 gold = lua_interface->GetInt32Value(state, 4);
  3417. int32 plat = lua_interface->GetInt32Value(state, 5);
  3418. lua_interface->ResetFunctionStack(state);
  3419. if (quest) {
  3420. quest->AddRewardCoins(copper, silver, gold, plat);
  3421. }
  3422. return 0;
  3423. }
  3424. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3425. if (!lua_interface)
  3426. return 0;
  3427. Quest* quest = lua_interface->GetQuest(state);
  3428. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3429. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3430. lua_interface->ResetFunctionStack(state);
  3431. if (quest && faction_id > 0 && amount != 0)
  3432. quest->AddRewardFaction(faction_id, amount);
  3433. return 0;
  3434. }
  3435. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3436. if (!lua_interface)
  3437. return 0;
  3438. Quest* quest = lua_interface->GetQuest(state);
  3439. int32 status = lua_interface->GetInt32Value(state, 2);
  3440. lua_interface->ResetFunctionStack(state);
  3441. if (quest) {
  3442. quest->SetRewardStatus(status);
  3443. }
  3444. return 0;
  3445. }
  3446. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3447. if (!lua_interface)
  3448. return 0;
  3449. Quest* quest = lua_interface->GetQuest(state);
  3450. int32 status = lua_interface->GetInt32Value(state, 2);
  3451. lua_interface->ResetFunctionStack(state);
  3452. if (quest) {
  3453. quest->SetStatusTmpReward(status);
  3454. }
  3455. return 0;
  3456. }
  3457. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3458. if (!lua_interface)
  3459. return 0;
  3460. Quest* quest = lua_interface->GetQuest(state);
  3461. int64 coins = lua_interface->GetInt64Value(state, 2);
  3462. lua_interface->ResetFunctionStack(state);
  3463. if (quest) {
  3464. quest->SetCoinTmpReward(coins);
  3465. }
  3466. return 0;
  3467. }
  3468. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3469. if (!lua_interface)
  3470. return 0;
  3471. Quest* quest = lua_interface->GetQuest(state);
  3472. string comment = lua_interface->GetStringValue(state, 2);
  3473. lua_interface->ResetFunctionStack(state);
  3474. if (quest) {
  3475. quest->SetRewardComment(comment);
  3476. }
  3477. return 0;
  3478. }
  3479. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3480. if (!lua_interface)
  3481. return 0;
  3482. Quest* quest = lua_interface->GetQuest(state);
  3483. int32 exp = lua_interface->GetInt32Value(state, 2);
  3484. lua_interface->ResetFunctionStack(state);
  3485. if (quest) {
  3486. quest->SetRewardXP(exp);
  3487. }
  3488. return 0;
  3489. }
  3490. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3491. Quest* quest = lua_interface->GetQuest(state);
  3492. int32 step = lua_interface->GetInt32Value(state, 2);
  3493. string description = lua_interface->GetStringValue(state, 3);
  3494. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3495. float percentage = lua_interface->GetFloatValue(state, 5);
  3496. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3497. int16 icon = lua_interface->GetInt16Value(state, 7);
  3498. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3499. if (quest) {
  3500. const char* taskgroup = 0;
  3501. if (str_taskgroup.length() > 0)
  3502. taskgroup = str_taskgroup.c_str();
  3503. int32 id = 0;
  3504. vector<int32>* ids = 0;
  3505. int i = 0;
  3506. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3507. if (ids == 0)
  3508. ids = new vector<int32>;
  3509. ids->push_back(id);
  3510. i++;
  3511. }
  3512. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3513. if (quest_step && icon && quantity > 0)
  3514. quest_step->SetIcon(icon);
  3515. if (quest->GetPlayer()) {
  3516. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3517. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3518. }
  3519. }
  3520. lua_interface->ResetFunctionStack(state);
  3521. return 0;
  3522. }
  3523. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3524. {
  3525. if (!lua_interface)
  3526. return 0;
  3527. Quest* quest = lua_interface->GetQuest(state);
  3528. int32 step = lua_interface->GetInt32Value(state, 2);
  3529. string description = lua_interface->GetStringValue(state, 3);
  3530. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3531. float percentage = lua_interface->GetFloatValue(state, 5);
  3532. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3533. int16 icon = lua_interface->GetInt16Value(state, 7);
  3534. if (quest) {
  3535. const char* taskgroup = 0;
  3536. if (str_taskgroup.length() > 0)
  3537. taskgroup = str_taskgroup.c_str();
  3538. int32 id = 0;
  3539. vector<int32>* ids = 0;
  3540. int i = 0;
  3541. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3542. if (ids == 0)
  3543. ids = new vector<int32>;
  3544. ids->push_back(id);
  3545. i++;
  3546. }
  3547. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3548. if (quest_step && icon > 0 && quantity > 0)
  3549. quest_step->SetIcon(icon);
  3550. if (quest->GetPlayer()) {
  3551. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3552. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3553. }
  3554. safe_delete(ids);
  3555. }
  3556. lua_interface->ResetFunctionStack(state);
  3557. return 0;
  3558. }
  3559. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3560. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3561. }
  3562. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3563. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3564. }
  3565. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3566. if (!lua_interface)
  3567. return 0;
  3568. Quest* quest = lua_interface->GetQuest(state);
  3569. int32 step = lua_interface->GetInt32Value(state, 2);
  3570. string description = lua_interface->GetStringValue(state, 3);
  3571. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3572. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3573. int16 icon = lua_interface->GetInt16Value(state, 6);
  3574. if (quest) {
  3575. const char* taskgroup = 0;
  3576. if (str_taskgroup.length() > 0)
  3577. taskgroup = str_taskgroup.c_str();
  3578. int32 npc_id = 0;
  3579. vector<int32>* ids = 0;
  3580. int i = 0;
  3581. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3582. if (ids == 0)
  3583. ids = new vector<int32>;
  3584. ids->push_back(npc_id);
  3585. i++;
  3586. }
  3587. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3588. if (quest_step && icon > 0)
  3589. quest_step->SetIcon(icon);
  3590. if (quest->GetPlayer()) {
  3591. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3592. if(client)
  3593. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3594. }
  3595. safe_delete(ids);
  3596. }
  3597. lua_interface->ResetFunctionStack(state);
  3598. return 0;
  3599. }
  3600. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3601. if (!lua_interface)
  3602. return 0;
  3603. Quest* quest = lua_interface->GetQuest(state);
  3604. int32 step = lua_interface->GetInt32Value(state, 2);
  3605. string description = lua_interface->GetStringValue(state, 3);
  3606. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3607. float percentage = lua_interface->GetFloatValue(state, 5);
  3608. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3609. int16 icon = lua_interface->GetInt16Value(state, 7);
  3610. if (quest) {
  3611. const char* taskgroup = 0;
  3612. if (str_taskgroup.length() > 0)
  3613. taskgroup = str_taskgroup.c_str();
  3614. int32 item_id = 0;
  3615. vector<int32>* ids = 0;
  3616. int i = 0;
  3617. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3618. if (ids == 0)
  3619. ids = new vector<int32>;
  3620. ids->push_back(item_id);
  3621. i++;
  3622. }
  3623. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3624. if (quest_step && icon > 0 && quantity > 0)
  3625. quest_step->SetIcon(icon);
  3626. if (quest->GetPlayer()) {
  3627. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3628. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3629. }
  3630. safe_delete(ids);
  3631. }
  3632. lua_interface->ResetFunctionStack(state);
  3633. return 0;
  3634. }
  3635. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3636. if (!lua_interface)
  3637. return 0;
  3638. Quest* quest = lua_interface->GetQuest(state);
  3639. int32 step = lua_interface->GetInt32Value(state, 2);
  3640. string description = lua_interface->GetStringValue(state, 3);
  3641. float max_variation = lua_interface->GetFloatValue(state, 4);
  3642. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3643. int16 icon = lua_interface->GetInt16Value(state, 6);
  3644. if (quest) {
  3645. const char* taskgroup = 0;
  3646. if (str_taskgroup.length() > 0)
  3647. taskgroup = str_taskgroup.c_str();
  3648. vector<Location>* locations = 0;
  3649. int8 i = 7;
  3650. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3651. while (true) {
  3652. Location loc;
  3653. loc.x = lua_interface->GetFloatValue(state, i);
  3654. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3655. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3656. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3657. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3658. break;
  3659. if (locations == 0)
  3660. locations = new vector<Location>;
  3661. locations->push_back(loc);
  3662. i += 4;
  3663. }
  3664. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3665. if (quest_step && icon > 0)
  3666. quest_step->SetIcon(icon);
  3667. if (quest->GetPlayer()) {
  3668. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3669. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3670. }
  3671. }
  3672. lua_interface->ResetFunctionStack(state);
  3673. return 0;
  3674. }
  3675. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3676. if (!lua_interface)
  3677. return 0;
  3678. Quest* quest = lua_interface->GetQuest(state);
  3679. int32 step = lua_interface->GetInt32Value(state, 2);
  3680. string description = lua_interface->GetStringValue(state, 3);
  3681. float max_variation = lua_interface->GetFloatValue(state, 4);
  3682. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3683. int16 icon = lua_interface->GetInt16Value(state, 6);
  3684. if (quest) {
  3685. const char* taskgroup = 0;
  3686. if (str_taskgroup.length() > 0)
  3687. taskgroup = str_taskgroup.c_str();
  3688. vector<Location>* locations = 0;
  3689. int8 i = 7;
  3690. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3691. while (true) {
  3692. Location loc;
  3693. loc.x = lua_interface->GetFloatValue(state, i);
  3694. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3695. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3696. loc.zone_id = 0;
  3697. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3698. break;
  3699. if (locations == 0)
  3700. locations = new vector<Location>;
  3701. locations->push_back(loc);
  3702. i += 3;
  3703. }
  3704. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3705. if (quest_step && icon > 0)
  3706. quest_step->SetIcon(icon);
  3707. if (quest->GetPlayer()) {
  3708. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3709. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3710. }
  3711. }
  3712. lua_interface->ResetFunctionStack(state);
  3713. return 0;
  3714. }
  3715. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3716. if (!lua_interface)
  3717. return 0;
  3718. Quest* quest = lua_interface->GetQuest(state);
  3719. int32 step = lua_interface->GetInt32Value(state, 2);
  3720. string description = lua_interface->GetStringValue(state, 3);
  3721. float max_variation = lua_interface->GetFloatValue(state, 4);
  3722. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3723. int16 icon = lua_interface->GetInt16Value(state, 6);
  3724. if (quest) {
  3725. const char* taskgroup = 0;
  3726. if (str_taskgroup.length() > 0)
  3727. taskgroup = str_taskgroup.c_str();
  3728. vector<Location>* locations = 0;
  3729. int i = 7;
  3730. while (true) {
  3731. Location loc;
  3732. loc.x = lua_interface->GetFloatValue(state, i);
  3733. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3734. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3735. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3736. break;
  3737. if (locations == 0)
  3738. locations = new vector<Location>;
  3739. locations->push_back(loc);
  3740. i += 3;
  3741. }
  3742. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3743. if (quest_step && icon > 0)
  3744. quest_step->SetIcon(icon);
  3745. if (quest->GetPlayer()) {
  3746. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3747. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3748. }
  3749. }
  3750. lua_interface->ResetFunctionStack(state);
  3751. return 0;
  3752. }
  3753. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3754. Quest* quest = lua_interface->GetQuest(state);
  3755. int32 step = lua_interface->GetInt32Value(state, 2);
  3756. string description = lua_interface->GetStringValue(state, 3);
  3757. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3758. float percentage = lua_interface->GetFloatValue(state, 5);
  3759. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3760. int16 icon = lua_interface->GetInt16Value(state, 7);
  3761. if (quest) {
  3762. const char* taskgroup = 0;
  3763. if (str_taskgroup.length() > 0)
  3764. taskgroup = str_taskgroup.c_str();
  3765. int32 spell_id = 0;
  3766. vector<int32>* ids = 0;
  3767. int i = 0;
  3768. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3769. if (ids == 0)
  3770. ids = new vector<int32>;
  3771. ids->push_back(spell_id);
  3772. i++;
  3773. }
  3774. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3775. if (quest_step && icon > 0 && quantity > 0)
  3776. quest_step->SetIcon(icon);
  3777. if (quest->GetPlayer()) {
  3778. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3779. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3780. }
  3781. safe_delete(ids);
  3782. }
  3783. lua_interface->ResetFunctionStack(state);
  3784. return 0;
  3785. }
  3786. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3787. if (!lua_interface)
  3788. return 0;
  3789. Quest* quest = lua_interface->GetQuest(state);
  3790. int32 step = lua_interface->GetInt32Value(state, 2);
  3791. string description = lua_interface->GetStringValue(state, 3);
  3792. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3793. float percentage = lua_interface->GetFloatValue(state, 5);
  3794. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3795. int16 icon = lua_interface->GetInt16Value(state, 7);
  3796. if (quest) {
  3797. const char* taskgroup = 0;
  3798. if (str_taskgroup.length() > 0)
  3799. taskgroup = str_taskgroup.c_str();
  3800. int32 item_id = 0;
  3801. vector<int32>* ids = 0;
  3802. int i = 0;
  3803. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3804. if (ids == 0)
  3805. ids = new vector<int32>;
  3806. ids->push_back(item_id);
  3807. i++;
  3808. }
  3809. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3810. if (quest_step && icon > 0 && quantity > 0)
  3811. quest_step->SetIcon(icon);
  3812. if (quest->GetPlayer()) {
  3813. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3814. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3815. }
  3816. safe_delete(ids);
  3817. }
  3818. lua_interface->ResetFunctionStack(state);
  3819. return 0;
  3820. }
  3821. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3822. if (!lua_interface)
  3823. return 0;
  3824. Quest* quest = lua_interface->GetQuest(state);
  3825. int32 step = lua_interface->GetInt32Value(state, 2);
  3826. string description = lua_interface->GetStringValue(state, 3);
  3827. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3828. float percentage = lua_interface->GetFloatValue(state, 5);
  3829. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3830. int16 icon = lua_interface->GetInt16Value(state, 7);
  3831. if (quest) {
  3832. const char* taskgroup = 0;
  3833. if (str_taskgroup.length() > 0)
  3834. taskgroup = str_taskgroup.c_str();
  3835. int32 item_id = 0;
  3836. vector<int32>* ids = 0;
  3837. int i = 0;
  3838. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3839. if (ids == 0)
  3840. ids = new vector<int32>;
  3841. ids->push_back(item_id);
  3842. i++;
  3843. }
  3844. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3845. if (quest_step && icon > 0 && quantity > 0)
  3846. quest_step->SetIcon(icon);
  3847. if (quest->GetPlayer()) {
  3848. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3849. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3850. }
  3851. safe_delete(ids);
  3852. }
  3853. lua_interface->ResetFunctionStack(state);
  3854. return 0;
  3855. }
  3856. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3857. if (!lua_interface)
  3858. return 0;
  3859. Quest* quest = lua_interface->GetQuest(state);
  3860. string action = lua_interface->GetStringValue(state, 2);
  3861. lua_interface->ResetFunctionStack(state);
  3862. if (quest) {
  3863. if (action.length() > 0)
  3864. quest->SetCompleteAction(action);
  3865. }
  3866. return 0;
  3867. }
  3868. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3869. if (!lua_interface)
  3870. return 0;
  3871. Quest* quest = lua_interface->GetQuest(state);
  3872. int32 step = lua_interface->GetInt32Value(state, 2);
  3873. string action = lua_interface->GetStringValue(state, 3);
  3874. lua_interface->ResetFunctionStack(state);
  3875. if (quest) {
  3876. if (step > 0 && action.length() > 0)
  3877. quest->AddCompleteAction(step, action);
  3878. }
  3879. return 0;
  3880. }
  3881. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3882. if (!lua_interface)
  3883. return 0;
  3884. Quest* quest = lua_interface->GetQuest(state);
  3885. int32 step = lua_interface->GetInt32Value(state, 2);
  3886. string action = lua_interface->GetStringValue(state, 3);
  3887. lua_interface->ResetFunctionStack(state);
  3888. if (quest) {
  3889. if (step > 0 && action.length() > 0)
  3890. quest->AddProgressAction(step, action);
  3891. }
  3892. return 0;
  3893. }
  3894. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3895. if (!lua_interface)
  3896. return 0;
  3897. Quest* quest = lua_interface->GetQuest(state);
  3898. string description = lua_interface->GetStringValue(state, 2);
  3899. lua_interface->ResetFunctionStack(state);
  3900. if (quest && description.length() > 0)
  3901. quest->SetDescription(description);
  3902. return 0;
  3903. }
  3904. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3905. if (!lua_interface)
  3906. return 0;
  3907. Quest* quest = lua_interface->GetQuest(state);
  3908. string description = lua_interface->GetStringValue(state, 2);
  3909. lua_interface->ResetFunctionStack(state);
  3910. if (quest && description.length() > 0)
  3911. quest->SetCompletedDescription(description);
  3912. return 0;
  3913. }
  3914. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3915. if (!lua_interface)
  3916. return 0;
  3917. Quest* quest = lua_interface->GetQuest(state);
  3918. int32 step = lua_interface->GetInt32Value(state, 2);
  3919. string description = lua_interface->GetStringValue(state, 3);
  3920. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3921. lua_interface->ResetFunctionStack(state);
  3922. if (quest && step > 0 && description.length() > 0) {
  3923. quest->SetTaskGroupDescription(step, description, display_bullets);
  3924. /* if (quest->GetPlayer()) {
  3925. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3926. if (client)
  3927. client->SendQuestUpdateStep(quest, step, false);
  3928. }*/
  3929. }
  3930. return 0;
  3931. }
  3932. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3933. if (!lua_interface)
  3934. return 0;
  3935. Quest* quest = lua_interface->GetQuest(state);
  3936. int32 step = lua_interface->GetInt32Value(state, 2);
  3937. string description = lua_interface->GetStringValue(state, 3);
  3938. lua_interface->ResetFunctionStack(state);
  3939. if (quest && step > 0 && description.length() > 0) {
  3940. quest->SetStepDescription(step, description);
  3941. /*if (quest->GetPlayer()) {
  3942. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3943. if (client)
  3944. client->SendQuestUpdateStepImmediately(quest, step);
  3945. }*/
  3946. }
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3950. Quest* quest = lua_interface->GetQuest(state);
  3951. string zone = lua_interface->GetStringValue(state, 2);
  3952. lua_interface->ResetFunctionStack(state);
  3953. if (quest && zone.length() > 0)
  3954. quest->SetZone(zone);
  3955. return 0;
  3956. }
  3957. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3958. if (!lua_interface)
  3959. return 0;
  3960. Quest* quest = lua_interface->GetQuest(state);
  3961. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3962. lua_interface->ResetFunctionStack(state);
  3963. if (quest && spawn) {
  3964. if (spawn->IsPlayer()) {
  3965. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3966. if (client)
  3967. {
  3968. client->AddPendingQuestAcceptReward(quest);
  3969. client->AddPendingQuestReward(quest);
  3970. }
  3971. }
  3972. }
  3973. return 0;
  3974. }
  3975. int EQ2Emu_lua_Harvest(lua_State* state) {
  3976. if (!lua_interface)
  3977. return 0;
  3978. Spawn* player = lua_interface->GetSpawn(state);
  3979. Spawn* node = lua_interface->GetSpawn(state, 2);
  3980. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3981. Client* client = player->GetZone()->GetClientBySpawn(player);
  3982. if (client) {
  3983. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3984. ((GroundSpawn*)node)->ProcessHarvest(client);
  3985. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  3986. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  3987. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  3988. }
  3989. }
  3990. }
  3991. else if (player && player->IsPlayer()) {
  3992. Client* client = player->GetZone()->GetClientBySpawn(player);
  3993. if (client)
  3994. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3995. }
  3996. lua_interface->ResetFunctionStack(state);
  3997. return 0;
  3998. }
  3999. int EQ2Emu_lua_Bind(lua_State* state) {
  4000. if (!lua_interface)
  4001. return 0;
  4002. Spawn* spawn = lua_interface->GetSpawn(state);
  4003. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4004. float x = lua_interface->GetFloatValue(state, 3);
  4005. float y = lua_interface->GetFloatValue(state, 4);
  4006. float z = lua_interface->GetFloatValue(state, 5);
  4007. float h = lua_interface->GetFloatValue(state, 6);
  4008. lua_interface->ResetFunctionStack(state);
  4009. if (!spawn) {
  4010. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4011. return 0;
  4012. }
  4013. if (!spawn->IsPlayer()) {
  4014. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4015. return 0;
  4016. }
  4017. if (zone_id == 0) {
  4018. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4019. if (!client) {
  4020. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4021. return 0;
  4022. }
  4023. if (!client->Bind())
  4024. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4025. }
  4026. else {
  4027. Player* player = (Player*)spawn;
  4028. player->GetPlayerInfo()->SetBindZone(zone_id);
  4029. player->GetPlayerInfo()->SetBindX(x);
  4030. player->GetPlayerInfo()->SetBindY(y);
  4031. player->GetPlayerInfo()->SetBindZ(z);
  4032. player->GetPlayerInfo()->SetBindHeading(h);
  4033. }
  4034. return 0;
  4035. }
  4036. int EQ2Emu_lua_Gate(lua_State* state) {
  4037. if (!lua_interface)
  4038. return 0;
  4039. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4040. Spawn* spawn = lua_interface->GetSpawn(state);
  4041. lua_interface->ResetFunctionStack(state);
  4042. if (spawn) {
  4043. if (spawn->IsPlayer()) {
  4044. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4045. if (client) {
  4046. if (!client->Gate((spell != nullptr) ? true : false))
  4047. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4048. }
  4049. }
  4050. }
  4051. return 0;
  4052. }
  4053. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4054. if (!lua_interface)
  4055. return 0;
  4056. bool ret = false;
  4057. Spawn* spawn = lua_interface->GetSpawn(state);
  4058. lua_interface->ResetFunctionStack(state);
  4059. if (spawn) {
  4060. if (spawn->IsPlayer()) {
  4061. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4062. if (client)
  4063. ret = client->BindAllowed();
  4064. }
  4065. }
  4066. lua_interface->SetBooleanValue(state, ret);
  4067. return 1;
  4068. }
  4069. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4070. if (!lua_interface)
  4071. return 0;
  4072. bool ret = false;
  4073. Spawn* spawn = lua_interface->GetSpawn(state);
  4074. lua_interface->ResetFunctionStack(state);
  4075. if (spawn) {
  4076. if (spawn->IsPlayer()) {
  4077. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4078. if (client)
  4079. ret = client->GateAllowed();
  4080. }
  4081. }
  4082. lua_interface->SetBooleanValue(state, ret);
  4083. return 1;
  4084. }
  4085. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4086. Spawn* spawn = lua_interface->GetSpawn(state);
  4087. lua_interface->ResetFunctionStack(state);
  4088. if (spawn) {
  4089. lua_interface->SetBooleanValue(state, spawn->Alive());
  4090. return 1;
  4091. }
  4092. return 0;
  4093. }
  4094. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4095. if (!lua_interface)
  4096. return 0;
  4097. Spawn* spawn = lua_interface->GetSpawn(state);
  4098. lua_interface->ResetFunctionStack(state);
  4099. if (spawn && spawn->IsEntity()) {
  4100. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4101. return 1;
  4102. }
  4103. return 0;
  4104. }
  4105. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4106. Spawn* spawn = lua_interface->GetSpawn(state);
  4107. string message = lua_interface->GetStringValue(state, 2);
  4108. string color_str = lua_interface->GetStringValue(state, 3);
  4109. lua_interface->ResetFunctionStack(state);
  4110. int8 color = CHANNEL_NARRATIVE;
  4111. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4112. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4113. if (client) {
  4114. if (color_str.length() > 0) {
  4115. // leave for backwards compat, but all future should just use the number
  4116. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4117. color = CHANNEL_COLOR_RED;
  4118. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4119. color = CHANNEL_COLOR_YELLOW;
  4120. else
  4121. {
  4122. // use a number to specify the channel as per Commands/Commands.h defines
  4123. color = (int8)atoul(color_str.c_str());
  4124. }
  4125. }
  4126. client->SimpleMessage(color, message.c_str());
  4127. }
  4128. }
  4129. return 0;
  4130. }
  4131. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4132. Spawn* spawn = lua_interface->GetSpawn(state);
  4133. string message = lua_interface->GetStringValue(state, 2);
  4134. int8 red = lua_interface->GetInt8Value(state, 3);
  4135. int8 green = lua_interface->GetInt8Value(state, 4);
  4136. int8 blue = lua_interface->GetInt8Value(state, 5);
  4137. lua_interface->ResetFunctionStack(state);
  4138. if (!spawn) {
  4139. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4140. return 0;
  4141. }
  4142. int32 words = ::CountWordsInString(message.c_str());
  4143. if (words < 5)
  4144. words = 5;
  4145. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4146. if (client)
  4147. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4148. return 0;
  4149. }
  4150. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4151. Spawn* spawn = lua_interface->GetSpawn(state);
  4152. int8 param = lua_interface->GetInt8Value(state, 2);
  4153. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4154. int8 value = lua_interface->GetInt8Value(state, 4);
  4155. lua_interface->ResetFunctionStack(state);
  4156. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4157. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4158. if (client) {
  4159. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4160. switch (param) {
  4161. case 1: {
  4162. packet->setDataByName("parameter1", param_value);
  4163. break;
  4164. }
  4165. case 2: {
  4166. packet->setDataByName("parameter2", param_value);
  4167. break;
  4168. }
  4169. case 3: {
  4170. packet->setDataByName("parameter3", param_value);
  4171. break;
  4172. }
  4173. case 4: {
  4174. packet->setDataByName("parameter4", param_value);
  4175. break;
  4176. }
  4177. case 5: {
  4178. packet->setDataByName("parameter5", param_value);
  4179. break;
  4180. }
  4181. }
  4182. packet->setDataByName("value", value);
  4183. client->QueuePacket(packet->serialize());
  4184. safe_delete(packet);
  4185. }
  4186. }
  4187. return 0;
  4188. }
  4189. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4190. Spawn* spawn = lua_interface->GetSpawn(state);
  4191. lua_interface->ResetFunctionStack(state);
  4192. if (spawn && spawn->IsPlayer()) {
  4193. if (((Player*)spawn)->GetIsTracking())
  4194. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4195. else
  4196. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4197. }
  4198. return 0;
  4199. }
  4200. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4201. Spawn* player = lua_interface->GetSpawn(state);
  4202. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4203. string name = lua_interface->GetStringValue(state, 3);
  4204. float distance = lua_interface->GetFloatValue(state, 4);
  4205. string command = lua_interface->GetStringValue(state, 5);
  4206. string error_text = lua_interface->GetStringValue(state, 6);
  4207. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4208. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4209. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4210. lua_interface->ResetFunctionStack(state);
  4211. if (spawn) {
  4212. if (distance == 0)
  4213. distance = 10.0f;
  4214. if (command.length() == 0)
  4215. command = name;
  4216. if (command.length() < 1 && name.length() < 1)
  4217. {
  4218. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4219. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4220. spawn->RemovePrimaryCommands();
  4221. }
  4222. else
  4223. {
  4224. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4225. }
  4226. }
  4227. return 0;
  4228. }
  4229. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4230. if (!lua_interface)
  4231. return 0;
  4232. Spawn* player = lua_interface->GetSpawn(state);
  4233. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4234. int16 tier = lua_interface->GetInt16Value(state, 3);
  4235. lua_interface->ResetFunctionStack(state);
  4236. if (player && player->IsPlayer()) {
  4237. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4238. return 1;
  4239. }
  4240. return 0;
  4241. }
  4242. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4243. if (!lua_interface)
  4244. return 0;
  4245. Spawn* player = lua_interface->GetSpawn(state);
  4246. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4247. int16 tier = lua_interface->GetInt16Value(state, 3);
  4248. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4249. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4250. bool add_to_hotbar = true;
  4251. if (num_args > 4) {
  4252. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4253. }
  4254. lua_interface->ResetFunctionStack(state);
  4255. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4256. if (player && spell && player->IsPlayer()) {
  4257. Client* client = player->GetClient();
  4258. if (client) {
  4259. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4260. {
  4261. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4262. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4263. client->GetPlayer()->UnlockSpell(spell);
  4264. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4265. }
  4266. else
  4267. {
  4268. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4269. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4270. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4271. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4272. client->GetPlayer()->UnlockSpell(spell);
  4273. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4274. }
  4275. //if (client ) {
  4276. // ((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);
  4277. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4278. if (outapp)
  4279. client->QueuePacket(outapp);
  4280. }
  4281. }
  4282. return 0;
  4283. }
  4284. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4285. if (!lua_interface)
  4286. return 0;
  4287. Spawn* player = lua_interface->GetSpawn(state);
  4288. lua_interface->ResetFunctionStack(state);
  4289. if (player && player->IsPlayer()) {
  4290. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4291. return 1;
  4292. }
  4293. return 0;
  4294. }
  4295. int EQ2Emu_lua_Attack(lua_State* state) {
  4296. if (lua_interface) {
  4297. Spawn* npc = lua_interface->GetSpawn(state);
  4298. Spawn* player = lua_interface->GetSpawn(state, 2);
  4299. lua_interface->ResetFunctionStack(state);
  4300. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4301. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4302. }
  4303. return 0;
  4304. }
  4305. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4306. if (lua_interface) {
  4307. Spawn* target = lua_interface->GetSpawn(state);
  4308. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4309. lua_interface->ResetFunctionStack(state);
  4310. if (target && target->GetZone())
  4311. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4312. }
  4313. return 0;
  4314. }
  4315. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4316. Spawn* player;
  4317. if (lua_interface) {
  4318. player = lua_interface->GetSpawn(state);
  4319. lua_interface->ResetFunctionStack(state);
  4320. if (player && player->IsPlayer()) {
  4321. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4322. return 1;
  4323. }
  4324. }
  4325. return 0;
  4326. }
  4327. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4328. Spawn* player;
  4329. Client* client;
  4330. if (lua_interface) {
  4331. player = lua_interface->GetSpawn(state);
  4332. lua_interface->ResetFunctionStack(state);
  4333. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4334. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4335. client->HandInCollections();
  4336. }
  4337. return 0;
  4338. }
  4339. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4340. Spawn* widget;
  4341. if (lua_interface) {
  4342. widget = lua_interface->GetSpawn(state);
  4343. lua_interface->ResetFunctionStack(state);
  4344. if (widget && widget->IsWidget())
  4345. ((Widget*)widget)->HandleUse(nullptr, "");
  4346. }
  4347. return 0;
  4348. }
  4349. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4350. Spawn* spawn = 0;
  4351. int32 primary_list = 0;
  4352. int32 secondary_list = 0;
  4353. if (lua_interface) {
  4354. spawn = lua_interface->GetSpawn(state);
  4355. primary_list = lua_interface->GetInt32Value(state, 2);
  4356. secondary_list = lua_interface->GetInt32Value(state, 3);
  4357. lua_interface->ResetFunctionStack(state);
  4358. if (!spawn->IsNPC()) {
  4359. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4360. return 0;
  4361. }
  4362. NPC* npc = (NPC*)spawn;
  4363. npc->SetPrimarySpellList(primary_list);
  4364. npc->SetSecondarySpellList(secondary_list);
  4365. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4366. }
  4367. return 0;
  4368. }
  4369. int EQ2Emu_lua_GetPet(lua_State* state) {
  4370. if (!lua_interface)
  4371. return 0;
  4372. Spawn* spawn = lua_interface->GetSpawn(state);
  4373. lua_interface->ResetFunctionStack(state);
  4374. if (spawn) {
  4375. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4376. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4377. return 1;
  4378. }
  4379. }
  4380. return 0;
  4381. }
  4382. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4383. if (!lua_interface)
  4384. return 0;
  4385. Spawn* spawn = lua_interface->GetSpawn(state);
  4386. lua_interface->ResetFunctionStack(state);
  4387. if (spawn) {
  4388. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4389. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4390. return 1;
  4391. }
  4392. }
  4393. return 0;
  4394. }
  4395. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4396. if (!lua_interface)
  4397. return 0;
  4398. Spawn* spawn = lua_interface->GetSpawn(state);
  4399. lua_interface->ResetFunctionStack(state);
  4400. if (spawn) {
  4401. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4402. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4403. return 1;
  4404. }
  4405. }
  4406. return 0;
  4407. }
  4408. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4409. if (!lua_interface)
  4410. return 0;
  4411. Spawn* spawn = lua_interface->GetSpawn(state);
  4412. lua_interface->ResetFunctionStack(state);
  4413. if (spawn) {
  4414. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4415. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4416. return 1;
  4417. }
  4418. }
  4419. return 0;
  4420. }
  4421. int EQ2Emu_lua_Charm(lua_State* state) {
  4422. if (!lua_interface)
  4423. return 0;
  4424. Spawn* owner = lua_interface->GetSpawn(state);
  4425. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4426. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4427. lua_interface->ResetFunctionStack(state);
  4428. if (!luaspell) {
  4429. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4430. return 0;
  4431. }
  4432. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4433. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4434. pet->SetPet(true);
  4435. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4436. ((NPC*)pet)->SetOwner((Entity*)owner);
  4437. // If owner is player and player does not have a summoned pet set the players charsheet
  4438. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4439. Player* player = (Player*)owner;
  4440. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4441. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4442. player->GetInfoStruct()->set_pet_movement(2);
  4443. player->GetInfoStruct()->set_pet_behavior(3);
  4444. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4445. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4446. // Make sure the values get sent to the client
  4447. player->SetCharSheetChanged(true);
  4448. }
  4449. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4450. pet->SetSpawnScript("");
  4451. // Set faction to the same as the owner
  4452. pet->SetFactionID(owner->GetFactionID());
  4453. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4454. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4455. // Clear hate list
  4456. ((NPC*)pet)->Brain()->ClearHate();
  4457. // Set the brain to a pet brain
  4458. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4459. }
  4460. return 0;
  4461. }
  4462. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4463. if (!lua_interface)
  4464. return 0;
  4465. Spawn* spawn = lua_interface->GetSpawn(state);
  4466. lua_interface->ResetFunctionStack(state);
  4467. if (!spawn) {
  4468. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4469. return 0;
  4470. }
  4471. vector<Spawn*> groupMembers;
  4472. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4473. groupMembers = *spawn->GetSpawnGroup();
  4474. }
  4475. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4476. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4477. deque<GroupMemberInfo*>::iterator itr;
  4478. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4479. if (group)
  4480. {
  4481. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4482. deque<GroupMemberInfo*>* members = group->GetMembers();
  4483. GroupMemberInfo* info = 0;
  4484. for (itr = members->begin(); itr != members->end(); itr++) {
  4485. info = *itr;
  4486. if (info->client)
  4487. groupMembers.push_back(info->client->GetPlayer());
  4488. }
  4489. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4490. }
  4491. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4492. }
  4493. else
  4494. return 0;
  4495. lua_createtable(state, groupMembers.size(), 0);
  4496. int newTable = lua_gettop(state);
  4497. for (int32 i = 0; i < groupMembers.size(); i++) {
  4498. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4499. lua_rawseti(state, newTable, i + 1);
  4500. }
  4501. return 1;
  4502. }
  4503. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4504. if (!lua_interface)
  4505. return 0;
  4506. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4507. lua_interface->SetOptionWindowValue(state, option_window);
  4508. return 1;
  4509. }
  4510. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4511. if (!lua_interface)
  4512. return 0;
  4513. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4514. if (option_window) {
  4515. OptionWindowOption option_window_option;
  4516. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4517. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4518. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4519. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4520. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4521. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4522. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4523. option_window->push_back(option_window_option);
  4524. }
  4525. return 0;
  4526. }
  4527. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4528. if (!lua_interface)
  4529. return 0;
  4530. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4531. Spawn* player = lua_interface->GetSpawn(state, 2);
  4532. string window_title = lua_interface->GetStringValue(state, 3);
  4533. string cancel_command = lua_interface->GetStringValue(state, 4);
  4534. Client* client = player->GetZone()->GetClientBySpawn(player);
  4535. if (option_window && window_title.length() > 0 && client) {
  4536. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4537. if (!packet)
  4538. return 0;
  4539. packet->setDataByName("title_text", window_title.c_str());
  4540. if (cancel_command.length() > 0)
  4541. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4542. packet->setArrayLengthByName("num_selections", option_window->size());
  4543. vector<OptionWindowOption>::iterator itr;
  4544. int8 i = 0;
  4545. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4546. OptionWindowOption opt = *itr;
  4547. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4548. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4549. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4550. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4551. if (opt.optionCommand.length() > 0)
  4552. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4553. if (opt.optionConfirmTitle.length() > 0)
  4554. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4555. i++;
  4556. }
  4557. client->QueuePacket(packet->serialize());
  4558. safe_delete(option_window);
  4559. safe_delete(packet);
  4560. }
  4561. return 0;
  4562. }
  4563. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4564. if (!lua_interface)
  4565. return 0;
  4566. Spawn* spawn = lua_interface->GetSpawn(state);
  4567. if (spawn) {
  4568. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4569. return 1;
  4570. }
  4571. else
  4572. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4573. return 0;
  4574. }
  4575. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4576. if (!lua_interface)
  4577. return 0;
  4578. Spawn* spawn = lua_interface->GetSpawn(state);
  4579. if (spawn) {
  4580. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4581. return 1;
  4582. }
  4583. else
  4584. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4585. return 0;
  4586. }
  4587. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4588. if (!lua_interface)
  4589. return 0;
  4590. Spawn* spawn = lua_interface->GetSpawn(state);
  4591. if (spawn) {
  4592. int8 class_id = spawn->GetTradeskillClass();
  4593. // Need to add 42 for the offset in the array
  4594. class_id += 44;
  4595. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4596. return 1;
  4597. }
  4598. else
  4599. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4600. return 0;
  4601. }
  4602. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4603. if (!lua_interface)
  4604. return 0;
  4605. Spawn* spawn = lua_interface->GetSpawn(state);
  4606. int16 level = lua_interface->GetInt8Value(state, 2);
  4607. if (spawn) {
  4608. if (spawn->IsPlayer())
  4609. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4610. else
  4611. spawn->SetTSLevel(level);
  4612. }
  4613. else
  4614. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4615. return 0;
  4616. }
  4617. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4618. if (!lua_interface)
  4619. return 0;
  4620. Spawn* spawn = lua_interface->GetSpawn(state);
  4621. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4622. if (spawn) {
  4623. spawn->SetAttackable(attackable);
  4624. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4625. }
  4626. return 0;
  4627. }
  4628. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4629. // Check to see if we have a valid lua_interface
  4630. if (!lua_interface)
  4631. return 0;
  4632. // Get the spawn that is getting the pet
  4633. Spawn* spawn = lua_interface->GetSpawn(state);
  4634. // Get the DB ID of the pet
  4635. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4636. // The max level the pet can gain
  4637. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4638. // Get the spell that this command was called from
  4639. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4640. // Check to make sure the spawn pointer is valid
  4641. if (!spawn) {
  4642. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4643. return 0;
  4644. }
  4645. // Check to make sure the spawn is an entity
  4646. if (!spawn->IsEntity()) {
  4647. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4648. return 0;
  4649. }
  4650. // Check to make sure the spawn doesn't already have a pet of this type
  4651. if (((Entity*)spawn)->GetPet()) {
  4652. if (spawn->IsPlayer()) {
  4653. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4654. if (client)
  4655. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4656. }
  4657. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4658. return 0;
  4659. }
  4660. // Check to see if the DB ID for the pet is set
  4661. if (pet_id == 0) {
  4662. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4663. return 0;
  4664. }
  4665. // Check to see if the pointer to the spell is valid
  4666. if (!luaspell) {
  4667. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4668. return 0;
  4669. }
  4670. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4671. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4672. if (!pet) {
  4673. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4674. return 0;
  4675. }
  4676. // Check to make sure the pet is an npc
  4677. if (!pet->IsNPC()) {
  4678. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4679. return 0;
  4680. }
  4681. // Spawn the pet at the same location as the owner
  4682. pet->SetX(spawn->GetX());
  4683. pet->SetY(spawn->GetY());
  4684. pet->SetZ(spawn->GetZ());
  4685. pet->SetLocation(spawn->GetLocation());
  4686. pet->SetHeading(spawn->GetHeading());
  4687. spawn->GetZone()->AddSpawn(pet);
  4688. /*
  4689. const char* spawn_script = world.GetSpawnScript(pet_id);
  4690. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4691. spawn->SetSpawnScript(string(spawn_script));
  4692. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4693. }*/
  4694. // Get a random pet name
  4695. string random_pet_name;
  4696. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4697. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4698. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4699. // If player set various values for the char sheet (pet window)
  4700. if (spawn->IsPlayer()) {
  4701. Player* player = (Player*)spawn;
  4702. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4703. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4704. player->GetInfoStruct()->set_pet_movement(2);
  4705. player->GetInfoStruct()->set_pet_behavior(3);
  4706. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4707. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4708. // Make sure the values get sent to the client
  4709. player->SetCharSheetChanged(true);
  4710. }
  4711. // Set the pets name
  4712. pet->SetName(random_pet_name.c_str());
  4713. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4714. if (max_level > 0)
  4715. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4716. else
  4717. pet->SetLevel(spawn->GetLevel());
  4718. // Set the max level this pet can reach
  4719. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4720. // Set the faction of the pet to the same faction as the owner
  4721. pet->SetFactionID(spawn->GetFactionID());
  4722. // Set the spawn as a pet
  4723. pet->SetPet(true);
  4724. // Give a pointer of the owner to the pet
  4725. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4726. // Give a pointer of the pet to the owner
  4727. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4728. // Set the pet type
  4729. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4730. // Set the spell id used to create this pet
  4731. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4732. // Set the spell tier used to create this pet
  4733. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4734. // Set the pets spawn type to 6
  4735. pet->SetSpawnType(6);
  4736. // Set the pets brain
  4737. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4738. // Check to see if the pet has a subtitle
  4739. if (strlen(pet->GetSubTitle()) > 0) {
  4740. // Add the players name to the front of the sub title
  4741. string pet_subtitle;
  4742. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4743. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4744. // Set the pets subtitle to the new one
  4745. pet->SetSubTitle(pet_subtitle.c_str());
  4746. }
  4747. // Add the "Pet Options" entity command to the pet
  4748. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4749. // Set the pet as the return value for this function
  4750. lua_interface->SetSpawnValue(state, pet);
  4751. return 1;
  4752. }
  4753. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4754. if (!lua_interface)
  4755. return 0;
  4756. Spawn* spawn = lua_interface->GetSpawn(state);
  4757. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4758. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4759. if (!spawn) {
  4760. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4761. return 0;
  4762. }
  4763. if (!spawn->IsEntity()) {
  4764. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4765. return 0;
  4766. }
  4767. if (((Entity*)spawn)->GetDeityPet()) {
  4768. if (spawn->IsPlayer()) {
  4769. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4770. if (client)
  4771. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4772. }
  4773. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4774. return 0;
  4775. }
  4776. if (pet_id == 0) {
  4777. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4778. return 0;
  4779. }
  4780. if (!luaspell) {
  4781. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4782. return 0;
  4783. }
  4784. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4785. if (!pet) {
  4786. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4787. return 0;
  4788. }
  4789. if (!pet->IsNPC()) {
  4790. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4791. return 0;
  4792. }
  4793. pet->SetX(spawn->GetX());
  4794. pet->SetY(spawn->GetY());
  4795. pet->SetZ(spawn->GetZ());
  4796. pet->SetLocation(spawn->GetLocation());
  4797. pet->SetHeading(spawn->GetHeading());
  4798. spawn->GetZone()->AddSpawn(pet);
  4799. string random_pet_name;
  4800. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4801. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4802. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4803. pet->SetName(random_pet_name.c_str());
  4804. pet->SetLevel(spawn->GetLevel());
  4805. pet->SetFactionID(spawn->GetFactionID());
  4806. pet->SetPet(true);
  4807. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4808. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4809. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4810. pet->SetSpawnType(6);
  4811. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4812. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4813. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4814. if (strlen(pet->GetSubTitle()) > 0) {
  4815. string pet_subtitle;
  4816. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4817. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4818. pet->SetSubTitle(pet_subtitle.c_str());
  4819. }
  4820. // deity and cosmetic pets are not attackable
  4821. pet->SetAttackable(false);
  4822. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4823. lua_interface->SetSpawnValue(state, pet);
  4824. return 1;
  4825. }
  4826. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4827. if (!lua_interface)
  4828. return 0;
  4829. Spawn* spawn = lua_interface->GetSpawn(state);
  4830. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4831. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4832. if (!spawn) {
  4833. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4834. return 0;
  4835. }
  4836. if (!spawn->IsEntity()) {
  4837. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4838. return 0;
  4839. }
  4840. if (((Entity*)spawn)->GetCosmeticPet()) {
  4841. if (spawn->IsPlayer()) {
  4842. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4843. if (client)
  4844. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4845. }
  4846. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4847. return 0;
  4848. }
  4849. if (pet_id == 0) {
  4850. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4851. return 0;
  4852. }
  4853. if (!luaspell) {
  4854. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4855. return 0;
  4856. }
  4857. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4858. if (!pet) {
  4859. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4860. return 0;
  4861. }
  4862. if (!pet->IsNPC()) {
  4863. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4864. return 0;
  4865. }
  4866. pet->SetX(spawn->GetX());
  4867. pet->SetY(spawn->GetY());
  4868. pet->SetZ(spawn->GetZ());
  4869. pet->SetLocation(spawn->GetLocation());
  4870. pet->SetHeading(spawn->GetHeading());
  4871. spawn->GetZone()->AddSpawn(pet);
  4872. string random_pet_name;
  4873. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4874. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4875. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4876. pet->SetName(random_pet_name.c_str());
  4877. pet->SetLevel(spawn->GetLevel());
  4878. pet->SetFactionID(spawn->GetFactionID());
  4879. pet->SetPet(true);
  4880. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4881. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4882. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4883. pet->SetSpawnType(6);
  4884. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4885. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4886. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4887. if (strlen(pet->GetSubTitle()) > 0) {
  4888. string pet_subtitle;
  4889. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4890. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4891. pet->SetSubTitle(pet_subtitle.c_str());
  4892. }
  4893. pet->SetAttackable(false);
  4894. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4895. lua_interface->SetSpawnValue(state, pet);
  4896. return 1;
  4897. }
  4898. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4899. if (!lua_interface)
  4900. return 0;
  4901. Spawn* spawn = lua_interface->GetSpawn(state);
  4902. if (!spawn) {
  4903. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4904. return 0;
  4905. }
  4906. if (!spawn->IsPet()) {
  4907. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4908. return 0;
  4909. }
  4910. if (!((NPC*)spawn)->IsDismissing())
  4911. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4912. return 0;
  4913. }
  4914. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4915. if (!lua_interface)
  4916. return 0;
  4917. Quest* quest = lua_interface->GetQuest(state);
  4918. if (!quest) {
  4919. 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));
  4920. return 0;
  4921. }
  4922. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4923. if (feather_color > 0)
  4924. quest->SetFeatherColor(feather_color);
  4925. return 0;
  4926. }
  4927. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4928. if (!lua_interface)
  4929. return 0;
  4930. Spawn* spawn = lua_interface->GetSpawn(state);
  4931. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4932. if (!spawn) {
  4933. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4934. return 0;
  4935. }
  4936. if (!spawn2) {
  4937. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4938. return 0;
  4939. }
  4940. spawn->RemoveSpawnAccess(spawn2);
  4941. return 0;
  4942. }
  4943. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4944. if (!lua_interface)
  4945. return 0;
  4946. ZoneServer* zone = lua_interface->GetZone(state);
  4947. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4948. if (!zone) {
  4949. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4950. return 0;
  4951. }
  4952. if (location_id == 0) {
  4953. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4954. return 0;
  4955. }
  4956. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4957. if (!location) {
  4958. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4959. return 0;
  4960. }
  4961. Spawn* spawn = 0;
  4962. if (location->entities[0]) {
  4963. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4964. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4965. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4966. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4967. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4968. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4969. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4970. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4971. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4972. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4973. if(spawn && spawn->IsOmittedByDBFlag())
  4974. {
  4975. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  4976. safe_delete(spawn);
  4977. spawn = 0;
  4978. return 0;
  4979. }
  4980. if (spawn) {
  4981. const char* script = 0;
  4982. for (int x = 0; x < 3; x++) {
  4983. switch (x) {
  4984. case 0:
  4985. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4986. break;
  4987. case 1:
  4988. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4989. break;
  4990. case 2:
  4991. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4992. break;
  4993. }
  4994. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4995. spawn->SetSpawnScript(string(script));
  4996. break;
  4997. }
  4998. }
  4999. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5000. lua_interface->SetSpawnValue(state, spawn);
  5001. return 1;
  5002. }
  5003. else {
  5004. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5005. safe_delete(spawn);
  5006. }
  5007. }
  5008. return 0;
  5009. }
  5010. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5011. if (!lua_interface)
  5012. return 0;
  5013. Spawn* caster = lua_interface->GetSpawn(state);
  5014. Spawn* target = lua_interface->GetSpawn(state, 2);
  5015. int32 id = lua_interface->GetInt32Value(state, 3);
  5016. string command = lua_interface->GetStringValue(state, 4);
  5017. if (!caster) {
  5018. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5019. return 0;
  5020. }
  5021. if (!target) {
  5022. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. if (!caster->IsPlayer()) {
  5026. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5027. return 0;
  5028. }
  5029. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5030. if (!entity_command) {
  5031. 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());
  5032. return 0;
  5033. }
  5034. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5035. if (!client) {
  5036. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5037. return 0;
  5038. }
  5039. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5040. return 0;
  5041. }
  5042. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5043. if (!lua_interface)
  5044. return 0;
  5045. Spawn* spawn = lua_interface->GetSpawn(state);
  5046. if (!spawn) {
  5047. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5048. return 0;
  5049. }
  5050. if (!spawn->IsNPC()) {
  5051. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5052. return 0;
  5053. }
  5054. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5055. return 0;
  5056. }
  5057. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5058. if (!lua_interface)
  5059. return 0;
  5060. Spawn* spawn = lua_interface->GetSpawn(state);
  5061. int16 tick = lua_interface->GetInt16Value(state, 2);
  5062. if (!spawn) {
  5063. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5064. return 0;
  5065. }
  5066. if (!spawn->IsNPC()) {
  5067. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5068. return 0;
  5069. }
  5070. if (tick < 20) {
  5071. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5072. return 0;
  5073. }
  5074. ((NPC*)spawn)->Brain()->SetTick(tick);
  5075. return 0;
  5076. }
  5077. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5078. if (!lua_interface)
  5079. return 0;
  5080. Spawn* spawn = lua_interface->GetSpawn(state);
  5081. Spawn* target = lua_interface->GetSpawn(state, 2);
  5082. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5083. if (!spawn) {
  5084. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5085. return 0;
  5086. }
  5087. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5088. spawn->SetFollowTarget(target, follow_distance);
  5089. return 0;
  5090. }
  5091. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5092. if (!lua_interface)
  5093. return 0;
  5094. Spawn* spawn = lua_interface->GetSpawn(state);
  5095. if (!spawn) {
  5096. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5097. return 0;
  5098. }
  5099. Spawn* target = spawn->GetFollowTarget();
  5100. if (target) {
  5101. lua_interface->SetSpawnValue(state, target);
  5102. return 1;
  5103. }
  5104. return 0;
  5105. }
  5106. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5107. if (!lua_interface)
  5108. return 0;
  5109. Spawn* spawn = lua_interface->GetSpawn(state);
  5110. if (!spawn) {
  5111. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5112. return 0;
  5113. }
  5114. if (spawn->following)
  5115. spawn->following = false;
  5116. else
  5117. spawn->following = true;
  5118. return 0;
  5119. }
  5120. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5121. if (!lua_interface)
  5122. return 0;
  5123. Spawn* spawn = lua_interface->GetSpawn(state);
  5124. if (!spawn) {
  5125. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5126. return 0;
  5127. }
  5128. lua_interface->SetBooleanValue(state, spawn->following);
  5129. return 1;
  5130. }
  5131. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5132. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5133. // I will attempt to explain how this function works for future refrence
  5134. // Fist lets make sure lua_interface is valid, if not return out
  5135. if (!lua_interface)
  5136. return 0;
  5137. // Next we grab the first 2 params same as we usually would
  5138. Spawn* spawn = lua_interface->GetSpawn(state);
  5139. string var = lua_interface->GetStringValue(state, 2);
  5140. // 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
  5141. // 1 = Spawn
  5142. // 2 = Zone
  5143. // 3 = Item
  5144. // 4 = Quest
  5145. // 5 = String
  5146. // 6 = nil (null)
  5147. int8 dataType = 0;
  5148. // Define pointers for each potential type
  5149. Spawn* spawnVal = 0;
  5150. ZoneServer* zone = 0;
  5151. Item* item = 0;
  5152. Quest* quest = 0;
  5153. string val;
  5154. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5155. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5156. // options window are also light user data be we do not handle those.
  5157. // We check with lua_islightuserdata(lua_State*, index)
  5158. if (lua_islightuserdata(state, 3)) {
  5159. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5160. // and convert it to LUAUserData*
  5161. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5162. // Check to make sure the data we got is valid, if not give an error
  5163. if (!data || !data->IsCorrectlyInitialized()) {
  5164. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5165. }
  5166. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5167. else if (data->IsSpawn()) {
  5168. spawnVal = data->spawn;
  5169. dataType = 1;
  5170. }
  5171. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5172. else if (data->IsZone()) {
  5173. zone = data->zone;
  5174. dataType = 2;
  5175. }
  5176. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5177. else if (data->IsItem()) {
  5178. item = data->item;
  5179. dataType = 3;
  5180. }
  5181. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5182. else if (data->IsQuest()) {
  5183. quest = data->quest;
  5184. dataType = 4;
  5185. }
  5186. }
  5187. // Wasn't light user data, check if it is nil(null)
  5188. else if (lua_isnil(state, 3)) {
  5189. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5190. dataType = 6;
  5191. }
  5192. // Wasn't light user data or nil (null), must be a string
  5193. else {
  5194. // Set the string and dataType variable
  5195. val = lua_interface->GetStringValue(state, 3);
  5196. dataType = 5;
  5197. }
  5198. // We now have all the params, lets check to make sure they are valid
  5199. if (!spawn) {
  5200. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5201. return 0;
  5202. }
  5203. if (var.length() == 0) {
  5204. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5205. return 0;
  5206. }
  5207. if (dataType == 0) {
  5208. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5209. return 0;
  5210. }
  5211. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5212. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5213. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5214. switch (dataType) {
  5215. case 1:
  5216. // 1 = Spawn
  5217. spawn->AddTempVariable(var, spawnVal);
  5218. break;
  5219. case 2:
  5220. // 2 = Zone
  5221. spawn->AddTempVariable(var, zone);
  5222. break;
  5223. case 3:
  5224. // 3 = Item
  5225. spawn->AddTempVariable(var, item);
  5226. break;
  5227. case 4:
  5228. // 4 = Quest
  5229. spawn->AddTempVariable(var, quest);
  5230. break;
  5231. case 5:
  5232. // 5 = String
  5233. spawn->AddTempVariable(var, val);
  5234. break;
  5235. case 6:
  5236. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5237. spawn->DeleteTempVariable(var);
  5238. break;
  5239. }
  5240. // And we are done so return out
  5241. return 0;
  5242. }
  5243. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5244. if (!lua_interface)
  5245. return 0;
  5246. Spawn* spawn = lua_interface->GetSpawn(state);
  5247. string var = lua_interface->GetStringValue(state, 2);
  5248. if (!spawn) {
  5249. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5250. return 0;
  5251. }
  5252. if (var.length() == 0) {
  5253. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5254. return 0;
  5255. }
  5256. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5257. int8 type = spawn->GetTempVariableType(var);
  5258. Spawn* spawn2 = 0;
  5259. ZoneServer* zone = 0;
  5260. Item* item = 0;
  5261. Quest* quest = 0;
  5262. // Set the lua function return value based on the type of data the variable contains
  5263. switch (type) {
  5264. case 1:
  5265. spawn2 = spawn->GetTempVariableSpawn(var);
  5266. if (!spawn2)
  5267. return 0;
  5268. lua_interface->SetSpawnValue(state, spawn2);
  5269. break;
  5270. case 2:
  5271. zone = spawn->GetTempVariableZone(var);
  5272. if (!zone)
  5273. return 0;
  5274. lua_interface->SetZoneValue(state, zone);
  5275. break;
  5276. case 3:
  5277. item = spawn->GetTempVariableItem(var);
  5278. if (!item)
  5279. return 0;
  5280. lua_interface->SetItemValue(state, item);
  5281. break;
  5282. case 4:
  5283. quest = spawn->GetTempVariableQuest(var);
  5284. if (!quest)
  5285. return 0;
  5286. lua_interface->SetQuestValue(state, quest);
  5287. break;
  5288. case 5:
  5289. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5290. break;
  5291. default:
  5292. // Not a valid type then the variable was not set so return out
  5293. return 0;
  5294. }
  5295. // Return value was set so return out
  5296. return 1;
  5297. }
  5298. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5299. {
  5300. if (!lua_interface)
  5301. return 0;
  5302. Quest* quest = lua_interface->GetQuest(state);
  5303. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5304. string description = lua_interface->GetStringValue(state, 3);
  5305. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5306. if (!quest) {
  5307. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5308. lua_interface->SetBooleanValue(state, false);
  5309. return 1;
  5310. }
  5311. if (!spawn) {
  5312. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5313. lua_interface->SetBooleanValue(state, false);
  5314. return 1;
  5315. }
  5316. if (!spawn->IsPlayer()) {
  5317. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5318. lua_interface->SetBooleanValue(state, false);
  5319. return 1;
  5320. }
  5321. if (item_id == 0) {
  5322. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5323. lua_interface->SetBooleanValue(state, false);
  5324. return 1;
  5325. }
  5326. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5327. if (!client) {
  5328. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5329. lua_interface->SetBooleanValue(state, false);
  5330. return 1;
  5331. }
  5332. Item* item = master_item_list.GetItem(item_id);
  5333. if (!item) {
  5334. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5335. lua_interface->SetBooleanValue(state, false);
  5336. return 1;
  5337. }
  5338. Item* firstItem = new Item(item);
  5339. quest->AddTmpRewardItem(firstItem);
  5340. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5341. bool itemsAddedSuccessfully = true;
  5342. if(num_args > 4)
  5343. {
  5344. for(int8 n=5;n<num_args+1;n++)
  5345. {
  5346. int32 new_item = lua_interface->GetInt32Value(state, n);
  5347. Item* tmpItem = master_item_list.GetItem(new_item);
  5348. if(tmpItem)
  5349. {
  5350. Item* newTmpItem = new Item(tmpItem);
  5351. quest->AddTmpRewardItem(newTmpItem);
  5352. }
  5353. else
  5354. itemsAddedSuccessfully = false;
  5355. }
  5356. }
  5357. client->AddPendingQuestAcceptReward(quest);
  5358. client->DisplayQuestComplete(quest, true, description);
  5359. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5360. return 1;
  5361. }
  5362. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5363. if (!lua_interface)
  5364. return 0;
  5365. Quest* quest = lua_interface->GetQuest(state);
  5366. if (!quest) {
  5367. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5368. return 0;
  5369. }
  5370. quest->SetRepeatable(true);
  5371. return 0;
  5372. }
  5373. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5374. if (!lua_interface)
  5375. return 0;
  5376. Spawn* spawn = lua_interface->GetSpawn(state);
  5377. if (!spawn) {
  5378. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5379. return 0;
  5380. }
  5381. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5382. string ret = classes.GetClassNameCase(base_class);
  5383. if (ret.length() > 0) {
  5384. lua_interface->SetStringValue(state, ret.c_str());
  5385. return 1;
  5386. }
  5387. return 0;
  5388. }
  5389. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5390. if (!lua_interface)
  5391. return 0;
  5392. Spawn* player = lua_interface->GetSpawn(state);
  5393. if (player && player->IsPlayer()) {
  5394. Client* client = player->GetClient();
  5395. if (client)
  5396. client->SendWaypoints();
  5397. }
  5398. return 0;
  5399. }
  5400. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5401. if (!lua_interface)
  5402. return 0;
  5403. Spawn* player = lua_interface->GetSpawn(state);
  5404. string name = lua_interface->GetStringValue(state, 2);
  5405. int32 type = lua_interface->GetInt32Value(state, 3);
  5406. if (type == 0)
  5407. type = 2;
  5408. if (name.length() > 0) {
  5409. if (player && player->IsPlayer()) {
  5410. Client* client = player->GetClient();
  5411. if (client)
  5412. client->AddWaypoint(name, type);
  5413. }
  5414. }
  5415. return 0;
  5416. }
  5417. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5418. if (!lua_interface)
  5419. return 0;
  5420. Spawn* player = lua_interface->GetSpawn(state);
  5421. string name = lua_interface->GetStringValue(state, 2);
  5422. if (name.length() > 0) {
  5423. if (player && player->IsPlayer()) {
  5424. Client* client = player->GetClient();
  5425. if (client)
  5426. client->RemoveWaypoint(name);
  5427. }
  5428. }
  5429. return 0;
  5430. }
  5431. int EQ2Emu_lua_AddWard(lua_State* state) {
  5432. if (!lua_interface)
  5433. return 0;
  5434. int32 damage = lua_interface->GetInt32Value(state);
  5435. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5436. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5437. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5438. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5439. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5440. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5441. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5442. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5443. bool ward_was_added = false;
  5444. ZoneServer* zone = spell->caster->GetZone();
  5445. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5446. for (int32 i = 0; i < spell->targets.size(); i++) {
  5447. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5448. if (!target)
  5449. continue;
  5450. if (target->IsEntity()) {
  5451. // If the ward is already active remove it
  5452. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5453. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5454. // Create new ward info
  5455. WardInfo* ward = new WardInfo;
  5456. ward->Spell = spell;
  5457. ward->BaseDamage = damage;
  5458. ward->DamageLeft = damage;
  5459. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5460. ward->keepWard = keepWard;
  5461. ward->WardType = wardType;
  5462. if (damageAbsorptionPercent > 100)
  5463. damageAbsorptionPercent = 100;
  5464. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5465. if (damageAbsorptionMaxHealthPercent > 100)
  5466. damageAbsorptionMaxHealthPercent = 100;
  5467. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5468. ward->RedirectDamagePercent = redirectDamagePercent;
  5469. ward->LastRedirectDamage = 0;
  5470. ward->LastAbsorbedDamage = 0;
  5471. ward->HitCount = 0;
  5472. spell->num_triggers = maxHitCount;
  5473. spell->had_triggers = true;
  5474. spell->cancel_after_all_triggers = false;
  5475. ward->MaxHitCount = maxHitCount;
  5476. if (wardType == WARD_TYPE_MAGICAL)
  5477. ward->DamageType = damageTypes;
  5478. // Add the ward to the entity
  5479. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5480. ward_was_added = true;
  5481. }
  5482. }
  5483. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5484. if (ward_was_added && spell->caster->IsPlayer()) {
  5485. spell->had_dmg_remaining = true;
  5486. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5487. }
  5488. return 0;
  5489. }
  5490. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5491. if (!lua_interface)
  5492. return 0;
  5493. int32 amount = lua_interface->GetInt32Value(state);
  5494. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5495. WardInfo* ward = 0;
  5496. ZoneServer* zone = spell->caster->GetZone();
  5497. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5498. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5499. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5500. ward = target->GetWard(spell->spell->GetSpellID());
  5501. if (target && ward) {
  5502. ward->DamageLeft += amount;
  5503. if (ward->DamageLeft > ward->BaseDamage)
  5504. ward->DamageLeft = ward->BaseDamage;
  5505. for (int32 i = 0; i < spell->targets.size(); i++) {
  5506. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5507. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5508. }
  5509. }
  5510. }
  5511. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5512. if (ward && spell->caster->IsPlayer())
  5513. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5514. return 0;
  5515. }
  5516. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5517. if (!lua_interface)
  5518. return 0;
  5519. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5520. if (!spell) {
  5521. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5522. return 0;
  5523. }
  5524. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5525. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5526. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5527. if (ward) {
  5528. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5529. return 1;
  5530. }
  5531. }
  5532. return 0;
  5533. }
  5534. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5535. if (!lua_interface)
  5536. return 0;
  5537. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5538. if (!spell) {
  5539. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5540. return 0;
  5541. }
  5542. string type = lua_interface->GetStringValue(state, 2);
  5543. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5544. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5545. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5546. if (ward) {
  5547. if (boost::iequals(type, "damageleft"))
  5548. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5549. else if (boost::iequals(type, "basedamage"))
  5550. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5551. else if (boost::iequals(type, "keepward"))
  5552. lua_interface->SetBooleanValue(state, ward->keepWard);
  5553. else if (boost::iequals(type, "wardtype"))
  5554. lua_interface->SetInt32Value(state, ward->WardType);
  5555. else if (boost::iequals(type, "dmgabsorptionpct"))
  5556. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5557. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5558. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5559. else if (boost::iequals(type, "redirectdamagepercent"))
  5560. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5561. else if (boost::iequals(type, "lastredirectdamage"))
  5562. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5563. else if (boost::iequals(type, "lastabsorbeddamage"))
  5564. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5565. else if (boost::iequals(type, "hitcount"))
  5566. lua_interface->SetInt32Value(state, ward->HitCount);
  5567. else if (boost::iequals(type, "maxhitcount"))
  5568. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5569. else
  5570. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5571. return 1;
  5572. }
  5573. }
  5574. return 0;
  5575. }
  5576. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5577. if (!lua_interface)
  5578. return 0;
  5579. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5580. ZoneServer* zone = spell->caster->GetZone();
  5581. Spawn* target = 0;
  5582. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5583. for (int32 i = 0; i < spell->targets.size(); i++) {
  5584. target = zone->GetSpawnByID(spell->targets.at(i));
  5585. if (target && target->IsEntity()) {
  5586. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5587. }
  5588. }
  5589. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5590. return 0;
  5591. }
  5592. int EQ2Emu_lua_Interrupt(lua_State* state)
  5593. {
  5594. if (!lua_interface)
  5595. return 0;
  5596. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5597. Spawn* target = lua_interface->GetSpawn(state, 2);
  5598. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5599. if (!caster)
  5600. {
  5601. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5602. return 0;
  5603. }
  5604. if (!target)
  5605. {
  5606. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5607. return 0;
  5608. }
  5609. if (!spell) {
  5610. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5611. return 0;
  5612. }
  5613. if (!target->IsEntity() && !spell)
  5614. {
  5615. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5616. return 0;
  5617. }
  5618. if (!target && spell) {
  5619. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5620. for (int8 i = 0; i < spell->targets.size(); i++) {
  5621. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5622. if (!target || !target->IsEntity())
  5623. continue;
  5624. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5625. }
  5626. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5627. }
  5628. else
  5629. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5630. return 0;
  5631. }
  5632. int EQ2Emu_lua_Stealth(lua_State* state) {
  5633. if (!lua_interface)
  5634. return 0;
  5635. int8 type = lua_interface->GetInt8Value(state);
  5636. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5637. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5638. if (!spell) {
  5639. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5640. return 0;
  5641. }
  5642. ZoneServer* zone = spell->caster->GetZone();
  5643. if (spawn) {
  5644. if (spawn->IsEntity()) {
  5645. if (type == 1) {
  5646. ((Entity*)spawn)->AddStealthSpell(spell);
  5647. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5648. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5649. }
  5650. else if (type == 2) {
  5651. ((Entity*)spawn)->AddInvisSpell(spell);
  5652. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5653. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5654. }
  5655. return 0;
  5656. }
  5657. else {
  5658. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5659. return 0;
  5660. }
  5661. }
  5662. else {
  5663. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5664. for (int32 i = 0; i < spell->targets.size(); i++) {
  5665. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5666. if (!spawn || !spawn->IsEntity())
  5667. continue;
  5668. if (type == 1) {
  5669. ((Entity*)spawn)->AddStealthSpell(spell);
  5670. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5671. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5672. }
  5673. else if (type == 2) {
  5674. ((Entity*)spawn)->AddInvisSpell(spell);
  5675. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5676. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5677. }
  5678. else {
  5679. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5680. break;
  5681. }
  5682. }
  5683. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5684. }
  5685. return 0;
  5686. }
  5687. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5688. if (!lua_interface)
  5689. return 0;
  5690. Spawn* spawn = lua_interface->GetSpawn(state);
  5691. if (!spawn) {
  5692. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5693. return 0;
  5694. }
  5695. if (spawn->IsEntity()) {
  5696. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5697. return 1;
  5698. }
  5699. else
  5700. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5701. return 0;
  5702. }
  5703. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5704. if (!lua_interface)
  5705. return 0;
  5706. Spawn* spawn = lua_interface->GetSpawn(state);
  5707. if (!spawn) {
  5708. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5709. return 0;
  5710. }
  5711. if (spawn->IsEntity()) {
  5712. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5713. return 1;
  5714. }
  5715. else
  5716. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5717. return 0;
  5718. }
  5719. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5720. if (!lua_interface)
  5721. return 0;
  5722. Spawn* player = lua_interface->GetSpawn(state);
  5723. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5724. lua_interface->ResetFunctionStack(state);
  5725. if (!player->IsPlayer()) {
  5726. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5727. return 0;
  5728. }
  5729. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5730. return 1;
  5731. }
  5732. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5733. if (!lua_interface)
  5734. return 0;
  5735. Spawn* player = lua_interface->GetSpawn(state);
  5736. int8 slot = lua_interface->GetInt8Value(state, 2);
  5737. lua_interface->ResetFunctionStack(state);
  5738. if (!player) {
  5739. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5740. return 0;
  5741. }
  5742. if (!player->IsPlayer()) {
  5743. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5744. return 0;
  5745. }
  5746. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5747. if (!item) {
  5748. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5749. return 0;
  5750. }
  5751. lua_interface->SetItemValue(state, item);
  5752. return 1;
  5753. }
  5754. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5755. if (!lua_interface)
  5756. return 0;
  5757. Spawn* player = lua_interface->GetSpawn(state);
  5758. int32 id = lua_interface->GetInt32Value(state, 2);
  5759. lua_interface->ResetFunctionStack(state);
  5760. if (!player) {
  5761. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5762. return 0;
  5763. }
  5764. if (!player->IsPlayer()) {
  5765. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5766. return 0;
  5767. }
  5768. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5769. if (!item) {
  5770. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5771. return 0;
  5772. }
  5773. lua_interface->SetItemValue(state, item);
  5774. return 1;
  5775. }
  5776. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5777. if (!lua_interface)
  5778. return 0;
  5779. Spawn* spawn = lua_interface->GetSpawn(state);
  5780. int8 slot = lua_interface->GetInt8Value(state, 2);
  5781. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5782. lua_interface->ResetFunctionStack(state);
  5783. if (!spawn) {
  5784. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5785. return 0;
  5786. }
  5787. if (!spawn->IsEntity()) {
  5788. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5789. return 0;
  5790. }
  5791. Item* item = master_item_list.GetItem(item_id);
  5792. if (!item) {
  5793. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5794. return 0;
  5795. }
  5796. Item* copy = new Item(item);
  5797. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5798. if(result)
  5799. {
  5800. ((Entity*)spawn)->SetEquipment(copy, slot);
  5801. spawn->vis_changed = true;
  5802. if(spawn->IsPlayer())
  5803. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5804. }
  5805. else
  5806. {
  5807. safe_delete(copy);
  5808. }
  5809. lua_interface->SetBooleanValue(state, result);
  5810. return 1;
  5811. }
  5812. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5813. if (!lua_interface)
  5814. return 0;
  5815. Spawn* spawn = lua_interface->GetSpawn(state);
  5816. int8 slot = lua_interface->GetInt8Value(state, 2);
  5817. Item* item = lua_interface->GetItem(state, 3);
  5818. lua_interface->ResetFunctionStack(state);
  5819. if (!spawn) {
  5820. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5821. return 0;
  5822. }
  5823. if (!spawn->IsEntity()) {
  5824. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5825. return 0;
  5826. }
  5827. if (!item) {
  5828. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5829. return 0;
  5830. }
  5831. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5832. if(result)
  5833. {
  5834. ((Entity*)spawn)->SetEquipment(item, slot);
  5835. spawn->vis_changed = true;
  5836. if(spawn->IsPlayer())
  5837. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5838. }
  5839. lua_interface->SetBooleanValue(state, result);
  5840. return 1;
  5841. }
  5842. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5843. if (!lua_interface)
  5844. return 0;
  5845. Spawn* spawn = lua_interface->GetSpawn(state);
  5846. int8 slot = lua_interface->GetInt8Value(state, 2);
  5847. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5848. lua_interface->ResetFunctionStack(state);
  5849. if (!spawn) {
  5850. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5851. return 0;
  5852. }
  5853. if (!spawn->IsEntity()) {
  5854. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5855. return 0;
  5856. }
  5857. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5858. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5859. spawn->vis_changed = true;
  5860. if(spawn->IsPlayer())
  5861. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5862. lua_interface->SetBooleanValue(state, true);
  5863. return 1;
  5864. }
  5865. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5866. if (!lua_interface)
  5867. return 0;
  5868. Spawn* spawn = lua_interface->GetSpawn(state);
  5869. int8 slot = lua_interface->GetInt8Value(state, 2);
  5870. int16 type = lua_interface->GetInt16Value(state, 3);
  5871. int8 r = lua_interface->GetInt8Value(state, 4);
  5872. int8 g = lua_interface->GetInt8Value(state, 5);
  5873. int8 b = lua_interface->GetInt8Value(state, 6);
  5874. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5875. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5876. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5877. lua_interface->ResetFunctionStack(state);
  5878. if (!spawn) {
  5879. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5880. return 0;
  5881. }
  5882. if (!spawn->IsEntity()) {
  5883. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5887. spawn->vis_changed = true;
  5888. lua_interface->SetBooleanValue(state, true);
  5889. return 1;
  5890. }
  5891. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5892. if (!lua_interface)
  5893. return 0;
  5894. Spawn* player = lua_interface->GetSpawn(state);
  5895. int32 id = lua_interface->GetInt32Value(state, 2);
  5896. int8 count = lua_interface->GetInt8Value(state, 3);
  5897. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5898. lua_interface->ResetFunctionStack(state);
  5899. if (!player) {
  5900. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5901. return 0;
  5902. }
  5903. if (!player->IsPlayer()) {
  5904. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5905. return 0;
  5906. }
  5907. if (!count)
  5908. count = 1;
  5909. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5910. if (!item) {
  5911. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5912. return 0;
  5913. }
  5914. lua_interface->SetItemValue(state, item);
  5915. return 1;
  5916. }
  5917. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5918. if (!lua_interface)
  5919. return 0;
  5920. Spawn* spawn = lua_interface->GetSpawn(state);
  5921. int32 anim = lua_interface->GetInt32Value(state, 2);
  5922. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5923. int8 type = lua_interface->GetInt8Value(state, 4);
  5924. if (!spawn) {
  5925. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5926. return 0;
  5927. }
  5928. if (spawn2) {
  5929. if (spawn2->IsPlayer()) {
  5930. if (type != 1 && type != 2)
  5931. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5932. else
  5933. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5934. return 0;
  5935. }
  5936. else {
  5937. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5938. return 0;
  5939. }
  5940. }
  5941. else
  5942. spawn->GetZone()->PlayAnimation(spawn, anim);
  5943. return 0;
  5944. }
  5945. int EQ2Emu_lua_IsPet(lua_State* state) {
  5946. if (!lua_interface)
  5947. return 0;
  5948. Spawn* spawn = lua_interface->GetSpawn(state);
  5949. if (!spawn) {
  5950. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5951. return 0;
  5952. }
  5953. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5954. return 1;
  5955. }
  5956. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5957. if (!lua_interface)
  5958. return 0;
  5959. Spawn* spawn = lua_interface->GetSpawn(state);
  5960. if (!spawn) {
  5961. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5962. return 0;
  5963. }
  5964. if (!spawn->IsNPC()) {
  5965. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5966. return 0;
  5967. }
  5968. if (((NPC*)spawn)->GetOwner()) {
  5969. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5970. return 1;
  5971. }
  5972. return 0;
  5973. }
  5974. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5975. if (!lua_interface)
  5976. return 0;
  5977. Spawn* spawn = lua_interface->GetSpawn(state);
  5978. Spawn* target = lua_interface->GetSpawn(state, 2);
  5979. if (!spawn) {
  5980. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5981. return 0;
  5982. }
  5983. if (!spawn) {
  5984. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5985. return 0;
  5986. }
  5987. spawn->SetTarget(target);
  5988. return 0;
  5989. }
  5990. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5991. if (!lua_interface)
  5992. return 0;
  5993. Spawn* spawn = lua_interface->GetSpawn(state);
  5994. bool val = lua_interface->GetBooleanValue(state, 2);
  5995. if (!spawn) {
  5996. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5997. return 0;
  5998. }
  5999. if (!spawn->IsEntity()) {
  6000. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6001. return 0;
  6002. }
  6003. ((Entity*)spawn)->InCombat(val);
  6004. if (val) {
  6005. spawn->ClearRunningLocations();
  6006. spawn->CalculateRunningLocation(true);
  6007. }
  6008. return 0;
  6009. }
  6010. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6011. if (!lua_interface)
  6012. return 0;
  6013. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6014. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6015. if (!spawn1) {
  6016. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6017. return 0;
  6018. }
  6019. if (!spawn2) {
  6020. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6021. return 0;
  6022. }
  6023. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6024. return 1;
  6025. }
  6026. int EQ2Emu_lua_Runback(lua_State* state) {
  6027. if (!lua_interface)
  6028. return 0;
  6029. Spawn* spawn = lua_interface->GetSpawn(state);
  6030. if (!spawn) {
  6031. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6032. return 0;
  6033. }
  6034. if (!spawn->IsNPC()) {
  6035. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6036. return 0;
  6037. }
  6038. ((NPC*)spawn)->Runback();
  6039. return 0;
  6040. }
  6041. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6042. if (!lua_interface)
  6043. return 0;
  6044. Spawn* spawn = lua_interface->GetSpawn(state);
  6045. if (!spawn) {
  6046. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6047. return 0;
  6048. }
  6049. if (!spawn->IsNPC()) {
  6050. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6051. return 0;
  6052. }
  6053. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6054. return 1;
  6055. }
  6056. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6057. if (!lua_interface)
  6058. return 0;
  6059. Spawn* spawn = lua_interface->GetSpawn(state);
  6060. if (!spawn) {
  6061. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6062. return 0;
  6063. }
  6064. if (!spawn->IsEntity()) {
  6065. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6066. return 0;
  6067. }
  6068. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6069. return 1;
  6070. }
  6071. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6072. if (!lua_interface)
  6073. return 0;
  6074. Spawn* spawn = lua_interface->GetSpawn(state);
  6075. if (!spawn) {
  6076. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6077. return 0;
  6078. }
  6079. if (!spawn->IsEntity()) {
  6080. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6081. return 0;
  6082. }
  6083. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6084. return 1;
  6085. }
  6086. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6087. if (!lua_interface)
  6088. return 0;
  6089. Spawn* spawn = lua_interface->GetSpawn(state);
  6090. if (!spawn) {
  6091. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6092. return 0;
  6093. }
  6094. if (!spawn->IsEntity()) {
  6095. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6096. return 0;
  6097. }
  6098. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6099. return 1;
  6100. }
  6101. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6102. if (!lua_interface)
  6103. return 0;
  6104. Spawn* spawn = lua_interface->GetSpawn(state);
  6105. if (!spawn) {
  6106. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6107. return 0;
  6108. }
  6109. if (!spawn->IsEntity()) {
  6110. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6111. return 0;
  6112. }
  6113. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6114. return 1;
  6115. }
  6116. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6117. if (!lua_interface)
  6118. return 0;
  6119. Spawn* spawn = lua_interface->GetSpawn(state);
  6120. Spawn* target = lua_interface->GetSpawn(state, 2);
  6121. float distance = lua_interface->GetFloatValue(state, 3);
  6122. if (!spawn) {
  6123. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6124. return 0;
  6125. }
  6126. if (!target) {
  6127. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6128. return 0;
  6129. }
  6130. if (!spawn->IsNPC()) {
  6131. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6132. return 0;
  6133. }
  6134. if (!target->IsEntity()) {
  6135. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6139. return 1;
  6140. }
  6141. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6142. if (!lua_interface)
  6143. return 0;
  6144. Spawn* spawn = lua_interface->GetSpawn(state);
  6145. Spawn* target = lua_interface->GetSpawn(state, 2);
  6146. float distance = lua_interface->GetFloatValue(state, 3);
  6147. if (!spawn) {
  6148. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6149. return 0;
  6150. }
  6151. if (!target) {
  6152. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6153. return 0;
  6154. }
  6155. if (!spawn->IsNPC()) {
  6156. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6157. return 0;
  6158. }
  6159. if (!target->IsEntity()) {
  6160. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6161. return 0;
  6162. }
  6163. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6164. return 0;
  6165. }
  6166. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6167. if (!lua_interface)
  6168. return 0;
  6169. Spawn* spawn = lua_interface->GetSpawn(state);
  6170. if (!spawn) {
  6171. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6172. return 0;
  6173. }
  6174. if (!spawn->IsNPC()) {
  6175. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6176. return 0;
  6177. }
  6178. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6179. return 1;
  6180. }
  6181. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6182. if (!lua_interface)
  6183. return 0;
  6184. Spawn* spawn = lua_interface->GetSpawn(state);
  6185. if (!spawn) {
  6186. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6187. return 0;
  6188. }
  6189. if (!spawn->IsNPC()) {
  6190. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6191. return 0;
  6192. }
  6193. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6194. return 1;
  6195. }
  6196. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6197. if (!lua_interface)
  6198. return 0;
  6199. Spawn* spawn = lua_interface->GetSpawn(state);
  6200. if (!spawn) {
  6201. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6202. return 0;
  6203. }
  6204. if (!spawn->IsNPC()) {
  6205. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6206. return 0;
  6207. }
  6208. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6209. if (hated) {
  6210. lua_interface->SetSpawnValue(state, hated);
  6211. return 1;
  6212. }
  6213. return 0;
  6214. }
  6215. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6216. if (!lua_interface)
  6217. return 0;
  6218. Spawn* spawn = lua_interface->GetSpawn(state);
  6219. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6220. if (!spawn) {
  6221. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6222. return 0;
  6223. }
  6224. if (!spawn->IsNPC()) {
  6225. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. if (!hated) {
  6229. ((NPC*)spawn)->Brain()->ClearHate();
  6230. return 0;
  6231. }
  6232. else
  6233. {
  6234. if (!hated->IsEntity()) {
  6235. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6239. return 0;
  6240. }
  6241. return 0;
  6242. }
  6243. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6244. if (!lua_interface)
  6245. return 0;
  6246. Spawn* spawn = lua_interface->GetSpawn(state);
  6247. if (!spawn) {
  6248. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6249. return 0;
  6250. }
  6251. if (!spawn->IsNPC()) {
  6252. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6253. return 0;
  6254. }
  6255. ((NPC*)spawn)->Brain()->ClearEncounter();
  6256. return 0;
  6257. }
  6258. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6259. if (!lua_interface)
  6260. return 0;
  6261. Spawn* spawn = lua_interface->GetSpawn(state);
  6262. if (!spawn) {
  6263. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6264. return 0;
  6265. }
  6266. if (!spawn->IsNPC()) {
  6267. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6268. return 0;
  6269. }
  6270. // Temp list to store hate list
  6271. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6272. if (encounterList->size() == 0) {
  6273. safe_delete(encounterList);
  6274. return 0;
  6275. }
  6276. lua_createtable(state, encounterList->size(), 0);
  6277. int newTable = lua_gettop(state);
  6278. for (int32 i = 0; i < encounterList->size(); i++) {
  6279. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6280. if (temp)
  6281. lua_interface->SetSpawnValue(state, temp);
  6282. lua_rawseti(state, newTable, i + 1);
  6283. }
  6284. safe_delete(encounterList);
  6285. return 1;
  6286. }
  6287. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6288. if (!lua_interface)
  6289. return 0;
  6290. Spawn* spawn = lua_interface->GetSpawn(state);
  6291. if (!spawn) {
  6292. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6293. return 0;
  6294. }
  6295. if (!spawn->IsNPC()) {
  6296. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6297. return 0;
  6298. }
  6299. // Temp list to store hate list
  6300. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6301. if (hateList->size() == 0) {
  6302. safe_delete(hateList);
  6303. return 0;
  6304. }
  6305. lua_createtable(state, hateList->size(), 0);
  6306. int newTable = lua_gettop(state);
  6307. for (int32 i = 0; i < hateList->size(); i++) {
  6308. lua_interface->SetSpawnValue(state, hateList->at(i));
  6309. lua_rawseti(state, newTable, i + 1);
  6310. }
  6311. safe_delete(hateList);
  6312. return 1;
  6313. }
  6314. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6315. if (!lua_interface)
  6316. return 0;
  6317. Spawn* spawn = lua_interface->GetSpawn(state);
  6318. if (!spawn) {
  6319. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6320. return 0;
  6321. }
  6322. if (spawn->IsPlayer()) {
  6323. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6324. lua_interface->SetBooleanValue(state, true);
  6325. else
  6326. lua_interface->SetBooleanValue(state, false);
  6327. return 1;
  6328. }
  6329. else {
  6330. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6331. return 1;
  6332. }
  6333. }
  6334. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6335. if (!lua_interface)
  6336. return 0;
  6337. Quest* quest = lua_interface->GetQuest(state);
  6338. if (!quest) {
  6339. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6340. return 0;
  6341. }
  6342. quest->SetCompletedFlag(true);
  6343. return 0;
  6344. }
  6345. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6346. if (!lua_interface)
  6347. return 0;
  6348. Spawn* spawn = lua_interface->GetSpawn(state);
  6349. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6350. int8 tier = lua_interface->GetInt8Value(state, 3);
  6351. if (!spawn) {
  6352. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6353. return 0;
  6354. }
  6355. if (!spawn->IsEntity()) {
  6356. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6357. return 0;
  6358. }
  6359. if (spellID == 0) {
  6360. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6361. return 0;
  6362. }
  6363. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6364. if (effect) {
  6365. if (tier > 0) {
  6366. // If a tier was passed chec to see if it is the same as the effect
  6367. if (tier == effect->tier)
  6368. lua_interface->SetBooleanValue(state, true);
  6369. else
  6370. lua_interface->SetBooleanValue(state, false);
  6371. return 1;
  6372. }
  6373. else {
  6374. // Have an effect but no tier was passed so return true
  6375. lua_interface->SetBooleanValue(state, true);
  6376. }
  6377. return 1;
  6378. }
  6379. // no effect so return false
  6380. lua_interface->SetBooleanValue(state, false);
  6381. return 1;
  6382. }
  6383. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6384. if (!lua_interface)
  6385. return 0;
  6386. Spawn* spawn = lua_interface->GetSpawn(state);
  6387. int32 id = lua_interface->GetInt32Value(state, 2);
  6388. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6389. Spawn* spawn2 = 0;
  6390. vector<Spawn*> list;
  6391. if (!spawn) {
  6392. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6393. return 0;
  6394. }
  6395. //If zone not provided, use spawn's zone
  6396. if (!zone)
  6397. zone = spawn->GetZone();
  6398. list = zone->GetSpawnsByID(id);
  6399. if (list.size() == 0) {
  6400. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6401. return 0;
  6402. }
  6403. vector<Spawn*>::iterator itr = list.begin();
  6404. for (int8 i = 0; i < list.size(); i++) {
  6405. spawn2 = itr[i];
  6406. if (spawn2)
  6407. spawn2->AddAllowAccessSpawn(spawn);
  6408. }
  6409. return 0;
  6410. }
  6411. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6412. if (!lua_interface)
  6413. return 0;
  6414. Spawn* spawn = lua_interface->GetSpawn(state);
  6415. int32 id = lua_interface->GetInt32Value(state, 2);
  6416. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6417. Spawn* spawn2 = 0;
  6418. if (!spawn) {
  6419. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6420. return 0;
  6421. }
  6422. //If zone not provided, use spawn's zone
  6423. if (!zone)
  6424. zone = spawn->GetZone();
  6425. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6426. vector<Spawn*>::iterator itr = list.begin();
  6427. if (list.size() == 0) {
  6428. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6429. return 0;
  6430. }
  6431. for (int8 i = 0; i < list.size(); i++) {
  6432. spawn2 = itr[i];
  6433. if (spawn2)
  6434. spawn2->RemoveSpawnAccess(spawn);
  6435. }
  6436. return 0;
  6437. }
  6438. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6439. if (!lua_interface)
  6440. return 0;
  6441. Quest* quest = lua_interface->GetQuest(state);
  6442. if (!quest) {
  6443. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6444. return 0;
  6445. }
  6446. quest->SetYellowName(true);
  6447. return 0;
  6448. }
  6449. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6450. if (!lua_interface)
  6451. return 0;
  6452. Spawn* spawn = lua_interface->GetSpawn(state);
  6453. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6454. if (!spawn) {
  6455. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6456. return 0;
  6457. }
  6458. if (!spawn->IsPlayer()) {
  6459. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6460. return 0;
  6461. }
  6462. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6463. return 1;
  6464. }
  6465. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6466. if (!lua_interface)
  6467. return 0;
  6468. Spawn* spawn = lua_interface->GetSpawn(state);
  6469. if (!spawn) {
  6470. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6471. return 0;
  6472. }
  6473. if (!spawn->IsPlayer()) {
  6474. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6475. return 0;
  6476. }
  6477. ZoneServer* zone = spawn->GetZone();
  6478. if (!zone) {
  6479. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6480. return 0;
  6481. }
  6482. Instance_Type iType = zone->GetInstanceType();
  6483. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6484. iType == GROUP_LOCKOUT_INSTANCE ||
  6485. iType == RAID_LOCKOUT_INSTANCE ||
  6486. iType == SOLO_PERSIST_INSTANCE ||
  6487. iType == GROUP_PERSIST_INSTANCE ||
  6488. iType == RAID_PERSIST_INSTANCE) {
  6489. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6490. if (data) {
  6491. // Check to see if the timer has already been set, if it has return out.
  6492. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6493. return 0;
  6494. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6495. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6496. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6497. if (client) {
  6498. string time_msg = "";
  6499. int32 time = data->success_lockout_time;
  6500. int16 hour;
  6501. int8 min;
  6502. int8 sec;
  6503. hour = time / 3600;
  6504. time = time % 3600;
  6505. min = time / 60;
  6506. time = time % 60;
  6507. sec = time;
  6508. if (hour > 0) {
  6509. char temp[10];
  6510. sprintf(temp, " %i", hour);
  6511. time_msg.append(temp);
  6512. time_msg.append(" hour");
  6513. time_msg.append((hour > 1) ? "s" : "");
  6514. }
  6515. if (min > 0) {
  6516. char temp[5];
  6517. sprintf(temp, " %i", min);
  6518. time_msg.append(temp);
  6519. time_msg.append(" minute");
  6520. time_msg.append((min > 1) ? "s" : "");
  6521. }
  6522. // Only add seconds if minutes and hours are 0
  6523. if (hour == 0 && min == 0 && sec > 0) {
  6524. char temp[5];
  6525. sprintf(temp, " %i", sec);
  6526. time_msg.append(temp);
  6527. time_msg.append(" second");
  6528. time_msg.append((sec > 1) ? "s" : "");
  6529. }
  6530. 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());
  6531. }
  6532. }
  6533. else
  6534. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6535. }
  6536. else
  6537. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6538. return 0;
  6539. }
  6540. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6541. if (!lua_interface)
  6542. return 0;
  6543. Spawn* spawn = lua_interface->GetSpawn(state);
  6544. if (!spawn) {
  6545. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6546. return 0;
  6547. }
  6548. if (!spawn->IsPlayer()) {
  6549. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6550. return 0;
  6551. }
  6552. ZoneServer* zone = spawn->GetZone();
  6553. if (!zone) {
  6554. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6555. return 0;
  6556. }
  6557. Instance_Type iType = zone->GetInstanceType();
  6558. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6559. iType == GROUP_LOCKOUT_INSTANCE ||
  6560. iType == RAID_LOCKOUT_INSTANCE ||
  6561. iType == SOLO_PERSIST_INSTANCE ||
  6562. iType == GROUP_PERSIST_INSTANCE ||
  6563. iType == RAID_PERSIST_INSTANCE) {
  6564. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6565. if (data) {
  6566. // Check to see if the timer has already been set, if it has return out.
  6567. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6568. return 0;
  6569. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6570. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6571. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6572. if (client) {
  6573. string time_msg = "";
  6574. int32 time = data->failure_lockout_time;
  6575. int16 hour;
  6576. int8 min;
  6577. int8 sec;
  6578. hour = time / 3600;
  6579. time = time % 3600;
  6580. min = time / 60;
  6581. time = time % 60;
  6582. sec = time;
  6583. if (hour > 0) {
  6584. char temp[10];
  6585. sprintf(temp, " %i", hour);
  6586. time_msg.append(temp);
  6587. time_msg.append(" hour");
  6588. time_msg.append((hour > 1) ? "s" : "");
  6589. }
  6590. if (min > 0) {
  6591. char temp[5];
  6592. sprintf(temp, " %i", min);
  6593. time_msg.append(temp);
  6594. time_msg.append(" minute");
  6595. time_msg.append((min > 1) ? "s" : "");
  6596. }
  6597. // Only add seconds if minutes and hours are 0
  6598. if (hour == 0 && min == 0 && sec > 0) {
  6599. char temp[5];
  6600. sprintf(temp, " %i", sec);
  6601. time_msg.append(temp);
  6602. time_msg.append(" second");
  6603. time_msg.append((sec > 1) ? "s" : "");
  6604. }
  6605. 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());
  6606. }
  6607. }
  6608. else
  6609. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6610. }
  6611. else
  6612. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6616. if (!lua_interface)
  6617. return 0;
  6618. Spawn* spawn = lua_interface->GetSpawn(state);
  6619. if (!spawn) {
  6620. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6621. return 0;
  6622. }
  6623. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6624. return 1;
  6625. }
  6626. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6627. if (!lua_interface)
  6628. return 0;
  6629. Spawn* player = lua_interface->GetSpawn(state);
  6630. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6631. if (!player) {
  6632. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6633. return 0;
  6634. }
  6635. if (!player->IsPlayer()) {
  6636. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6637. return 0;
  6638. }
  6639. if (!ground) {
  6640. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6641. return 0;
  6642. }
  6643. if (!ground->IsGroundSpawn()) {
  6644. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6645. return 0;
  6646. }
  6647. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6648. if (!groundspawn_entries) {
  6649. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6650. return 0;
  6651. }
  6652. Skill* skill = 0;
  6653. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6654. if (collection_skill == "Collecting")
  6655. skill = ((Player*)player)->GetSkillByName("Gathering");
  6656. else
  6657. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6658. if (!skill) {
  6659. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6660. return 0;
  6661. }
  6662. vector<GroundSpawnEntry*>::iterator itr;
  6663. GroundSpawnEntry* entry = 0;
  6664. bool can_harvest = false;
  6665. sint32 min_skill = -1;
  6666. int16 totalSkill = skill->current_val;
  6667. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6668. if(skillID != 0xFFFFFFFF)
  6669. {
  6670. ((Entity*)player)->MStats.lock();
  6671. totalSkill += ((Entity*)player)->stats[skillID];
  6672. ((Entity*)player)->MStats.unlock();
  6673. }
  6674. // first, iterate through groundspawn_entries, discard tables player cannot use
  6675. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6676. {
  6677. entry = *itr;
  6678. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6679. min_skill = entry->min_skill_level;
  6680. // if player lacks skill, skip table
  6681. if (entry->min_skill_level > totalSkill)
  6682. continue;
  6683. // if bonus, but player lacks level, skip table
  6684. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6685. continue;
  6686. can_harvest = true;
  6687. break;
  6688. }
  6689. lua_interface->SetBooleanValue(state, can_harvest);
  6690. // If false, send the message to the client
  6691. if (!can_harvest) {
  6692. Client* client = player->GetZone()->GetClientBySpawn(player);
  6693. if (client) {
  6694. string msg = "You do not have enough skill to ";
  6695. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6696. msg.append("gather");
  6697. else if (collection_skill == "Mining")
  6698. msg.append("mine");
  6699. else if (collection_skill == "Trapping")
  6700. msg.append("trap");
  6701. else if (collection_skill == "Foresting")
  6702. msg.append("forest");
  6703. else if (collection_skill == "Fishing")
  6704. msg.append("catch");
  6705. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6706. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6707. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6708. }
  6709. }
  6710. return 1;
  6711. }
  6712. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6713. if (!lua_interface)
  6714. return 0;
  6715. Spawn* player = lua_interface->GetSpawn(state);
  6716. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6717. if (!player) {
  6718. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6719. return 0;
  6720. }
  6721. if (!player->IsPlayer()) {
  6722. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6723. return 0;
  6724. }
  6725. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6726. lua_interface->SetBooleanValue(state, ret);
  6727. return 1;
  6728. }
  6729. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6730. // Check to see if we have a valid lua_interface
  6731. if (!lua_interface)
  6732. return 0;
  6733. // Get the spawn that is getting the pet
  6734. Spawn* spawn = lua_interface->GetSpawn(state);
  6735. Spawn* target = lua_interface->GetSpawn(state, 2);
  6736. // Get the DB ID of the pet
  6737. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6738. float x = lua_interface->GetFloatValue(state, 4);
  6739. float y = lua_interface->GetFloatValue(state, 5);
  6740. float z = lua_interface->GetFloatValue(state, 6);
  6741. // Get the spell that this command was called from
  6742. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6743. // Check to make sure the spawn pointer is valid
  6744. if (!spawn) {
  6745. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6746. return 0;
  6747. }
  6748. // Check to make sure the spawn is an entity
  6749. if (!spawn->IsEntity()) {
  6750. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6751. return 0;
  6752. }
  6753. if (!target) {
  6754. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6755. return 0;
  6756. }
  6757. if (!target->IsEntity()) {
  6758. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6759. return 0;
  6760. }
  6761. // Check to see if the DB ID for the pet is set
  6762. if (pet_id == 0) {
  6763. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6764. return 0;
  6765. }
  6766. // Check to see if the pointer to the spell is valid
  6767. if (!luaspell) {
  6768. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6769. return 0;
  6770. }
  6771. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6772. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6773. if (!pet) {
  6774. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6775. return 0;
  6776. }
  6777. // Check to make sure the pet is an npc
  6778. if (!pet->IsNPC()) {
  6779. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6780. return 0;
  6781. }
  6782. if (x == 0)
  6783. x = spawn->GetX();
  6784. if (y == 0)
  6785. y = spawn->GetY();
  6786. if (z == 0)
  6787. z = spawn->GetZ();
  6788. // Spawn the pet at the same location as the owner
  6789. pet->SetX(x);
  6790. pet->SetY(y);
  6791. pet->SetZ(z);
  6792. pet->SetLocation(spawn->GetLocation());
  6793. pet->SetHeading(spawn->GetHeading());
  6794. spawn->GetZone()->AddSpawn(pet);
  6795. /*
  6796. const char* spawn_script = world.GetSpawnScript(pet_id);
  6797. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6798. spawn->SetSpawnScript(string(spawn_script));
  6799. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6800. }*/
  6801. // Get a random pet name
  6802. string random_pet_name;
  6803. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6804. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6805. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6806. // Set the pets name
  6807. pet->SetName(random_pet_name.c_str());
  6808. // Set the level of the pet to the owners level
  6809. pet->SetLevel(spawn->GetLevel());
  6810. // Set the faction of the pet to the same faction as the owner
  6811. pet->SetFactionID(spawn->GetFactionID());
  6812. // Set the spawn as a pet
  6813. pet->SetPet(true);
  6814. // Give a pointer of the owner to the pet
  6815. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6816. // Set the pet type
  6817. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6818. // Set the spell id used to create this pet
  6819. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6820. // Set the spell tier used to create this pet
  6821. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6822. // Set the pets spawn type to 6
  6823. pet->SetSpawnType(6);
  6824. // Set the pets brain
  6825. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6826. // Check to see if the pet has a subtitle
  6827. if (strlen(pet->GetSubTitle()) > 0) {
  6828. // Add the players name to the front of the sub title
  6829. string pet_subtitle;
  6830. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6831. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6832. // Set the pets subtitle to the new one
  6833. pet->SetSubTitle(pet_subtitle.c_str());
  6834. }
  6835. // Set the pet as the return value for this function
  6836. lua_interface->SetSpawnValue(state, pet);
  6837. return 1;
  6838. }
  6839. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6840. if (!lua_interface)
  6841. return 0;
  6842. Spawn* spawn = lua_interface->GetSpawn(state);
  6843. Spawn* player = lua_interface->GetSpawn(state, 2);
  6844. float max_distance = lua_interface->GetFloatValue(state, 3);
  6845. string type = lua_interface->GetStringValue(state, 4);
  6846. if (!spawn || (spawn && spawn->IsPlayer())) {
  6847. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6848. return 0;
  6849. }
  6850. if (!player || (player && !player->IsPlayer())) {
  6851. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6852. return 0;
  6853. }
  6854. Client* client = 0;
  6855. if (player->GetZone())
  6856. client = player->GetZone()->GetClientBySpawn(player);
  6857. if (!client) {
  6858. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6859. return 0;
  6860. }
  6861. //Set max_distance to default if not set or not proper value
  6862. if (max_distance <= 0)
  6863. max_distance = 500;
  6864. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6865. if (packet) {
  6866. float unknown2_3 = 0;
  6867. int8 placement_mode = 0;
  6868. if (type == "wall") {
  6869. placement_mode = 2;
  6870. unknown2_3 = 150;
  6871. }
  6872. else if (type == "ceiling")
  6873. placement_mode = 1;
  6874. packet->setDataByName("placement_mode", placement_mode);
  6875. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6876. packet->setDataByName("model_type", spawn->GetModelType());
  6877. packet->setDataByName("unknown", 1); //size
  6878. packet->setDataByName("unknown2", 1); //size 2
  6879. packet->setDataByName("unknown2", .5, 1); //size 3
  6880. packet->setDataByName("unknown2", 3, 2);
  6881. packet->setDataByName("unknown2", unknown2_3, 3);
  6882. packet->setDataByName("max_distance", max_distance);
  6883. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6884. client->QueuePacket(packet->serialize());
  6885. safe_delete(packet);
  6886. }
  6887. return 0;
  6888. }
  6889. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6890. if (!lua_interface)
  6891. return 0;
  6892. Item* item = lua_interface->GetItem(state);
  6893. if (!item) {
  6894. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6895. return 0;
  6896. }
  6897. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6898. return 1;
  6899. }
  6900. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6901. if (!lua_interface)
  6902. return 0;
  6903. Spawn* spawn = lua_interface->GetSpawn(state);
  6904. if (!spawn) {
  6905. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6906. return 0;
  6907. }
  6908. if (spawn->GetZone())
  6909. spawn->GetZone()->AddTransportSpawn(spawn);
  6910. return 0;
  6911. }
  6912. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6913. if (!lua_interface)
  6914. return 0;
  6915. Spawn* spawn = lua_interface->GetSpawn(state);
  6916. if (!spawn) {
  6917. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6918. return 0;
  6919. }
  6920. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  6921. return 1;
  6922. }
  6923. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6924. if (!lua_interface)
  6925. return 0;
  6926. Skill* skill = lua_interface->GetSkill(state);
  6927. if (!skill) {
  6928. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6929. return 0;
  6930. }
  6931. lua_interface->SetInt32Value(state, skill->current_val);
  6932. return 1;
  6933. }
  6934. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6935. if (!lua_interface)
  6936. return 0;
  6937. Skill* skill = lua_interface->GetSkill(state);
  6938. if (!skill) {
  6939. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6940. return 0;
  6941. }
  6942. lua_interface->SetInt32Value(state, skill->max_val);
  6943. return 1;
  6944. }
  6945. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6946. if (!lua_interface)
  6947. return 0;
  6948. Skill* skill = lua_interface->GetSkill(state);
  6949. if (!skill) {
  6950. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6951. return 0;
  6952. }
  6953. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6954. return 1;
  6955. }
  6956. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6957. if (!lua_interface)
  6958. return 0;
  6959. Skill* skill = lua_interface->GetSkill(state);
  6960. int16 value = lua_interface->GetInt16Value(state, 2);
  6961. if (!skill) {
  6962. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6963. return 0;
  6964. }
  6965. skill->max_val = value;
  6966. if (skill->max_val < skill->current_val)
  6967. skill->current_val = skill->max_val;
  6968. return 0;
  6969. }
  6970. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6971. if (!lua_interface)
  6972. return 0;
  6973. Skill* skill = lua_interface->GetSkill(state);
  6974. int16 value = lua_interface->GetInt16Value(state, 2);
  6975. if (!skill) {
  6976. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6977. return 0;
  6978. }
  6979. if (value > skill->max_val)
  6980. skill->current_val = skill->max_val;
  6981. else
  6982. skill->current_val = value;
  6983. return 0;
  6984. }
  6985. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6986. if (!lua_interface)
  6987. return 0;
  6988. Spawn* player = lua_interface->GetSpawn(state);
  6989. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6990. if (skill_id > 0 && player && player->IsPlayer()) {
  6991. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6992. return 1;
  6993. }
  6994. return 0;
  6995. }
  6996. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6997. if (!lua_interface)
  6998. return 0;
  6999. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7000. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7001. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7002. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7003. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7004. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7005. if (player_spawn && player_spawn->IsPlayer()) {
  7006. Player* player = (Player*)player_spawn;
  7007. bool added = false;
  7008. if (!player->skill_list.HasSkill(skill_id)) {
  7009. player->AddSkill(skill_id, current_val, max_val, true);
  7010. added = true;
  7011. }
  7012. 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
  7013. Client* client = player->GetClient();
  7014. if (client) {
  7015. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7016. if (packet)
  7017. client->QueuePacket(packet);
  7018. }
  7019. }
  7020. if (added) {
  7021. lua_interface->SetBooleanValue(state, true);
  7022. return 1;
  7023. }
  7024. }
  7025. else {
  7026. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7027. }
  7028. }
  7029. else {
  7030. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7031. }
  7032. lua_interface->SetBooleanValue(state, false);
  7033. return 1;
  7034. }
  7035. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7036. if (!lua_interface)
  7037. return 0;
  7038. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7039. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7040. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7041. if (skill_id > 0) {
  7042. if (player_spawn && player_spawn->IsPlayer()) {
  7043. Player* player = (Player*)player_spawn;
  7044. if (player->skill_list.HasSkill(skill_id)) {
  7045. player->RemovePlayerSkill(skill_id);
  7046. if (!more_to_remove) {
  7047. Client* client = player->GetClient();
  7048. if (client) {
  7049. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7050. if (packet)
  7051. client->QueuePacket(packet);
  7052. }
  7053. }
  7054. }
  7055. }
  7056. else {
  7057. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7058. }
  7059. }
  7060. else {
  7061. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7062. }
  7063. return 0;
  7064. }
  7065. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7066. if (!lua_interface)
  7067. return 0;
  7068. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7069. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7070. int16 amount = lua_interface->GetInt8Value(state, 3);
  7071. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7072. if (amount > 0 && skill_type < 100) {
  7073. if (player_spawn && player_spawn->IsPlayer()) {
  7074. Player* player = (Player*)player_spawn;
  7075. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7076. if (!more_to_increase) {
  7077. Client* client = player->GetClient();
  7078. if (client) {
  7079. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7080. if (packet)
  7081. client->QueuePacket(packet);
  7082. }
  7083. }
  7084. }
  7085. else {
  7086. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7087. }
  7088. }
  7089. else {
  7090. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7091. }
  7092. return 0;
  7093. }
  7094. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7095. if (!lua_interface)
  7096. return 0;
  7097. Spawn* spawn = lua_interface->GetSpawn(state);
  7098. string name = lua_interface->GetStringValue(state, 2);
  7099. if (!spawn) {
  7100. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7101. return 0;
  7102. }
  7103. if (!spawn->IsEntity()) {
  7104. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7105. return 0;
  7106. }
  7107. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7108. if (skill) {
  7109. lua_interface->SetSkillValue(state, skill);
  7110. return 1;
  7111. }
  7112. return 0;
  7113. }
  7114. int EQ2Emu_lua_AddProc(lua_State* state) {
  7115. if (!lua_interface)
  7116. return 0;
  7117. Spawn* spawn = lua_interface->GetSpawn(state);
  7118. int8 type = lua_interface->GetInt8Value(state, 2);
  7119. float chance = lua_interface->GetFloatValue(state, 3);
  7120. Item* item = lua_interface->GetItem(state, 4);
  7121. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7122. LuaSpell* spell = 0;
  7123. if (!spawn && (!spell || !use_all_spelltargets)) {
  7124. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7125. return 0;
  7126. }
  7127. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7128. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7129. return 0;
  7130. }
  7131. if (!item)
  7132. spell = lua_interface->GetCurrentSpell(state);
  7133. if (!item && !spell) {
  7134. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7135. return 0;
  7136. }
  7137. if (spell && use_all_spelltargets) {
  7138. Spawn* target;
  7139. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7140. for (int8 i = 0; i < spell->targets.size(); i++) {
  7141. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7142. if (!target || !target->IsEntity())
  7143. continue;
  7144. ((Entity*)target)->AddProc(type, chance, item, spell);
  7145. }
  7146. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7147. }
  7148. else
  7149. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7150. return 0;
  7151. }
  7152. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7153. if (!lua_interface)
  7154. return 0;
  7155. Spawn* spawn = lua_interface->GetSpawn(state);
  7156. Item* item = lua_interface->GetItem(state, 2);
  7157. LuaSpell* spell = 0;
  7158. if (!spawn) {
  7159. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7160. return 0;
  7161. }
  7162. if (!spawn->IsEntity()) {
  7163. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7164. return 0;
  7165. }
  7166. if (!item)
  7167. spell = lua_interface->GetCurrentSpell(state);
  7168. if (!item && !spell) {
  7169. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7170. return 0;
  7171. }
  7172. if (spell) {
  7173. Spawn* target;
  7174. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7175. for (int8 i = 0; i < spell->targets.size(); i++) {
  7176. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7177. if (!target || !target->IsEntity())
  7178. continue;
  7179. ((Entity*)target)->RemoveProc(item, spell);
  7180. }
  7181. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7182. spell->caster->RemoveProc(item, spell);
  7183. }
  7184. else
  7185. ((Entity*)spawn)->RemoveProc(item, spell);
  7186. return 0;
  7187. }
  7188. int EQ2Emu_lua_Knockback(lua_State* state) {
  7189. if (!lua_interface)
  7190. return 0;
  7191. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7192. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7193. int32 duration = lua_interface->GetInt32Value(state, 3);
  7194. float vertical = lua_interface->GetFloatValue(state, 4);
  7195. float horizontal = lua_interface->GetFloatValue(state, 5);
  7196. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7197. if (!target_spawn) {
  7198. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7199. return 0;
  7200. }
  7201. if (!spawn) {
  7202. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7206. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7207. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7208. if (packet) {
  7209. packet->setDataByName("target_x", target_spawn->GetX());
  7210. packet->setDataByName("target_y", target_spawn->GetY());
  7211. packet->setDataByName("target_z", target_spawn->GetZ());
  7212. packet->setDataByName("vertical_movement", vertical);
  7213. packet->setDataByName("horizontal_movement", horizontal);
  7214. if (use_heading)
  7215. packet->setDataByName("use_player_heading", 1);
  7216. client->QueuePacket(packet->serialize());
  7217. }
  7218. safe_delete(packet);
  7219. }
  7220. return 0;
  7221. }
  7222. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7223. if (!lua_interface)
  7224. return 0;
  7225. Spawn* spawn = lua_interface->GetSpawn(state);
  7226. if (!spawn) {
  7227. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7228. return 0;
  7229. }
  7230. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7231. return 1;
  7232. }
  7233. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7234. if (!lua_interface)
  7235. return 0;
  7236. Spawn* caster = lua_interface->GetSpawn(state);
  7237. Spawn* target = lua_interface->GetSpawn(state, 2);
  7238. string name = lua_interface->GetStringValue(state, 3);
  7239. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7240. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7241. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7242. string success_msg = lua_interface->GetStringValue(state, 7);
  7243. string effect_msg = lua_interface->GetStringValue(state, 8);
  7244. if (!caster) {
  7245. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7246. return 0;
  7247. }
  7248. if (!caster->IsEntity()) {
  7249. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7250. return 0;
  7251. }
  7252. if (!target) {
  7253. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7254. return 0;
  7255. }
  7256. if (!target->IsEntity()) {
  7257. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7258. return 0;
  7259. }
  7260. if (name.length() == 0) {
  7261. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7262. return 0;
  7263. }
  7264. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7265. return 0;
  7266. }
  7267. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7268. if (!lua_interface)
  7269. return 0;
  7270. string name = lua_interface->GetStringValue(state);
  7271. if (name.length() == 0) {
  7272. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7273. return 0;
  7274. }
  7275. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7276. if (!skill) {
  7277. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7278. return 0;
  7279. }
  7280. lua_interface->SetInt32Value(state, skill->skill_id);
  7281. return 1;
  7282. }
  7283. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7284. if (!lua_interface)
  7285. return 0;
  7286. Spawn* spawn = lua_interface->GetSpawn(state);
  7287. if (!spawn) {
  7288. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7289. return 0;
  7290. }
  7291. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7292. return 1;
  7293. }
  7294. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7295. if (!lua_interface)
  7296. return 0;
  7297. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7298. if (!luaspell) {
  7299. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7300. return 0;
  7301. }
  7302. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7303. return 1;
  7304. }
  7305. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7306. if (!lua_interface)
  7307. return 0;
  7308. Spawn* spawn = lua_interface->GetSpawn(state);
  7309. Spawn* target = lua_interface->GetSpawn(state, 2);
  7310. if (!spawn) {
  7311. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7312. return 0;
  7313. }
  7314. if (!spawn->IsEntity()) {
  7315. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7316. return 0;
  7317. }
  7318. if (!target) {
  7319. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7320. return 0;
  7321. }
  7322. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7323. return 1;
  7324. }
  7325. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7326. if (!lua_interface)
  7327. return 0;
  7328. Spawn* spawn = lua_interface->GetSpawn(state);
  7329. Spawn* target = lua_interface->GetSpawn(state, 2);
  7330. if (!spawn) {
  7331. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7332. return 0;
  7333. }
  7334. if (!spawn->IsEntity()) {
  7335. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7336. return 0;
  7337. }
  7338. if (!target) {
  7339. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7340. return 0;
  7341. }
  7342. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7343. return 1;
  7344. }
  7345. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7346. if (!lua_interface)
  7347. return 0;
  7348. Item* item = lua_interface->GetItem(state);
  7349. if (!item) {
  7350. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7351. return 0;
  7352. }
  7353. lua_interface->SetInt32Value(state, item->details.count);
  7354. return 1;
  7355. }
  7356. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7357. if (!lua_interface)
  7358. return 0;
  7359. Item* item = lua_interface->GetItem(state);
  7360. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7361. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7362. if (!item) {
  7363. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7364. return 0;
  7365. }
  7366. if (!owner) {
  7367. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7368. return 0;
  7369. }
  7370. if (!owner->IsPlayer()) {
  7371. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7372. return 0;
  7373. }
  7374. if (item->stack_count < new_count) {
  7375. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7376. return 0;
  7377. }
  7378. if (new_count > 0) {
  7379. item->details.count = new_count;
  7380. item->save_needed = true;
  7381. }
  7382. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7383. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7384. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7385. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7386. else
  7387. {
  7388. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7389. return 0;
  7390. }
  7391. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7392. if (!client)
  7393. return 0;
  7394. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7395. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7396. if (app)
  7397. client->QueuePacket(app);
  7398. return 0;
  7399. }
  7400. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7401. if (!lua_interface)
  7402. return 0;
  7403. int32 time = lua_interface->GetInt32Value(state);
  7404. string function = lua_interface->GetStringValue(state, 2);
  7405. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7406. Spawn* target = lua_interface->GetSpawn(state, 4);
  7407. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7408. if (time == 0) {
  7409. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7410. return 0;
  7411. }
  7412. if (function.length() == 0) {
  7413. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7414. return 0;
  7415. }
  7416. if (!spell) {
  7417. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7418. return 0;
  7419. }
  7420. SpellScriptTimer* timer = new SpellScriptTimer;
  7421. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7422. #ifdef WIN32
  7423. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7424. #else
  7425. bzero(timer, sizeof(SpellScriptTimer));
  7426. #endif*/
  7427. timer->caster = 0;
  7428. timer->deleteWhenDone = false;
  7429. timer->target = 0;
  7430. timer->time = Timer::GetCurrentTime2() + time;
  7431. timer->customFunction = function;
  7432. timer->spell = spell;
  7433. if (caster)
  7434. timer->caster = caster->GetID();
  7435. if (target)
  7436. timer->target = target->GetID();
  7437. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7438. return 0;
  7439. }
  7440. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7441. if (!lua_interface)
  7442. return 0;
  7443. float hp_perc = lua_interface->GetFloatValue(state);
  7444. float power_perc = lua_interface->GetFloatValue(state, 2);
  7445. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7446. Spawn* target = lua_interface->GetSpawn(state, 4);
  7447. string heal_name = lua_interface->GetStringValue(state, 5);
  7448. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7449. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7450. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7451. if (!spell) {
  7452. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7453. return 0;
  7454. }
  7455. Entity* caster = spell->caster;
  7456. if (!caster) {
  7457. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7458. return 0;
  7459. }
  7460. Client* client = 0;
  7461. PendingResurrection* rez = 0;
  7462. ZoneServer* zone = spell->caster->GetZone();
  7463. if (!target) {
  7464. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7465. if (spell->targets.size() > 0) {
  7466. vector<int32> spell_targets = spell->targets;
  7467. for (int8 i = 0; i < spell_targets.size(); i++) {
  7468. target = zone->GetSpawnByID(spell_targets.at(i));
  7469. if (!target)
  7470. continue;
  7471. if (!target->IsPlayer())
  7472. continue;
  7473. client = target->GetZone()->GetClientBySpawn(target);
  7474. if (!client)
  7475. continue;
  7476. rez = client->GetCurrentRez();
  7477. if (rez->active)
  7478. continue;
  7479. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7480. rez->active = true;
  7481. rez->caster = caster;
  7482. rez->expire_timer = new Timer;
  7483. int32 duration = spell->spell->GetSpellDuration();
  7484. rez->expire_timer->Start(duration * 100);
  7485. rez->hp_perc = hp_perc;
  7486. rez->mp_perc = power_perc;
  7487. rez->range = spell->spell->GetSpellData()->range;
  7488. rez->spell_name = spell->spell->GetName();
  7489. if (heal_name.length() > 0)
  7490. rez->heal_name = heal_name;
  7491. else
  7492. rez->heal_name = rez->spell_name;
  7493. rez->no_calcs = no_calcs;
  7494. rez->crit_mod = crit_mod;
  7495. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7496. if (send_window)
  7497. client->SendResurrectionWindow();
  7498. else {
  7499. target->GetZone()->ResurrectSpawn(target, client);
  7500. rez->should_delete = true;
  7501. }
  7502. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7503. }
  7504. }
  7505. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7506. }
  7507. else {
  7508. client = target->GetZone()->GetClientBySpawn(target);
  7509. if (!client)
  7510. return 0;
  7511. rez = client->GetCurrentRez();
  7512. if (rez->active)
  7513. return 0;
  7514. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7515. rez->active = true;
  7516. rez->caster = caster;
  7517. rez->expire_timer = new Timer;
  7518. int32 duration = spell->spell->GetSpellDuration();
  7519. rez->expire_timer->Start(duration * 100);
  7520. rez->hp_perc = hp_perc;
  7521. rez->mp_perc = power_perc;
  7522. rez->range = spell->spell->GetSpellData()->range;
  7523. rez->spell_name = spell->spell->GetName();
  7524. if (heal_name.length() > 0)
  7525. rez->heal_name = heal_name;
  7526. else
  7527. rez->heal_name = rez->spell_name;
  7528. rez->no_calcs = no_calcs;
  7529. rez->crit_mod = crit_mod;
  7530. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7531. if (send_window)
  7532. client->SendResurrectionWindow();
  7533. else {
  7534. target->GetZone()->ResurrectSpawn(target, client);
  7535. rez->should_delete = true;
  7536. }
  7537. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7538. }
  7539. return 0;
  7540. }
  7541. int EQ2Emu_lua_SetVision(lua_State* state) {
  7542. if (!lua_interface)
  7543. return 0;
  7544. Spawn* spawn = lua_interface->GetSpawn(state);
  7545. int8 vision = lua_interface->GetInt8Value(state, 2);
  7546. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7547. if (!spawn) {
  7548. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7549. return 0;
  7550. }
  7551. if (!spawn->IsEntity()) {
  7552. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7553. return 0;
  7554. }
  7555. if (spell && spell->targets.size() > 0) {
  7556. ZoneServer* zone = spell->caster->GetZone();
  7557. for (int8 i = 0; i < spell->targets.size(); i++) {
  7558. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7559. if (target && target->IsEntity()) {
  7560. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7561. if (target->IsPlayer())
  7562. ((Player*)target)->SetCharSheetChanged(true);
  7563. }
  7564. }
  7565. }
  7566. else {
  7567. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7568. if (spawn->IsPlayer())
  7569. ((Player*)spawn)->SetCharSheetChanged(true);
  7570. }
  7571. return 0;
  7572. }
  7573. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7574. if (!lua_interface)
  7575. return 0;
  7576. Spawn* spawn = lua_interface->GetSpawn(state);
  7577. float intensity = lua_interface->GetFloatValue(state, 2);
  7578. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7579. if (!spawn) {
  7580. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7581. return 0;
  7582. }
  7583. if (!spawn->IsEntity()) {
  7584. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7585. return 0;
  7586. }
  7587. if (spell && spell->targets.size() > 0) {
  7588. ZoneServer* zone = spell->caster->GetZone();
  7589. for (int8 i = 0; i < spell->targets.size(); i++) {
  7590. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7591. if (target && target->IsEntity()) {
  7592. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7593. if (target->IsPlayer())
  7594. ((Player*)target)->SetCharSheetChanged(true);
  7595. }
  7596. }
  7597. }
  7598. else {
  7599. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7600. if (spawn->IsPlayer())
  7601. ((Player*)spawn)->SetCharSheetChanged(true);
  7602. }
  7603. return 0;
  7604. }
  7605. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7606. if (!lua_interface)
  7607. return 0;
  7608. Spawn* spawn = lua_interface->GetSpawn(state);
  7609. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7610. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7611. if (!spawn) {
  7612. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7613. return 0;
  7614. }
  7615. if (!spawn->IsEntity()) {
  7616. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7617. return 0;
  7618. }
  7619. if (spell && spell->targets.size() > 0) {
  7620. ZoneServer* zone = spell->caster->GetZone();
  7621. for (int8 i = 0; i < spell->targets.size(); i++) {
  7622. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7623. if (target && target->IsEntity()) {
  7624. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7625. if (target->IsPlayer())
  7626. ((Player*)target)->SetCharSheetChanged(true);
  7627. }
  7628. }
  7629. }
  7630. else {
  7631. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7632. if (spawn->IsPlayer())
  7633. ((Player*)spawn)->SetCharSheetChanged(true);
  7634. }
  7635. return 0;
  7636. }
  7637. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7638. if (!lua_interface)
  7639. return 0;
  7640. Item* item = lua_interface->GetItem(state);
  7641. int8 type = lua_interface->GetInt32Value(state, 2);
  7642. if (!item) {
  7643. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7644. return 0;
  7645. }
  7646. if (type == 1)
  7647. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7648. else if (type == 2)
  7649. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7650. return 1;
  7651. }
  7652. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7653. if (!lua_interface)
  7654. return 0;
  7655. Spawn* target = lua_interface->GetSpawn(state);
  7656. float val = lua_interface->GetFloatValue(state, 2);
  7657. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7658. // Added from Gangrenous post
  7659. if (spell && spell->resisted)
  7660. return 0;
  7661. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7662. if (val > 1.0f)
  7663. val = 1.0f - (val / 100.0f);
  7664. if (spell && spell->spell && spell->targets.size() > 0) {
  7665. ZoneServer* zone = spell->caster->GetZone();
  7666. for (int32 i = 0; i != spell->targets.size(); i++) {
  7667. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7668. if (spawn && spawn->IsEntity()) {
  7669. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7670. if (spawn->IsPlayer())
  7671. ((Player*)spawn)->SetCharSheetChanged(true);
  7672. }
  7673. }
  7674. }
  7675. else {
  7676. if (target && target->IsEntity()) {
  7677. ((Entity*)target)->SetSpeedMultiplier(val);
  7678. if (target->IsPlayer())
  7679. ((Player*)target)->SetCharSheetChanged(true);
  7680. }
  7681. }
  7682. return 0;
  7683. }
  7684. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7685. if (!lua_interface)
  7686. return 0;
  7687. Spawn* spawn = lua_interface->GetSpawn(state);
  7688. int16 model = lua_interface->GetInt16Value(state, 2);
  7689. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7690. if (spell && spell->spell && spell->targets.size() > 0) {
  7691. ZoneServer* zone = spell->caster->GetZone();
  7692. for (int32 i = 0; i < spell->targets.size(); i++) {
  7693. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7694. if (target)
  7695. target->SetIllusionModel(model);
  7696. }
  7697. }
  7698. else {
  7699. if (!spawn) {
  7700. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7701. return 0;
  7702. }
  7703. spawn->SetIllusionModel(model);
  7704. }
  7705. return 0;
  7706. }
  7707. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7708. if (!lua_interface)
  7709. return 0;
  7710. Spawn* spawn = lua_interface->GetSpawn(state);
  7711. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7712. if (spell && spell->spell && spell->targets.size() > 0) {
  7713. ZoneServer* zone = spell->caster->GetZone();
  7714. for (int32 i = 0; i < spell->targets.size(); i++) {
  7715. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7716. if (target)
  7717. target->SetIllusionModel(0);
  7718. }
  7719. }
  7720. else {
  7721. if (!spawn) {
  7722. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7723. return 0;
  7724. }
  7725. spawn->SetIllusionModel(0);
  7726. }
  7727. return 0;
  7728. }
  7729. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7730. if (!lua_interface)
  7731. return 0;
  7732. Spawn* caster = lua_interface->GetSpawn(state);
  7733. Spawn* target = lua_interface->GetSpawn(state, 2);
  7734. float chance = lua_interface->GetFloatValue(state, 3);
  7735. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7736. if (!caster) {
  7737. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7738. return 0;
  7739. }
  7740. if (!caster->IsEntity()) {
  7741. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7742. return 0;
  7743. }
  7744. if (!target) {
  7745. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7746. return 0;
  7747. }
  7748. if (!target->IsEntity()) {
  7749. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7750. return 0;
  7751. }
  7752. if (chance <= 0) {
  7753. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7754. return 0;
  7755. }
  7756. if (!spell) {
  7757. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7758. return 0;
  7759. }
  7760. if (((Entity*)caster)->GetThreatTransfer()) {
  7761. return 0;
  7762. }
  7763. ThreatTransfer* transfer = new ThreatTransfer;
  7764. transfer->Target = target->GetID();
  7765. transfer->Amount = chance;
  7766. transfer->Spell = spell;
  7767. ((Entity*)caster)->SetThreatTransfer(transfer);
  7768. return 0;
  7769. }
  7770. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7771. if (!lua_interface)
  7772. return 0;
  7773. Spawn* spawn = lua_interface->GetSpawn(state);
  7774. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7775. if (!spawn) {
  7776. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7777. return 0;
  7778. }
  7779. if (!spell) {
  7780. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7781. return 0;
  7782. }
  7783. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7784. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7785. ((Entity*)spawn)->SetThreatTransfer(0);
  7786. safe_delete(transfer);
  7787. }
  7788. return 0;
  7789. }
  7790. int EQ2Emu_lua_CureByType(lua_State* state) {
  7791. if (!lua_interface)
  7792. return 0;
  7793. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7794. if (!spell) {
  7795. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7796. return 0;
  7797. }
  7798. int8 cure_count = lua_interface->GetInt8Value(state);
  7799. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7800. string cure_name = lua_interface->GetStringValue(state, 3);
  7801. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7802. Spawn* target = lua_interface->GetSpawn(state, 5);
  7803. if (target) {
  7804. if (!target->IsEntity()) {
  7805. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7806. return 0;
  7807. }
  7808. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7809. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7810. }
  7811. else {
  7812. ZoneServer* zone = spell->caster->GetZone();
  7813. vector<int32> targets = spell->targets;
  7814. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7815. for (int8 i = 0; i < targets.size(); i++) {
  7816. target = zone->GetSpawnByID(targets.at(i));
  7817. if (!target || !target->IsEntity())
  7818. continue;
  7819. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7820. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7821. }
  7822. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7823. }
  7824. return 0;
  7825. }
  7826. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7827. if (!lua_interface)
  7828. return 0;
  7829. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7830. if (!spell) {
  7831. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7832. return 0;
  7833. }
  7834. int8 cure_count = lua_interface->GetInt8Value(state);
  7835. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7836. string cure_name = lua_interface->GetStringValue(state, 3);
  7837. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7838. Spawn* target = lua_interface->GetSpawn(state, 5);
  7839. if (target) {
  7840. if (!target->IsEntity()) {
  7841. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7842. return 0;
  7843. }
  7844. if (((Entity*)target)->GetDetCount() > 0)
  7845. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7846. }
  7847. else {
  7848. ZoneServer* zone = spell->caster->GetZone();
  7849. vector<int32> targets = spell->targets;
  7850. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7851. for (int8 i = 0; i < targets.size(); i++) {
  7852. target = zone->GetSpawnByID(targets.at(i));
  7853. if (!target || !target->IsEntity())
  7854. continue;
  7855. if (((Entity*)target)->GetDetCount() > 0)
  7856. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7857. }
  7858. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7859. }
  7860. return 0;
  7861. }
  7862. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7863. if (!lua_interface)
  7864. return 0;
  7865. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7866. if (!spell) {
  7867. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7868. return 0;
  7869. }
  7870. if (!spell->caster) {
  7871. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7872. return 0;
  7873. }
  7874. if (!spell->caster->GetZone()) {
  7875. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7876. return 0;
  7877. }
  7878. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7879. return 0;
  7880. }
  7881. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7882. if (!lua_interface)
  7883. return 0;
  7884. Spawn* spawn = lua_interface->GetSpawn(state);
  7885. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7886. if (!spell) {
  7887. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7888. return 0;
  7889. }
  7890. if (spawn && spawn->IsEntity())
  7891. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7892. else {
  7893. ZoneServer* zone = spell->caster->GetZone();
  7894. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7895. for (int32 i = 0; i < spell->targets.size(); i++) {
  7896. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7897. if (!spawn || !spawn->IsEntity())
  7898. continue;
  7899. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7900. }
  7901. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7902. }
  7903. return 0;
  7904. }
  7905. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7906. if (!lua_interface)
  7907. return 0;
  7908. Spawn* spawn = lua_interface->GetSpawn(state);
  7909. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7910. if (!spell) {
  7911. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7912. return 0;
  7913. }
  7914. if (spawn && spawn->IsEntity())
  7915. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7916. else {
  7917. ZoneServer* zone = spell->caster->GetZone();
  7918. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7919. for (int32 i = 0; i < spell->targets.size(); i++) {
  7920. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7921. if (!spawn || !spawn->IsEntity())
  7922. continue;
  7923. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7924. }
  7925. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7926. }
  7927. return 0;
  7928. }
  7929. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7930. if (!lua_interface)
  7931. return 0;
  7932. Spawn* caster = lua_interface->GetSpawn(state);
  7933. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7934. if (!caster) {
  7935. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7936. return 0;
  7937. }
  7938. if (!caster->IsPlayer()) {
  7939. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7940. return 0;
  7941. }
  7942. Spawn* target = caster->GetTarget();
  7943. if (!target) {
  7944. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7945. return 0;
  7946. }
  7947. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7948. if (!client) {
  7949. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7950. return 0;
  7951. }
  7952. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7953. if (ho) {
  7954. ho->SetTarget(target->GetID());
  7955. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7956. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7957. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7958. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7959. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7960. deque<GroupMemberInfo*>::iterator itr;
  7961. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7962. if (group)
  7963. {
  7964. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7965. deque<GroupMemberInfo*>* members = group->GetMembers();
  7966. for (itr = members->begin(); itr != members->end(); itr++) {
  7967. if ((*itr)->client)
  7968. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7969. }
  7970. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7971. }
  7972. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7973. }
  7974. else
  7975. safe_delete(ho);
  7976. }
  7977. else {
  7978. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7979. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7980. }
  7981. else
  7982. safe_delete(ho);
  7983. }
  7984. }
  7985. return 0;
  7986. }
  7987. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7988. if (!lua_interface)
  7989. return 0;
  7990. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7991. if (!spell) {
  7992. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7993. return 0;
  7994. }
  7995. int16 triggerCount = lua_interface->GetInt16Value(state);
  7996. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7997. if (!triggerCount) {
  7998. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7999. return 0;
  8000. }
  8001. spell->num_triggers = triggerCount;
  8002. spell->had_triggers = true;
  8003. spell->cancel_after_all_triggers = cancel_after_triggers;
  8004. return 0;
  8005. }
  8006. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8007. if (!lua_interface)
  8008. return 0;
  8009. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8010. if (!spell) {
  8011. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8012. return 0;
  8013. }
  8014. lua_interface->SetInt32Value(state, spell->num_triggers);
  8015. return 1;
  8016. }
  8017. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8018. if (!lua_interface)
  8019. return 0;
  8020. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8021. if (!spell) {
  8022. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. int16 remove_count = lua_interface->GetInt16Value(state);
  8026. if (!remove_count)
  8027. remove_count = 1;
  8028. if (remove_count >= spell->num_triggers) {
  8029. spell->num_triggers = 0;
  8030. if (spell->cancel_after_all_triggers)
  8031. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8032. }
  8033. else {
  8034. spell->num_triggers -= remove_count;
  8035. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8036. }
  8037. return 0;
  8038. }
  8039. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8040. if (!lua_interface)
  8041. return 0;
  8042. Spawn* spawn = lua_interface->GetSpawn(state);
  8043. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8044. if (!spawn) {
  8045. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8046. return 0;
  8047. }
  8048. if (!copy_spawn) {
  8049. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8050. return 0;
  8051. }
  8052. spawn->CopySpawnAppearance(copy_spawn);
  8053. return 0;
  8054. }
  8055. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8056. Spawn* spawn = lua_interface->GetSpawn(state);
  8057. int8 type = lua_interface->GetInt8Value(state, 2);
  8058. if (!spawn) {
  8059. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8060. return 0;
  8061. }
  8062. else if (!spawn->IsEntity()) {
  8063. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8064. return 0;
  8065. }
  8066. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8067. return 1;
  8068. }
  8069. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8070. if (!lua_interface)
  8071. return 0;
  8072. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8073. int8 type = lua_interface->GetInt8Value(state);
  8074. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8075. if (!spell) {
  8076. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8077. return 0;
  8078. }
  8079. if (spawn) {
  8080. if (!spawn->IsEntity()) {
  8081. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8082. return 0;
  8083. }
  8084. Entity* entity = ((Entity*)spawn);
  8085. entity->AddImmunity(spell, type);
  8086. }
  8087. else {
  8088. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8089. for (int8 i = 0; i < spell->targets.size(); i++) {
  8090. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8091. if (!spawn || !spawn->IsEntity())
  8092. continue;
  8093. Entity* entity = ((Entity*)spawn);
  8094. entity->AddImmunity(spell, type);
  8095. }
  8096. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8097. }
  8098. return 0;
  8099. }
  8100. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8101. if (!lua_interface)
  8102. return 0;
  8103. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8104. int8 type = lua_interface->GetInt8Value(state);
  8105. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8106. if (!spell) {
  8107. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8108. return 0;
  8109. }
  8110. if (spawn) {
  8111. if (!spawn->IsEntity()) {
  8112. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8113. return 0;
  8114. }
  8115. Entity* entity = ((Entity*)spawn);
  8116. entity->RemoveImmunity(spell, type);
  8117. }
  8118. else {
  8119. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8120. for (int8 i = 0; i < spell->targets.size(); i++) {
  8121. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8122. if (!spawn || !spawn->IsEntity())
  8123. continue;
  8124. Entity* entity = ((Entity*)spawn);
  8125. entity->RemoveImmunity(spell, type);
  8126. }
  8127. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8128. }
  8129. return 0;
  8130. }
  8131. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8132. if (!lua_interface)
  8133. return 0;
  8134. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8135. if (!spell) {
  8136. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8137. return 0;
  8138. }
  8139. float snare = lua_interface->GetFloatValue(state);
  8140. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8141. // convert the val to the speed multipler value (100 - val)
  8142. float val = 100.0 - snare;
  8143. val /= 100.0;
  8144. if (spawn) {
  8145. if (!spawn->IsEntity()) {
  8146. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8147. return 0;
  8148. }
  8149. ((Entity*)spawn)->SetSnareValue(spell, val);
  8150. }
  8151. else {
  8152. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8153. for (int8 i = 0; i < spell->targets.size(); i++) {
  8154. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8155. if (!spawn || !spawn->IsEntity())
  8156. continue;
  8157. ((Entity*)spawn)->SetSnareValue(spell, val);
  8158. }
  8159. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8160. }
  8161. return 0;
  8162. }
  8163. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8164. if (!lua_interface)
  8165. return 0;
  8166. Spawn* spawn = lua_interface->GetSpawn(state);
  8167. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8168. if (!spawn) {
  8169. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8170. return 0;
  8171. }
  8172. if (race_id == 0) {
  8173. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8174. return 0;
  8175. }
  8176. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8177. return 1;
  8178. }
  8179. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8180. if (!lua_interface)
  8181. return 0;
  8182. Spawn* spawn = lua_interface->GetSpawn(state);
  8183. if (!spawn) {
  8184. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8185. return 0;
  8186. }
  8187. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8188. return 1;
  8189. }
  8190. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8191. if (!lua_interface)
  8192. return 0;
  8193. Spawn* spawn = lua_interface->GetSpawn(state);
  8194. if (!spawn) {
  8195. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8196. return 0;
  8197. }
  8198. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8199. return 1;
  8200. }
  8201. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8202. if (!lua_interface)
  8203. return 0;
  8204. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8205. if (!spell) {
  8206. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8207. return 0;
  8208. }
  8209. lua_interface->SetStringValue(state, spell->spell->GetName());
  8210. return 1;
  8211. }
  8212. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8213. if (!lua_interface)
  8214. return 0;
  8215. Quest* quest = lua_interface->GetQuest(state);
  8216. if (!quest) {
  8217. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8218. return 0;
  8219. }
  8220. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8221. return 1;
  8222. }
  8223. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8224. if (!lua_interface)
  8225. return 0;
  8226. Quest* quest = lua_interface->GetQuest(state);
  8227. int32 flags = lua_interface->GetInt32Value(state, 2);
  8228. if (!quest) {
  8229. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8230. return 0;
  8231. }
  8232. quest->SetQuestFlags(flags);
  8233. return 0;
  8234. }
  8235. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8236. if (!lua_interface)
  8237. return 0;
  8238. Quest* quest = lua_interface->GetQuest(state);
  8239. Spawn* player = lua_interface->GetSpawn(state, 2);
  8240. int32 step = lua_interface->GetInt32Value(state, 3);
  8241. int32 duration = lua_interface->GetInt32Value(state, 4);
  8242. string action = lua_interface->GetStringValue(state, 5);
  8243. if (!quest) {
  8244. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. if (!player) {
  8248. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8249. return 0;
  8250. }
  8251. if (!player->IsPlayer()) {
  8252. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8253. return 0;
  8254. }
  8255. if (step == 0) {
  8256. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8257. return 0;
  8258. }
  8259. if (duration == 0) {
  8260. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8261. return 0;
  8262. }
  8263. if (action.length() == 0) {
  8264. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8265. return 0;
  8266. }
  8267. Client* client = player->GetZone()->GetClientBySpawn(player);
  8268. if (!client) {
  8269. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8270. return 0;
  8271. }
  8272. quest->SetTimerStep(step);
  8273. quest->AddFailedAction(step, action);
  8274. quest->SetStepTimer(duration);
  8275. client->AddQuestTimer(quest->GetQuestID());
  8276. return 0;
  8277. }
  8278. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8279. if (!lua_interface)
  8280. return 0;
  8281. Quest* quest = lua_interface->GetQuest(state);
  8282. Spawn* player = lua_interface->GetSpawn(state, 2);
  8283. if (!quest) {
  8284. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8285. return 0;
  8286. }
  8287. if (!player) {
  8288. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8289. return 0;
  8290. }
  8291. if (!player->IsPlayer()) {
  8292. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8293. return 0;
  8294. }
  8295. Client* client = player->GetZone()->GetClientBySpawn(player);
  8296. if (!client) {
  8297. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8298. return 0;
  8299. }
  8300. quest->SetTimerStep(0);
  8301. quest->SetStepTimer(0);
  8302. client->RemoveQuestTimer(quest->GetQuestID());
  8303. return 0;
  8304. }
  8305. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8306. if (!lua_interface)
  8307. return 0;
  8308. Spawn* player = lua_interface->GetSpawn(state);
  8309. Quest* quest = lua_interface->GetQuest(state, 2);
  8310. int32 step = lua_interface->GetInt32Value(state, 3);
  8311. if (!player) {
  8312. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8313. return 0;
  8314. }
  8315. if (!player->IsPlayer()) {
  8316. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8317. return 0;
  8318. }
  8319. if (!quest) {
  8320. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8321. return 0;
  8322. }
  8323. if (step == 0) {
  8324. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. Client* client = player->GetZone()->GetClientBySpawn(player);
  8328. if (!client) {
  8329. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8330. return 0;
  8331. }
  8332. if (quest->RemoveQuestStep(step, client)) {
  8333. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8334. client->GetCurrentZone()->SendQuestUpdates(client);
  8335. }
  8336. else
  8337. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8338. return 0;
  8339. }
  8340. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8341. if (!lua_interface)
  8342. return 0;
  8343. Quest* quest = lua_interface->GetQuest(state, 1);
  8344. int32 step = lua_interface->GetInt32Value(state, 2);
  8345. string desc = lua_interface->GetStringValue(state, 3);
  8346. string task_group = lua_interface->GetStringValue(state, 4);
  8347. if (!quest) {
  8348. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8349. return 0;
  8350. }
  8351. if (step == 0) {
  8352. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8353. return 0;
  8354. }
  8355. QuestStep* quest_step = quest->GetQuestStep(step);
  8356. if (!quest_step) {
  8357. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8358. return 0;
  8359. }
  8360. quest_step->SetStepProgress(0);
  8361. quest_step->SetTaskGroup(task_group);
  8362. quest_step->SetDescription(desc);
  8363. return 0;
  8364. }
  8365. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8366. if (!lua_interface)
  8367. return 0;
  8368. Quest* quest = lua_interface->GetQuest(state);
  8369. int32 step = lua_interface->GetInt32Value(state, 2);
  8370. string action = lua_interface->GetStringValue(state, 3);
  8371. if (!quest) {
  8372. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8373. return 0;
  8374. }
  8375. if (step == 0) {
  8376. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8377. return 0;
  8378. }
  8379. if (action.length() == 0) {
  8380. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8381. return 0;
  8382. }
  8383. quest->AddFailedAction(step, action);
  8384. return 0;
  8385. }
  8386. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8387. if (!lua_interface)
  8388. return 0;
  8389. Spawn* player = lua_interface->GetSpawn(state);
  8390. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8391. int32 step = lua_interface->GetInt32Value(state, 3);
  8392. if (!player) {
  8393. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8394. return 0;
  8395. }
  8396. if (!player->IsPlayer()) {
  8397. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8398. return 0;
  8399. }
  8400. if (quest_id == 0) {
  8401. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8402. return 0;
  8403. }
  8404. if (step == 0) {
  8405. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8406. return 0;
  8407. }
  8408. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8409. if (!quest) {
  8410. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8411. return 0;
  8412. }
  8413. quest->StepFailed(step);
  8414. return 0;
  8415. }
  8416. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8417. if (!lua_interface)
  8418. return 0;
  8419. Spawn* player = lua_interface->GetSpawn(state);
  8420. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8421. if (!player) {
  8422. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. if (!player->IsPlayer()) {
  8426. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8427. return 0;
  8428. }
  8429. if (quest_id == 0) {
  8430. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8431. return 0;
  8432. }
  8433. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8434. if (!quest) {
  8435. lua_interface->SetInt32Value(state, 0);
  8436. return 1;
  8437. }
  8438. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8439. return 1;
  8440. }
  8441. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8442. if (!lua_interface)
  8443. return 0;
  8444. string name = lua_interface->GetStringValue(state);
  8445. string value = lua_interface->GetStringValue(state, 2);
  8446. string comment = lua_interface->GetStringValue(state, 3);
  8447. if (name.length() == 0) {
  8448. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8449. return 0;
  8450. }
  8451. if (value.length() == 0) {
  8452. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8453. return 0;
  8454. }
  8455. string varname = string("lua_").append(name);
  8456. Variable* var = variables.FindVariable(varname);
  8457. if (var)
  8458. var->SetValue(value.c_str());
  8459. else {
  8460. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8461. variables.AddVariable(var);
  8462. }
  8463. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8464. return 0;
  8465. }
  8466. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8467. if (!lua_interface)
  8468. return 0;
  8469. string name = lua_interface->GetStringValue(state);
  8470. if (name.length() == 0) {
  8471. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8472. return 0;
  8473. }
  8474. string varname = string("lua_").append(name);
  8475. Variable* var = variables.FindVariable(varname);
  8476. if (var)
  8477. lua_interface->SetStringValue(state, var->GetValue());
  8478. else
  8479. lua_interface->SetStringValue(state, "NULL");
  8480. return 1;
  8481. }
  8482. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8483. if (!lua_interface)
  8484. return 0;
  8485. Spawn* player = lua_interface->GetSpawn(state);
  8486. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8487. if (!player) {
  8488. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8489. return 0;
  8490. }
  8491. if (!player->IsPlayer()) {
  8492. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8493. return 0;
  8494. }
  8495. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8496. return 1;
  8497. }
  8498. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8499. if (!lua_interface)
  8500. return 0;
  8501. Spawn* player = lua_interface->GetSpawn(state);
  8502. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8503. if (!player) {
  8504. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8505. return 0;
  8506. }
  8507. if (!player->IsPlayer()) {
  8508. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8509. return 0;
  8510. }
  8511. Language* language = master_languages_list.GetLanguage(language_id);
  8512. if (language)
  8513. {
  8514. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8515. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8516. }
  8517. return 0;
  8518. }
  8519. int EQ2Emu_lua_IsNight(lua_State* state) {
  8520. if (!lua_interface)
  8521. return 0;
  8522. ZoneServer* zone = lua_interface->GetZone(state);
  8523. if (!zone) {
  8524. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8525. return 0;
  8526. }
  8527. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8528. return 1;
  8529. }
  8530. int EQ2Emu_lua_AddMultiFloorLift(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 AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. if (!spawn->IsWidget()) {
  8539. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8540. return 0;
  8541. }
  8542. ((Widget*)spawn)->SetMultiFloorLift(true);
  8543. if (spawn->GetZone())
  8544. spawn->GetZone()->AddTransportSpawn(spawn);
  8545. return 0;
  8546. }
  8547. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8548. if (!lua_interface)
  8549. return 0;
  8550. Spawn* player = lua_interface->GetSpawn(state);
  8551. int32 path = lua_interface->GetInt32Value(state, 2);
  8552. if (!player) {
  8553. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8554. return 0;
  8555. }
  8556. if (!player->IsPlayer()) {
  8557. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8558. return 0;
  8559. }
  8560. if (path == 0) {
  8561. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8562. return 0;
  8563. }
  8564. Client* client = player->GetZone()->GetClientBySpawn(player);
  8565. if (!client) {
  8566. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8567. return 0;
  8568. }
  8569. client->SendFlightAutoMount(path);
  8570. return 0;
  8571. }
  8572. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8573. if (!lua_interface)
  8574. return 0;
  8575. Spawn* player = lua_interface->GetSpawn(state);
  8576. if (!player) {
  8577. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8578. return 0;
  8579. }
  8580. if (!player->IsPlayer()) {
  8581. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8582. return 0;
  8583. }
  8584. Client* client = player->GetZone()->GetClientBySpawn(player);
  8585. if (!client) {
  8586. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8587. return 0;
  8588. }
  8589. client->EndAutoMount();
  8590. return 0;
  8591. }
  8592. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8593. if (!lua_interface)
  8594. return 0;
  8595. Spawn* player = lua_interface->GetSpawn(state);
  8596. if (!player) {
  8597. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8598. return 0;
  8599. }
  8600. if (!player->IsPlayer()) {
  8601. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8602. return 0;
  8603. }
  8604. Client* client = player->GetZone()->GetClientBySpawn(player);
  8605. if (!client) {
  8606. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8607. return 0;
  8608. }
  8609. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8610. return 1;
  8611. }
  8612. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8613. if (!lua_interface)
  8614. return 0;
  8615. Spawn* player = lua_interface->GetSpawn(state);
  8616. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8617. int32 value = lua_interface->GetInt32Value(state, 3);
  8618. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8619. if (!player) {
  8620. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8621. return 0;
  8622. }
  8623. if (!player->IsPlayer()) {
  8624. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8625. return 0;
  8626. }
  8627. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8628. return 0;
  8629. }
  8630. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8631. if (!lua_interface)
  8632. return 0;
  8633. Spawn* player = lua_interface->GetSpawn(state);
  8634. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8635. if (!player) {
  8636. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8637. return 0;
  8638. }
  8639. if (!player->IsPlayer()) {
  8640. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8641. return 0;
  8642. }
  8643. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8644. if (!hd)
  8645. return 0;
  8646. lua_interface->SetInt32Value(state, hd->Value);
  8647. lua_interface->SetInt32Value(state, hd->Value2);
  8648. return 2;
  8649. }
  8650. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8651. if (!lua_interface)
  8652. return 0;
  8653. Spawn* spawn = lua_interface->GetSpawn(state);
  8654. int32 grid = lua_interface->GetInt32Value(state, 2);
  8655. if (!spawn) {
  8656. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8657. return 0;
  8658. }
  8659. if (grid == 0) {
  8660. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8661. return 0;
  8662. }
  8663. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8664. return 0;
  8665. }
  8666. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8667. if (!lua_interface)
  8668. return 0;
  8669. Spawn* spawn = lua_interface->GetSpawn(state);
  8670. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8671. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8672. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8673. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8674. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8675. if (!spawn) {
  8676. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8677. return 0;
  8678. }
  8679. //Add this quest to the list of required quests for this spawn
  8680. spawn->SetRequiredHistory(event_id, value1, value2);
  8681. //If private spawn value set
  8682. if (private_spawn) {
  8683. //Set the spawn to be private when not granted access via history
  8684. spawn->AddAllowAccessSpawn(spawn);
  8685. spawn->SetPrivateQuestSpawn(true);
  8686. }
  8687. //This value will override vis_flags in the vis packet
  8688. if (flag_override > 0)
  8689. spawn->SetQuestsRequiredOverride(flag_override);
  8690. return 0;
  8691. }
  8692. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8693. if (!lua_interface)
  8694. return 0;
  8695. Spawn* player = lua_interface->GetSpawn(state);
  8696. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8697. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8698. if (!player) {
  8699. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8700. return 0;
  8701. }
  8702. if (!player->IsPlayer()) {
  8703. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8704. return 0;
  8705. }
  8706. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8707. return 1;
  8708. }
  8709. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8710. if (!lua_interface)
  8711. return 0;
  8712. Spawn* player = lua_interface->GetSpawn(state);
  8713. int8 level = lua_interface->GetInt8Value(state, 2);
  8714. if (!player) {
  8715. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8716. return 0;
  8717. }
  8718. if (!player->IsPlayer()) {
  8719. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8720. return 0;
  8721. }
  8722. if (level == 0) {
  8723. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8724. return 0;
  8725. }
  8726. Client* client = player->GetZone()->GetClientBySpawn(player);
  8727. if (!client) {
  8728. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8729. return 0;
  8730. }
  8731. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8732. return 0;
  8733. }
  8734. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8735. if (!lua_interface)
  8736. return 0;
  8737. Spawn* player = lua_interface->GetSpawn(state);
  8738. int32 amount = lua_interface->GetInt32Value(state, 2);
  8739. if (!player) {
  8740. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8741. return 0;
  8742. }
  8743. if (!player->IsPlayer()) {
  8744. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8745. return 0;
  8746. }
  8747. if (amount == 0) {
  8748. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8749. return 0;
  8750. }
  8751. ((Player*)player)->AddCoins(amount);
  8752. return 0;
  8753. }
  8754. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8755. if (!lua_interface)
  8756. return 0;
  8757. Spawn* player = lua_interface->GetSpawn(state);
  8758. int32 amount = lua_interface->GetInt32Value(state, 2);
  8759. if (!player) {
  8760. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8761. return 0;
  8762. }
  8763. if (!player->IsPlayer()) {
  8764. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8765. return 0;
  8766. }
  8767. if (amount == 0) {
  8768. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8769. return 0;
  8770. }
  8771. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8772. return 1;
  8773. }
  8774. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8775. if (!lua_interface)
  8776. return 0;
  8777. ZoneServer* zone = lua_interface->GetZone(state);
  8778. if (!zone) {
  8779. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8780. return 0;
  8781. }
  8782. vector<Entity*> players = zone->GetPlayers();
  8783. if (players.size() == 0)
  8784. return 0;
  8785. lua_createtable(state, players.size(), 0);
  8786. int newTable = lua_gettop(state);
  8787. for (int32 i = 0; i < players.size(); i++) {
  8788. lua_interface->SetSpawnValue(state, players.at(i));
  8789. lua_rawseti(state, newTable, i + 1);
  8790. }
  8791. return 1;
  8792. }
  8793. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8794. if (!lua_interface)
  8795. return 0;
  8796. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8797. if (!zone) {
  8798. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8799. return 0;
  8800. }
  8801. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8802. //Map of <placement_id, location_id>
  8803. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8804. map<int32, int32>::iterator itr;
  8805. vector<Spawn*> group;
  8806. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8807. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8808. if (!location) {
  8809. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8810. return 0;
  8811. }
  8812. Spawn* spawn = 0;
  8813. if (location->entities[0]) {
  8814. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8815. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8816. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8817. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8818. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8819. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8820. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8821. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8822. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8823. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8824. if(spawn && spawn->IsOmittedByDBFlag())
  8825. {
  8826. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  8827. safe_delete(spawn);
  8828. continue;
  8829. }
  8830. if (spawn) {
  8831. const char* script = 0;
  8832. for (int x = 0; x < 3; x++) {
  8833. switch (x) {
  8834. case 0:
  8835. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8836. break;
  8837. case 1:
  8838. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8839. break;
  8840. case 2:
  8841. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8842. break;
  8843. }
  8844. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8845. spawn->SetSpawnScript(string(script));
  8846. break;
  8847. }
  8848. }
  8849. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8850. lua_interface->SetSpawnValue(state, spawn);
  8851. group.push_back(spawn);
  8852. }
  8853. else {
  8854. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  8855. safe_delete(spawn);
  8856. }
  8857. }
  8858. }
  8859. if (!group.empty()) {
  8860. lua_createtable(state, group.size(), 0);
  8861. int newTable = lua_gettop(state);
  8862. for (int32 i = 0; i < group.size(); i++) {
  8863. lua_interface->SetSpawnValue(state, group[i]);
  8864. lua_rawseti(state, newTable, i + 1);
  8865. }
  8866. }
  8867. else
  8868. lua_pushnil(state);
  8869. return 1;
  8870. }
  8871. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8872. if (!lua_interface)
  8873. return 0;
  8874. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8875. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8876. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8877. if (!spawn) {
  8878. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8879. return 0;
  8880. }
  8881. if (anim_id == 0) {
  8882. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8883. return 0;
  8884. }
  8885. if (leeway == 0)
  8886. leeway = 5000;
  8887. spawn->SetSpawnAnim(anim_id);
  8888. spawn->SetSpawnAnimLeeway(leeway);
  8889. return 0;
  8890. }
  8891. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8892. if (!lua_interface)
  8893. return 0;
  8894. Spawn* player = lua_interface->GetSpawn(state);
  8895. if (!player) {
  8896. return 0;
  8897. }
  8898. Client* client = player->GetZone()->GetClientBySpawn(player);
  8899. if (!client) {
  8900. return 0;
  8901. }
  8902. lua_interface->SetInt32Value(state, client->GetVersion());
  8903. return 1;
  8904. }
  8905. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8906. if (!lua_interface)
  8907. return 0;
  8908. Item* item = lua_interface->GetItem(state);
  8909. if (!item) {
  8910. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8911. return 0;
  8912. }
  8913. lua_interface->SetInt32Value(state, item->details.item_id);
  8914. return 1;
  8915. }
  8916. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8917. if (!lua_interface)
  8918. return 0;
  8919. Spawn* spawn = lua_interface->GetSpawn(state);
  8920. if (!spawn) {
  8921. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8922. return 0;
  8923. }
  8924. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8925. return 1;
  8926. }
  8927. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8928. if (!lua_interface)
  8929. return 0;
  8930. Spawn* spawn = lua_interface->GetSpawn(state);
  8931. if (!spawn) {
  8932. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8933. return 0;
  8934. }
  8935. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8936. return 1;
  8937. }
  8938. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8939. if (!lua_interface)
  8940. return 0;
  8941. Spawn* spawn = lua_interface->GetSpawn(state);
  8942. if (!spawn) {
  8943. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8944. return 0;
  8945. }
  8946. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8947. return 1;
  8948. }
  8949. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8950. if (!lua_interface)
  8951. return 0;
  8952. Spawn* spawn = lua_interface->GetSpawn(state);
  8953. if (!spawn) {
  8954. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8955. return 0;
  8956. }
  8957. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8958. return 1;
  8959. }
  8960. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8961. if (!lua_interface)
  8962. return 0;
  8963. Spawn* spawn = lua_interface->GetSpawn(state);
  8964. float pct = lua_interface->GetFloatValue(state, 2);
  8965. if (!spawn) {
  8966. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8967. return 0;
  8968. }
  8969. if (pct == 0) {
  8970. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8971. return 0;
  8972. }
  8973. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8974. lua_interface->SetInt32Value(state, amount);
  8975. return 1;
  8976. }
  8977. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8978. if (!lua_interface)
  8979. return 0;
  8980. Spawn* spawn = lua_interface->GetSpawn(state);
  8981. float pct = lua_interface->GetFloatValue(state, 2);
  8982. if (!spawn) {
  8983. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8984. return 0;
  8985. }
  8986. if (pct == 0) {
  8987. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8988. return 0;
  8989. }
  8990. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8991. lua_interface->SetInt32Value(state, amount);
  8992. return 1;
  8993. }
  8994. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8995. if (!lua_interface)
  8996. return 0;
  8997. Spawn* spawn = lua_interface->GetSpawn(state);
  8998. if (!spawn) {
  8999. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9000. return 0;
  9001. }
  9002. if (!spawn->IsPlayer()) {
  9003. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9004. return 0;
  9005. }
  9006. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9007. return 1;
  9008. }
  9009. int EQ2Emu_lua_Evac(lua_State* state) {
  9010. if (!lua_interface)
  9011. return 0;
  9012. Spawn* target = lua_interface->GetSpawn(state);
  9013. if (target) {
  9014. float x = target->GetZone()->GetSafeX();
  9015. float y = target->GetZone()->GetSafeY();
  9016. float z = target->GetZone()->GetSafeZ();
  9017. float h = target->GetZone()->GetSafeHeading();
  9018. target->SetX(x);
  9019. target->SetY(y);
  9020. target->SetZ(z);
  9021. target->SetHeading(h);
  9022. target->SetSpawnOrigX(target->GetX());
  9023. target->SetSpawnOrigY(target->GetY());
  9024. target->SetSpawnOrigZ(target->GetZ());
  9025. target->SetSpawnOrigHeading(target->GetHeading());
  9026. if (target->IsPlayer()) {
  9027. Client* client = target->GetZone()->GetClientBySpawn(target);
  9028. if (client) {
  9029. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9030. if (packet)
  9031. {
  9032. packet->setDataByName("x", x);
  9033. packet->setDataByName("y", y);
  9034. packet->setDataByName("z", z);
  9035. client->QueuePacket(packet->serialize());
  9036. safe_delete(packet);
  9037. }
  9038. }
  9039. }
  9040. }
  9041. else {
  9042. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9043. ZoneServer* zone = spell->caster->GetZone();
  9044. float x = spell->caster->GetZone()->GetSafeX();
  9045. float y = spell->caster->GetZone()->GetSafeY();
  9046. float z = spell->caster->GetZone()->GetSafeZ();
  9047. float h = spell->caster->GetZone()->GetSafeHeading();
  9048. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9049. for (int32 i = 0; i < spell->targets.size(); i++) {
  9050. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9051. if (!target2)
  9052. continue;
  9053. target2->SetX(x);
  9054. target2->SetY(y);
  9055. target2->SetZ(z);
  9056. target2->SetHeading(h);
  9057. target2->SetSpawnOrigX(target2->GetX());
  9058. target2->SetSpawnOrigY(target2->GetY());
  9059. target2->SetSpawnOrigZ(target2->GetZ());
  9060. target2->SetSpawnOrigHeading(target2->GetHeading());
  9061. if (target2->IsPlayer()) {
  9062. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9063. if (client) {
  9064. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9065. if (packet)
  9066. {
  9067. client->SetReloadingZone(true);
  9068. packet->setDataByName("x", x);
  9069. packet->setDataByName("y", y);
  9070. packet->setDataByName("z", z);
  9071. client->QueuePacket(packet->serialize());
  9072. safe_delete(packet);
  9073. }
  9074. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9075. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  9076. }
  9077. }
  9078. }
  9079. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9080. }
  9081. return 0;
  9082. }
  9083. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9084. if (!lua_interface)
  9085. return 0;
  9086. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9087. if (!luaspell) {
  9088. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9089. return 0;
  9090. }
  9091. int8 tier = luaspell->spell->GetSpellTier();
  9092. lua_interface->SetInt32Value(state, tier);
  9093. return 1;
  9094. }
  9095. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9096. if (!lua_interface)
  9097. return 0;
  9098. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9099. if (!luaspell) {
  9100. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9101. return 0;
  9102. }
  9103. int32 spell_id = luaspell->spell->GetSpellID();
  9104. lua_interface->SetInt32Value(state, spell_id);
  9105. return 1;
  9106. }
  9107. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9108. if (!lua_interface)
  9109. return 0;
  9110. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9111. if (!spawn) {
  9112. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9113. return 0;
  9114. }
  9115. if (!spawn->IsPlayer()) {
  9116. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9117. return 0;
  9118. }
  9119. ZoneServer* zone = spawn->GetZone();
  9120. if (!zone) {
  9121. return 0;
  9122. }
  9123. Client* client = zone->GetClientBySpawn(spawn);
  9124. if (!client) {
  9125. return 0;
  9126. }
  9127. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9128. return 0;
  9129. }
  9130. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9131. if (!lua_interface)
  9132. return 0;
  9133. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9134. if (!spawn) {
  9135. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9136. return 0;
  9137. }
  9138. if (!spawn->IsPlayer()) {
  9139. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9140. return 0;
  9141. }
  9142. ZoneServer* zone = spawn->GetZone();
  9143. if (!zone) {
  9144. return 0;
  9145. }
  9146. Client* client = zone->GetClientBySpawn(spawn);
  9147. if (!client) {
  9148. return 0;
  9149. }
  9150. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9151. return 0;
  9152. }
  9153. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9154. if (!lua_interface)
  9155. return 0;
  9156. Spawn* caster = lua_interface->GetSpawn(state);
  9157. Spawn* target = lua_interface->GetSpawn(state, 2);
  9158. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9159. string spell_name = lua_interface->GetStringValue(state, 4);
  9160. if (!caster) {
  9161. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9162. return 0;
  9163. }
  9164. if (!caster->IsEntity()) {
  9165. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9166. return 0;
  9167. }
  9168. if (!target) {
  9169. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9170. return 0;
  9171. }
  9172. if (!target->IsEntity()) {
  9173. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9174. return 0;
  9175. }
  9176. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9177. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9178. return 0;
  9179. }
  9180. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9181. if (!lua_interface)
  9182. return 0;
  9183. Spawn* player = lua_interface->GetSpawn(state);
  9184. int32 amount = lua_interface->GetInt32Value(state, 2);
  9185. if (player && player->IsPlayer() && amount > 0) {
  9186. ((Player*)player)->AddXP(amount);
  9187. ((Player*)player)->SetCharSheetChanged(true);
  9188. Client* client = player->GetZone()->GetClientBySpawn(player);
  9189. if (client) {
  9190. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9191. }
  9192. }
  9193. return 0;
  9194. }
  9195. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9196. if (!lua_interface)
  9197. return 0;
  9198. Spawn* player = lua_interface->GetSpawn(state);
  9199. int8 type = lua_interface->GetInt8Value(state, 2);
  9200. string text = lua_interface->GetStringValue(state, 3);
  9201. Client* client = 0;
  9202. if (player && player->IsPlayer())
  9203. client = player->GetZone()->GetClientBySpawn(player);
  9204. if (!client || text.length() == 0) {
  9205. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9206. return 0;
  9207. }
  9208. client->SimpleMessage(type, text.c_str());
  9209. return 0;
  9210. }
  9211. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9212. if (!lua_interface)
  9213. return 0;
  9214. Spawn* player = lua_interface->GetSpawn(state);
  9215. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9216. Client* client = 0;
  9217. if (player && player->IsPlayer())
  9218. client = player->GetZone()->GetClientBySpawn(player);
  9219. if (!client || !spawn) {
  9220. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9221. return 0;
  9222. }
  9223. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9224. if (!items) {
  9225. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9226. return 0;
  9227. }
  9228. client->Loot(spawn->GetLootCoins(), items, spawn);
  9229. return 0;
  9230. }
  9231. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9232. if (!lua_interface)
  9233. return 0;
  9234. Spawn* spawnref = lua_interface->GetSpawn(state);
  9235. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9236. if (spawn_id > 0 && spawnref) {
  9237. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9238. if (spawns.size() == 0) {
  9239. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9240. return 0;
  9241. }
  9242. Spawn* spawn = 0;
  9243. int16 index = MakeRandomInt(0, spawns.size());
  9244. if (index >= spawns.size() || index < 0)
  9245. index = 0;
  9246. spawn = spawns[index];
  9247. lua_interface->SetSpawnValue(state, spawn);
  9248. return 1;
  9249. }
  9250. else {
  9251. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9252. }
  9253. return 0;
  9254. }
  9255. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9256. Spawn* player = lua_interface->GetSpawn(state);
  9257. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9258. string name = lua_interface->GetStringValue(state, 3);
  9259. float distance = lua_interface->GetFloatValue(state, 4);
  9260. string command = lua_interface->GetStringValue(state, 5);
  9261. string error_text = lua_interface->GetStringValue(state, 6);
  9262. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9263. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9264. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9265. if (distance == 0)
  9266. distance = 10.0f;
  9267. if (command.length() == 0)
  9268. command = name;
  9269. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9270. if (spawns.size() == 0) {
  9271. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9272. return 0;
  9273. }
  9274. Spawn* spawn = 0;
  9275. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9276. spawn = *itr;
  9277. if (spawn) {
  9278. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9279. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9280. }
  9281. }
  9282. }
  9283. return 0;
  9284. }
  9285. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9286. if (!lua_interface)
  9287. return 0;
  9288. Client* client = 0;
  9289. Spawn* player = lua_interface->GetSpawn(state);
  9290. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9291. if (player && player->IsPlayer() && player->GetZone())
  9292. client = player->GetZone()->GetClientBySpawn(player);
  9293. else{
  9294. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9295. return 0;
  9296. }
  9297. if (client) {
  9298. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9299. if (packet) {
  9300. packet->setDataByName("goal_num", goal_num);
  9301. client->QueuePacket(packet->serialize());
  9302. safe_delete(packet);
  9303. }
  9304. }
  9305. return 0;
  9306. }
  9307. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9308. if (!lua_interface)
  9309. return 0;
  9310. Client* client = 0;
  9311. Spawn* player = lua_interface->GetSpawn(state);
  9312. if (player && player->IsPlayer() && player->GetZone())
  9313. client = player->GetZone()->GetClientBySpawn(player);
  9314. else {
  9315. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9316. return 0;
  9317. }
  9318. if (client) {
  9319. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9320. }
  9321. return 0;
  9322. }
  9323. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9324. if (!lua_interface)
  9325. return 0;
  9326. Client* client = 0;
  9327. Spawn* player = lua_interface->GetSpawn(state);
  9328. float duration = lua_interface->GetFloatValue(state, 2);
  9329. string text = lua_interface->GetStringValue(state, 3);
  9330. string voice = lua_interface->GetStringValue(state, 4);
  9331. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9332. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9333. string signal = lua_interface->GetStringValue(state, 7);
  9334. string goal1 = lua_interface->GetStringValue(state, 8);
  9335. string task1 = lua_interface->GetStringValue(state, 9);
  9336. string goal2 = lua_interface->GetStringValue(state, 10);
  9337. string task2 = lua_interface->GetStringValue(state, 11);
  9338. string goal3 = lua_interface->GetStringValue(state, 12);
  9339. string task3 = lua_interface->GetStringValue(state, 13);
  9340. string goal4 = lua_interface->GetStringValue(state, 14);
  9341. string task4 = lua_interface->GetStringValue(state, 15);
  9342. if (!player) {
  9343. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9344. return 0;
  9345. }
  9346. if (!player->IsPlayer()) {
  9347. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9348. return 0;
  9349. }
  9350. else
  9351. client = ((Player*)player)->GetClient();
  9352. if (!client) {
  9353. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9354. return 0;
  9355. }
  9356. if (text.length() == 0) {
  9357. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9358. return 0;
  9359. }
  9360. if (duration >= 0 && duration < 2)
  9361. duration = 2;
  9362. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9363. if (packet) {
  9364. packet->setDataByName("open_seconds_max", duration);
  9365. packet->setDataByName("text", text.c_str());
  9366. packet->setDataByName("voice", voice.c_str());
  9367. int8 num_goals = 1;
  9368. if (task2.length() > 0)
  9369. num_goals++;
  9370. if (task3.length() > 0)
  9371. num_goals++;
  9372. if (task4.length() > 0)
  9373. num_goals++;
  9374. packet->setArrayLengthByName("num_goals", num_goals);
  9375. for (int8 i = 0; i < num_goals; i++) {
  9376. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9377. }
  9378. if (goal1.length() > 0)
  9379. packet->setArrayDataByName("goal_text", goal1.c_str());
  9380. if (goal2.length() > 0)
  9381. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9382. if (goal3.length() > 0)
  9383. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9384. if (goal4.length() > 0)
  9385. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9386. packet->setSubArrayDataByName("task_text", task1.c_str());
  9387. if (task2.length() > 0)
  9388. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9389. if (task3.length() > 0)
  9390. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9391. if (task4.length() > 0)
  9392. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9393. packet->setDataByName("complete_sound", "click");
  9394. packet->setDataByName("signal", signal.c_str());
  9395. packet->setDataByName("voice_key1", voice_key1);
  9396. packet->setDataByName("voice_key2", voice_key2);
  9397. client->QueuePacket(packet->serialize());
  9398. safe_delete(packet);
  9399. }
  9400. return 0;
  9401. }
  9402. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9403. if (!lua_interface)
  9404. return 0;
  9405. Client* client = 0;
  9406. Spawn* player = lua_interface->GetSpawn(state);
  9407. string window = lua_interface->GetStringValue(state, 2);
  9408. int8 show = lua_interface->GetInt8Value(state, 3);
  9409. if (!player) {
  9410. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9411. return 0;
  9412. }
  9413. if (!player->IsPlayer()) {
  9414. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9415. return 0;
  9416. }
  9417. else
  9418. client = ((Player*)player)->GetClient();
  9419. if (!client) {
  9420. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9421. return 0;
  9422. }
  9423. if (window.length() == 0) {
  9424. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9425. return 0;
  9426. }
  9427. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9428. if (packet) {
  9429. packet->setDataByName("window", window.c_str());
  9430. packet->setDataByName("show", show);
  9431. client->QueuePacket(packet->serialize());
  9432. safe_delete(packet);
  9433. }
  9434. return 0;
  9435. }
  9436. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9437. //See GameEvents.txt for options that can be used for this function
  9438. if (!lua_interface)
  9439. return 0;
  9440. Client* client = 0;
  9441. Spawn* player = lua_interface->GetSpawn(state);
  9442. string event_name = lua_interface->GetStringValue(state, 2);
  9443. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9444. if (!player || !player->IsPlayer()) {
  9445. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9446. return 0;
  9447. }
  9448. if (player->GetZone())
  9449. client = player->GetZone()->GetClientBySpawn(player);
  9450. if (!client) {
  9451. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9452. return 0;
  9453. }
  9454. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9455. if (packet) {
  9456. packet->setDataByName("event_name", event_name.c_str());
  9457. packet->setDataByName("enabled", enabled);
  9458. client->QueuePacket(packet->serialize());
  9459. safe_delete(packet);
  9460. }
  9461. return 0;
  9462. }
  9463. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9464. if (!lua_interface)
  9465. return 0;
  9466. Spawn* player = lua_interface->GetSpawn(state);
  9467. if (player && player->IsPlayer()) {
  9468. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9469. return 1;
  9470. }
  9471. return 0;
  9472. }
  9473. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9474. if (!lua_interface)
  9475. return 0;
  9476. Spawn* player = lua_interface->GetSpawn(state);
  9477. int8 step = lua_interface->GetInt8Value(state, 2);
  9478. if (player && player->IsPlayer() && step > 0) {
  9479. ((Player*)player)->SetTutorialStep(step);
  9480. }
  9481. return 0;
  9482. }
  9483. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9484. if (!lua_interface)
  9485. return 0;
  9486. Client* client = 0;
  9487. Spawn* player = lua_interface->GetSpawn(state);
  9488. string window = lua_interface->GetStringValue(state, 2);
  9489. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9490. if (!player) {
  9491. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9492. return 0;
  9493. }
  9494. if (!player->IsPlayer()) {
  9495. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9496. return 0;
  9497. }
  9498. else
  9499. client = ((Player*)player)->GetClient();
  9500. if (!client) {
  9501. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9502. return 0;
  9503. }
  9504. if (window.length() == 0) {
  9505. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9506. return 0;
  9507. }
  9508. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9509. if (packet) {
  9510. packet->setDataByName("window", window.c_str());
  9511. packet->setDataByName("flash_seconds", flash_seconds);
  9512. client->QueuePacket(packet->serialize());
  9513. safe_delete(packet);
  9514. }
  9515. return 0;
  9516. }
  9517. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9518. if (!lua_interface)
  9519. return 0;
  9520. Spawn* spawn = lua_interface->GetSpawn(state);
  9521. Spawn* target = lua_interface->GetSpawn(state, 2);
  9522. if (spawn && target)
  9523. return spawn->CheckLoS(target);
  9524. return 0;
  9525. }
  9526. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9527. if (!lua_interface)
  9528. return 0;
  9529. Spawn* spawn = lua_interface->GetSpawn(state);
  9530. float x = lua_interface->GetFloatValue(state, 2);
  9531. float y = lua_interface->GetFloatValue(state, 3);
  9532. float z = lua_interface->GetFloatValue(state, 4);
  9533. if (spawn)
  9534. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9535. return 0;
  9536. }
  9537. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9538. if (!lua_interface)
  9539. return 0;
  9540. ZoneServer* zone = lua_interface->GetZone(state);
  9541. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9542. if (zone)
  9543. zone->SetExpansionFlag(xpackFlag);
  9544. return 0;
  9545. }
  9546. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9547. if (!lua_interface)
  9548. return 0;
  9549. ZoneServer* zone = lua_interface->GetZone(state);
  9550. if (zone) {
  9551. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9552. return 1;
  9553. }
  9554. return 0;
  9555. }
  9556. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9557. if (!lua_interface)
  9558. return 0;
  9559. ZoneServer* zone = lua_interface->GetZone(state);
  9560. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9561. if (zone)
  9562. zone->SetHolidayFlag(holidayFlag);
  9563. return 0;
  9564. }
  9565. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9566. if (!lua_interface)
  9567. return 0;
  9568. ZoneServer* zone = lua_interface->GetZone(state);
  9569. if (zone) {
  9570. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9571. return 1;
  9572. }
  9573. return 0;
  9574. }
  9575. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9576. if (!lua_interface)
  9577. return 0;
  9578. Spawn* spawn = lua_interface->GetSpawn(state);
  9579. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9580. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9581. float distance = lua_interface->GetFloatValue(state, 4);
  9582. string in_range_function = lua_interface->GetStringValue(state, 5);
  9583. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9584. if (spawn && distance > 0 && in_range_function.length() > 0)
  9585. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9586. return 0;
  9587. }
  9588. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9589. if (!lua_interface)
  9590. return 0;
  9591. Spawn* spawn = lua_interface->GetSpawn(state);
  9592. Spawn* target = lua_interface->GetSpawn(state, 2);
  9593. if (spawn && target)
  9594. {
  9595. if (spawn->IsPlayer() && target->IsEntity())
  9596. {
  9597. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9598. return 1;
  9599. }
  9600. else if (spawn->IsEntity() && target->IsEntity())
  9601. {
  9602. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9603. return 1;
  9604. }
  9605. }
  9606. return 0;
  9607. }
  9608. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9609. if (!lua_interface)
  9610. return 0;
  9611. Spawn* spawn = lua_interface->GetSpawn(state);
  9612. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9613. if (spawn && spawn->IsEntity())
  9614. {
  9615. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9616. if (spawn->IsPlayer())
  9617. {
  9618. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9619. if (client)
  9620. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9621. }
  9622. }
  9623. return 0;
  9624. }
  9625. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9626. if (!lua_interface)
  9627. return 0;
  9628. Spawn* spawn = lua_interface->GetSpawn(state);
  9629. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9630. if (spawn && spawn->IsEntity())
  9631. {
  9632. ((Entity*)spawn)->SetSeeHideSpell(val);
  9633. if (spawn->IsPlayer())
  9634. {
  9635. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9636. if (client)
  9637. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9638. }
  9639. }
  9640. return 0;
  9641. }
  9642. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9643. {
  9644. if (!lua_interface)
  9645. return 0;
  9646. Spawn* player = lua_interface->GetSpawn(state);
  9647. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9648. string command = lua_interface->GetStringValue(state, 3);
  9649. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9650. lua_interface->ResetFunctionStack(state);
  9651. if (spawn && player && player->IsPlayer())
  9652. {
  9653. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9654. bool res = false;
  9655. if (cmd)
  9656. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9657. lua_interface->SetBooleanValue(state, res);
  9658. return 1;
  9659. }
  9660. return 0;
  9661. }
  9662. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9663. {
  9664. if (!lua_interface)
  9665. return 0;
  9666. Spawn* spawn = lua_interface->GetSpawn(state);
  9667. int32 charID = lua_interface->GetInt32Value(state, 2);
  9668. string command = lua_interface->GetStringValue(state, 3);
  9669. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9670. lua_interface->ResetFunctionStack(state);
  9671. if (spawn && charID)
  9672. {
  9673. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9674. bool res = false;
  9675. if (cmd)
  9676. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9677. lua_interface->SetBooleanValue(state, res);
  9678. return 1;
  9679. }
  9680. return 0;
  9681. }
  9682. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9683. {
  9684. if (!lua_interface)
  9685. return 0;
  9686. Spawn* spawn = lua_interface->GetSpawn(state);
  9687. string command = lua_interface->GetStringValue(state, 2);
  9688. lua_interface->ResetFunctionStack(state);
  9689. if (spawn && command.length() > 0)
  9690. spawn->RemovePrimaryEntityCommand(command.c_str());
  9691. return 0;
  9692. }
  9693. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9694. if (!lua_interface)
  9695. return 0;
  9696. Spawn* spawn = lua_interface->GetSpawn(state);
  9697. float distance = lua_interface->GetFloatValue(state, 2);
  9698. string command = lua_interface->GetStringValue(state, 3);
  9699. Spawn* player = lua_interface->GetSpawn(state, 4);
  9700. lua_interface->ResetFunctionStack(state);
  9701. if (spawn) {
  9702. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9703. }
  9704. return 0;
  9705. }
  9706. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9707. if (!lua_interface)
  9708. return 0;
  9709. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9710. Spawn* spawn = lua_interface->GetSpawn(state);
  9711. Spawn* player = lua_interface->GetSpawn(state, 2);
  9712. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9713. lua_interface->ResetFunctionStack(state);
  9714. if (spawn && player && transport_id && player->IsPlayer()) {
  9715. Client* client = 0;
  9716. if (player && player->IsPlayer())
  9717. client = player->GetZone()->GetClientBySpawn(player);
  9718. if (!client)
  9719. return 0;
  9720. vector<TransportDestination*> destinations;
  9721. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9722. if (destinations.size())
  9723. {
  9724. client->SetTemporaryTransportID(transport_id);
  9725. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9726. }
  9727. else
  9728. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9729. }
  9730. return 0;
  9731. }
  9732. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9733. if (!lua_interface)
  9734. return 0;
  9735. Spawn* player = lua_interface->GetSpawn(state);
  9736. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9737. lua_interface->ResetFunctionStack(state);
  9738. if (player && player->IsPlayer()) {
  9739. Client* client = 0;
  9740. if (player && player->IsPlayer())
  9741. client = player->GetZone()->GetClientBySpawn(player);
  9742. if (!client)
  9743. return 0;
  9744. client->SetTemporaryTransportID(transport_id);
  9745. }
  9746. return 0;
  9747. }
  9748. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9749. if (!lua_interface)
  9750. return 0;
  9751. Spawn* player = lua_interface->GetSpawn(state);
  9752. lua_interface->ResetFunctionStack(state);
  9753. if (player && player->IsPlayer()) {
  9754. Client* client = 0;
  9755. if (player && player->IsPlayer())
  9756. client = player->GetZone()->GetClientBySpawn(player);
  9757. if (!client)
  9758. return 0;
  9759. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9760. return 1;
  9761. }
  9762. return 0;
  9763. }
  9764. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9765. if (!lua_interface)
  9766. return 0;
  9767. Spawn* spawn = lua_interface->GetSpawn(state);
  9768. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9769. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9770. if (!spawn) {
  9771. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9772. return 0;
  9773. }
  9774. if (!spawn->IsEntity()) {
  9775. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9776. return 0;
  9777. }
  9778. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9779. {
  9780. 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);
  9781. return 0;
  9782. }
  9783. lua_interface->ResetFunctionStack(state);
  9784. if (spell && spell->targets.size() > 0) {
  9785. ZoneServer* zone = spell->caster->GetZone();
  9786. for (int8 i = 0; i < spell->targets.size(); i++) {
  9787. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9788. if (target && target->IsEntity()) {
  9789. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9790. if (target->IsPlayer())
  9791. ((Player*)target)->SetCharSheetChanged(true);
  9792. }
  9793. }
  9794. }
  9795. else {
  9796. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9797. if (spawn->IsPlayer())
  9798. ((Player*)spawn)->SetCharSheetChanged(true);
  9799. }
  9800. return 0;
  9801. }
  9802. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9803. if (!lua_interface)
  9804. return 0;
  9805. Spawn* spawn = lua_interface->GetSpawn(state);
  9806. lua_interface->ResetFunctionStack(state);
  9807. if (!spawn) {
  9808. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9809. return 0;
  9810. }
  9811. if (!spawn->IsEntity()) {
  9812. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9813. return 0;
  9814. }
  9815. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9816. return 1;
  9817. }
  9818. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9819. if (!lua_interface)
  9820. return 0;
  9821. int32 spell_id = lua_interface->GetInt32Value(state);
  9822. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9823. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9824. if (spell_id > 0) {
  9825. if (spell_tier == 0)
  9826. spell_tier = 1;
  9827. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9828. LuaSpell* lua_spell = 0;
  9829. if(custom_lua_script.size() > 0)
  9830. {
  9831. // attempt to load the custom script since it isn't already loaded
  9832. // we will re-obtain the lua_spell further below
  9833. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9834. {
  9835. LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
  9836. lua_interface->LoadLuaSpell(custom_lua_script);
  9837. }
  9838. }
  9839. else
  9840. custom_lua_script = spell->GetSpellData()->lua_script;
  9841. if (!lua_spell && lua_interface)
  9842. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9843. if (!lua_spell)
  9844. {
  9845. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9846. return 0;
  9847. }
  9848. lua_spell->spell = new Spell(spell);
  9849. lua_interface->AddCustomSpell(lua_spell);
  9850. lua_interface->SetSpellValue(state, lua_spell);
  9851. return 1;
  9852. }
  9853. return 0;
  9854. }
  9855. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9856. if (!lua_interface)
  9857. return 0;
  9858. LuaSpell* spell = lua_interface->GetSpell(state);
  9859. string field = lua_interface->GetStringValue(state, 2);
  9860. if (!spell) {
  9861. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9862. return 0;
  9863. }
  9864. if (!spell->spell || !spell->spell->GetSpellData()) {
  9865. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9866. return 0;
  9867. }
  9868. boost::to_lower(field);
  9869. return spell->spell->GetSpellData(state, field);
  9870. }
  9871. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9872. if (!lua_interface)
  9873. return 0;
  9874. LuaSpell* spell = lua_interface->GetSpell(state);
  9875. string field = lua_interface->GetStringValue(state, 2);
  9876. int8 fieldArg = 3; // field value after the initial set
  9877. if (!spell) {
  9878. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9879. return 0;
  9880. }
  9881. if (!spell->spell || !spell->spell->GetSpellData()) {
  9882. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9883. return 0;
  9884. }
  9885. boost::to_lower(field);
  9886. bool valSet = false;
  9887. spell->spell->SetSpellData(state, field, fieldArg);
  9888. return valSet;
  9889. }
  9890. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9891. if (!lua_interface)
  9892. return 0;
  9893. LuaSpell* spell = lua_interface->GetSpell(state);
  9894. int8 idx = lua_interface->GetInt32Value(state, 2);
  9895. if (!spell) {
  9896. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9897. return 0;
  9898. }
  9899. if (!spell->spell || !spell->spell->GetSpellData()) {
  9900. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9901. return 0;
  9902. }
  9903. if (spell->spell->lua_data.size() <= idx)
  9904. {
  9905. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9906. return 0;
  9907. }
  9908. bool setVal = true;
  9909. LUAData* data = spell->spell->lua_data[idx];
  9910. switch (data->type)
  9911. {
  9912. case 0:
  9913. {
  9914. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9915. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9916. data->int_value = value;
  9917. data->int_value2 = value2;
  9918. break;
  9919. }
  9920. case 1:
  9921. {
  9922. float value = lua_interface->GetFloatValue(state, 3);
  9923. float value2 = lua_interface->GetFloatValue(state, 4);
  9924. data->float_value = value;
  9925. data->float_value2 = value2;
  9926. break;
  9927. }
  9928. case 2:
  9929. {
  9930. bool value = lua_interface->GetBooleanValue(state, 3);
  9931. data->bool_value = value;
  9932. break;
  9933. }
  9934. case 3:
  9935. {
  9936. string value = lua_interface->GetStringValue(state, 3);
  9937. string value2 = lua_interface->GetStringValue(state, 4);
  9938. data->string_value = value;
  9939. data->string_value2 = value2;
  9940. break;
  9941. }
  9942. default:
  9943. setVal = false;
  9944. }
  9945. return setVal;
  9946. }
  9947. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9948. if (!lua_interface)
  9949. return 0;
  9950. LuaSpell* spell = lua_interface->GetSpell(state);
  9951. int8 idx = lua_interface->GetInt32Value(state, 2);
  9952. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9953. if (!spell) {
  9954. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9955. return 0;
  9956. }
  9957. if (!spell->spell || !spell->spell->GetSpellData()) {
  9958. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9959. return 0;
  9960. }
  9961. if (spell->spell->lua_data.size() <= idx)
  9962. {
  9963. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9964. return 0;
  9965. }
  9966. bool setVal = true;
  9967. LUAData* data = spell->spell->lua_data[idx];
  9968. switch (data->type)
  9969. {
  9970. case 0:
  9971. {
  9972. if(!secondfield)
  9973. lua_interface->SetSInt32Value(state, data->int_value);
  9974. else
  9975. lua_interface->SetSInt32Value(state, data->int_value2);
  9976. break;
  9977. }
  9978. case 1:
  9979. {
  9980. if (!secondfield)
  9981. lua_interface->SetFloatValue(state, data->float_value);
  9982. else
  9983. lua_interface->SetFloatValue(state, data->float_value2);
  9984. break;
  9985. }
  9986. case 2:
  9987. {
  9988. lua_interface->SetBooleanValue(state, data->bool_value);
  9989. break;
  9990. }
  9991. case 3:
  9992. {
  9993. if (!secondfield)
  9994. lua_interface->SetStringValue(state, data->string_value.c_str());
  9995. else
  9996. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9997. break;
  9998. }
  9999. default:
  10000. setVal = false;
  10001. }
  10002. return setVal;
  10003. }
  10004. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10005. if (!lua_interface)
  10006. return 0;
  10007. LuaSpell* spell = lua_interface->GetSpell(state);
  10008. int8 idx = lua_interface->GetInt32Value(state, 2);
  10009. string field = lua_interface->GetStringValue(state, 3);
  10010. boost::to_lower(field);
  10011. if (!spell) {
  10012. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10013. return 0;
  10014. }
  10015. if (!spell->spell || !spell->spell->GetSpellData()) {
  10016. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10017. return 0;
  10018. }
  10019. if (spell->spell->effects.size() <= idx)
  10020. {
  10021. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10022. return 0;
  10023. }
  10024. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10025. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10026. if (field == "description")
  10027. effect->description = string(lua_interface->GetStringValue(state, 4));
  10028. else if (field == "bullet")
  10029. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10030. else if (field == "percentage")
  10031. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10032. else // no match
  10033. return 0;
  10034. return 1;
  10035. }
  10036. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10037. if (!lua_interface)
  10038. return 0;
  10039. LuaSpell* spell = lua_interface->GetSpell(state);
  10040. int8 idx = lua_interface->GetInt32Value(state, 2);
  10041. string field = lua_interface->GetStringValue(state, 3);
  10042. boost::to_lower(field);
  10043. if (!spell) {
  10044. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10045. return 0;
  10046. }
  10047. if (!spell->spell || !spell->spell->GetSpellData()) {
  10048. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10049. return 0;
  10050. }
  10051. if (spell->spell->effects.size() <= idx)
  10052. {
  10053. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10054. return 0;
  10055. }
  10056. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10057. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10058. if (field == "description")
  10059. lua_interface->SetStringValue(state, effect->description.c_str());
  10060. else if (field == "bullet")
  10061. lua_interface->SetInt32Value(state, effect->subbullet);
  10062. else if (field == "percentage")
  10063. lua_interface->SetInt32Value(state, effect->percentage);
  10064. else // no match
  10065. return 0;
  10066. return 1;
  10067. }
  10068. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10069. if (!lua_interface)
  10070. return 0;
  10071. LuaSpell* spell = lua_interface->GetSpell(state);
  10072. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10073. Spawn* target = lua_interface->GetSpawn(state, 3);
  10074. if (!target) {
  10075. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10076. return 0;
  10077. }
  10078. if (!target->IsEntity()) {
  10079. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10080. return 0;
  10081. }
  10082. if (!spell) {
  10083. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10084. return 0;
  10085. }
  10086. if (caster && !caster->IsEntity()) {
  10087. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10088. return 0;
  10089. }
  10090. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10091. return 0;
  10092. }
  10093. int EQ2Emu_lua_InWater(lua_State* state) {
  10094. if (!lua_interface)
  10095. return 0;
  10096. Spawn* spawn = lua_interface->GetSpawn(state);
  10097. lua_interface->ResetFunctionStack(state);
  10098. if (spawn) {
  10099. lua_interface->SetBooleanValue(state, spawn->InWater());
  10100. return 1;
  10101. }
  10102. return 0;
  10103. }
  10104. int EQ2Emu_lua_InLava(lua_State* state) {
  10105. if (!lua_interface)
  10106. return 0;
  10107. Spawn* spawn = lua_interface->GetSpawn(state);
  10108. lua_interface->ResetFunctionStack(state);
  10109. if (spawn) {
  10110. lua_interface->SetBooleanValue(state, spawn->InLava());
  10111. return 1;
  10112. }
  10113. return 0;
  10114. }
  10115. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10116. if (!lua_interface)
  10117. return 0;
  10118. Spawn* attacker = lua_interface->GetSpawn(state);
  10119. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10120. int8 type = lua_interface->GetInt8Value(state, 3);
  10121. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10122. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10123. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10124. string spell_name = lua_interface->GetStringValue(state, 7);
  10125. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10126. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10127. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10128. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10129. lua_interface->ResetFunctionStack(state);
  10130. if (!attacker) {
  10131. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10132. return 0;
  10133. }
  10134. if (!attacker->IsEntity()) {
  10135. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10136. return 0;
  10137. }
  10138. if (!victim) {
  10139. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10140. return 0;
  10141. }
  10142. if (!victim->IsEntity()) {
  10143. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10144. return 0;
  10145. }
  10146. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10147. return 0;
  10148. }
  10149. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10150. if (!lua_interface)
  10151. return 0;
  10152. Spawn* spawn = lua_interface->GetSpawn(state);
  10153. lua_interface->ResetFunctionStack(state);
  10154. if (spawn) {
  10155. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10156. return 1;
  10157. }
  10158. return 0;
  10159. }
  10160. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10161. if (!lua_interface)
  10162. return 0;
  10163. Spawn* spawn = lua_interface->GetSpawn(state);
  10164. bool invul = lua_interface->GetBooleanValue(state, 2);
  10165. lua_interface->ResetFunctionStack(state);
  10166. if (spawn) {
  10167. spawn->SetInvulnerable(invul);
  10168. }
  10169. return 0;
  10170. }
  10171. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10172. if (!lua_interface)
  10173. return 0;
  10174. string category = lua_interface->GetStringValue(state);
  10175. string name = lua_interface->GetStringValue(state, 2);
  10176. lua_interface->ResetFunctionStack(state);
  10177. Rule *ret = 0;
  10178. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10179. lua_interface->SetBooleanValue(state, ret->GetBool());
  10180. return 1;
  10181. }
  10182. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10183. return 0;
  10184. }
  10185. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10186. if (!lua_interface)
  10187. return 0;
  10188. string category = lua_interface->GetStringValue(state);
  10189. string name = lua_interface->GetStringValue(state, 2);
  10190. lua_interface->ResetFunctionStack(state);
  10191. Rule *ret = 0;
  10192. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10193. lua_interface->SetInt32Value(state, ret->GetInt32());
  10194. return 1;
  10195. }
  10196. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10197. return 0;
  10198. }
  10199. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10200. if (!lua_interface)
  10201. return 0;
  10202. string category = lua_interface->GetStringValue(state);
  10203. string name = lua_interface->GetStringValue(state, 2);
  10204. lua_interface->ResetFunctionStack(state);
  10205. Rule *ret = 0;
  10206. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10207. lua_interface->SetFloatValue(state, ret->GetFloat());
  10208. return 1;
  10209. }
  10210. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10211. return 0;
  10212. }
  10213. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10214. if (!lua_interface)
  10215. return 0;
  10216. Spawn* spawn = lua_interface->GetSpawn(state);
  10217. string type = lua_interface->GetStringValue(state, 2);
  10218. lua_interface->ResetFunctionStack(state);
  10219. if (spawn) {
  10220. int res = 1;
  10221. boost::to_lower(type);
  10222. if(type == "assigned_aa")
  10223. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10224. else if ( type == "unassigned_aa")
  10225. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10226. else if ( type == "assigned_tradeskill_aa")
  10227. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10228. else if ( type == "unassigned_tradeskill_aa")
  10229. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10230. else if ( type == "assigned_prestige_aa")
  10231. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10232. else if ( type == "unassigned_prestige_aa")
  10233. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10234. else if ( type == "assigned_tradeskill_prestige_aa")
  10235. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10236. else if ( type == "unassigned_tradeskill_prestige_aa")
  10237. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10238. else
  10239. res = 0;
  10240. return res;
  10241. }
  10242. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10243. return 0;
  10244. }
  10245. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10246. if (!lua_interface)
  10247. return 0;
  10248. Spawn* spawn = lua_interface->GetSpawn(state);
  10249. string type = lua_interface->GetStringValue(state, 2);
  10250. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10251. lua_interface->ResetFunctionStack(state);
  10252. if (spawn) {
  10253. boost::to_lower(type);
  10254. if(type == "assigned_aa")
  10255. spawn->SetAssignedAA((sint16)value);
  10256. else if ( type == "unassigned_aa")
  10257. spawn->SetUnassignedAA((sint16)value);
  10258. else if ( type == "assigned_tradeskill_aa")
  10259. spawn->SetTradeskillAA((sint16)value);
  10260. else if ( type == "unassigned_tradeskill_aa")
  10261. spawn->SetUnassignedTradeskillAA((sint16)value);
  10262. else if ( type == "assigned_prestige_aa")
  10263. spawn->SetPrestigeAA((sint16)value);
  10264. else if ( type == "unassigned_prestige_aa")
  10265. spawn->SetUnassignedPrestigeAA((sint16)value);
  10266. else if ( type == "assigned_tradeskill_prestige_aa")
  10267. spawn->SetTradeskillPrestigeAA((sint16)value);
  10268. else if ( type == "unassigned_tradeskill_prestige_aa")
  10269. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10270. if(spawn->IsPlayer())
  10271. ((Player*)spawn)->SetCharSheetChanged(true);
  10272. }
  10273. return 0;
  10274. }
  10275. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10276. if (!lua_interface)
  10277. return 0;
  10278. string titleName = lua_interface->GetStringValue(state);
  10279. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10280. lua_interface->ResetFunctionStack(state);
  10281. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10282. lua_interface->SetSInt32Value(state, index);
  10283. return 1;
  10284. }
  10285. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10286. if (!lua_interface)
  10287. return 0;
  10288. Spawn* spawn = lua_interface->GetSpawn(state);
  10289. string titleName = lua_interface->GetStringValue(state, 2);
  10290. lua_interface->ResetFunctionStack(state);
  10291. if(!spawn->IsPlayer())
  10292. {
  10293. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10294. lua_interface->SetSInt32Value(state, -1);
  10295. return 1;
  10296. }
  10297. Player* player = (Player*)spawn;
  10298. // check if player already has the title, don't need to add twice
  10299. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10300. if ( playerHasTitle)
  10301. {
  10302. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10303. return 1;
  10304. }
  10305. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10306. if(!title)
  10307. {
  10308. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10309. lua_interface->SetSInt32Value(state, -1);
  10310. return 1;
  10311. }
  10312. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10313. if(returnIdx < 0)
  10314. {
  10315. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10316. }
  10317. lua_interface->SetSInt32Value(state, returnIdx);
  10318. player->GetClient()->SendTitleUpdate();
  10319. return 1;
  10320. }
  10321. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10322. if (!lua_interface)
  10323. return 0;
  10324. Spawn* spawn = lua_interface->GetSpawn(state);
  10325. string titleName = lua_interface->GetStringValue(state, 2);
  10326. lua_interface->ResetFunctionStack(state);
  10327. if(!spawn->IsPlayer())
  10328. {
  10329. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10330. return 0;
  10331. }
  10332. Player* player = (Player*)spawn;
  10333. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10334. if(!title)
  10335. {
  10336. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10337. return 0;
  10338. }
  10339. if(title->GetPrefix())
  10340. {
  10341. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title with name '%s' is not valid as a suffix, only prefix", lua_interface->GetScriptName(state), titleName.c_str());
  10342. return 0;
  10343. }
  10344. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10345. player->GetClient()->SendTitleUpdate();
  10346. return 1;
  10347. }
  10348. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10349. if (!lua_interface)
  10350. return 0;
  10351. Spawn* spawn = lua_interface->GetSpawn(state);
  10352. string titleName = lua_interface->GetStringValue(state, 2);
  10353. lua_interface->ResetFunctionStack(state);
  10354. if(!spawn->IsPlayer())
  10355. {
  10356. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10357. return 0;
  10358. }
  10359. Player* player = (Player*)spawn;
  10360. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10361. if(!title)
  10362. {
  10363. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10364. return 0;
  10365. }
  10366. if(!title->GetPrefix())
  10367. {
  10368. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title with name '%s' is not valid as a prefix, only suffix", lua_interface->GetScriptName(state), titleName.c_str());
  10369. return 0;
  10370. }
  10371. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10372. player->GetClient()->SendTitleUpdate();
  10373. return 1;
  10374. }
  10375. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10376. if (!lua_interface)
  10377. return 0;
  10378. Spawn* spawn = lua_interface->GetSpawn(state);
  10379. lua_interface->ResetFunctionStack(state);
  10380. if(!spawn->IsPlayer())
  10381. {
  10382. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10383. return 0;
  10384. }
  10385. Player* player = (Player*)spawn;
  10386. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10387. player->GetClient()->SendTitleUpdate();
  10388. return 1;
  10389. }
  10390. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10391. if (!lua_interface)
  10392. return 0;
  10393. Spawn* spawn = lua_interface->GetSpawn(state);
  10394. lua_interface->ResetFunctionStack(state);
  10395. if(!spawn->IsPlayer())
  10396. {
  10397. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10398. return 0;
  10399. }
  10400. Player* player = (Player*)spawn;
  10401. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10402. player->GetClient()->SendTitleUpdate();
  10403. return 1;
  10404. }
  10405. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10406. if (!lua_interface)
  10407. return 0;
  10408. Spawn* spawn = lua_interface->GetSpawn(state);
  10409. string field = lua_interface->GetStringValue(state, 2);
  10410. lua_interface->ResetFunctionStack(state);
  10411. if(!spawn || !spawn->IsEntity())
  10412. {
  10413. lua_interface->LogError("%s: LUA GetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10414. return 0;
  10415. }
  10416. Entity* ent = (Entity*)spawn;
  10417. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10418. return 1;
  10419. }
  10420. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10421. if (!lua_interface)
  10422. return 0;
  10423. Spawn* spawn = lua_interface->GetSpawn(state);
  10424. string field = lua_interface->GetStringValue(state, 2);
  10425. lua_interface->ResetFunctionStack(state);
  10426. if(!spawn || !spawn->IsEntity())
  10427. {
  10428. lua_interface->LogError("%s: LUA GetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10429. return 0;
  10430. }
  10431. Entity* ent = (Entity*)spawn;
  10432. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10433. return 1;
  10434. }
  10435. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10436. if (!lua_interface)
  10437. return 0;
  10438. Spawn* spawn = lua_interface->GetSpawn(state);
  10439. string field = lua_interface->GetStringValue(state, 2);
  10440. lua_interface->ResetFunctionStack(state);
  10441. if(!spawn || !spawn->IsEntity())
  10442. {
  10443. lua_interface->LogError("%s: LUA GetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10444. return 0;
  10445. }
  10446. Entity* ent = (Entity*)spawn;
  10447. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10448. return 1;
  10449. }
  10450. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10451. if (!lua_interface)
  10452. return 0;
  10453. Spawn* spawn = lua_interface->GetSpawn(state);
  10454. string field = lua_interface->GetStringValue(state, 2);
  10455. lua_interface->ResetFunctionStack(state);
  10456. if(!spawn || !spawn->IsEntity())
  10457. {
  10458. lua_interface->LogError("%s: LUA GetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10459. return 0;
  10460. }
  10461. Entity* ent = (Entity*)spawn;
  10462. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10463. return 1;
  10464. }
  10465. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10466. if (!lua_interface)
  10467. return 0;
  10468. Spawn* spawn = lua_interface->GetSpawn(state);
  10469. string field = lua_interface->GetStringValue(state, 2);
  10470. string value = lua_interface->GetStringValue(state, 3);
  10471. lua_interface->ResetFunctionStack(state);
  10472. if(!spawn || !spawn->IsEntity())
  10473. {
  10474. lua_interface->LogError("%s: LUA SetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10475. return 0;
  10476. }
  10477. Entity* ent = (Entity*)spawn;
  10478. bool set_ = ent->SetInfoStructString(field, value);
  10479. lua_interface->SetBooleanValue(state, set_);
  10480. return 1;
  10481. }
  10482. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10483. if (!lua_interface)
  10484. return 0;
  10485. Spawn* spawn = lua_interface->GetSpawn(state);
  10486. string field = lua_interface->GetStringValue(state, 2);
  10487. int64 value = lua_interface->GetInt64Value(state, 3);
  10488. lua_interface->ResetFunctionStack(state);
  10489. if(!spawn || !spawn->IsEntity())
  10490. {
  10491. lua_interface->LogError("%s: LUA SetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10492. return 0;
  10493. }
  10494. Entity* ent = (Entity*)spawn;
  10495. bool set_ = ent->SetInfoStructUInt(field, value);
  10496. lua_interface->SetBooleanValue(state, set_);
  10497. return 1;
  10498. }
  10499. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10500. if (!lua_interface)
  10501. return 0;
  10502. Spawn* spawn = lua_interface->GetSpawn(state);
  10503. string field = lua_interface->GetStringValue(state, 2);
  10504. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10505. lua_interface->ResetFunctionStack(state);
  10506. if(!spawn || !spawn->IsEntity())
  10507. {
  10508. lua_interface->LogError("%s: LUA SetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10509. return 0;
  10510. }
  10511. Entity* ent = (Entity*)spawn;
  10512. bool set_ = ent->SetInfoStructSInt(field, value);
  10513. lua_interface->SetBooleanValue(state, set_);
  10514. return 1;
  10515. }
  10516. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10517. if (!lua_interface)
  10518. return 0;
  10519. Spawn* spawn = lua_interface->GetSpawn(state);
  10520. string field = lua_interface->GetStringValue(state, 2);
  10521. float value = lua_interface->GetFloatValue(state, 3);
  10522. lua_interface->ResetFunctionStack(state);
  10523. if(!spawn || !spawn->IsEntity())
  10524. {
  10525. lua_interface->LogError("%s: LUA SetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10526. return 0;
  10527. }
  10528. Entity* ent = (Entity*)spawn;
  10529. bool set_ = ent->SetInfoStructFloat(field, value);
  10530. lua_interface->SetBooleanValue(state, set_);
  10531. return 1;
  10532. }
  10533. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10534. if (!lua_interface)
  10535. return 0;
  10536. Spawn* spawn = lua_interface->GetSpawn(state);
  10537. bool value = lua_interface->GetBooleanValue(state, 2);
  10538. lua_interface->ResetFunctionStack(state);
  10539. if(!spawn || !spawn->IsPlayer())
  10540. {
  10541. lua_interface->LogError("%s: LUA SetCharSheetChanged command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  10542. return 0;
  10543. }
  10544. ((Player*)spawn)->SetCharSheetChanged(value);
  10545. return 0;
  10546. }
  10547. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10548. if (!lua_interface)
  10549. return 0;
  10550. Spawn* spawn = lua_interface->GetSpawn(state);
  10551. std::string fromName = lua_interface->GetStringValue(state, 2);
  10552. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10553. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10554. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10555. int32 copper = lua_interface->GetInt32Value(state, 6);
  10556. int32 silver = lua_interface->GetInt32Value(state, 7);
  10557. int32 gold = lua_interface->GetInt32Value(state, 8);
  10558. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10559. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10560. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10561. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10562. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10563. lua_interface->ResetFunctionStack(state);
  10564. if(!spawn || !spawn->IsPlayer())
  10565. {
  10566. lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  10567. lua_interface->SetBooleanValue(state, false);
  10568. return 1;
  10569. }
  10570. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10571. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10572. lua_interface->SetBooleanValue(state, true);
  10573. return 1;
  10574. }
  10575. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10576. if (!lua_interface)
  10577. return 0;
  10578. int32 char_id = lua_interface->GetInt32Value(state);
  10579. std::string fromName = lua_interface->GetStringValue(state, 2);
  10580. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10581. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10582. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10583. int32 copper = lua_interface->GetInt32Value(state, 6);
  10584. int32 silver = lua_interface->GetInt32Value(state, 7);
  10585. int32 gold = lua_interface->GetInt32Value(state, 8);
  10586. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10587. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10588. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10589. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10590. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10591. lua_interface->ResetFunctionStack(state);
  10592. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10593. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10594. lua_interface->SetBooleanValue(state, true);
  10595. return 1;
  10596. }
  10597. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10598. Spawn* widget;
  10599. if (lua_interface) {
  10600. widget = lua_interface->GetSpawn(state);
  10601. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10602. lua_interface->ResetFunctionStack(state);
  10603. if (widget && widget->IsWidget())
  10604. {
  10605. ((Widget*)widget)->OpenDoor();
  10606. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10607. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10608. }
  10609. else
  10610. lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10611. }
  10612. return 0;
  10613. }
  10614. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10615. Spawn* widget;
  10616. if (lua_interface) {
  10617. widget = lua_interface->GetSpawn(state);
  10618. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10619. lua_interface->ResetFunctionStack(state);
  10620. if (widget && widget->IsWidget())
  10621. {
  10622. ((Widget*)widget)->CloseDoor();
  10623. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10624. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10625. }
  10626. else
  10627. lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10628. }
  10629. return 0;
  10630. }
  10631. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10632. if (!lua_interface)
  10633. return 0;
  10634. Spawn* widget = lua_interface->GetSpawn(state);
  10635. lua_interface->ResetFunctionStack(state);
  10636. if (widget && widget->IsWidget())
  10637. {
  10638. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10639. return 1;
  10640. }
  10641. return 0;
  10642. }
  10643. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10644. if (!lua_interface)
  10645. return 0;
  10646. sint32 min = lua_interface->GetSInt32Value(state);
  10647. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10648. lua_interface->ResetFunctionStack(state);
  10649. sint32 result = MakeRandomInt(min, max);
  10650. lua_interface->SetSInt32Value(state, result);
  10651. return 1;
  10652. }
  10653. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10654. if (!lua_interface)
  10655. return 0;
  10656. float min = lua_interface->GetFloatValue(state);
  10657. float max = lua_interface->GetFloatValue(state, 2);
  10658. lua_interface->ResetFunctionStack(state);
  10659. float result = MakeRandomFloat(min, max);
  10660. lua_interface->SetFloatValue(state, result);
  10661. return 1;
  10662. }
  10663. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10664. if (!lua_interface)
  10665. return 0;
  10666. Spawn* spawn = lua_interface->GetSpawn(state);
  10667. int32 value = lua_interface->GetInt32Value(state, 2);
  10668. lua_interface->ResetFunctionStack(state);
  10669. if(!spawn)
  10670. {
  10671. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10672. lua_interface->SetBooleanValue(state, false);
  10673. return 1;
  10674. }
  10675. spawn->AddIconValue(value);
  10676. lua_interface->SetBooleanValue(state, true);
  10677. return 1;
  10678. }
  10679. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10680. if (!lua_interface)
  10681. return 0;
  10682. Spawn* spawn = lua_interface->GetSpawn(state);
  10683. int32 value = lua_interface->GetInt32Value(state, 2);
  10684. lua_interface->ResetFunctionStack(state);
  10685. if(!spawn)
  10686. {
  10687. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10688. lua_interface->SetBooleanValue(state, false);
  10689. return 1;
  10690. }
  10691. spawn->RemoveIconValue(value);
  10692. lua_interface->SetBooleanValue(state, true);
  10693. return 1;
  10694. }
  10695. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10696. Spawn* npc = lua_interface->GetSpawn(state);
  10697. lua_interface->ResetFunctionStack(state);
  10698. if (npc && npc->IsNPC()) {
  10699. NPC* shard = (NPC*)npc;
  10700. int32 shardid = shard->GetShardID();
  10701. lua_interface->SetInt32Value(state, shardid);
  10702. return 1;
  10703. }
  10704. lua_interface->SetInt32Value(state, 0);
  10705. return 1;
  10706. }
  10707. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10708. Spawn* npc = lua_interface->GetSpawn(state);
  10709. lua_interface->ResetFunctionStack(state);
  10710. if (npc && npc->IsNPC()) {
  10711. NPC* shard = (NPC*)npc;
  10712. int32 charid = shard->GetShardCharID();
  10713. lua_interface->SetInt32Value(state, charid);
  10714. return 1;
  10715. }
  10716. lua_interface->SetInt32Value(state, 0);
  10717. return 1;
  10718. }
  10719. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10720. Spawn* npc = lua_interface->GetSpawn(state);
  10721. lua_interface->ResetFunctionStack(state);
  10722. if (npc && npc->IsNPC()) {
  10723. NPC* shard = (NPC*)npc;
  10724. int64 timestamp = shard->GetShardCreatedTimestamp();
  10725. lua_interface->SetSInt64Value(state, timestamp);
  10726. return 1;
  10727. }
  10728. lua_interface->SetSInt64Value(state, 0);
  10729. return 1;
  10730. }
  10731. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10732. if (!lua_interface)
  10733. return 0;
  10734. int32 shardid = lua_interface->GetInt32Value(state);
  10735. lua_interface->ResetFunctionStack(state);
  10736. if(shardid < 1)
  10737. lua_interface->SetBooleanValue(state, false);
  10738. else
  10739. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10740. return 1;
  10741. }
  10742. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10743. if (!lua_interface)
  10744. return 0;
  10745. Spawn* spawn = lua_interface->GetSpawn(state);
  10746. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10747. if (spawn) {
  10748. spawn->PauseMovement(delay_in_ms);
  10749. }
  10750. lua_interface->ResetFunctionStack(state);
  10751. return 0;
  10752. }
  10753. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10754. if (!lua_interface)
  10755. return 0;
  10756. Spawn* spawn = lua_interface->GetSpawn(state);
  10757. if (spawn) {
  10758. spawn->StopMovement();
  10759. }
  10760. lua_interface->ResetFunctionStack(state);
  10761. return 0;
  10762. }
  10763. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10764. Player* player = (Player*)lua_interface->GetSpawn(state);
  10765. int8 level = lua_interface->GetInt8Value(state, 2);
  10766. lua_interface->ResetFunctionStack(state);
  10767. if (player && player->IsPlayer() && level > 0) {
  10768. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10769. return 1;
  10770. }
  10771. return 0;
  10772. }
  10773. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10774. Player* player = (Player*)lua_interface->GetSpawn(state);
  10775. int8 level = lua_interface->GetInt8Value(state, 2);
  10776. lua_interface->ResetFunctionStack(state);
  10777. if (player && player->IsPlayer() && level > 0) {
  10778. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10779. return 1;
  10780. }
  10781. return 0;
  10782. }
  10783. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10784. ZoneServer* zone = lua_interface->GetZone(state);
  10785. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10786. lua_interface->ResetFunctionStack(state);
  10787. if (zone) {
  10788. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10789. if (spawn) {
  10790. lua_interface->SetSpawnValue(state, spawn);
  10791. return 1;
  10792. }
  10793. }
  10794. return 0;
  10795. }
  10796. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10797. if (!lua_interface)
  10798. return 0;
  10799. Spawn* spawn = lua_interface->GetSpawn(state);
  10800. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10801. lua_interface->ResetFunctionStack(state);
  10802. bool res = false;
  10803. if(spawn && spawn->IsTransportSpawn())
  10804. {
  10805. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10806. spawn->SetRailID(rail_id);
  10807. res = true;
  10808. }
  10809. else if (!spawn) {
  10810. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10811. }
  10812. else if(!spawn->IsTransportSpawn()) {
  10813. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  10814. }
  10815. lua_interface->SetBooleanValue(state, res);
  10816. return 1;
  10817. }
  10818. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10819. if (!lua_interface)
  10820. return 0;
  10821. ZoneServer* zone = lua_interface->GetZone(state);
  10822. lua_interface->ResetFunctionStack(state);
  10823. if (zone) {
  10824. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10825. return 1;
  10826. }
  10827. return 0;
  10828. }
  10829. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10830. if (!lua_interface)
  10831. return 0;
  10832. Spawn* spawn = lua_interface->GetSpawn(state);
  10833. lua_interface->ResetFunctionStack(state);
  10834. if (spawn) {
  10835. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10836. return 1;
  10837. }
  10838. return 0;
  10839. }
  10840. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  10841. if (!lua_interface)
  10842. return 0;
  10843. Spawn* player = lua_interface->GetSpawn(state);
  10844. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  10845. bool displayClient = lua_interface->GetInt32Value(state, 3);
  10846. lua_interface->ResetFunctionStack(state);
  10847. if (!player || !player->IsPlayer() || !player->GetClient()) {
  10848. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  10849. }
  10850. else if(!zoneID) {
  10851. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  10852. }
  10853. else
  10854. {
  10855. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  10856. return 1;
  10857. }
  10858. return 0;
  10859. }
  10860. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  10861. if (!lua_interface)
  10862. return 0;
  10863. int16 newYear = lua_interface->GetInt16Value(state, 1);
  10864. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  10865. int16 newHour = lua_interface->GetInt16Value(state, 3);
  10866. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  10867. lua_interface->ResetFunctionStack(state);
  10868. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  10869. world.GetWorldTimeStruct()->year = newYear;
  10870. world.GetWorldTimeStruct()->month = newMonth;
  10871. world.GetWorldTimeStruct()->hour = newHour;
  10872. world.GetWorldTimeStruct()->minute = newMinute;
  10873. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  10874. return 0;
  10875. }
  10876. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  10877. if (!lua_interface)
  10878. return 0;
  10879. lua_interface->ResetFunctionStack(state);
  10880. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10881. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  10882. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10883. return 1;
  10884. }
  10885. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  10886. if (!lua_interface)
  10887. return 0;
  10888. lua_interface->ResetFunctionStack(state);
  10889. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10890. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  10891. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10892. return 1;
  10893. }
  10894. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  10895. if (!lua_interface)
  10896. return 0;
  10897. lua_interface->ResetFunctionStack(state);
  10898. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10899. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  10900. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10901. return 1;
  10902. }
  10903. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  10904. if (!lua_interface)
  10905. return 0;
  10906. lua_interface->ResetFunctionStack(state);
  10907. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10908. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  10909. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10910. return 1;
  10911. }
  10912. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  10913. if (!lua_interface)
  10914. return 0;
  10915. lua_interface->ResetFunctionStack(state);
  10916. world.SendTimeUpdate();
  10917. return 0;
  10918. }