LuaFunctions.cpp 265 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "../common/Log.h"
  29. #include <math.h>
  30. #include "HeroicOp/HeroicOp.h"
  31. #include "RaceTypes/RaceTypes.h"
  32. #include "ClientPacketFunctions.h"
  33. extern WorldDatabase database;
  34. extern LuaInterface* lua_interface;
  35. extern ConfigReader configReader;
  36. extern MasterQuestList master_quest_list;
  37. extern MasterItemList master_item_list;
  38. extern MasterSpellList master_spell_list;
  39. extern World world;
  40. extern Commands commands;
  41. extern ZoneList zone_list;
  42. extern Races races;
  43. extern Classes classes;
  44. extern Variables variables;
  45. extern MasterSkillList master_skill_list;
  46. extern MasterHeroicOPList master_ho_list;
  47. extern MasterRaceTypeList race_types_list;
  48. extern MasterLanguagesList master_languages_list;
  49. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  50. if (!lua_interface)
  51. return 0;
  52. Spawn* spawn = lua_interface->GetSpawn(state);
  53. string mp3_string = lua_interface->GetStringValue(state, 2);
  54. string text_string = lua_interface->GetStringValue(state, 3);
  55. string emote_string = lua_interface->GetStringValue(state, 4);
  56. int32 key1 = lua_interface->GetInt32Value(state, 5);
  57. int32 key2 = lua_interface->GetInt32Value(state, 6);
  58. Spawn* player = lua_interface->GetSpawn(state, 7);
  59. int8 language = lua_interface->GetInt8Value(state, 8);
  60. if (spawn) {
  61. const char* mp3 = 0;
  62. const char* text = 0;
  63. const char* emote = 0;
  64. if (mp3_string.length() > 0)
  65. mp3 = mp3_string.c_str();
  66. if (text_string.length() > 0)
  67. text = text_string.c_str();
  68. if (emote_string.length() > 0)
  69. emote = emote_string.c_str();
  70. Client* client = 0;
  71. if (player && player->IsPlayer())
  72. client = spawn->GetZone()->GetClientBySpawn(player);
  73. if (client) {
  74. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  75. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  76. }
  77. else
  78. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  79. }
  80. return 0;
  81. }
  82. int EQ2Emu_lua_PlaySound(lua_State* state) {
  83. if (!lua_interface)
  84. return 0;
  85. Spawn* spawn = lua_interface->GetSpawn(state);
  86. string sound_string = lua_interface->GetStringValue(state, 2);
  87. float x = lua_interface->GetFloatValue(state, 3);
  88. float y = lua_interface->GetFloatValue(state, 4);
  89. float z = lua_interface->GetFloatValue(state, 5);
  90. Spawn* player = lua_interface->GetSpawn(state, 6);
  91. if (spawn && sound_string.length() > 0) {
  92. Client* client = 0;
  93. if (player && player->IsPlayer())
  94. client = spawn->GetZone()->GetClientBySpawn(player);
  95. if (client)
  96. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  97. else
  98. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  99. }
  100. return 0;
  101. }
  102. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  103. if (!lua_interface)
  104. return 0;
  105. Spawn* spawn = lua_interface->GetSpawn(state);
  106. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  107. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  108. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  109. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  110. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  111. if (!spawn) {
  112. lua_interface->LogError("LUA SetRequiredQuest command error: spawn is not valid");
  113. return 0;
  114. }
  115. if (quest_id > 0) {
  116. //Add this quest to the list of required quests for this spawn
  117. spawn->SetQuestsRequired(quest_id, quest_step);
  118. //If private spawn value set
  119. if (private_spawn) {
  120. //Set the spawn to be private when not granted access through this quest
  121. spawn->AddAllowAccessSpawn(spawn);
  122. spawn->SetPrivateQuestSpawn(true);
  123. }
  124. //This value allows access after a quest step, or the whole quest has been completed
  125. if (continued_access)
  126. spawn->SetQuestsRequiredContinuedAccess(true);
  127. //This value will override vis_flags in the vis packet
  128. if (flag_override > 0)
  129. spawn->SetQuestsRequiredOverride(flag_override);
  130. }
  131. return 0;
  132. }
  133. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  134. if (!lua_interface)
  135. return 0;
  136. Spawn* spawn = lua_interface->GetSpawn(state);
  137. float max_distance = lua_interface->GetFloatValue(state, 2);
  138. string variable = lua_interface->GetStringValue(state, 3);
  139. string value = lua_interface->GetStringValue(state, 4);
  140. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  141. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  142. return 0;
  143. }
  144. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Client* client = 0;
  148. Spawn* player = lua_interface->GetSpawn(state);
  149. if (player->GetZone())
  150. client = player->GetZone()->GetClientBySpawn(player);
  151. if (!client) {
  152. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  153. return 0;
  154. }
  155. int16 value1 = lua_interface->GetInt16Value(state, 2);
  156. int16 value2 = lua_interface->GetInt16Value(state, 3);
  157. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  158. if (packet) {
  159. packet->setDataByName("unknown1", value1);
  160. packet->setDataByName("unknown2", value2);
  161. client->QueuePacket(packet->serialize());
  162. safe_delete(packet);
  163. }
  164. return 0;
  165. }
  166. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  167. if (!lua_interface)
  168. return 0;
  169. Spawn* dead = lua_interface->GetSpawn(state);
  170. Spawn* killer = lua_interface->GetSpawn(state, 2);
  171. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  172. if (dead && dead->Alive() && dead->GetZone())
  173. dead->GetZone()->KillSpawn(dead, killer, send_packet);
  174. return 0;
  175. }
  176. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  177. if (!lua_interface)
  178. return 0;
  179. Spawn* spawn = lua_interface->GetSpawn(state);
  180. float max_distance = lua_interface->GetFloatValue(state, 2);
  181. bool include_players = lua_interface->GetInt8Value(state, 3);
  182. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  183. if (max_distance > 0 && spawn && spawn->GetZone())
  184. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  185. return 0;
  186. }
  187. int EQ2Emu_lua_Despawn(lua_State* state) {
  188. if (!lua_interface)
  189. return 0;
  190. Spawn* spawn = lua_interface->GetSpawn(state);
  191. int32 delay = lua_interface->GetInt32Value(state, 2);
  192. if (spawn && spawn->GetZone())
  193. spawn->GetZone()->Despawn(spawn, delay);
  194. return 0;
  195. }
  196. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  197. if (!lua_interface)
  198. return 0;
  199. Spawn* spawn = lua_interface->GetSpawn(state);
  200. string variable = lua_interface->GetStringValue(state, 2);
  201. string value = lua_interface->GetStringValue(state, 3);
  202. int32 type = commands.GetSpawnSetType(variable);
  203. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  204. commands.SetSpawnCommand(0, spawn, type, value.c_str());
  205. return 0;
  206. }
  207. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  208. if (!lua_interface)
  209. return 0;
  210. Spawn* spawn = lua_interface->GetSpawn(state);
  211. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  212. if (spawn && spawn_id > 0) {
  213. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  214. if (closest_spawn) {
  215. lua_interface->SetSpawnValue(state, closest_spawn);
  216. return 1;
  217. }
  218. }
  219. return 0;
  220. }
  221. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  222. if (!lua_interface)
  223. return 0;
  224. string variable_name = lua_interface->GetStringValue(state);
  225. Variable* var = variables.FindVariable(variable_name);
  226. if (var) {
  227. lua_interface->SetStringValue(state, var->GetValue());
  228. return 1;
  229. }
  230. return 0;
  231. }
  232. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  233. if (!lua_interface)
  234. return 0;
  235. int32 total_coins = lua_interface->GetInt32Value(state);
  236. if (total_coins == 0) {
  237. lua_interface->SetStringValue(state, "0 copper");
  238. return 1;
  239. }
  240. char tmp[64] = { 0 };
  241. string message = "";
  242. int32 val = 0;
  243. if (total_coins >= 1000000) {
  244. val = total_coins / 1000000;
  245. total_coins -= 1000000 * val;
  246. sprintf(tmp, " %u Platinum", val);
  247. message.append(tmp);
  248. memset(tmp, 0, 64);
  249. }
  250. if (total_coins >= 10000) {
  251. val = total_coins / 10000;
  252. total_coins -= 10000 * val;
  253. sprintf(tmp, " %u Gold", val);
  254. message.append(tmp);
  255. memset(tmp, 0, 64);
  256. }
  257. if (total_coins >= 100) {
  258. val = total_coins / 100;
  259. total_coins -= 100 * val;
  260. sprintf(tmp, " %u Silver", val);
  261. message.append(tmp);
  262. memset(tmp, 0, 64);
  263. }
  264. if (total_coins > 0) {
  265. sprintf(tmp, " %u Copper", (int32)total_coins);
  266. message.append(tmp);
  267. }
  268. lua_interface->SetStringValue(state, message.c_str());
  269. return 1;
  270. }
  271. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  272. ZoneServer* zone = lua_interface->GetZone(state);
  273. int32 group_id = lua_interface->GetInt32Value(state, 2);
  274. if (zone) {
  275. Spawn* spawn = zone->GetSpawnGroup(group_id);
  276. if (spawn) {
  277. lua_interface->SetSpawnValue(state, spawn);
  278. return 1;
  279. }
  280. }
  281. return 0;
  282. }
  283. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  284. ZoneServer* zone = lua_interface->GetZone(state);
  285. int32 location_id = lua_interface->GetInt32Value(state, 2);
  286. if (zone) {
  287. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  288. if (spawn) {
  289. lua_interface->SetSpawnValue(state, spawn);
  290. return 1;
  291. }
  292. }
  293. return 0;
  294. }
  295. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. if (spawn) {
  298. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  299. return 1;
  300. }
  301. return 0;
  302. }
  303. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  304. Spawn* spawn = lua_interface->GetSpawn(state);
  305. if (spawn) {
  306. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  307. return 1;
  308. }
  309. return 0;
  310. }
  311. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  312. Spawn* spawn = lua_interface->GetSpawn(state);
  313. if (spawn) {
  314. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  315. return 1;
  316. }
  317. return 0;
  318. }
  319. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  320. Spawn* spawn = lua_interface->GetSpawn(state);
  321. if (spawn) {
  322. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  323. return 1;
  324. }
  325. return 0;
  326. }
  327. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  328. Player* player = (Player*)lua_interface->GetSpawn(state);
  329. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  330. if (player && player->IsPlayer() && faction_id > 0) {
  331. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  332. return 1;
  333. }
  334. return 0;
  335. }
  336. int EQ2Emu_lua_GetGender(lua_State* state) {
  337. Spawn* spawn = lua_interface->GetSpawn(state);
  338. if (spawn) {
  339. lua_interface->SetInt32Value(state, spawn->GetGender());
  340. return 1;
  341. }
  342. return 0;
  343. }
  344. int EQ2Emu_lua_GetTarget(lua_State* state) {
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  347. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  348. return 1;
  349. }
  350. return 0;
  351. }
  352. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  353. if (!lua_interface)
  354. return 0;
  355. Spawn* spawn = lua_interface->GetSpawn(state);
  356. string mp3_string = lua_interface->GetStringValue(state, 2);
  357. int32 key1 = lua_interface->GetInt32Value(state, 3);
  358. int32 key2 = lua_interface->GetInt32Value(state, 4);
  359. Spawn* player = lua_interface->GetSpawn(state, 5);
  360. if (spawn && mp3_string.length() > 0) {
  361. Client* client = 0;
  362. if (player && player->IsPlayer())
  363. client = spawn->GetZone()->GetClientBySpawn(player);
  364. if (client) {
  365. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  366. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  367. }
  368. else
  369. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  370. }
  371. return 0;
  372. }
  373. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  374. if (!lua_interface)
  375. return 0;
  376. Spawn* spawn = lua_interface->GetSpawn(state);
  377. if (spawn) {
  378. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  379. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  380. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  381. return 3;
  382. }
  383. return 0;
  384. }
  385. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  386. if (!lua_interface)
  387. return 0;
  388. Spawn* spawn = lua_interface->GetSpawn(state);
  389. if (spawn && spawn->IsEntity()) {
  390. int32 item_id = lua_interface->GetInt32Value(state, 2);
  391. int16 charges = lua_interface->GetInt16Value(state, 3);
  392. if (charges == 0)
  393. charges = 1;
  394. ((Entity*)spawn)->AddLootItem(item_id, charges);
  395. }
  396. return 0;
  397. }
  398. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  399. if (!lua_interface)
  400. return 0;
  401. Spawn* spawn = lua_interface->GetSpawn(state);
  402. if (spawn && spawn->IsEntity()) {
  403. int32 item_id = lua_interface->GetInt32Value(state, 2);
  404. ((Entity*)spawn)->LootItem(item_id);
  405. }
  406. return 0;
  407. }
  408. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  409. if (!lua_interface)
  410. return 0;
  411. Spawn* spawn = lua_interface->GetSpawn(state);
  412. if (spawn && spawn->IsEntity()) {
  413. int32 val = lua_interface->GetInt32Value(state, 2);
  414. ((Entity*)spawn)->AddLootCoins(val);
  415. }
  416. return 0;
  417. }
  418. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  419. if (!lua_interface)
  420. return 0;
  421. Spawn* entity = lua_interface->GetSpawn(state);
  422. Spawn* player = lua_interface->GetSpawn(state, 2);
  423. if (entity && entity->IsEntity() && player && player->IsPlayer()) {
  424. int32 coins = lua_interface->GetInt32Value(state, 3);
  425. vector<Item*>* items = 0;
  426. int i = 0;
  427. int32 item_id = 0;
  428. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  429. if (items == 0)
  430. items = new vector<Item*>;
  431. if (master_item_list.GetItem(item_id))
  432. items->push_back(master_item_list.GetItem(item_id));
  433. i++;
  434. }
  435. Client* client = 0;
  436. client = entity->GetZone()->GetClientBySpawn(player);
  437. if (client) {
  438. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  439. client->Loot(coins, ((Player*)player)->GetPendingLootItems(entity->GetID()), (Entity*)entity);
  440. }
  441. safe_delete(items);
  442. }
  443. return 0;
  444. }
  445. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  446. if (!lua_interface)
  447. return 0;
  448. Spawn* entity = lua_interface->GetSpawn(state);
  449. Spawn* player = lua_interface->GetSpawn(state, 2);
  450. int32 item_id = lua_interface->GetInt32Value(state, 3);
  451. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  452. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  453. return 1;
  454. }
  455. return 0;
  456. }
  457. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  458. if (!lua_interface)
  459. return 0;
  460. Spawn* entity = lua_interface->GetSpawn(state);
  461. Spawn* player = lua_interface->GetSpawn(state, 2);
  462. if (entity && entity->IsEntity() && player && player->IsPlayer()) {
  463. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  464. return 1;
  465. }
  466. return 0;
  467. }
  468. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  469. if (!lua_interface)
  470. return 0;
  471. vector<ConversationOption>* conversation = new vector<ConversationOption>();
  472. lua_interface->SetConversationValue(state, conversation);
  473. return 1;
  474. }
  475. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  476. if (!lua_interface)
  477. return 0;
  478. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  479. if (conversation) {
  480. ConversationOption conv_option;
  481. conv_option.option = lua_interface->GetStringValue(state, 2);
  482. conv_option.function = lua_interface->GetStringValue(state, 3);
  483. if (conv_option.option.length() > 0)
  484. conversation->push_back(conv_option);
  485. }
  486. return 0;
  487. }
  488. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  489. if (!lua_interface)
  490. return 0;
  491. Spawn* npc = lua_interface->GetSpawn(state);
  492. Spawn* player = lua_interface->GetSpawn(state, 2);
  493. if (npc && player && player->IsPlayer() && player->GetZone()) {
  494. Client* client = player->GetZone()->GetClientBySpawn(player);
  495. if (client) {
  496. int32 conversation_id = client->GetConversationID(npc, 0);
  497. client->CloseDialog(conversation_id);
  498. }
  499. }
  500. return 0;
  501. }
  502. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  503. if (!lua_interface)
  504. return 0;
  505. Item* item = lua_interface->GetItem(state);
  506. Spawn* player = lua_interface->GetSpawn(state, 2);
  507. if (item && player && player->IsPlayer() && player->GetZone()) {
  508. Client* client = player->GetZone()->GetClientBySpawn(player);
  509. if (client) {
  510. int32 conversation_id = client->GetConversationID(0, item);
  511. client->CloseDialog(conversation_id);
  512. }
  513. }
  514. return 0;
  515. }
  516. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  517. if (!lua_interface)
  518. return 0;
  519. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  520. Spawn* spawn = 0;
  521. Item* item = 0;
  522. int8 type = lua_interface->GetInt8Value(state, 2);
  523. if (type == 1 || type == 3)
  524. spawn = lua_interface->GetSpawn(state, 3);
  525. else if (type == 2 || type == 4)
  526. item = lua_interface->GetItem(state, 3);
  527. Spawn* player = lua_interface->GetSpawn(state, 4);
  528. string text = lua_interface->GetStringValue(state, 5);
  529. string mp3 = lua_interface->GetStringValue(state, 6);
  530. int32 key1 = lua_interface->GetInt32Value(state, 7);
  531. int32 key2 = lua_interface->GetInt32Value(state, 8);
  532. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  533. Client* client = player->GetZone()->GetClientBySpawn(player);
  534. if (client) {
  535. if (spawn) {
  536. // Need to do this so the function works the same as it did before
  537. if (type == 1)
  538. type++;
  539. if (mp3.length() > 0)
  540. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  541. else
  542. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  543. }
  544. else {
  545. if (mp3.length() > 0)
  546. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  547. else
  548. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  549. }
  550. }
  551. }
  552. safe_delete(conversation);
  553. return 0;
  554. }
  555. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  556. if(!lua_interface)
  557. return 0;
  558. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  559. Item* item = lua_interface->GetItem(state, 2);
  560. Spawn* player = lua_interface->GetSpawn(state, 3);
  561. string text = lua_interface->GetStringValue(state, 4);
  562. string mp3 = lua_interface->GetStringValue(state, 5);
  563. int32 key1 = lua_interface->GetInt32Value(state, 6);
  564. int32 key2 = lua_interface->GetInt32Value(state, 7);
  565. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  566. Client* client = player->GetZone()->GetClientBySpawn(player);
  567. if(client){
  568. if(mp3.length() > 0)
  569. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  570. else
  571. client->DisplayConversation(item, conversation, (char*)text.c_str());
  572. }
  573. safe_delete(conversation);
  574. }
  575. return 0;
  576. }*/
  577. int EQ2Emu_lua_StartConversation(lua_State* state) {
  578. if (!lua_interface)
  579. return 0;
  580. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  581. Spawn* npc = lua_interface->GetSpawn(state, 2);
  582. Spawn* player = lua_interface->GetSpawn(state, 3);
  583. string text = lua_interface->GetStringValue(state, 4);
  584. string mp3 = lua_interface->GetStringValue(state, 5);
  585. int32 key1 = lua_interface->GetInt32Value(state, 6);
  586. int32 key2 = lua_interface->GetInt32Value(state, 7);
  587. if (conversation && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  588. Client* client = npc->GetZone()->GetClientBySpawn(player);
  589. if (mp3.length() > 0)
  590. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  591. else
  592. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  593. safe_delete(conversation);
  594. }
  595. return 0;
  596. }
  597. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  598. if (!lua_interface)
  599. return 0;
  600. Spawn* spawn = lua_interface->GetSpawn(state);
  601. float distance = lua_interface->GetFloatValue(state, 2);
  602. string in_range_function = lua_interface->GetStringValue(state, 3);
  603. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  604. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  605. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  606. return 0;
  607. }
  608. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  609. ZoneServer* zone = lua_interface->GetZone(state);
  610. float x = lua_interface->GetFloatValue(state, 2);
  611. float y = lua_interface->GetFloatValue(state, 3);
  612. float z = lua_interface->GetFloatValue(state, 4);
  613. float max_variation = lua_interface->GetFloatValue(state, 5);
  614. string in_range_function = lua_interface->GetStringValue(state, 6);
  615. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  616. if (zone && in_range_function.length() > 0)
  617. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  618. return 0;
  619. }
  620. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  621. if (!lua_interface)
  622. return 0;
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. if (spawn && spawn->IsEntity()) {
  625. int32 val = lua_interface->GetInt32Value(state, 2);
  626. ((Entity*)spawn)->SetLootCoins(val);
  627. }
  628. return 0;
  629. }
  630. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  631. if (!lua_interface)
  632. return 0;
  633. Spawn* spawn = lua_interface->GetSpawn(state);
  634. if (spawn && spawn->IsEntity()) {
  635. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  636. return 1;
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. float x = lua_interface->GetFloatValue(state, 2);
  645. float y = lua_interface->GetFloatValue(state, 3);
  646. float z = lua_interface->GetFloatValue(state, 4);
  647. float speed = lua_interface->GetFloatValue(state, 5);
  648. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  649. string function = lua_interface->GetStringValue(state, 7);
  650. if (spawn) {
  651. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  652. spawn->GetZone()->AddMovementNPC(spawn);
  653. }
  654. lua_interface->ResetFunctionStack(state);
  655. return 0;
  656. }
  657. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  658. if (!lua_interface)
  659. return 0;
  660. Spawn* spawn = lua_interface->GetSpawn(state);
  661. if (spawn) {
  662. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  663. return 1;
  664. }
  665. return 0;
  666. }
  667. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  668. if (!lua_interface)
  669. return 0;
  670. Spawn* spawn = lua_interface->GetSpawn(state);
  671. Spawn* target = lua_interface->GetSpawn(state, 2);
  672. if (spawn && target) {
  673. if (spawn->IsEntity())
  674. // ((Entity*)spawn)->FaceTarget(target);
  675. static_cast<Entity*>(spawn)->FaceTarget(target);
  676. }
  677. lua_interface->ResetFunctionStack(state);
  678. return 0;
  679. }
  680. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  681. if (!lua_interface)
  682. return 0;
  683. Spawn* spawn = lua_interface->GetSpawn(state);
  684. float x = lua_interface->GetFloatValue(state, 2);
  685. float y = lua_interface->GetFloatValue(state, 3);
  686. float z = lua_interface->GetFloatValue(state, 4);
  687. float speed = lua_interface->GetFloatValue(state, 5);
  688. string lua_function = lua_interface->GetStringValue(state, 6);
  689. bool more_points = lua_interface->GetBooleanValue(state, 7);
  690. if (spawn) {
  691. if (speed == 0)
  692. speed = spawn->GetSpeed();
  693. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  694. }
  695. lua_interface->ResetFunctionStack(state);
  696. return 0;
  697. }
  698. int EQ2Emu_lua_Say(lua_State* state) {
  699. if (!lua_interface)
  700. return 0;
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. string message = lua_interface->GetStringValue(state, 2);
  703. Spawn* player = lua_interface->GetSpawn(state, 3);
  704. int32 language = lua_interface->GetInt32Value(state, 4);
  705. if (spawn && message.length() > 0) {
  706. Client* client = 0;
  707. if (player && player->IsPlayer())
  708. client = spawn->GetZone()->GetClientBySpawn(player);
  709. if (client)
  710. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  711. else
  712. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  713. }
  714. lua_interface->ResetFunctionStack(state);
  715. return 0;
  716. }
  717. int EQ2Emu_lua_Shout(lua_State* state) {
  718. if (!lua_interface)
  719. return 0;
  720. Spawn* spawn = lua_interface->GetSpawn(state);
  721. string message = lua_interface->GetStringValue(state, 2);
  722. Spawn* player = lua_interface->GetSpawn(state, 3);
  723. if (spawn && message.length() > 0) {
  724. Client* client = 0;
  725. if (player && player->IsPlayer())
  726. client = spawn->GetZone()->GetClientBySpawn(player);
  727. if (client)
  728. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  729. else
  730. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  731. }
  732. lua_interface->ResetFunctionStack(state);
  733. return 0;
  734. }
  735. int EQ2Emu_lua_SayOOC(lua_State* state) {
  736. if (!lua_interface)
  737. return 0;
  738. Spawn* spawn = lua_interface->GetSpawn(state);
  739. string message = lua_interface->GetStringValue(state, 2);
  740. Spawn* player = lua_interface->GetSpawn(state, 3);
  741. if (spawn && message.length() > 0) {
  742. Client* client = 0;
  743. if (player && player->IsPlayer())
  744. client = spawn->GetZone()->GetClientBySpawn(player);
  745. if (client)
  746. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  747. else
  748. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  749. }
  750. lua_interface->ResetFunctionStack(state);
  751. return 0;
  752. }
  753. int EQ2Emu_lua_Emote(lua_State* state) {
  754. if (!lua_interface)
  755. return 0;
  756. Spawn* spawn = lua_interface->GetSpawn(state);
  757. string message = lua_interface->GetStringValue(state, 2);
  758. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  759. Spawn* player = lua_interface->GetSpawn(state, 4);
  760. char* to = 0;
  761. if (spawn2)
  762. to = spawn2->GetName();
  763. if (spawn && message.length() > 0) {
  764. Client* client = 0;
  765. if (player && player->IsPlayer())
  766. client = spawn->GetZone()->GetClientBySpawn(player);
  767. if (client)
  768. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  769. else
  770. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  771. }
  772. lua_interface->ResetFunctionStack(state);
  773. return 0;
  774. }
  775. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  776. if (!lua_interface)
  777. return 0;
  778. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  779. if (!luaspell)
  780. return 0;
  781. Spawn* caster = luaspell->caster;
  782. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  783. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  784. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  785. Spawn* target = lua_interface->GetSpawn(state, 4);
  786. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  787. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  788. lua_interface->ResetFunctionStack(state);
  789. if (caster && caster->IsEntity()) {
  790. bool success = false;
  791. luaspell->resisted = false;
  792. if (target) {
  793. float distance = caster->GetDistance(target, true);
  794. distance -= caster->appearance.pos.collision_radius / 10;
  795. distance -= target->appearance.pos.collision_radius / 10;
  796. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs))
  797. success = true;
  798. }
  799. if (luaspell->targets.size() > 0) {
  800. Spawn* target = 0;
  801. ZoneServer* zone = luaspell->caster->GetZone();
  802. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  803. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  804. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  805. float distance = caster->GetDistance(target, true);
  806. distance -= caster->appearance.pos.collision_radius / 10;
  807. distance -= target->appearance.pos.collision_radius / 10;
  808. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs);
  809. }
  810. }
  811. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  812. success = true;
  813. }
  814. if (success) {
  815. if (caster->GetZone())
  816. caster->GetZone()->TriggerCharSheetTimer();
  817. }
  818. }
  819. return 0;
  820. }
  821. int EQ2Emu_lua_SummonItem(lua_State* state) {
  822. if (!lua_interface)
  823. return 0;
  824. Spawn* spawn = lua_interface->GetSpawn(state);
  825. int32 item_id = lua_interface->GetInt32Value(state, 2);
  826. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  827. string location = lua_interface->GetStringValue(state, 4);
  828. if (spawn && spawn->IsPlayer()) {
  829. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  830. if (client && item_id > 0) {
  831. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  832. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  833. else
  834. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  835. if (send_messages) {
  836. Item* item = master_item_list.GetItem(item_id);
  837. if (item) {
  838. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  839. string popup_text = "You receive " + item->name;
  840. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  841. }
  842. }
  843. return 1;
  844. }
  845. }
  846. lua_interface->SetBooleanValue(state, false);
  847. return 1;
  848. }
  849. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  850. Spawn* spawn = lua_interface->GetSpawn(state);
  851. int32 item_id = lua_interface->GetInt32Value(state, 2);
  852. Client* client;
  853. Item* item;
  854. if (spawn && spawn->IsPlayer() && item_id > 0) {
  855. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  856. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  857. if (client->RemoveItem(item, 1)) {
  858. lua_interface->SetBooleanValue(state, true);
  859. return 1;
  860. }
  861. }
  862. }
  863. }
  864. lua_interface->SetBooleanValue(state, false);
  865. return 1;
  866. }
  867. int EQ2Emu_lua_HasItem(lua_State* state) {
  868. Spawn* player = lua_interface->GetSpawn(state);
  869. int32 item_id = lua_interface->GetInt32Value(state, 2);
  870. bool include_bank = lua_interface->GetInt8Value(state, 3);
  871. if (player && player->IsPlayer()) {
  872. bool hasItem = false;
  873. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  874. if (!hasItem)
  875. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  876. lua_interface->SetBooleanValue(state, hasItem);
  877. return 1;
  878. }
  879. lua_interface->SetBooleanValue(state, false);
  880. return 1;
  881. }
  882. int EQ2Emu_lua_Spawn(lua_State* state) {
  883. if (!lua_interface)
  884. return 0;
  885. ZoneServer* zone = lua_interface->GetZone(state);
  886. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  887. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  888. float x = lua_interface->GetFloatValue(state, 4);
  889. float y = lua_interface->GetFloatValue(state, 5);
  890. float z = lua_interface->GetFloatValue(state, 6);
  891. float heading = lua_interface->GetFloatValue(state, 7);
  892. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  893. Spawn* spawn = zone->GetSpawn(spawn_id);
  894. if (!spawn)
  895. lua_interface->LogError("LUA Spawn command error: Could not find spawn with id of %u.", spawn_id);
  896. else {
  897. spawn->SetX(x);
  898. spawn->SetY(y);
  899. spawn->SetZ(z);
  900. spawn->SetLocation(zone->GetClosestLocation(spawn));
  901. spawn->SetHeading(heading);
  902. if (restricted_npc)
  903. spawn->AddAllowAccessSpawn(spawn);
  904. zone->AddSpawn(spawn);
  905. const char* spawn_script = world.GetSpawnScript(spawn_id);
  906. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  907. spawn->SetSpawnScript(string(spawn_script));
  908. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  909. }
  910. lua_interface->SetSpawnValue(state, spawn);
  911. return 1;
  912. }
  913. }
  914. else {
  915. string output = "Invalid paramaters to LUA Spawn command: \n";
  916. if (!zone)
  917. output = output.append("\t").append("Missing zone reference. \n");
  918. if (spawn_id == 0)
  919. output = output.append("\t").append("Missing spawn_id.");
  920. lua_interface->LogError("Error in EQ2Emu_lua_Zone - %s", output.c_str());
  921. }
  922. return 0;
  923. }
  924. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  925. if (!lua_interface)
  926. return 0;
  927. ZoneServer* zone = lua_interface->GetZone(state);
  928. if (zone) {
  929. lua_interface->SetStringValue(state, zone->GetZoneName());
  930. return 1;
  931. }
  932. return 0;
  933. }
  934. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  935. if (!lua_interface)
  936. return 0;
  937. ZoneServer* zone = lua_interface->GetZone(state);
  938. if (zone) {
  939. lua_interface->SetInt32Value(state, zone->GetZoneID());
  940. return 1;
  941. }
  942. return 0;
  943. }
  944. int EQ2Emu_lua_GetZone(lua_State* state) {
  945. if (!lua_interface)
  946. return 0;
  947. int32 zone_id = lua_interface->GetInt32Value(state);
  948. ZoneServer* zone = 0;
  949. if (zone_id > 0)
  950. zone = zone_list.Get(zone_id);
  951. else {
  952. string zone_name = lua_interface->GetStringValue(state);
  953. if (zone_name.length() > 0) {
  954. zone = zone_list.Get(zone_name.c_str());
  955. }
  956. else {
  957. Spawn* spawn = lua_interface->GetSpawn(state);
  958. if (spawn)
  959. zone = spawn->GetZone();
  960. }
  961. }
  962. if (zone) {
  963. lua_interface->SetZoneValue(state, zone);
  964. return 1;
  965. }
  966. return 0;
  967. }
  968. int EQ2Emu_lua_AddHate(lua_State* state) {
  969. Spawn* entity = lua_interface->GetSpawn(state);
  970. Spawn* npc = lua_interface->GetSpawn(state, 2);
  971. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  972. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  973. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  974. if (entity && entity->IsEntity() && amount != 0) {
  975. if (luaspell) {
  976. ZoneServer* zone = luaspell->caster->GetZone();
  977. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  978. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  979. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  980. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  981. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  982. if (send_packet)
  983. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  984. }
  985. }
  986. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  987. }
  988. else if (npc && npc->IsNPC() && npc->GetZone())
  989. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  990. }
  991. return 0;
  992. }
  993. int EQ2Emu_lua_Zone(lua_State* state) {
  994. if (!lua_interface)
  995. return 0;
  996. ZoneServer* zone = lua_interface->GetZone(state);
  997. Spawn* player = lua_interface->GetSpawn(state, 2);
  998. Client* client = 0;
  999. if (player && player->IsPlayer())
  1000. client = player->GetZone()->GetClientBySpawn(player);
  1001. float x = lua_interface->GetFloatValue(state, 3);
  1002. float y = lua_interface->GetFloatValue(state, 4);
  1003. float z = lua_interface->GetFloatValue(state, 5);
  1004. float heading = lua_interface->GetFloatValue(state, 6);
  1005. if (zone && client) {
  1006. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1007. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1008. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1009. {
  1010. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1011. return 0;
  1012. }
  1013. if (x != 0 || y != 0 || z != 0) {
  1014. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1015. player->SetX(x);
  1016. player->SetY(y);
  1017. player->SetZ(z);
  1018. player->SetHeading(heading);
  1019. client->Zone(zone->GetZoneName(), false);
  1020. }
  1021. else
  1022. client->Zone(zone->GetZoneName());
  1023. }
  1024. else
  1025. lua_interface->SimpleLogError("Error in EQ2Emu_lua_Zone: invalid zone or spawn input.");
  1026. return 0;
  1027. }
  1028. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1029. if (!lua_interface)
  1030. return 0;
  1031. Spawn* spawn = lua_interface->GetSpawn(state);
  1032. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1033. if (spawn && spawn2)
  1034. spawn->AddAllowAccessSpawn(spawn2);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1038. if (!lua_interface)
  1039. return 0;
  1040. Spawn* target = lua_interface->GetSpawn(state);
  1041. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1042. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1043. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1044. if (!target) {
  1045. lua_interface->LogError("LUA CastSpell command error: target is not a valid spawn");
  1046. return 0;
  1047. }
  1048. if (!target->IsEntity()) {
  1049. lua_interface->LogError("LUA CastSpell command error: target (%s) is not an entity", target->GetName());
  1050. return 0;
  1051. }
  1052. if (spell_id <= 0) {
  1053. lua_interface->LogError("LUA CastSpell command error: spell id is not valid");
  1054. return 0;
  1055. }
  1056. if (caster && !caster->IsEntity()) {
  1057. lua_interface->LogError("LUA CastSpell command error: caster (%s) is not an entity", caster->GetName());
  1058. return 0;
  1059. }
  1060. if (spell_tier == 0)
  1061. spell_tier = 1;
  1062. if (!caster)
  1063. caster = target;
  1064. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target);
  1065. return 0;
  1066. }
  1067. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1068. if (!lua_interface)
  1069. return 0;
  1070. Spawn* target = lua_interface->GetSpawn(state);
  1071. int32 target_id = 0;
  1072. if (target)
  1073. target_id = target->GetID();
  1074. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1075. if (!luaspell)
  1076. return 0;
  1077. Spawn* caster = luaspell->caster;
  1078. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1079. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1080. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1081. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1082. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1083. //lua_interface->ResetFunctionStack(state);
  1084. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1085. vector<int16> faction_req;
  1086. vector<int16> race_req;
  1087. int32 class_req = 0;
  1088. int32 i = 0;
  1089. int8 f = 0;
  1090. int8 r = 0;
  1091. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1092. if (class_id < 100) {
  1093. class_req += pow(2.0, double(class_id - 1));
  1094. }
  1095. else if (class_id > 100 && class_id < 1000) {
  1096. race_req.push_back(class_id);
  1097. r++;
  1098. }
  1099. else {
  1100. faction_req.push_back(class_id);
  1101. f++;
  1102. }
  1103. i++;
  1104. }
  1105. if (caster && caster->IsEntity()) {
  1106. bool race_match = false;
  1107. bool success = false;
  1108. luaspell->resisted = false;
  1109. if (luaspell->initial_target == target_id) {
  1110. int xxx = 0;
  1111. }
  1112. if (luaspell->targets.size() > 0 && (luaspell->initial_target != target_id)) {
  1113. ZoneServer* zone = luaspell->caster->GetZone();
  1114. Spawn* target = 0;
  1115. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1116. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1117. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1118. if (race_req.size() > 0) {
  1119. for (int8 i = 0; i < race_req.size(); i++) {
  1120. int32 xxx = target->GetLuaRaceId();
  1121. if (target->GetLuaRaceId() == race_req[i]) {
  1122. race_match = true;
  1123. }
  1124. }
  1125. }
  1126. else
  1127. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1128. if (race_match == true) {
  1129. float distance = caster->GetDistance(target, true);
  1130. distance -= caster->appearance.pos.collision_radius / 10;
  1131. distance -= target->appearance.pos.collision_radius / 10;
  1132. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1133. }
  1134. }
  1135. }
  1136. success = true;
  1137. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1138. }
  1139. else if (target) {
  1140. //check class and race/faction here
  1141. if (race_req.size() > 0) {
  1142. for (int8 i = 0; i < race_req.size(); i++) {
  1143. if (target->GetLuaRaceId() == race_req[i]) {
  1144. race_match = true;
  1145. }
  1146. }
  1147. }
  1148. else
  1149. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1150. if (race_match == true) {
  1151. float distance = caster->GetDistance(target, true);
  1152. distance -= caster->appearance.pos.collision_radius / 10;
  1153. distance -= target->appearance.pos.collision_radius / 10;
  1154. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1155. success = true;
  1156. }
  1157. }
  1158. if (success) {
  1159. Spell* spell = luaspell->spell;
  1160. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1161. ((Player*)caster)->InCombat(true);
  1162. if (caster->GetZone())
  1163. caster->GetZone()->TriggerCharSheetTimer();
  1164. }
  1165. }
  1166. }
  1167. return 0;
  1168. }
  1169. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1170. if (!lua_interface)
  1171. return 0;
  1172. Spawn* spawn = lua_interface->GetSpawn(state);
  1173. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1174. lua_interface->ResetFunctionStack(state);
  1175. if (spawn && value != 0) {
  1176. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1177. spawn->SetPower(spawn->GetTotalPower());
  1178. else
  1179. spawn->SetPower(spawn->GetPower() + value);
  1180. }
  1181. return 0;
  1182. }
  1183. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1184. if (!lua_interface)
  1185. return 0;
  1186. Spawn* spawn = lua_interface->GetSpawn(state);
  1187. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1188. lua_interface->ResetFunctionStack(state);
  1189. if (spawn && value != 0) {
  1190. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1191. spawn->SetHP(spawn->GetTotalHP());
  1192. else
  1193. spawn->SetHP(spawn->GetHP() + value);
  1194. }
  1195. return 0;
  1196. }
  1197. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1198. if (!lua_interface)
  1199. return 0;
  1200. Spawn* spawn = lua_interface->GetSpawn(state);
  1201. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1202. lua_interface->ResetFunctionStack(state);
  1203. if (spawn && value != 0) {
  1204. spawn->SetPower(spawn->GetPower() + value);
  1205. if (value > spawn->GetTotalHPBase())
  1206. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1207. }
  1208. return 0;
  1209. }
  1210. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1211. if (!lua_interface)
  1212. return 0;
  1213. Spawn* spawn = lua_interface->GetSpawn(state);
  1214. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1215. lua_interface->ResetFunctionStack(state);
  1216. if (spawn && value != 0) {
  1217. spawn->SetHP(spawn->GetHP() + value);
  1218. if (value > spawn->GetTotalHPBase())
  1219. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1220. }
  1221. return 0;
  1222. }
  1223. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1224. if (!lua_interface)
  1225. return 0;
  1226. Spawn* spawn = lua_interface->GetSpawn(state);
  1227. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1228. lua_interface->ResetFunctionStack(state);
  1229. if (spawn && value > 0) {
  1230. spawn->SetHP(value);
  1231. if (value > spawn->GetTotalHPBase())
  1232. spawn->SetTotalHP(value);
  1233. }
  1234. return 0;
  1235. }
  1236. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1237. if (!lua_interface)
  1238. return 0;
  1239. Spawn* spawn = lua_interface->GetSpawn(state);
  1240. float value = lua_interface->GetFloatValue(state, 2);
  1241. lua_interface->ResetFunctionStack(state);
  1242. if (spawn && spawn->IsEntity() && value > 0)
  1243. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1244. if (spawn->IsPlayer())
  1245. ((Player*)spawn)->SetCharSheetChanged(true);
  1246. return 0;
  1247. }
  1248. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1249. if (!lua_interface)
  1250. return 0;
  1251. Spawn* spawn = lua_interface->GetSpawn(state);
  1252. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1253. lua_interface->ResetFunctionStack(state);
  1254. if (spawn && spawn->IsEntity() && value > 0)
  1255. ((Entity*)spawn)->SetTotalHPBase(value);
  1256. return 0;
  1257. }
  1258. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1259. if (!lua_interface)
  1260. return 0;
  1261. Spawn* spawn = lua_interface->GetSpawn(state);
  1262. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1263. lua_interface->ResetFunctionStack(state);
  1264. if (spawn && value > 0) {
  1265. spawn->SetPower(value);
  1266. if (value > spawn->GetTotalPowerBase())
  1267. spawn->SetTotalPower(value);
  1268. }
  1269. return 0;
  1270. }
  1271. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1272. if (!lua_interface)
  1273. return 0;
  1274. Spawn* spawn = lua_interface->GetSpawn(state);
  1275. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1276. lua_interface->ResetFunctionStack(state);
  1277. if (spawn && spawn->IsEntity() && value > 0)
  1278. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1279. return 0;
  1280. }
  1281. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1282. if (!lua_interface)
  1283. return 0;
  1284. Spawn* spawn = lua_interface->GetSpawn(state);
  1285. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1286. lua_interface->ResetFunctionStack(state);
  1287. if (spawn && spawn->IsEntity() && value > 0)
  1288. ((Entity*)spawn)->SetTotalPowerBase(value);
  1289. return 0;
  1290. }
  1291. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1292. if (!lua_interface)
  1293. return 0;
  1294. Spawn* spawn = lua_interface->GetSpawn(state);
  1295. float x = lua_interface->GetFloatValue(state, 2);
  1296. float y = lua_interface->GetFloatValue(state, 3);
  1297. float z = lua_interface->GetFloatValue(state, 4);
  1298. float heading = lua_interface->GetFloatValue(state, 5);
  1299. lua_interface->ResetFunctionStack(state);
  1300. if (spawn) {
  1301. spawn->SetX(x);
  1302. spawn->SetY(y);
  1303. spawn->SetZ(z);
  1304. if (heading != 0)
  1305. spawn->SetHeading(heading);
  1306. spawn->SetSpawnOrigX(spawn->GetX());
  1307. spawn->SetSpawnOrigY(spawn->GetY());
  1308. spawn->SetSpawnOrigZ(spawn->GetZ());
  1309. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1310. if (spawn->IsPlayer()) {
  1311. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1312. if (client) {
  1313. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1314. client->QueuePacket(packet);
  1315. }
  1316. }
  1317. }
  1318. return 0;
  1319. }
  1320. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1321. if (!lua_interface)
  1322. return 0;
  1323. Spawn* spawn = lua_interface->GetSpawn(state);
  1324. float value = lua_interface->GetFloatValue(state, 2);
  1325. lua_interface->ResetFunctionStack(state);
  1326. if (spawn) {
  1327. spawn->SetHeading(value);
  1328. if (spawn->IsPlayer()) {
  1329. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1330. if (client) {
  1331. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1332. client->QueuePacket(packet);
  1333. }
  1334. }
  1335. }
  1336. return 0;
  1337. }
  1338. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1339. if (!lua_interface)
  1340. return 0;
  1341. Spawn* spawn = lua_interface->GetSpawn(state);
  1342. int16 value = lua_interface->GetInt16Value(state, 2);
  1343. lua_interface->ResetFunctionStack(state);
  1344. if (spawn)
  1345. spawn->SetModelType(value);
  1346. return 0;
  1347. }
  1348. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1349. if (!lua_interface)
  1350. return 0;
  1351. Spawn* spawn = lua_interface->GetSpawn(state);
  1352. int8 value = lua_interface->GetInt8Value(state, 2);
  1353. lua_interface->ResetFunctionStack(state);
  1354. if (spawn) {
  1355. if (spawn->IsPlayer())
  1356. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1357. else
  1358. spawn->SetAdventureClass(value);
  1359. }
  1360. return 0;
  1361. }
  1362. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1363. if (!lua_interface)
  1364. return 0;
  1365. Spawn* spawn = lua_interface->GetSpawn(state);
  1366. int8 value = lua_interface->GetInt8Value(state, 2);
  1367. lua_interface->ResetFunctionStack(state);
  1368. if (spawn) {
  1369. spawn->SetTradeskillClass(value);
  1370. if (spawn->IsEntity()) {
  1371. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1372. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1373. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1374. }
  1375. if (spawn->IsPlayer())
  1376. ((Player*)spawn)->SetCharSheetChanged(true);
  1377. }
  1378. return 0;
  1379. }
  1380. int EQ2Emu_lua_SetMount(lua_State* state) {
  1381. if (!lua_interface)
  1382. return 0;
  1383. Spawn* spawn = lua_interface->GetSpawn(state);
  1384. int16 value = lua_interface->GetInt16Value(state, 2);
  1385. if (spawn && spawn->IsEntity()) {
  1386. ((Entity*)spawn)->SetMount(value);
  1387. EQ2_Color color;
  1388. color.red = 255;
  1389. color.green = 255;
  1390. color.blue = 255;
  1391. ((Entity*)spawn)->SetMountColor(&color);
  1392. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1393. }
  1394. return 0;
  1395. }
  1396. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1397. if (!lua_interface)
  1398. return 0;
  1399. Spawn* spawn = lua_interface->GetSpawn(state);
  1400. EQ2_Color mount_color;
  1401. EQ2_Color saddle_color;
  1402. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1403. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1404. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1405. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1406. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1407. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1408. if (spawn && spawn->IsEntity()) {
  1409. ((Entity*)spawn)->SetMountColor(&mount_color);
  1410. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1411. }
  1412. return 0;
  1413. }
  1414. int EQ2Emu_lua_GetMount(lua_State* state) {
  1415. if (!lua_interface)
  1416. return 0;
  1417. Spawn* spawn = lua_interface->GetSpawn(state);
  1418. if (spawn && spawn->IsEntity()) {
  1419. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1420. return 1;
  1421. }
  1422. return 0;
  1423. }
  1424. int EQ2Emu_lua_GetRace(lua_State* state) {
  1425. if (!lua_interface)
  1426. return 0;
  1427. Spawn* spawn = lua_interface->GetSpawn(state);
  1428. if (spawn)
  1429. {
  1430. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1431. lua_interface->SetInt32Value(state, spawn->GetRace());
  1432. return 1;
  1433. }
  1434. return 0;
  1435. }
  1436. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1437. if (!lua_interface)
  1438. return 0;
  1439. Spawn* spawn = lua_interface->GetSpawn(state);
  1440. if (spawn) {
  1441. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1442. return 1;
  1443. }
  1444. return 0;
  1445. }
  1446. int EQ2Emu_lua_GetClass(lua_State* state) {
  1447. Spawn* spawn = lua_interface->GetSpawn(state);
  1448. if (spawn) {
  1449. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1450. return 1;
  1451. }
  1452. return 0;
  1453. }
  1454. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1455. Spawn* spawn = lua_interface->GetSpawn(state);
  1456. if (spawn) {
  1457. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1458. return 1;
  1459. }
  1460. return 0;
  1461. }
  1462. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1463. if (!lua_interface)
  1464. return 0;
  1465. Spawn* spawn = lua_interface->GetSpawn(state);
  1466. float value = lua_interface->GetFloatValue(state, 2);
  1467. lua_interface->ResetFunctionStack(state);
  1468. if (spawn) {
  1469. spawn->SetSpeed(value);
  1470. if (spawn->IsPlayer()) {
  1471. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1472. if (client) {
  1473. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1474. if (packet) {
  1475. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1476. packet->setDataByName("speed", value);
  1477. packet->setDataByName("size", 0.51);
  1478. EQ2Packet* app = packet->serialize();
  1479. client->QueuePacket(app);
  1480. safe_delete(packet);
  1481. }
  1482. }
  1483. }
  1484. }
  1485. return 0;
  1486. }
  1487. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1488. if (!lua_interface)
  1489. return 0;
  1490. Spawn* spawn = lua_interface->GetSpawn(state);
  1491. const int16 type = lua_interface->GetInt16Value(state, 2);
  1492. const float value = lua_interface->GetFloatValue(state, 3);
  1493. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1494. int64 class_req = 0;
  1495. int32 class_id = 0;
  1496. vector<int16> faction_req;
  1497. vector<int16> race_req;
  1498. int32 i = 0;
  1499. int8 f = 0;
  1500. int8 r = 0;
  1501. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1502. if (class_id < 100) {
  1503. class_req += pow(2.0, double(class_id - 1));
  1504. }
  1505. else if (class_id > 100 && class_id < 1000) {
  1506. race_req.push_back(class_id);
  1507. r++;
  1508. }
  1509. else {
  1510. faction_req.push_back(class_id);
  1511. f++;
  1512. }
  1513. i++;
  1514. }
  1515. if (value != 0 && type >= 0) {
  1516. if (luaspell && luaspell->spell && luaspell->caster) {
  1517. ZoneServer* zone = luaspell->caster->GetZone();
  1518. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1519. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1520. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1521. if (target) {
  1522. if (target->IsPlayer()) {
  1523. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1524. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1525. if (((Player*)target)->GetGroupMemberInfo())
  1526. ((Player*)target)->UpdateGroupMemberInfo();
  1527. ((Player*)target)->SetCharSheetChanged(true);
  1528. }
  1529. else if (target->IsNPC())
  1530. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1531. else
  1532. lua_interface->SimpleLogError("Error applying spell bonus on non entity.");
  1533. }
  1534. }
  1535. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1536. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1537. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1538. }
  1539. else if (spawn && spawn->IsEntity()) {
  1540. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1541. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1542. if (spawn->IsPlayer())
  1543. ((Player*)spawn)->SetCharSheetChanged(true);
  1544. }
  1545. else
  1546. lua_interface->SimpleLogError("Unable to apply spell bonus in AddSpellBonus.");
  1547. }
  1548. else
  1549. lua_interface->SimpleLogError("Invalid parameters for AddSpellBonus.");
  1550. return 0;
  1551. }
  1552. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1553. if (!lua_interface)
  1554. return 0;
  1555. Spawn* spawn = lua_interface->GetSpawn(state);
  1556. int16 type = lua_interface->GetInt16Value(state, 2);
  1557. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1558. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1559. if (!spawn) {
  1560. lua_interface->LogError("LUA AddSpawnSpellBonus command error: spawn is not valid");
  1561. return 0;
  1562. }
  1563. if (!spawn->IsEntity()) {
  1564. lua_interface->LogError("LUA AddSpawnSpellBonus command error: spawn is not an entity");
  1565. return 0;
  1566. }
  1567. if (value == 0) {
  1568. lua_interface->LogError("LUA AddSpawnSpellBonus command error: value must be set");
  1569. return 0;
  1570. }
  1571. if (!luaspell || !luaspell->spell) {
  1572. lua_interface->LogError("LUA AddSpawnSpellBonus command error: can only be used in a spell script");
  1573. return 0;
  1574. }
  1575. int32 class_req = 0;
  1576. vector<int16> faction_req;
  1577. vector<int16> race_req;
  1578. int32 class_id = 0;
  1579. int32 i = 0;
  1580. int8 f = 0;
  1581. int8 r = 0;
  1582. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1583. if (class_id < 100) {
  1584. class_req += pow(2.0, double(class_id - 1));
  1585. }
  1586. else if (class_id > 100 && class_id < 1000) {
  1587. race_req.push_back(class_id);
  1588. r++;
  1589. }
  1590. else {
  1591. faction_req.push_back(class_id);
  1592. f++;
  1593. }
  1594. i++;
  1595. }
  1596. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1597. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1598. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1599. if (spawn->IsPlayer())
  1600. ((Player*)spawn)->SetCharSheetChanged(true);
  1601. return 0;
  1602. }
  1603. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1604. if (!lua_interface)
  1605. return 0;
  1606. Spawn* spawn = lua_interface->GetSpawn(state);
  1607. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1608. if (luaspell && luaspell->spell) {
  1609. ZoneServer* zone = luaspell->caster->GetZone();
  1610. Spawn* target = 0;
  1611. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1612. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1613. target = zone->GetSpawnByID(luaspell->targets[i]);
  1614. if (target && target->IsEntity()) {
  1615. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1616. if (target->IsPlayer())
  1617. ((Player*)target)->SetCharSheetChanged(true);
  1618. }
  1619. }
  1620. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1621. }
  1622. else if (spawn && spawn->IsEntity()) {
  1623. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1624. if (spawn->IsPlayer())
  1625. ((Player*)spawn)->SetCharSheetChanged(true);
  1626. }
  1627. return 0;
  1628. }
  1629. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1630. if (!lua_interface)
  1631. return 0;
  1632. Spawn* spawn = lua_interface->GetSpawn(state);
  1633. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1634. float value = lua_interface->GetFloatValue(state, 3);
  1635. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1636. if (value != 0) {
  1637. int32 spell_id = 0;
  1638. if (luaspell && luaspell->spell && luaspell->caster) {
  1639. spell_id = luaspell->spell->GetSpellID();
  1640. ZoneServer* zone = luaspell->caster->GetZone();
  1641. Spawn* target = 0;
  1642. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1643. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1644. target = zone->GetSpawnByID(luaspell->targets[i]);
  1645. if (target && target->Alive()) {
  1646. if (target->IsPlayer()) {
  1647. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1648. Client* client = target->GetZone()->GetClientBySpawn(target);
  1649. if (client) {
  1650. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1651. if (packet)
  1652. client->QueuePacket(packet);
  1653. }
  1654. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1655. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1656. }
  1657. else if (target->IsNPC()) {
  1658. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1659. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1660. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1661. }
  1662. else
  1663. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1664. }
  1665. }
  1666. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1667. }
  1668. else if (spawn) {
  1669. if (spawn->IsPlayer()) {
  1670. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1671. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1672. if (client) {
  1673. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1674. if (packet)
  1675. client->QueuePacket(packet);
  1676. }
  1677. }
  1678. else if (spawn->IsNPC())
  1679. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1680. else
  1681. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1682. }
  1683. }
  1684. else
  1685. lua_interface->SimpleLogError("Invalid parameters for AddSkillBonus.");
  1686. return 0;
  1687. }
  1688. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1689. if (!lua_interface)
  1690. return 0;
  1691. Spawn* spawn = lua_interface->GetSpawn(state);
  1692. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1693. if (spawn && spawn->IsPlayer()) {
  1694. int32 spell_id = 0;
  1695. if (luaspell && luaspell->spell) {
  1696. spell_id = luaspell->spell->GetSpellID();
  1697. ZoneServer* zone = luaspell->caster->GetZone();
  1698. Spawn* target = 0;
  1699. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1700. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1701. target = zone->GetSpawnByID(luaspell->targets[i]);
  1702. if (target) {
  1703. if (target->IsPlayer()) {
  1704. ((Player*)target)->RemoveSkillBonus(spell_id);
  1705. Client* client = target->GetZone()->GetClientBySpawn(target);
  1706. if (client) {
  1707. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1708. if (packet)
  1709. client->QueuePacket(packet);
  1710. }
  1711. }
  1712. else if (target->IsNPC())
  1713. ((NPC*)target)->RemoveSkillBonus(spell_id);
  1714. else
  1715. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1716. }
  1717. }
  1718. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1719. }
  1720. else if (spawn) {
  1721. if (spawn->IsPlayer()) {
  1722. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  1723. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1724. if (client) {
  1725. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1726. if (packet)
  1727. client->QueuePacket(packet);
  1728. }
  1729. }
  1730. else if (spawn->IsNPC())
  1731. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  1732. else
  1733. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1734. }
  1735. }
  1736. return 0;
  1737. }
  1738. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  1739. if (!lua_interface)
  1740. return 0;
  1741. Spawn* spawn = lua_interface->GetSpawn(state);
  1742. int8 type = lua_interface->GetInt32Value(state, 2);
  1743. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1744. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1745. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  1746. ZoneServer* zone = luaspell->caster->GetZone();
  1747. Spawn* target = 0;
  1748. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1749. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1750. target = zone->GetSpawnByID(luaspell->targets[i]);
  1751. if (target && target->IsEntity()) {
  1752. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1753. ((Entity*)target)->AddMezSpell(luaspell);
  1754. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1755. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1756. if (target->IsNPC())
  1757. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1758. }
  1759. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1760. ((Entity*)target)->AddStifleSpell(luaspell);
  1761. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1762. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1763. if (target->IsNPC())
  1764. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1765. }
  1766. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1767. ((Entity*)target)->AddDazeSpell(luaspell);
  1768. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1769. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1770. if (target->IsNPC())
  1771. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1772. }
  1773. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1774. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1775. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1776. ((Entity*)target)->AddStunSpell(luaspell);
  1777. if (target->IsNPC())
  1778. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1779. }
  1780. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1781. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1782. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1783. ((Entity*)target)->AddRootSpell(luaspell);
  1784. if (target->IsNPC())
  1785. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1786. }
  1787. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1788. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1789. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1790. ((Entity*)target)->AddFearSpell(luaspell);
  1791. if (target->IsNPC())
  1792. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1793. }
  1794. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1795. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  1796. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1797. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1798. }
  1799. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1800. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  1801. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1802. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1803. }
  1804. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1805. ((Entity*)target)->AddSnareSpell(luaspell);
  1806. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1807. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1808. if (target->IsNPC())
  1809. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1810. }
  1811. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1812. ((Entity*)target)->AddFlightSpell(luaspell);
  1813. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1814. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1815. }
  1816. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1817. ((Entity*)target)->AddGlideSpell(luaspell);
  1818. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1819. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1820. }
  1821. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1822. ((Entity*)target)->AddSafefallSpell(luaspell);
  1823. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1824. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1825. }
  1826. else
  1827. lua_interface->LogError("Unhandled control effect type of %u.", type);
  1828. }
  1829. else
  1830. lua_interface->LogError("Error applying control effect on non entity '%s'.", target->GetName());
  1831. }
  1832. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1833. }
  1834. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  1835. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1836. ((Entity*)spawn)->AddMezSpell(luaspell);
  1837. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1838. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1839. }
  1840. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1841. ((Entity*)spawn)->AddStifleSpell(luaspell);
  1842. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1843. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1844. }
  1845. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1846. ((Entity*)spawn)->AddDazeSpell(luaspell);
  1847. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1848. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1849. }
  1850. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1851. ((Entity*)spawn)->AddStunSpell(luaspell);
  1852. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1853. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1854. }
  1855. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1856. ((Entity*)spawn)->AddRootSpell(luaspell);
  1857. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1858. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1859. }
  1860. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1861. ((Entity*)spawn)->AddFearSpell(luaspell);
  1862. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1863. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1864. }
  1865. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1866. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  1867. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1868. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1869. }
  1870. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1871. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  1872. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1873. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1874. }
  1875. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1876. ((Entity*)spawn)->AddSnareSpell(luaspell);
  1877. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1878. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1879. }
  1880. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1881. ((Entity*)spawn)->AddFlightSpell(luaspell);
  1882. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1883. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1884. }
  1885. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1886. ((Entity*)spawn)->AddGlideSpell(luaspell);
  1887. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1888. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1889. }
  1890. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1891. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  1892. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1893. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1894. }
  1895. else
  1896. lua_interface->LogError("Unhandled control effect type of %u.", type);
  1897. }
  1898. else
  1899. lua_interface->LogError("Error applying control effect on non entity '%s'.", spawn->GetName());
  1900. return 0;
  1901. }
  1902. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  1903. if (!lua_interface)
  1904. return 0;
  1905. Spawn* spawn = lua_interface->GetSpawn(state);
  1906. int8 type = lua_interface->GetInt8Value(state, 2);
  1907. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1908. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1909. if (spawn && spawn->IsEntity()) {
  1910. if (!only_remove_spawn && luaspell && luaspell->spell) {
  1911. ZoneServer* zone = luaspell->caster->GetZone();
  1912. Spawn* target = 0;
  1913. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1914. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1915. target = zone->GetSpawnByID(luaspell->targets[i]);
  1916. if (target) {
  1917. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1918. ((Entity*)target)->RemoveMezSpell(luaspell);
  1919. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1920. ((Entity*)target)->RemoveStifleSpell(luaspell);
  1921. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1922. ((Entity*)target)->RemoveDazeSpell(luaspell);
  1923. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1924. ((Entity*)target)->RemoveStunSpell(luaspell);
  1925. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1926. ((Entity*)target)->RemoveRootSpell(luaspell);
  1927. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1928. ((Entity*)target)->RemoveFearSpell(luaspell);
  1929. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1930. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  1931. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1932. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  1933. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  1934. ((Entity*)target)->RemoveSnareSpell(luaspell);
  1935. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  1936. ((Entity*)target)->RemoveFlightSpell(luaspell);
  1937. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  1938. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1939. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  1940. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1941. else
  1942. lua_interface->LogError("Unhandled control effect type of %u.", type);
  1943. }
  1944. }
  1945. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1946. }
  1947. else if (only_remove_spawn) {
  1948. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1949. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  1950. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1951. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  1952. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1953. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  1954. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1955. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  1956. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1957. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  1958. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1959. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  1960. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1961. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  1962. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1963. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  1964. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  1965. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  1966. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  1967. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  1968. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  1969. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  1970. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  1971. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  1972. else
  1973. lua_interface->LogError("Unhandled control effect type of %u.", type);
  1974. }
  1975. }
  1976. return 0;
  1977. }
  1978. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  1979. if (!lua_interface)
  1980. return 0;
  1981. Spawn* spawn = lua_interface->GetSpawn(state);
  1982. int16 value = lua_interface->GetInt16Value(state, 2);
  1983. if (spawn && spawn->IsEntity()) {
  1984. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  1985. if (spawn->IsPlayer())
  1986. ((Player*)spawn)->SetCharSheetChanged(true);
  1987. }
  1988. return 0;
  1989. }
  1990. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  1991. if (!lua_interface)
  1992. return 0;
  1993. Spawn* spawn = lua_interface->GetSpawn(state);
  1994. int16 value = lua_interface->GetInt16Value(state, 2);
  1995. if (spawn && spawn->IsEntity()) {
  1996. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  1997. if (spawn->IsPlayer())
  1998. ((Player*)spawn)->SetCharSheetChanged(true);
  1999. }
  2000. return 0;
  2001. }
  2002. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2003. if (!lua_interface)
  2004. return 0;
  2005. Spawn* spawn = lua_interface->GetSpawn(state);
  2006. int16 value = lua_interface->GetInt16Value(state, 2);
  2007. if (spawn && spawn->IsEntity()) {
  2008. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2009. if (spawn->IsPlayer())
  2010. ((Player*)spawn)->SetCharSheetChanged(true);
  2011. }
  2012. return 0;
  2013. }
  2014. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2015. if (!lua_interface)
  2016. return 0;
  2017. Spawn* spawn = lua_interface->GetSpawn(state);
  2018. int16 value = lua_interface->GetInt16Value(state, 2);
  2019. if (spawn && spawn->IsEntity()) {
  2020. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2021. if (spawn->IsPlayer())
  2022. ((Player*)spawn)->SetCharSheetChanged(true);
  2023. }
  2024. return 0;
  2025. }
  2026. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2027. if (!lua_interface)
  2028. return 0;
  2029. Spawn* spawn = lua_interface->GetSpawn(state);
  2030. int16 value = lua_interface->GetInt16Value(state, 2);
  2031. if (spawn && spawn->IsEntity()) {
  2032. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2033. if (spawn->IsPlayer())
  2034. ((Player*)spawn)->SetCharSheetChanged(true);
  2035. }
  2036. return 0;
  2037. }
  2038. int EQ2Emu_lua_SetInt(lua_State* state) {
  2039. if (!lua_interface)
  2040. return 0;
  2041. Spawn* spawn = lua_interface->GetSpawn(state);
  2042. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2043. if (spawn && spawn->IsEntity()) {
  2044. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2045. if (spawn->IsPlayer())
  2046. ((Player*)spawn)->SetCharSheetChanged(true);
  2047. }
  2048. return 0;
  2049. }
  2050. int EQ2Emu_lua_SetWis(lua_State* state) {
  2051. if (!lua_interface)
  2052. return 0;
  2053. Spawn* spawn = lua_interface->GetSpawn(state);
  2054. float value = lua_interface->GetFloatValue(state, 2);
  2055. if (spawn && spawn->IsEntity()) {
  2056. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2057. if (spawn->IsPlayer())
  2058. ((Player*)spawn)->SetCharSheetChanged(true);
  2059. }
  2060. return 0;
  2061. }
  2062. int EQ2Emu_lua_SetSta(lua_State* state) {
  2063. if (!lua_interface)
  2064. return 0;
  2065. Spawn* spawn = lua_interface->GetSpawn(state);
  2066. float value = lua_interface->GetFloatValue(state, 2);
  2067. if (spawn && spawn->IsEntity()) {
  2068. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2069. if (spawn->IsPlayer())
  2070. ((Player*)spawn)->SetCharSheetChanged(true);
  2071. }
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_SetStr(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. float value = lua_interface->GetFloatValue(state, 2);
  2079. if (spawn && spawn->IsEntity()) {
  2080. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2081. if (spawn->IsPlayer())
  2082. ((Player*)spawn)->SetCharSheetChanged(true);
  2083. }
  2084. return 0;
  2085. }
  2086. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2087. if (!lua_interface)
  2088. return 0;
  2089. Spawn* spawn = lua_interface->GetSpawn(state);
  2090. float value = lua_interface->GetFloatValue(state, 2);
  2091. if (spawn && spawn->IsEntity()) {
  2092. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2093. if (spawn->IsPlayer())
  2094. ((Player*)spawn)->SetCharSheetChanged(true);
  2095. }
  2096. return 0;
  2097. }
  2098. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2099. if (!lua_interface)
  2100. return 0;
  2101. Spawn* spawn = lua_interface->GetSpawn(state);
  2102. if (spawn) {
  2103. lua_interface->SetInt32Value(state, spawn->GetHP());
  2104. return 1;
  2105. }
  2106. return 0;
  2107. }
  2108. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2109. if (!lua_interface)
  2110. return 0;
  2111. Spawn* spawn = lua_interface->GetSpawn(state);
  2112. if (spawn) {
  2113. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2114. return 1;
  2115. }
  2116. return 0;
  2117. }
  2118. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2119. if (!lua_interface)
  2120. return 0;
  2121. Spawn* spawn = lua_interface->GetSpawn(state);
  2122. if (spawn) {
  2123. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2124. return 1;
  2125. }
  2126. return 0;
  2127. }
  2128. int EQ2Emu_lua_GetName(lua_State* state) {
  2129. if (!lua_interface)
  2130. return 0;
  2131. Spawn* spawn = lua_interface->GetSpawn(state);
  2132. if (spawn) {
  2133. lua_interface->SetStringValue(state, spawn->GetName());
  2134. return 1;
  2135. }
  2136. return 0;
  2137. }
  2138. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2139. Spawn* spawn = lua_interface->GetSpawn(state);
  2140. if (spawn) {
  2141. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2142. return 1;
  2143. }
  2144. return 0;
  2145. }
  2146. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2147. if (!lua_interface)
  2148. return 0;
  2149. Spawn* spawn = lua_interface->GetSpawn(state);
  2150. if (spawn) {
  2151. lua_interface->SetInt32Value(state, spawn->GetPower());
  2152. return 1;
  2153. }
  2154. return 0;
  2155. }
  2156. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2157. if (!lua_interface)
  2158. return 0;
  2159. Spawn* spawn = lua_interface->GetSpawn(state);
  2160. if (spawn) {
  2161. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2162. return 1;
  2163. }
  2164. return 0;
  2165. }
  2166. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2167. if (!lua_interface)
  2168. return 0;
  2169. Spawn* spawn = lua_interface->GetSpawn(state);
  2170. if (spawn) {
  2171. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2172. return 1;
  2173. }
  2174. return 0;
  2175. }
  2176. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2177. if (!lua_interface)
  2178. return 0;
  2179. Spawn* spawn = lua_interface->GetSpawn(state);
  2180. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2181. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2182. if (spawn && spawn2) {
  2183. float distance = spawn->GetDistance(spawn2);
  2184. if (include_radius) {
  2185. distance -= spawn->appearance.pos.collision_radius / 10;
  2186. distance -= spawn2->appearance.pos.collision_radius / 10;
  2187. }
  2188. lua_interface->SetFloatValue(state, distance);
  2189. return 1;
  2190. }
  2191. return 0;
  2192. }
  2193. int EQ2Emu_lua_GetX(lua_State* state) {
  2194. if (!lua_interface)
  2195. return 0;
  2196. Spawn* spawn = lua_interface->GetSpawn(state);
  2197. if (spawn) {
  2198. lua_interface->SetFloatValue(state, spawn->GetX());
  2199. return 1;
  2200. }
  2201. return 0;
  2202. }
  2203. int EQ2Emu_lua_GetY(lua_State* state) {
  2204. if (!lua_interface)
  2205. return 0;
  2206. Spawn* spawn = lua_interface->GetSpawn(state);
  2207. if (spawn) {
  2208. lua_interface->SetFloatValue(state, spawn->GetY());
  2209. return 1;
  2210. }
  2211. return 0;
  2212. }
  2213. int EQ2Emu_lua_GetZ(lua_State* state) {
  2214. if (!lua_interface)
  2215. return 0;
  2216. Spawn* spawn = lua_interface->GetSpawn(state);
  2217. if (spawn) {
  2218. lua_interface->SetFloatValue(state, spawn->GetZ());
  2219. return 1;
  2220. }
  2221. return 0;
  2222. }
  2223. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2224. if (!lua_interface)
  2225. return 0;
  2226. Spawn* spawn = lua_interface->GetSpawn(state);
  2227. if (spawn) {
  2228. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2229. return 1;
  2230. }
  2231. return 0;
  2232. }
  2233. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2234. if (!lua_interface)
  2235. return 0;
  2236. Spawn* spawn = lua_interface->GetSpawn(state);
  2237. if (spawn) {
  2238. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2239. return 1;
  2240. }
  2241. return 0;
  2242. }
  2243. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2244. if (!lua_interface)
  2245. return 0;
  2246. Spawn* spawn = lua_interface->GetSpawn(state);
  2247. if (spawn) {
  2248. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2249. return 1;
  2250. }
  2251. return 0;
  2252. }
  2253. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2254. if (!lua_interface)
  2255. return 0;
  2256. Spawn* spawn = lua_interface->GetSpawn(state);
  2257. if (spawn && spawn->IsEntity()) {
  2258. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2259. return 1;
  2260. }
  2261. return 0;
  2262. }
  2263. int EQ2Emu_lua_GetInt(lua_State* state) {
  2264. if (!lua_interface)
  2265. return 0;
  2266. Spawn* spawn = lua_interface->GetSpawn(state);
  2267. if (spawn && spawn->IsEntity()) {
  2268. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2269. return 1;
  2270. }
  2271. return 0;
  2272. }
  2273. int EQ2Emu_lua_GetWis(lua_State* state) {
  2274. if (!lua_interface)
  2275. return 0;
  2276. Spawn* spawn = lua_interface->GetSpawn(state);
  2277. if (spawn && spawn->IsEntity()) {
  2278. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2279. return 1;
  2280. }
  2281. return 0;
  2282. }
  2283. int EQ2Emu_lua_GetSta(lua_State* state) {
  2284. if (!lua_interface)
  2285. return 0;
  2286. Spawn* spawn = lua_interface->GetSpawn(state);
  2287. if (spawn && spawn->IsEntity()) {
  2288. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2289. return 1;
  2290. }
  2291. return 0;
  2292. }
  2293. int EQ2Emu_lua_GetStr(lua_State* state) {
  2294. if (!lua_interface)
  2295. return 0;
  2296. Spawn* spawn = lua_interface->GetSpawn(state);
  2297. if (spawn && spawn->IsEntity()) {
  2298. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2299. return 1;
  2300. }
  2301. return 0;
  2302. }
  2303. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2304. if (!lua_interface)
  2305. return 0;
  2306. Spawn* spawn = lua_interface->GetSpawn(state);
  2307. if (spawn && spawn->IsEntity()) {
  2308. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2309. return 1;
  2310. }
  2311. return 0;
  2312. }
  2313. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2314. if (!lua_interface)
  2315. return 0;
  2316. Spawn* spawn = lua_interface->GetSpawn(state);
  2317. if (spawn && spawn->IsEntity()) {
  2318. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2319. return 1;
  2320. }
  2321. return 0;
  2322. }
  2323. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2324. if (!lua_interface)
  2325. return 0;
  2326. Spawn* spawn = lua_interface->GetSpawn(state);
  2327. if (spawn && spawn->IsEntity()) {
  2328. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2329. return 1;
  2330. }
  2331. return 0;
  2332. }
  2333. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2334. if (!lua_interface)
  2335. return 0;
  2336. Spawn* spawn = lua_interface->GetSpawn(state);
  2337. if (spawn && spawn->IsEntity()) {
  2338. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2339. return 1;
  2340. }
  2341. return 0;
  2342. }
  2343. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2344. if (!lua_interface)
  2345. return 0;
  2346. Spawn* spawn = lua_interface->GetSpawn(state);
  2347. if (spawn && spawn->IsEntity()) {
  2348. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2349. return 1;
  2350. }
  2351. return 0;
  2352. }
  2353. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2354. if (!lua_interface)
  2355. return 0;
  2356. Spawn* spawn = lua_interface->GetSpawn(state);
  2357. if (spawn && spawn->IsEntity()) {
  2358. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2359. return 1;
  2360. }
  2361. return 0;
  2362. }
  2363. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2364. if (!lua_interface)
  2365. return 0;
  2366. Spawn* player = lua_interface->GetSpawn(state);
  2367. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2368. int32 step = lua_interface->GetInt32Value(state, 3);
  2369. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2370. Client* client = player->GetZone()->GetClientBySpawn(player);
  2371. if (client)
  2372. client->AddPendingQuestUpdate(quest_id, step);
  2373. }
  2374. return 0;
  2375. }
  2376. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2377. Spawn* player = lua_interface->GetSpawn(state);
  2378. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2379. int32 step = lua_interface->GetInt32Value(state, 3);
  2380. int32 progress = lua_interface->GetInt32Value(state, 4);
  2381. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2382. Client* client = player->GetZone()->GetClientBySpawn(player);
  2383. if (client)
  2384. client->AddPendingQuestUpdate(quest_id, step, progress);
  2385. }
  2386. return 0;
  2387. }
  2388. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2389. if (!lua_interface)
  2390. return 0;
  2391. Spawn* player = lua_interface->GetSpawn(state);
  2392. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2393. if (player && player->IsPlayer() && quest_id > 0) {
  2394. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2395. return 1;
  2396. }
  2397. return 0;
  2398. }
  2399. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2400. if (!lua_interface)
  2401. return 0;
  2402. Spawn* player = lua_interface->GetSpawn(state);
  2403. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2404. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2405. if (player && player->IsPlayer() && quest_id > 0) {
  2406. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2407. return 1;
  2408. }
  2409. return 0;
  2410. }
  2411. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2412. if (!lua_interface)
  2413. return 0;
  2414. Spawn* player = lua_interface->GetSpawn(state);
  2415. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2416. if (player && player->IsPlayer() && quest_id > 0) {
  2417. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2418. return 1;
  2419. }
  2420. return 0;
  2421. }
  2422. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2423. if (!lua_interface)
  2424. return 0;
  2425. Quest* quest = lua_interface->GetQuest(state);
  2426. string name = lua_interface->GetStringValue(state, 2);
  2427. string type = lua_interface->GetStringValue(state, 3);
  2428. string zone = lua_interface->GetStringValue(state, 4);
  2429. int16 level = lua_interface->GetInt16Value(state, 5);
  2430. string description = lua_interface->GetStringValue(state, 6);
  2431. bool load = true;
  2432. if (!quest) {
  2433. lua_interface->SimpleLogError("Quest not given in RegisterQuest!");
  2434. load = false;
  2435. }
  2436. if (load && name.length() == 0) {
  2437. lua_interface->SimpleLogError("Name not given in RegisterQuest!");
  2438. load = false;
  2439. }
  2440. if (load && type.length() == 0) {
  2441. lua_interface->LogError("Type not given in RegisterQuest for '%s'!", name.c_str());
  2442. load = false;
  2443. }
  2444. if (load && zone.length() == 0) {
  2445. lua_interface->LogError("Zone not given in RegisterQuest for '%s'!", name.c_str());
  2446. load = false;
  2447. }
  2448. if (load && description.length() == 0) {
  2449. lua_interface->LogError("Description not given in RegisterQuest for '%s'!", name.c_str());
  2450. load = false;
  2451. }
  2452. if (load && level == 0) {
  2453. lua_interface->LogError("Level not given in RegisterQuest for '%s'!", name.c_str());
  2454. load = false;
  2455. }
  2456. if (load)
  2457. quest->RegisterQuest(name, type, zone, level, description);
  2458. return 0;
  2459. }
  2460. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2461. if (!lua_interface)
  2462. return 0;
  2463. Quest* quest = lua_interface->GetQuest(state);
  2464. if (quest) {
  2465. int8 level = lua_interface->GetInt16Value(state, 2);
  2466. quest->SetPrereqLevel(level);
  2467. }
  2468. return 0;
  2469. }
  2470. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2471. if (!lua_interface)
  2472. return 0;
  2473. Quest* quest = lua_interface->GetQuest(state);
  2474. if (quest) {
  2475. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2476. quest->AddPrereqQuest(quest_id);
  2477. }
  2478. return 0;
  2479. }
  2480. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2481. if (!lua_interface)
  2482. return 0;
  2483. Quest* quest = lua_interface->GetQuest(state);
  2484. if (quest) {
  2485. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2486. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2487. if (quantity == 0)
  2488. quantity = 1;
  2489. Item* master_item = master_item_list.GetItem(item_id);
  2490. if (master_item) {
  2491. Item* item = new Item(master_item);
  2492. item->details.count = quantity;
  2493. quest->AddPrereqItem(item);
  2494. }
  2495. }
  2496. return 0;
  2497. }
  2498. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2499. if (!lua_interface)
  2500. return 0;
  2501. Spawn* player = lua_interface->GetSpawn(state);
  2502. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2503. if (player && player->IsPlayer() && quest_id > 0) {
  2504. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2505. return 1;
  2506. }
  2507. return 0;
  2508. }
  2509. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2510. if (!lua_interface)
  2511. return 0;
  2512. Quest* quest = lua_interface->GetQuest(state);
  2513. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2514. if (quest && spawn_id > 0)
  2515. quest->SetQuestReturnNPC(spawn_id);
  2516. return 0;
  2517. }
  2518. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2519. if (!lua_interface)
  2520. return 0;
  2521. Spawn* spawn = lua_interface->GetSpawn(state);
  2522. if (!spawn) {
  2523. lua_interface->LogError("LUA AddTimer command error: spawn is not valid");
  2524. return 0;
  2525. }
  2526. int32 time = lua_interface->GetInt32Value(state, 2);
  2527. if (time <= 0) {
  2528. lua_interface->LogError("LUA AddTimer command error: time is not set");
  2529. return 0;
  2530. }
  2531. string function = lua_interface->GetStringValue(state, 3);
  2532. if (function.length() == 0) {
  2533. lua_interface->LogError("LUA AddTimer command error: function is not set");
  2534. return 0;
  2535. }
  2536. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2537. Spawn* player = lua_interface->GetSpawn(state, 5);
  2538. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2539. timer->timer = Timer::GetCurrentTime2() + time;
  2540. timer->function = function;
  2541. timer->spawn = spawn->GetID();
  2542. timer->player = player ? player->GetID() : 0;
  2543. if (max_count == 0)
  2544. max_count = 1;
  2545. timer->max_count = max_count;
  2546. timer->current_count = 0;
  2547. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2548. return 0;
  2549. }
  2550. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2551. if (!lua_interface)
  2552. return 0;
  2553. Spawn* player = lua_interface->GetSpawn(state);
  2554. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2555. if (player && player->IsPlayer() && quest_id > 0) {
  2556. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2557. return 1;
  2558. }
  2559. return 0;
  2560. }
  2561. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2562. if (!lua_interface)
  2563. return 0;
  2564. Spawn* player = lua_interface->GetSpawn(state);
  2565. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2566. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2567. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2568. if (quest)
  2569. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2570. return 1;
  2571. }
  2572. return 0;
  2573. }
  2574. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2575. if (!lua_interface)
  2576. return 0;
  2577. Spawn* player = lua_interface->GetSpawn(state);
  2578. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2579. if (player && player->IsPlayer() && quest_id > 0) {
  2580. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2581. return 1;
  2582. }
  2583. return 0;
  2584. }
  2585. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2586. if (!lua_interface)
  2587. return 0;
  2588. Spawn* npc = lua_interface->GetSpawn(state);
  2589. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2590. if (npc && !npc->IsPlayer() && quest_id > 0)
  2591. npc->AddProvidedQuest(quest_id);
  2592. return 0;
  2593. }
  2594. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2595. if (!lua_interface)
  2596. return 0;
  2597. Spawn* npc = lua_interface->GetSpawn(state);
  2598. Spawn* player = lua_interface->GetSpawn(state, 2);
  2599. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2600. /* NPC is allowed to be null */
  2601. if (player && player->IsPlayer() && quest_id > 0) {
  2602. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  2603. if (master_quest) {
  2604. Client* client = player->GetZone()->GetClientBySpawn(player);
  2605. Quest* quest = new Quest(master_quest);
  2606. if (client && quest) {
  2607. client->AddPendingQuest(quest);
  2608. if (npc)
  2609. quest->SetQuestGiver(npc->GetDatabaseID());
  2610. else
  2611. quest->SetQuestGiver(0);
  2612. }
  2613. }
  2614. }
  2615. return 0;
  2616. }
  2617. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  2618. if (!lua_interface)
  2619. return 0;
  2620. Quest* quest = lua_interface->GetQuest(state);
  2621. if (quest) {
  2622. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2623. quest->AddPrereqClass(class_id);
  2624. }
  2625. return 0;
  2626. }
  2627. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  2628. if (!lua_interface)
  2629. return 0;
  2630. Quest* quest = lua_interface->GetQuest(state);
  2631. if (quest) {
  2632. int8 race = lua_interface->GetInt8Value(state, 2);
  2633. quest->AddPrereqRace(race);
  2634. }
  2635. return 0;
  2636. }
  2637. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  2638. if (!lua_interface)
  2639. return 0;
  2640. Quest* quest = lua_interface->GetQuest(state);
  2641. if (quest) {
  2642. int16 model_type = lua_interface->GetInt16Value(state, 2);
  2643. quest->AddPrereqModelType(model_type);
  2644. }
  2645. return 0;
  2646. }
  2647. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  2648. if (!lua_interface)
  2649. return 0;
  2650. Quest* quest = lua_interface->GetQuest(state);
  2651. if (!quest) {
  2652. lua_interface->LogError("LUA AddQuestPrereqTradeskillLevel command error: quest is not valid");
  2653. return 0;
  2654. }
  2655. int8 level = lua_interface->GetInt8Value(state, 2);
  2656. quest->SetPrereqTSLevel(level);
  2657. return 0;
  2658. }
  2659. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  2660. if (!lua_interface)
  2661. return 0;
  2662. Quest* quest = lua_interface->GetQuest(state);
  2663. if (!quest) {
  2664. lua_interface->LogError("LUA AddQuestPrereqTradeskillClass command error: quest is not valid");
  2665. return 0;
  2666. }
  2667. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2668. quest->AddPrereqTradeskillClass(class_id);
  2669. return 0;
  2670. }
  2671. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  2672. if (!lua_interface)
  2673. return 0;
  2674. Quest* quest = lua_interface->GetQuest(state);
  2675. if (quest) {
  2676. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2677. sint32 min = lua_interface->GetSInt32Value(state, 3);
  2678. sint32 max = lua_interface->GetSInt32Value(state, 4);
  2679. quest->AddPrereqFaction(faction_id, min, max);
  2680. }
  2681. return 0;
  2682. }
  2683. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  2684. if (!lua_interface)
  2685. return 0;
  2686. Quest* quest = lua_interface->GetQuest(state);
  2687. if (quest) {
  2688. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2689. int8 quantity = lua_interface->GetInt8Value(state, 3);
  2690. if (quantity == 0)
  2691. quantity = 1;
  2692. Item* master_item = master_item_list.GetItem(item_id);
  2693. if (master_item) {
  2694. Item* item = new Item(master_item);
  2695. item->details.count = quantity;
  2696. quest->AddSelectableRewardItem(item);
  2697. }
  2698. }
  2699. return 0;
  2700. }
  2701. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  2702. if (!lua_interface)
  2703. return 0;
  2704. Quest* quest = lua_interface->GetQuest(state);
  2705. if (quest) {
  2706. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2707. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2708. if (quantity == 0)
  2709. quantity = 1;
  2710. Item* master_item = master_item_list.GetItem(item_id);
  2711. if (master_item) {
  2712. Item* item = new Item(master_item);
  2713. item->details.count = quantity;
  2714. quest->AddRewardItem(item);
  2715. }
  2716. }
  2717. return 0;
  2718. }
  2719. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  2720. if (!lua_interface)
  2721. return 0;
  2722. Quest* quest = lua_interface->GetQuest(state);
  2723. if (quest) {
  2724. int32 copper = lua_interface->GetInt32Value(state, 2);
  2725. int32 silver = lua_interface->GetInt32Value(state, 3);
  2726. int32 gold = lua_interface->GetInt32Value(state, 4);
  2727. int32 plat = lua_interface->GetInt32Value(state, 5);
  2728. quest->AddRewardCoins(copper, silver, gold, plat);
  2729. }
  2730. return 0;
  2731. }
  2732. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  2733. if (!lua_interface)
  2734. return 0;
  2735. Quest* quest = lua_interface->GetQuest(state);
  2736. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2737. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  2738. if (quest && faction_id > 0 && amount != 0)
  2739. quest->AddRewardFaction(faction_id, amount);
  2740. return 0;
  2741. }
  2742. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  2743. if (!lua_interface)
  2744. return 0;
  2745. Quest* quest = lua_interface->GetQuest(state);
  2746. if (quest) {
  2747. int32 status = lua_interface->GetInt32Value(state, 2);
  2748. quest->SetRewardStatus(status);
  2749. }
  2750. return 0;
  2751. }
  2752. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  2753. if (!lua_interface)
  2754. return 0;
  2755. Quest* quest = lua_interface->GetQuest(state);
  2756. if (quest) {
  2757. string comment = lua_interface->GetStringValue(state, 2);
  2758. quest->SetRewardComment(comment);
  2759. }
  2760. return 0;
  2761. }
  2762. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  2763. if (!lua_interface)
  2764. return 0;
  2765. Quest* quest = lua_interface->GetQuest(state);
  2766. if (quest) {
  2767. int32 exp = lua_interface->GetInt32Value(state, 2);
  2768. quest->SetRewardXP(exp);
  2769. }
  2770. return 0;
  2771. }
  2772. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  2773. Quest* quest = lua_interface->GetQuest(state);
  2774. if (quest) {
  2775. int32 step = lua_interface->GetInt32Value(state, 2);
  2776. string description = lua_interface->GetStringValue(state, 3);
  2777. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2778. float percentage = lua_interface->GetFloatValue(state, 5);
  2779. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2780. int16 icon = lua_interface->GetInt16Value(state, 7);
  2781. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  2782. const char* taskgroup = 0;
  2783. if (str_taskgroup.length() > 0)
  2784. taskgroup = str_taskgroup.c_str();
  2785. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  2786. if (quest_step && icon && quantity > 0)
  2787. quest_step->SetIcon(icon);
  2788. }
  2789. return 0;
  2790. }
  2791. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  2792. if (!lua_interface)
  2793. return 0;
  2794. Quest* quest = lua_interface->GetQuest(state);
  2795. if (quest) {
  2796. int32 step = lua_interface->GetInt32Value(state, 2);
  2797. string description = lua_interface->GetStringValue(state, 3);
  2798. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2799. float percentage = lua_interface->GetFloatValue(state, 5);
  2800. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2801. int16 icon = lua_interface->GetInt16Value(state, 7);
  2802. const char* taskgroup = 0;
  2803. if (str_taskgroup.length() > 0)
  2804. taskgroup = str_taskgroup.c_str();
  2805. int32 npc_id = 0;
  2806. vector<int32>* ids = 0;
  2807. Spawn* spawn = nullptr;
  2808. int i = 0;
  2809. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2810. if (ids == 0)
  2811. ids = new vector<int32>;
  2812. ids->push_back(npc_id);
  2813. i++;
  2814. }
  2815. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2816. if (quest_step && icon > 0 && quantity > 0)
  2817. quest_step->SetIcon(icon);
  2818. }
  2819. return 0;
  2820. }
  2821. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  2822. if (!lua_interface)
  2823. return 0;
  2824. Quest* quest = lua_interface->GetQuest(state);
  2825. if (quest) {
  2826. int32 step = lua_interface->GetInt32Value(state, 2);
  2827. string description = lua_interface->GetStringValue(state, 3);
  2828. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2829. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2830. int16 icon = lua_interface->GetInt16Value(state, 6);
  2831. const char* taskgroup = 0;
  2832. if (str_taskgroup.length() > 0)
  2833. taskgroup = str_taskgroup.c_str();
  2834. int32 npc_id = 0;
  2835. vector<int32>* ids = 0;
  2836. int i = 0;
  2837. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  2838. if (ids == 0)
  2839. ids = new vector<int32>;
  2840. ids->push_back(npc_id);
  2841. i++;
  2842. }
  2843. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  2844. if (quest_step && icon > 0)
  2845. quest_step->SetIcon(icon);
  2846. if (quest->GetPlayer()) {
  2847. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  2848. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  2849. }
  2850. }
  2851. return 0;
  2852. }
  2853. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  2854. if (!lua_interface)
  2855. return 0;
  2856. Quest* quest = lua_interface->GetQuest(state);
  2857. if (quest) {
  2858. int32 step = lua_interface->GetInt32Value(state, 2);
  2859. string description = lua_interface->GetStringValue(state, 3);
  2860. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2861. float percentage = lua_interface->GetFloatValue(state, 5);
  2862. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2863. int16 icon = lua_interface->GetInt16Value(state, 7);
  2864. const char* taskgroup = 0;
  2865. if (str_taskgroup.length() > 0)
  2866. taskgroup = str_taskgroup.c_str();
  2867. int32 item_id = 0;
  2868. vector<int32>* ids = 0;
  2869. int i = 0;
  2870. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2871. if (ids == 0)
  2872. ids = new vector<int32>;
  2873. ids->push_back(item_id);
  2874. i++;
  2875. }
  2876. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2877. if (quest_step && icon > 0 && quantity > 0)
  2878. quest_step->SetIcon(icon);
  2879. }
  2880. return 0;
  2881. }
  2882. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  2883. if (!lua_interface)
  2884. return 0;
  2885. Quest* quest = lua_interface->GetQuest(state);
  2886. if (quest) {
  2887. int32 step = lua_interface->GetInt32Value(state, 2);
  2888. string description = lua_interface->GetStringValue(state, 3);
  2889. float max_variation = lua_interface->GetFloatValue(state, 4);
  2890. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2891. int16 icon = lua_interface->GetInt16Value(state, 6);
  2892. const char* taskgroup = 0;
  2893. if (str_taskgroup.length() > 0)
  2894. taskgroup = str_taskgroup.c_str();
  2895. vector<Location>* locations = 0;
  2896. int i = 7;
  2897. while (true) {
  2898. Location loc;
  2899. loc.x = lua_interface->GetFloatValue(state, i);
  2900. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2901. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2902. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2903. break;
  2904. if (locations == 0)
  2905. locations = new vector<Location>;
  2906. locations->push_back(loc);
  2907. i += 3;
  2908. }
  2909. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2910. if (quest_step && icon > 0)
  2911. quest_step->SetIcon(icon);
  2912. }
  2913. return 0;
  2914. }
  2915. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  2916. if (!lua_interface)
  2917. return 0;
  2918. Quest* quest = lua_interface->GetQuest(state);
  2919. if (quest) {
  2920. int32 step = lua_interface->GetInt32Value(state, 2);
  2921. string description = lua_interface->GetStringValue(state, 3);
  2922. float max_variation = lua_interface->GetFloatValue(state, 4);
  2923. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2924. int16 icon = lua_interface->GetInt16Value(state, 6);
  2925. const char* taskgroup = 0;
  2926. if (str_taskgroup.length() > 0)
  2927. taskgroup = str_taskgroup.c_str();
  2928. vector<Location>* locations = 0;
  2929. int i = 7;
  2930. while (true) {
  2931. Location loc;
  2932. loc.x = lua_interface->GetFloatValue(state, i);
  2933. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2934. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2935. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2936. break;
  2937. if (locations == 0)
  2938. locations = new vector<Location>;
  2939. locations->push_back(loc);
  2940. i += 3;
  2941. }
  2942. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2943. if (quest_step && icon > 0)
  2944. quest_step->SetIcon(icon);
  2945. }
  2946. return 0;
  2947. }
  2948. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  2949. Quest* quest = lua_interface->GetQuest(state);
  2950. if (quest) {
  2951. int32 step = lua_interface->GetInt32Value(state, 2);
  2952. string description = lua_interface->GetStringValue(state, 3);
  2953. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2954. float percentage = lua_interface->GetFloatValue(state, 5);
  2955. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2956. int16 icon = lua_interface->GetInt16Value(state, 7);
  2957. const char* taskgroup = 0;
  2958. if (str_taskgroup.length() > 0)
  2959. taskgroup = str_taskgroup.c_str();
  2960. int32 spell_id = 0;
  2961. vector<int32>* ids = 0;
  2962. int i = 0;
  2963. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2964. if (ids == 0)
  2965. ids = new vector<int32>;
  2966. ids->push_back(spell_id);
  2967. i++;
  2968. }
  2969. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2970. if (quest_step && icon > 0 && quantity > 0)
  2971. quest_step->SetIcon(icon);
  2972. }
  2973. return 0;
  2974. }
  2975. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  2976. if (!lua_interface)
  2977. return 0;
  2978. Quest* quest = lua_interface->GetQuest(state);
  2979. if (quest) {
  2980. int32 step = lua_interface->GetInt32Value(state, 2);
  2981. string description = lua_interface->GetStringValue(state, 3);
  2982. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2983. float percentage = lua_interface->GetFloatValue(state, 5);
  2984. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2985. int16 icon = lua_interface->GetInt16Value(state, 7);
  2986. const char* taskgroup = 0;
  2987. if (str_taskgroup.length() > 0)
  2988. taskgroup = str_taskgroup.c_str();
  2989. int32 item_id = 0;
  2990. vector<int32>* ids = 0;
  2991. int i = 0;
  2992. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2993. if (ids == 0)
  2994. ids = new vector<int32>;
  2995. ids->push_back(item_id);
  2996. i++;
  2997. }
  2998. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2999. if (quest_step && icon > 0 && quantity > 0)
  3000. quest_step->SetIcon(icon);
  3001. }
  3002. return 0;
  3003. }
  3004. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3005. if (!lua_interface)
  3006. return 0;
  3007. Quest* quest = lua_interface->GetQuest(state);
  3008. if (quest) {
  3009. int32 step = lua_interface->GetInt32Value(state, 2);
  3010. string description = lua_interface->GetStringValue(state, 3);
  3011. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3012. float percentage = lua_interface->GetFloatValue(state, 5);
  3013. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3014. int16 icon = lua_interface->GetInt16Value(state, 7);
  3015. const char* taskgroup = 0;
  3016. if (str_taskgroup.length() > 0)
  3017. taskgroup = str_taskgroup.c_str();
  3018. int32 item_id = 0;
  3019. vector<int32>* ids = 0;
  3020. int i = 0;
  3021. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3022. if (ids == 0)
  3023. ids = new vector<int32>;
  3024. ids->push_back(item_id);
  3025. i++;
  3026. }
  3027. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3028. if (quest_step && icon > 0 && quantity > 0)
  3029. quest_step->SetIcon(icon);
  3030. }
  3031. return 0;
  3032. }
  3033. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3034. if (!lua_interface)
  3035. return 0;
  3036. Quest* quest = lua_interface->GetQuest(state);
  3037. if (quest) {
  3038. string action = lua_interface->GetStringValue(state, 2);
  3039. if (action.length() > 0)
  3040. quest->SetCompleteAction(action);
  3041. }
  3042. return 0;
  3043. }
  3044. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3045. if (!lua_interface)
  3046. return 0;
  3047. Quest* quest = lua_interface->GetQuest(state);
  3048. if (quest) {
  3049. int32 step = lua_interface->GetInt32Value(state, 2);
  3050. string action = lua_interface->GetStringValue(state, 3);
  3051. if (step > 0 && action.length() > 0)
  3052. quest->AddCompleteAction(step, action);
  3053. }
  3054. return 0;
  3055. }
  3056. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3057. if (!lua_interface)
  3058. return 0;
  3059. Quest* quest = lua_interface->GetQuest(state);
  3060. if (quest) {
  3061. int32 step = lua_interface->GetInt32Value(state, 2);
  3062. string action = lua_interface->GetStringValue(state, 3);
  3063. if (step > 0 && action.length() > 0)
  3064. quest->AddProgressAction(step, action);
  3065. }
  3066. return 0;
  3067. }
  3068. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3069. if (!lua_interface)
  3070. return 0;
  3071. Quest* quest = lua_interface->GetQuest(state);
  3072. string description = lua_interface->GetStringValue(state, 2);
  3073. if (quest && description.length() > 0)
  3074. quest->SetDescription(description);
  3075. return 0;
  3076. }
  3077. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3078. if (!lua_interface)
  3079. return 0;
  3080. Quest* quest = lua_interface->GetQuest(state);
  3081. string description = lua_interface->GetStringValue(state, 2);
  3082. if (quest && description.length() > 0)
  3083. quest->SetCompletedDescription(description);
  3084. return 0;
  3085. }
  3086. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3087. if (!lua_interface)
  3088. return 0;
  3089. Quest* quest = lua_interface->GetQuest(state);
  3090. int32 step = lua_interface->GetInt32Value(state, 2);
  3091. string description = lua_interface->GetStringValue(state, 3);
  3092. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3093. if (quest && step > 0 && description.length() > 0) {
  3094. quest->SetTaskGroupDescription(step, description, display_bullets);
  3095. if (quest->GetPlayer()) {
  3096. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3097. if (client)
  3098. client->SendQuestUpdateStep(quest, step, false);
  3099. }
  3100. }
  3101. return 0;
  3102. }
  3103. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3104. if (!lua_interface)
  3105. return 0;
  3106. Quest* quest = lua_interface->GetQuest(state);
  3107. int32 step = lua_interface->GetInt32Value(state, 2);
  3108. string description = lua_interface->GetStringValue(state, 3);
  3109. if (quest && step > 0 && description.length() > 0) {
  3110. quest->SetStepDescription(step, description);
  3111. if (quest->GetPlayer()) {
  3112. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3113. if (client)
  3114. client->SendQuestUpdateStep(quest, step);
  3115. }
  3116. }
  3117. return 0;
  3118. }
  3119. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3120. Quest* quest = lua_interface->GetQuest(state);
  3121. string zone = lua_interface->GetStringValue(state, 2);
  3122. if (quest && zone.length() > 0)
  3123. quest->SetZone(zone);
  3124. return 0;
  3125. }
  3126. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3127. if (!lua_interface)
  3128. return 0;
  3129. Quest* quest = lua_interface->GetQuest(state);
  3130. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3131. if (quest && spawn) {
  3132. if (spawn->IsPlayer()) {
  3133. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3134. if (client)
  3135. client->AddPendingQuestReward(quest);
  3136. }
  3137. }
  3138. return 0;
  3139. }
  3140. int EQ2Emu_lua_Harvest(lua_State* state) {
  3141. if (!lua_interface)
  3142. return 0;
  3143. Spawn* player = lua_interface->GetSpawn(state);
  3144. Spawn* node = lua_interface->GetSpawn(state, 2);
  3145. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3146. Client* client = player->GetZone()->GetClientBySpawn(player);
  3147. if (client) {
  3148. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3149. ((GroundSpawn*)node)->ProcessHarvest(client);
  3150. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3151. player->GetZone()->RemoveSpawn(node, true);
  3152. }
  3153. }
  3154. else if (player && player->IsPlayer()) {
  3155. Client* client = player->GetZone()->GetClientBySpawn(player);
  3156. if (client)
  3157. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3158. }
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_Bind(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Spawn* spawn = lua_interface->GetSpawn(state);
  3165. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3166. float x = lua_interface->GetFloatValue(state, 3);
  3167. float y = lua_interface->GetFloatValue(state, 4);
  3168. float z = lua_interface->GetFloatValue(state, 5);
  3169. float h = lua_interface->GetFloatValue(state, 6);
  3170. if (!spawn) {
  3171. lua_interface->LogError("LUA Bind command error: spawn is not valid");
  3172. return 0;
  3173. }
  3174. if (!spawn->IsPlayer()) {
  3175. lua_interface->LogError("LUA Bind command error: spawn is not a player");
  3176. return 0;
  3177. }
  3178. if (zone_id == 0) {
  3179. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3180. if (!client) {
  3181. lua_interface->LogError("LUA Bind command error: unable to get client from spawn");
  3182. return 0;
  3183. }
  3184. if (!client->Bind())
  3185. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3186. }
  3187. else {
  3188. Player* player = (Player*)spawn;
  3189. player->GetPlayerInfo()->SetBindZone(zone_id);
  3190. player->GetPlayerInfo()->SetBindX(x);
  3191. player->GetPlayerInfo()->SetBindY(y);
  3192. player->GetPlayerInfo()->SetBindZ(z);
  3193. player->GetPlayerInfo()->SetBindHeading(h);
  3194. }
  3195. return 0;
  3196. }
  3197. int EQ2Emu_lua_Gate(lua_State* state) {
  3198. if (!lua_interface)
  3199. return 0;
  3200. Spawn* spawn = lua_interface->GetSpawn(state);
  3201. if (spawn) {
  3202. if (spawn->IsPlayer()) {
  3203. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3204. if (client) {
  3205. if (!client->Gate())
  3206. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3207. }
  3208. }
  3209. }
  3210. return 0;
  3211. }
  3212. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3213. if (!lua_interface)
  3214. return 0;
  3215. bool ret = false;
  3216. Spawn* spawn = lua_interface->GetSpawn(state);
  3217. if (spawn) {
  3218. if (spawn->IsPlayer()) {
  3219. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3220. if (client)
  3221. ret = client->BindAllowed();
  3222. }
  3223. }
  3224. lua_interface->SetBooleanValue(state, ret);
  3225. return 1;
  3226. }
  3227. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3228. if (!lua_interface)
  3229. return 0;
  3230. bool ret = false;
  3231. Spawn* spawn = lua_interface->GetSpawn(state);
  3232. if (spawn) {
  3233. if (spawn->IsPlayer()) {
  3234. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3235. if (client)
  3236. ret = client->GateAllowed();
  3237. }
  3238. }
  3239. lua_interface->SetBooleanValue(state, ret);
  3240. return 1;
  3241. }
  3242. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3243. Spawn* spawn = lua_interface->GetSpawn(state);
  3244. if (spawn) {
  3245. lua_interface->SetBooleanValue(state, spawn->Alive());
  3246. return 1;
  3247. }
  3248. return 0;
  3249. }
  3250. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3251. if (!lua_interface)
  3252. return 0;
  3253. Spawn* spawn = lua_interface->GetSpawn(state);
  3254. if (spawn && spawn->IsEntity()) {
  3255. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3256. return 1;
  3257. }
  3258. return 0;
  3259. }
  3260. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3261. Spawn* spawn = lua_interface->GetSpawn(state);
  3262. string message = lua_interface->GetStringValue(state, 2);
  3263. string color_str = lua_interface->GetStringValue(state, 3);
  3264. int8 color = CHANNEL_COLOR_WHITE;
  3265. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3266. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3267. if (client) {
  3268. if (color_str.length() > 0) {
  3269. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3270. color = CHANNEL_COLOR_RED;
  3271. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3272. color = CHANNEL_COLOR_YELLOW;
  3273. }
  3274. client->SimpleMessage(color, message.c_str());
  3275. }
  3276. }
  3277. return 0;
  3278. }
  3279. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3280. Spawn* spawn = lua_interface->GetSpawn(state);
  3281. string message = lua_interface->GetStringValue(state, 2);
  3282. int8 red = lua_interface->GetInt8Value(state, 3);
  3283. int8 green = lua_interface->GetInt8Value(state, 4);
  3284. int8 blue = lua_interface->GetInt8Value(state, 5);
  3285. if (!spawn) {
  3286. lua_interface->LogError("LUA SendPopUpMessage command error: Spawn is not valid.");
  3287. return 0;
  3288. }
  3289. int32 words = ::CountWordsInString(message.c_str());
  3290. if (words < 5)
  3291. words = 5;
  3292. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3293. if (client)
  3294. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3295. return 0;
  3296. }
  3297. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3298. Spawn* spawn = lua_interface->GetSpawn(state);
  3299. int8 param = lua_interface->GetInt8Value(state, 2);
  3300. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3301. int8 value = lua_interface->GetInt8Value(state, 4);
  3302. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3303. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3304. if (client) {
  3305. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3306. switch (param) {
  3307. case 1: {
  3308. packet->setDataByName("parameter1", param_value);
  3309. break;
  3310. }
  3311. case 2: {
  3312. packet->setDataByName("parameter2", param_value);
  3313. break;
  3314. }
  3315. case 3: {
  3316. packet->setDataByName("parameter3", param_value);
  3317. break;
  3318. }
  3319. case 4: {
  3320. packet->setDataByName("parameter4", param_value);
  3321. break;
  3322. }
  3323. case 5: {
  3324. packet->setDataByName("parameter5", param_value);
  3325. break;
  3326. }
  3327. }
  3328. packet->setDataByName("value", value);
  3329. client->QueuePacket(packet->serialize());
  3330. safe_delete(packet);
  3331. }
  3332. }
  3333. return 0;
  3334. }
  3335. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3336. Spawn* spawn = lua_interface->GetSpawn(state);
  3337. if (spawn && spawn->IsPlayer()) {
  3338. if (((Player*)spawn)->GetIsTracking())
  3339. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3340. else
  3341. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3342. }
  3343. return 0;
  3344. }
  3345. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3346. Spawn* player = lua_interface->GetSpawn(state);
  3347. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3348. string name = lua_interface->GetStringValue(state, 3);
  3349. float distance = lua_interface->GetFloatValue(state, 4);
  3350. string command = lua_interface->GetStringValue(state, 5);
  3351. string error_text = lua_interface->GetStringValue(state, 6);
  3352. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3353. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3354. if (spawn && player && player->IsPlayer() && name.length() > 0) {
  3355. if (distance == 0)
  3356. distance = 10.0f;
  3357. if (command.length() == 0)
  3358. command = name;
  3359. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  3360. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3361. }
  3362. return 0;
  3363. }
  3364. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3365. if (!lua_interface)
  3366. return 0;
  3367. Spawn* player = lua_interface->GetSpawn(state);
  3368. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3369. int16 tier = lua_interface->GetInt16Value(state, 3);
  3370. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3371. if (player && spell && player->IsPlayer()) {
  3372. Client* client = player->GetZone()->GetClientBySpawn(player);
  3373. if (client) {
  3374. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3375. {
  3376. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3377. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3378. client->GetPlayer()->UnlockSpell(spell);
  3379. client->SendSpellUpdate(spell);
  3380. }
  3381. else
  3382. {
  3383. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3384. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3385. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3386. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3387. client->GetPlayer()->UnlockSpell(spell);
  3388. client->SendSpellUpdate(spell);
  3389. }
  3390. //if (client ) {
  3391. // ((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);
  3392. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3393. if (outapp)
  3394. client->QueuePacket(outapp);
  3395. }
  3396. }
  3397. return 0;
  3398. }
  3399. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3400. if (!lua_interface)
  3401. return 0;
  3402. Spawn* player = lua_interface->GetSpawn(state);
  3403. if (player && player->IsPlayer()) {
  3404. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3405. return 1;
  3406. }
  3407. return 0;
  3408. }
  3409. int EQ2Emu_lua_Attack(lua_State* state) {
  3410. if (lua_interface) {
  3411. Spawn* npc = lua_interface->GetSpawn(state);
  3412. Spawn* player = lua_interface->GetSpawn(state, 2);
  3413. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3414. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3415. }
  3416. return 0;
  3417. }
  3418. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3419. if (lua_interface) {
  3420. Spawn* target = lua_interface->GetSpawn(state);
  3421. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3422. if (target && target->GetZone())
  3423. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3424. }
  3425. return 0;
  3426. }
  3427. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3428. Spawn* player;
  3429. if (lua_interface) {
  3430. player = lua_interface->GetSpawn(state);
  3431. if (player && player->IsPlayer()) {
  3432. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3433. return 1;
  3434. }
  3435. }
  3436. return 0;
  3437. }
  3438. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3439. Spawn* player;
  3440. Client* client;
  3441. if (lua_interface) {
  3442. player = lua_interface->GetSpawn(state);
  3443. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3444. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3445. client->HandInCollections();
  3446. }
  3447. return 0;
  3448. }
  3449. int EQ2Emu_lua_UseWidget(lua_State* state) {
  3450. Spawn* widget;
  3451. if (lua_interface) {
  3452. widget = lua_interface->GetSpawn(state);
  3453. if (widget && widget->IsWidget())
  3454. ((Widget*)widget)->HandleUse(NULL, "");
  3455. }
  3456. return 0;
  3457. }
  3458. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  3459. Spawn* spawn = 0;
  3460. int32 primary_list = 0;
  3461. int32 secondary_list = 0;
  3462. if (lua_interface) {
  3463. spawn = lua_interface->GetSpawn(state);
  3464. primary_list = lua_interface->GetInt32Value(state, 2);
  3465. secondary_list = lua_interface->GetInt32Value(state, 3);
  3466. if (!spawn->IsNPC()) {
  3467. lua_interface->LogError("LUA SetSpellList command error: Spawn was not a valid NPC");
  3468. return 0;
  3469. }
  3470. NPC* npc = (NPC*)spawn;
  3471. npc->SetPrimarySpellList(primary_list);
  3472. npc->SetSecondarySpellList(secondary_list);
  3473. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  3474. }
  3475. return 0;
  3476. }
  3477. int EQ2Emu_lua_GetPet(lua_State* state) {
  3478. if (!lua_interface)
  3479. return 0;
  3480. Spawn* spawn = lua_interface->GetSpawn(state);
  3481. if (spawn) {
  3482. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  3483. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  3484. return 1;
  3485. }
  3486. }
  3487. return 0;
  3488. }
  3489. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  3490. if (!lua_interface)
  3491. return 0;
  3492. Spawn* spawn = lua_interface->GetSpawn(state);
  3493. if (spawn) {
  3494. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  3495. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  3496. return 1;
  3497. }
  3498. }
  3499. return 0;
  3500. }
  3501. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  3502. if (!lua_interface)
  3503. return 0;
  3504. Spawn* spawn = lua_interface->GetSpawn(state);
  3505. if (spawn) {
  3506. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  3507. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  3508. return 1;
  3509. }
  3510. }
  3511. return 0;
  3512. }
  3513. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  3514. if (!lua_interface)
  3515. return 0;
  3516. Spawn* spawn = lua_interface->GetSpawn(state);
  3517. if (spawn) {
  3518. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  3519. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  3520. return 1;
  3521. }
  3522. }
  3523. return 0;
  3524. }
  3525. int EQ2Emu_lua_Charm(lua_State* state) {
  3526. if (!lua_interface)
  3527. return 0;
  3528. Spawn* owner = lua_interface->GetSpawn(state);
  3529. Spawn* pet = lua_interface->GetSpawn(state, 2);
  3530. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3531. if (!luaspell) {
  3532. lua_interface->LogError("LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.");
  3533. return 0;
  3534. }
  3535. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  3536. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  3537. pet->SetPet(true);
  3538. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  3539. ((NPC*)pet)->SetOwner((Entity*)owner);
  3540. // If owner is player and player does not have a summoned pet set the players charsheet
  3541. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  3542. Player* player = (Player*)owner;
  3543. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3544. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  3545. player->GetInfoStruct()->pet_movement = 2;
  3546. player->GetInfoStruct()->pet_behavior = 3;
  3547. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3548. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3549. // Make sure the values get sent to the client
  3550. player->SetCharSheetChanged(true);
  3551. }
  3552. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  3553. pet->SetSpawnScript("");
  3554. // Set faction to the same as the owner
  3555. pet->SetFactionID(owner->GetFactionID());
  3556. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3557. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3558. // Clear hate list
  3559. ((NPC*)pet)->Brain()->ClearHate();
  3560. // Set the brain to a pet brain
  3561. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3562. }
  3563. return 0;
  3564. }
  3565. int EQ2Emu_lua_GetGroup(lua_State* state) {
  3566. if (!lua_interface)
  3567. return 0;
  3568. Spawn* spawn = lua_interface->GetSpawn(state);
  3569. if (!spawn) {
  3570. lua_interface->LogError("LUA GetGroup command error: spawn is not valid");
  3571. return 0;
  3572. }
  3573. vector<Spawn*> groupMembers;
  3574. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  3575. groupMembers = *spawn->GetSpawnGroup();
  3576. }
  3577. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  3578. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  3579. deque<GroupMemberInfo*>::iterator itr;
  3580. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  3581. GroupMemberInfo* info = 0;
  3582. for (itr = members->begin(); itr != members->end(); itr++) {
  3583. info = *itr;
  3584. if (info->client)
  3585. groupMembers.push_back(info->client->GetPlayer());
  3586. }
  3587. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  3588. }
  3589. else
  3590. return 0;
  3591. lua_createtable(state, groupMembers.size(), 0);
  3592. int newTable = lua_gettop(state);
  3593. for (int32 i = 0; i < groupMembers.size(); i++) {
  3594. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  3595. lua_rawseti(state, newTable, i + 1);
  3596. }
  3597. return 1;
  3598. }
  3599. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  3600. if (!lua_interface)
  3601. return 0;
  3602. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  3603. lua_interface->SetOptionWindowValue(state, option_window);
  3604. return 1;
  3605. }
  3606. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  3607. if (!lua_interface)
  3608. return 0;
  3609. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3610. if (option_window) {
  3611. OptionWindowOption option_window_option;
  3612. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  3613. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  3614. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  3615. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  3616. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  3617. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  3618. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  3619. option_window->push_back(option_window_option);
  3620. }
  3621. return 0;
  3622. }
  3623. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  3624. if (!lua_interface)
  3625. return 0;
  3626. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3627. Spawn* player = lua_interface->GetSpawn(state, 2);
  3628. string window_title = lua_interface->GetStringValue(state, 3);
  3629. string cancel_command = lua_interface->GetStringValue(state, 4);
  3630. Client* client = player->GetZone()->GetClientBySpawn(player);
  3631. if (option_window && window_title.length() > 0 && client) {
  3632. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  3633. if (!packet)
  3634. return 0;
  3635. packet->setDataByName("title_text", window_title.c_str());
  3636. if (cancel_command.length() > 0)
  3637. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  3638. packet->setArrayLengthByName("num_selections", option_window->size());
  3639. vector<OptionWindowOption>::iterator itr;
  3640. int8 i = 0;
  3641. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  3642. OptionWindowOption opt = *itr;
  3643. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  3644. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  3645. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  3646. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  3647. if (opt.optionCommand.length() > 0)
  3648. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  3649. if (opt.optionConfirmTitle.length() > 0)
  3650. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  3651. i++;
  3652. }
  3653. client->QueuePacket(packet->serialize());
  3654. safe_delete(option_window);
  3655. safe_delete(packet);
  3656. }
  3657. return 0;
  3658. }
  3659. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  3660. if (!lua_interface)
  3661. return 0;
  3662. Spawn* spawn = lua_interface->GetSpawn(state);
  3663. if (spawn) {
  3664. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  3665. return 1;
  3666. }
  3667. else
  3668. lua_interface->LogError("LUA GetTradeskillClass command error: Spawn was not valid");
  3669. return 0;
  3670. }
  3671. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  3672. if (!lua_interface)
  3673. return 0;
  3674. Spawn* spawn = lua_interface->GetSpawn(state);
  3675. if (spawn) {
  3676. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  3677. return 1;
  3678. }
  3679. else
  3680. lua_interface->LogError("LUA GetTradeskillLevel command error: Spawns was not valid");
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Spawn* spawn = lua_interface->GetSpawn(state);
  3687. if (spawn) {
  3688. int8 class_id = spawn->GetTradeskillClass();
  3689. // Need to add 42 for the offset in the array
  3690. class_id += 44;
  3691. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  3692. return 1;
  3693. }
  3694. else
  3695. lua_interface->LogError("LUA GetTradeskillClassName command error: Spawn was not valid");
  3696. return 0;
  3697. }
  3698. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  3699. if (!lua_interface)
  3700. return 0;
  3701. Spawn* spawn = lua_interface->GetSpawn(state);
  3702. int16 level = lua_interface->GetInt8Value(state, 2);
  3703. if (spawn) {
  3704. if (spawn->IsPlayer())
  3705. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  3706. else
  3707. spawn->SetTSLevel(level);
  3708. }
  3709. else
  3710. lua_interface->LogError("LUA SetTradeskillLevel command error: Spawn was not valid");
  3711. return 0;
  3712. }
  3713. int EQ2Emu_lua_SummonPet(lua_State* state) {
  3714. // Check to see if we have a valid lua_interface
  3715. if (!lua_interface)
  3716. return 0;
  3717. // Get the spawn that is getting the pet
  3718. Spawn* spawn = lua_interface->GetSpawn(state);
  3719. // Get the DB ID of the pet
  3720. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3721. // The max level the pet can gain
  3722. int8 max_level = lua_interface->GetInt8Value(state, 3);
  3723. // Get the spell that this command was called from
  3724. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3725. // Check to make sure the spawn pointer is valid
  3726. if (!spawn) {
  3727. lua_interface->LogError("LUA SummonPet command error: Spawn is not valid");
  3728. return 0;
  3729. }
  3730. // Check to make sure the spawn is an entity
  3731. if (!spawn->IsEntity()) {
  3732. lua_interface->LogError("LUA SummonPet command error: Spawn is not an entity");
  3733. return 0;
  3734. }
  3735. // Check to make sure the spawn doesn't already have a pet of this type
  3736. if (((Entity*)spawn)->GetPet()) {
  3737. if (spawn->IsPlayer()) {
  3738. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3739. if (client)
  3740. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  3741. }
  3742. lua_interface->LogError("LUA SummonPet command error: spawn already has a pet of this type");
  3743. return 0;
  3744. }
  3745. // Check to see if the DB ID for the pet is set
  3746. if (pet_id == 0) {
  3747. lua_interface->LogError("LUA SummonPet command error: pet_id can not be set to 0");
  3748. return 0;
  3749. }
  3750. // Check to see if the pointer to the spell is valid
  3751. if (!luaspell) {
  3752. lua_interface->LogError("LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts");
  3753. return 0;
  3754. }
  3755. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  3756. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3757. if (!pet) {
  3758. lua_interface->LogError("LUA SummonPet command error: Could not find spawn with id of %u.", pet_id);
  3759. return 0;
  3760. }
  3761. // Check to make sure the pet is an npc
  3762. if (!pet->IsNPC()) {
  3763. lua_interface->LogError("LUA SummonPet command error: id (%u) did not point to a npc", pet_id);
  3764. return 0;
  3765. }
  3766. // Spawn the pet at the same location as the owner
  3767. pet->SetX(spawn->GetX());
  3768. pet->SetY(spawn->GetY());
  3769. pet->SetZ(spawn->GetZ());
  3770. pet->SetLocation(spawn->GetLocation());
  3771. pet->SetHeading(spawn->GetHeading());
  3772. spawn->GetZone()->AddSpawn(pet);
  3773. /*
  3774. const char* spawn_script = world.GetSpawnScript(pet_id);
  3775. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  3776. spawn->SetSpawnScript(string(spawn_script));
  3777. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  3778. }*/
  3779. // Get a random pet name
  3780. string random_pet_name;
  3781. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3782. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3783. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3784. // If player set various values for the char sheet (pet window)
  3785. if (spawn->IsPlayer()) {
  3786. Player* player = (Player*)spawn;
  3787. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3788. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  3789. player->GetInfoStruct()->pet_movement = 2;
  3790. player->GetInfoStruct()->pet_behavior = 3;
  3791. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3792. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3793. // Make sure the values get sent to the client
  3794. player->SetCharSheetChanged(true);
  3795. }
  3796. // Set the pets name
  3797. pet->SetName(random_pet_name.c_str());
  3798. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  3799. if (max_level > 0)
  3800. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  3801. else
  3802. pet->SetLevel(spawn->GetLevel());
  3803. // Set the max level this pet can reach
  3804. ((NPC*)pet)->SetMaxPetLevel(max_level);
  3805. // Set the faction of the pet to the same faction as the owner
  3806. pet->SetFactionID(spawn->GetFactionID());
  3807. // Set the spawn as a pet
  3808. pet->SetPet(true);
  3809. // Give a pointer of the owner to the pet
  3810. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3811. // Give a pointer of the pet to the owner
  3812. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  3813. // Set the pet type
  3814. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  3815. // Set the spell id used to create this pet
  3816. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3817. // Set the spell tier used to create this pet
  3818. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3819. // Set the pets spawn type to 6
  3820. pet->SetSpawnType(6);
  3821. // Set the pets brain
  3822. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3823. // Check to see if the pet has a subtitle
  3824. if (strlen(pet->GetSubTitle()) > 0) {
  3825. // Add the players name to the front of the sub title
  3826. string pet_subtitle;
  3827. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3828. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3829. // Set the pets subtitle to the new one
  3830. pet->SetSubTitle(pet_subtitle.c_str());
  3831. }
  3832. // Add the "Pet Options" entity command to the pet
  3833. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3834. // Set the pet as the return value for this function
  3835. lua_interface->SetSpawnValue(state, pet);
  3836. return 1;
  3837. }
  3838. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  3839. if (!lua_interface)
  3840. return 0;
  3841. Spawn* spawn = lua_interface->GetSpawn(state);
  3842. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3843. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3844. if (!spawn) {
  3845. lua_interface->LogError("LUA SummonDeityPet command error: Spawn is not valid");
  3846. return 0;
  3847. }
  3848. if (!spawn->IsEntity()) {
  3849. lua_interface->LogError("LUA SummonDeityPet command error: Spawn is not an entity");
  3850. return 0;
  3851. }
  3852. if (((Entity*)spawn)->GetDeityPet()) {
  3853. if (spawn->IsPlayer()) {
  3854. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3855. if (client)
  3856. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  3857. }
  3858. lua_interface->LogError("LUA SummonDeityPet command error: spawn already has a pet of this type");
  3859. return 0;
  3860. }
  3861. if (pet_id == 0) {
  3862. lua_interface->LogError("LUA SummonDeityPet command error: pet_id can not be set to 0");
  3863. return 0;
  3864. }
  3865. if (!luaspell) {
  3866. lua_interface->LogError("LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts");
  3867. return 0;
  3868. }
  3869. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3870. if (!pet) {
  3871. lua_interface->LogError("LUA SummonDeityPet command error: Could not find spawn with id of %u.", pet_id);
  3872. return 0;
  3873. }
  3874. if (!pet->IsNPC()) {
  3875. lua_interface->LogError("LUA SummonDeityPet command error: spawn with id of %u is not a npc", pet_id);
  3876. return 0;
  3877. }
  3878. pet->SetX(spawn->GetX());
  3879. pet->SetY(spawn->GetY());
  3880. pet->SetZ(spawn->GetZ());
  3881. pet->SetLocation(spawn->GetLocation());
  3882. pet->SetHeading(spawn->GetHeading());
  3883. spawn->GetZone()->AddSpawn(pet);
  3884. string random_pet_name;
  3885. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3886. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3887. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3888. pet->SetName(random_pet_name.c_str());
  3889. pet->SetLevel(spawn->GetLevel());
  3890. pet->SetFactionID(spawn->GetFactionID());
  3891. pet->SetPet(true);
  3892. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  3893. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3894. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  3895. pet->SetSpawnType(6);
  3896. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  3897. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3898. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3899. if (strlen(pet->GetSubTitle()) > 0) {
  3900. string pet_subtitle;
  3901. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3902. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3903. pet->SetSubTitle(pet_subtitle.c_str());
  3904. }
  3905. // deity and cosmetic pets are not attackable
  3906. pet->SetAttackable(false);
  3907. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3908. lua_interface->SetSpawnValue(state, pet);
  3909. return 1;
  3910. }
  3911. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  3912. if (!lua_interface)
  3913. return 0;
  3914. Spawn* spawn = lua_interface->GetSpawn(state);
  3915. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3916. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3917. if (!spawn) {
  3918. lua_interface->LogError("LUA SummonCosmeticPet command error: Spawn is not valid");
  3919. return 0;
  3920. }
  3921. if (!spawn->IsEntity()) {
  3922. lua_interface->LogError("LUA SummonCosmeticPet command error: Spawn is not an entity");
  3923. return 0;
  3924. }
  3925. if (((Entity*)spawn)->GetCosmeticPet()) {
  3926. if (spawn->IsPlayer()) {
  3927. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3928. if (client)
  3929. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  3930. }
  3931. lua_interface->LogError("LUA SummonCosmeticPet command error: spawn already has a pet of this type");
  3932. return 0;
  3933. }
  3934. if (pet_id == 0) {
  3935. lua_interface->LogError("LUA SummonCosmeticPet command error: pet_id can not be set to 0");
  3936. return 0;
  3937. }
  3938. if (!luaspell) {
  3939. lua_interface->LogError("LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts");
  3940. return 0;
  3941. }
  3942. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3943. if (!pet) {
  3944. lua_interface->LogError("LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", pet_id);
  3945. return 0;
  3946. }
  3947. if (!pet->IsNPC()) {
  3948. lua_interface->LogError("LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", pet_id);
  3949. return 0;
  3950. }
  3951. pet->SetX(spawn->GetX());
  3952. pet->SetY(spawn->GetY());
  3953. pet->SetZ(spawn->GetZ());
  3954. pet->SetLocation(spawn->GetLocation());
  3955. pet->SetHeading(spawn->GetHeading());
  3956. spawn->GetZone()->AddSpawn(pet);
  3957. string random_pet_name;
  3958. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3959. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3960. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3961. pet->SetName(random_pet_name.c_str());
  3962. pet->SetLevel(spawn->GetLevel());
  3963. pet->SetFactionID(spawn->GetFactionID());
  3964. pet->SetPet(true);
  3965. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  3966. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3967. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  3968. pet->SetSpawnType(6);
  3969. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  3970. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3971. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3972. if (strlen(pet->GetSubTitle()) > 0) {
  3973. string pet_subtitle;
  3974. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3975. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3976. pet->SetSubTitle(pet_subtitle.c_str());
  3977. }
  3978. pet->SetAttackable(false);
  3979. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3980. lua_interface->SetSpawnValue(state, pet);
  3981. return 1;
  3982. }
  3983. int EQ2Emu_lua_DismissPet(lua_State* state) {
  3984. if (!lua_interface)
  3985. return 0;
  3986. Spawn* spawn = lua_interface->GetSpawn(state);
  3987. if (!spawn) {
  3988. lua_interface->LogError("LUA DismissPet command error: spawn is not valid");
  3989. return 0;
  3990. }
  3991. if (!spawn->IsPet()) {
  3992. lua_interface->LogError("LUA DismissPet command error: spawn is not a pet");
  3993. return 0;
  3994. }
  3995. if (!((NPC*)spawn)->IsDismissing())
  3996. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  3997. return 0;
  3998. }
  3999. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4000. if (!lua_interface)
  4001. return 0;
  4002. Quest* quest = lua_interface->GetQuest(state);
  4003. if (!quest) {
  4004. lua_interface->LogError("LUA SetQuestFeatherColor command error: valid quest not found, SetQuestFeatherColor can only be called from a quest script");
  4005. return 0;
  4006. }
  4007. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4008. if (feather_color > 0)
  4009. quest->SetFeatherColor(feather_color);
  4010. return 0;
  4011. }
  4012. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4013. if (!lua_interface)
  4014. return 0;
  4015. Spawn* spawn = lua_interface->GetSpawn(state);
  4016. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4017. if (!spawn) {
  4018. lua_interface->LogError("LUA RemoveSpawnAccess command error: first spawn is not valid");
  4019. return 0;
  4020. }
  4021. if (!spawn2) {
  4022. lua_interface->LogError("LUA RemoveSpawnAccess command error: second spawn is not valid");
  4023. return 0;
  4024. }
  4025. spawn->RemoveSpawnAccess(spawn2);
  4026. return 0;
  4027. }
  4028. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4029. if (!lua_interface)
  4030. return 0;
  4031. ZoneServer* zone = lua_interface->GetZone(state);
  4032. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4033. if (!zone) {
  4034. lua_interface->LogError("LUA SpawnByLocationID command error: zone is not valid");
  4035. return 0;
  4036. }
  4037. if (location_id == 0) {
  4038. lua_interface->LogError("LUA SpawnByLocationID command error: location id can not be 0");
  4039. return 0;
  4040. }
  4041. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4042. if (!location) {
  4043. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", location_id);
  4044. return 0;
  4045. }
  4046. Spawn* spawn = 0;
  4047. if (location->entities[0]) {
  4048. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4049. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4050. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4051. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4052. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4053. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4054. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4055. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4056. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4057. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4058. if (spawn) {
  4059. const char* script = 0;
  4060. for (int x = 0; x < 3; x++) {
  4061. switch (x) {
  4062. case 0:
  4063. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4064. break;
  4065. case 1:
  4066. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4067. break;
  4068. case 2:
  4069. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4070. break;
  4071. }
  4072. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4073. spawn->SetSpawnScript(string(script));
  4074. break;
  4075. }
  4076. }
  4077. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4078. lua_interface->SetSpawnValue(state, spawn);
  4079. return 1;
  4080. }
  4081. else {
  4082. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4083. safe_delete(spawn);
  4084. }
  4085. }
  4086. return 0;
  4087. }
  4088. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4089. if (!lua_interface)
  4090. return 0;
  4091. Spawn* caster = lua_interface->GetSpawn(state);
  4092. Spawn* target = lua_interface->GetSpawn(state, 2);
  4093. int32 id = lua_interface->GetInt32Value(state, 3);
  4094. string command = lua_interface->GetStringValue(state, 4);
  4095. if (!caster) {
  4096. lua_interface->LogError("LUA CastEntityCommand command error: caster is not valid");
  4097. return 0;
  4098. }
  4099. if (!target) {
  4100. lua_interface->LogError("LUA CastEntityCommand command error: target is not valid");
  4101. return 0;
  4102. }
  4103. if (!caster->IsPlayer()) {
  4104. lua_interface->LogError("LUA CastEntityCommand command error: caster is not a player");
  4105. return 0;
  4106. }
  4107. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4108. if (!entity_command) {
  4109. lua_interface->LogError("LUA CastEntityCommand command error: unable to get a valid EntityCommand with the given ID (%u) and name (%s)", id, command.c_str());
  4110. return 0;
  4111. }
  4112. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4113. if (!client) {
  4114. lua_interface->LogError("LUA CastEntityCommand command error: unable to get a valid client for the given caster");
  4115. return 0;
  4116. }
  4117. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4118. return 0;
  4119. }
  4120. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4121. if (!lua_interface)
  4122. return 0;
  4123. Spawn* spawn = lua_interface->GetSpawn(state);
  4124. if (!spawn) {
  4125. lua_interface->LogError("LUA SetLuaBrain command error: spawn is not valid");
  4126. return 0;
  4127. }
  4128. if (!spawn->IsNPC()) {
  4129. lua_interface->LogError("LUA SetLuaBrain command error: spawn is not a npc");
  4130. return 0;
  4131. }
  4132. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4133. return 0;
  4134. }
  4135. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4136. if (!lua_interface)
  4137. return 0;
  4138. Spawn* spawn = lua_interface->GetSpawn(state);
  4139. int16 tick = lua_interface->GetInt16Value(state, 2);
  4140. if (!spawn) {
  4141. lua_interface->LogError("LUA SetBrainTick command error: spawn is not valid");
  4142. return 0;
  4143. }
  4144. if (!spawn->IsNPC()) {
  4145. lua_interface->LogError("LUA SetBrainTick command error: spawn is not a valid npc");
  4146. return 0;
  4147. }
  4148. if (tick < 20) {
  4149. lua_interface->LogError("LUA SetBrainTick command error: tick can not be set below 20 milliseconds");
  4150. return 0;
  4151. }
  4152. ((NPC*)spawn)->Brain()->SetTick(tick);
  4153. return 0;
  4154. }
  4155. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4156. if (!lua_interface)
  4157. return 0;
  4158. Spawn* spawn = lua_interface->GetSpawn(state);
  4159. Spawn* target = lua_interface->GetSpawn(state, 2);
  4160. if (!spawn) {
  4161. lua_interface->LogError("LUA SetFollowTarget command error: spawn is not valid");
  4162. return 0;
  4163. }
  4164. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4165. spawn->SetFollowTarget(target);
  4166. return 0;
  4167. }
  4168. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4169. if (!lua_interface)
  4170. return 0;
  4171. Spawn* spawn = lua_interface->GetSpawn(state);
  4172. if (!spawn) {
  4173. lua_interface->LogError("LUA GetFollowTarget command error: spawn is not valid");
  4174. return 0;
  4175. }
  4176. Spawn* target = spawn->GetFollowTarget();
  4177. if (target) {
  4178. lua_interface->SetSpawnValue(state, target);
  4179. return 1;
  4180. }
  4181. return 0;
  4182. }
  4183. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4184. if (!lua_interface)
  4185. return 0;
  4186. Spawn* spawn = lua_interface->GetSpawn(state);
  4187. if (!spawn) {
  4188. lua_interface->LogError("LUA ToggleFollow command error: spawn is not valid");
  4189. return 0;
  4190. }
  4191. if (spawn->following)
  4192. spawn->following = false;
  4193. else
  4194. spawn->following = true;
  4195. return 0;
  4196. }
  4197. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4198. if (!lua_interface)
  4199. return 0;
  4200. Spawn* spawn = lua_interface->GetSpawn(state);
  4201. if (!spawn) {
  4202. lua_interface->LogError("LUA IsFollowing command error: spawn is not valid");
  4203. return 0;
  4204. }
  4205. lua_interface->SetBooleanValue(state, spawn->following);
  4206. return 1;
  4207. }
  4208. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4209. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4210. // I will attempt to explain how this function works for future refrence
  4211. // Fist lets make sure lua_interface is valid, if not return out
  4212. if (!lua_interface)
  4213. return 0;
  4214. // Next we grab the first 2 params same as we usually would
  4215. Spawn* spawn = lua_interface->GetSpawn(state);
  4216. string var = lua_interface->GetStringValue(state, 2);
  4217. // 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
  4218. // 1 = Spawn
  4219. // 2 = Zone
  4220. // 3 = Item
  4221. // 4 = Quest
  4222. // 5 = String
  4223. // 6 = nil (null)
  4224. int8 dataType = 0;
  4225. // Define pointers for each potential type
  4226. Spawn* spawnVal = 0;
  4227. ZoneServer* zone = 0;
  4228. Item* item = 0;
  4229. Quest* quest = 0;
  4230. string val;
  4231. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4232. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4233. // options window are also light user data be we do not handle those.
  4234. // We check with lua_islightuserdata(lua_State*, index)
  4235. if (lua_islightuserdata(state, 3)) {
  4236. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4237. // and convert it to LUAUserData*
  4238. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4239. // Check to make sure the data we got is valid, if not give an error
  4240. if (!data || !data->IsCorrectlyInitialized()) {
  4241. lua_interface->LogError("LUA SetTempVariable command error while processing %s", lua_tostring(state, -1));
  4242. }
  4243. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4244. else if (data->IsSpawn()) {
  4245. spawnVal = data->spawn;
  4246. dataType = 1;
  4247. }
  4248. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4249. else if (data->IsZone()) {
  4250. zone = data->zone;
  4251. dataType = 2;
  4252. }
  4253. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4254. else if (data->IsItem()) {
  4255. item = data->item;
  4256. dataType = 3;
  4257. }
  4258. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4259. else if (data->IsQuest()) {
  4260. quest = data->quest;
  4261. dataType = 4;
  4262. }
  4263. }
  4264. // Wasn't light user data, check if it is nil(null)
  4265. else if (lua_isnil(state, 3)) {
  4266. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4267. dataType = 6;
  4268. }
  4269. // Wasn't light user data or nil (null), must be a string
  4270. else {
  4271. // Set the string and dataType variable
  4272. val = lua_interface->GetStringValue(state, 3);
  4273. dataType = 5;
  4274. }
  4275. // We now have all the params, lets check to make sure they are valid
  4276. if (!spawn) {
  4277. lua_interface->LogError("LUA SetTempVariable command error: spawn is not valid");
  4278. return 0;
  4279. }
  4280. if (var.length() == 0) {
  4281. lua_interface->LogError("LUA SetTempVariable command error: var must be set");
  4282. return 0;
  4283. }
  4284. if (dataType == 0) {
  4285. lua_interface->LogError("LUA SetTempVariable command error: unknown data type");
  4286. return 0;
  4287. }
  4288. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4289. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4290. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4291. switch (dataType) {
  4292. case 1:
  4293. // 1 = Spawn
  4294. spawn->AddTempVariable(var, spawnVal);
  4295. break;
  4296. case 2:
  4297. // 2 = Zone
  4298. spawn->AddTempVariable(var, zone);
  4299. break;
  4300. case 3:
  4301. // 3 = Item
  4302. spawn->AddTempVariable(var, item);
  4303. break;
  4304. case 4:
  4305. // 4 = Quest
  4306. spawn->AddTempVariable(var, quest);
  4307. break;
  4308. case 5:
  4309. // 5 = String
  4310. spawn->AddTempVariable(var, val);
  4311. break;
  4312. case 6:
  4313. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4314. spawn->DeleteTempVariable(var);
  4315. break;
  4316. }
  4317. // And we are done so return out
  4318. return 0;
  4319. }
  4320. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4321. if (!lua_interface)
  4322. return 0;
  4323. Spawn* spawn = lua_interface->GetSpawn(state);
  4324. string var = lua_interface->GetStringValue(state, 2);
  4325. if (!spawn) {
  4326. lua_interface->LogError("LUA GetTempVariable command error: spawn is not valid");
  4327. return 0;
  4328. }
  4329. if (var.length() == 0) {
  4330. lua_interface->LogError("LUA GetTempVariable command error: var must be set");
  4331. return 0;
  4332. }
  4333. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4334. int8 type = spawn->GetTempVariableType(var);
  4335. Spawn* spawn2 = 0;
  4336. ZoneServer* zone = 0;
  4337. Item* item = 0;
  4338. Quest* quest = 0;
  4339. // Set the lua function return value based on the type of data the variable contains
  4340. switch (type) {
  4341. case 1:
  4342. spawn2 = spawn->GetTempVariableSpawn(var);
  4343. if (!spawn2)
  4344. return 0;
  4345. lua_interface->SetSpawnValue(state, spawn2);
  4346. break;
  4347. case 2:
  4348. zone = spawn->GetTempVariableZone(var);
  4349. if (!zone)
  4350. return 0;
  4351. lua_interface->SetZoneValue(state, zone);
  4352. break;
  4353. case 3:
  4354. item = spawn->GetTempVariableItem(var);
  4355. if (!item)
  4356. return 0;
  4357. lua_interface->SetItemValue(state, item);
  4358. break;
  4359. case 4:
  4360. quest = spawn->GetTempVariableQuest(var);
  4361. if (!quest)
  4362. return 0;
  4363. lua_interface->SetQuestValue(state, quest);
  4364. break;
  4365. case 5:
  4366. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4367. break;
  4368. default:
  4369. // Not a valid type then the variable was not set so return out
  4370. return 0;
  4371. }
  4372. // Return value was set so return out
  4373. return 1;
  4374. }
  4375. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4376. {
  4377. if (!lua_interface)
  4378. return 0;
  4379. Quest* quest = lua_interface->GetQuest(state);
  4380. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4381. string description = lua_interface->GetStringValue(state, 3);
  4382. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4383. if (!quest) {
  4384. lua_interface->LogError("LUA GiveQuestItem command error: quest is not valid");
  4385. lua_interface->SetBooleanValue(state, false);
  4386. return 1;
  4387. }
  4388. if (!spawn) {
  4389. lua_interface->LogError("LUA GiveQuestItem command error: spawn is not valid");
  4390. lua_interface->SetBooleanValue(state, false);
  4391. return 1;
  4392. }
  4393. if (!spawn->IsPlayer()) {
  4394. lua_interface->LogError("LUA GiveQuestItem command error: spawn must be a player");
  4395. lua_interface->SetBooleanValue(state, false);
  4396. return 1;
  4397. }
  4398. if (item_id == 0) {
  4399. lua_interface->LogError("LUA GiveQuestItem command error: item_id is not valid");
  4400. lua_interface->SetBooleanValue(state, false);
  4401. return 1;
  4402. }
  4403. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4404. if (!client) {
  4405. lua_interface->LogError("LUA GiveQuestItem command error: unable to get a valid client from the given spawn");
  4406. lua_interface->SetBooleanValue(state, false);
  4407. return 1;
  4408. }
  4409. Item* item = master_item_list.GetItem(item_id);
  4410. if (!item) {
  4411. lua_interface->LogError("LUA GiveQuestItem command error: unable to get an item from the given id (%u)", item_id);
  4412. lua_interface->SetBooleanValue(state, false);
  4413. return 1;
  4414. }
  4415. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4416. if (packet) {
  4417. packet->setDataByName("title", "Quest Reward!");
  4418. packet->setDataByName("name", quest->GetName());
  4419. packet->setDataByName("description", description.c_str());
  4420. packet->setDataByName("level", quest->GetLevel());
  4421. packet->setArrayLengthByName("num_rewards", 1);
  4422. packet->setArrayDataByName("reward_id", item->details.item_id);
  4423. if (client->GetVersion() < 860)
  4424. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4425. else if (client->GetVersion() < 1193)
  4426. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4427. else
  4428. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4429. client->QueuePacket(packet->serialize());
  4430. safe_delete(packet);
  4431. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  4432. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  4433. return 1;
  4434. }
  4435. lua_interface->SetBooleanValue(state, false);
  4436. return 1;
  4437. }
  4438. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  4439. if (!lua_interface)
  4440. return 0;
  4441. Quest* quest = lua_interface->GetQuest(state);
  4442. if (!quest) {
  4443. lua_interface->LogError("LUA SetQuestRepeatable command error: quest is not valid");
  4444. return 0;
  4445. }
  4446. quest->SetRepeatable(true);
  4447. return 0;
  4448. }
  4449. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  4450. if (!lua_interface)
  4451. return 0;
  4452. Spawn* spawn = lua_interface->GetSpawn(state);
  4453. if (!spawn) {
  4454. lua_interface->LogError("LUA GetArchetypeName command error: spawn is not valid");
  4455. return 0;
  4456. }
  4457. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  4458. string ret = classes.GetClassNameCase(base_class);
  4459. if (ret.length() > 0) {
  4460. lua_interface->SetStringValue(state, ret.c_str());
  4461. return 1;
  4462. }
  4463. return 0;
  4464. }
  4465. int EQ2Emu_lua_AddWard(lua_State* state) {
  4466. if (!lua_interface)
  4467. return 0;
  4468. int32 damage = lua_interface->GetInt32Value(state);
  4469. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  4470. int8 wardType = lua_interface->GetInt8Value(state, 3);
  4471. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  4472. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4473. bool ward_was_added = false;
  4474. ZoneServer* zone = spell->caster->GetZone();
  4475. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4476. for (int32 i = 0; i < spell->targets.size(); i++) {
  4477. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  4478. if (!target)
  4479. continue;
  4480. if (target->IsEntity()) {
  4481. // If the ward is already active remove it
  4482. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  4483. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4484. // Create new ward info
  4485. WardInfo* ward = new WardInfo;
  4486. ward->Spell = spell;
  4487. ward->BaseDamage = damage;
  4488. ward->DamageLeft = damage;
  4489. ward->keepWard = keepWard;
  4490. ward->WardType = wardType;
  4491. if (wardType == WARD_TYPE_MAGICAL)
  4492. ward->DamageType = damageTypes;
  4493. // Add the ward to the entity
  4494. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  4495. ward_was_added = true;
  4496. }
  4497. }
  4498. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4499. if (ward_was_added && spell->caster->IsPlayer()) {
  4500. spell->had_dmg_remaining = true;
  4501. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  4502. }
  4503. return 0;
  4504. }
  4505. int EQ2Emu_lua_AddToWard(lua_State* state) {
  4506. if (!lua_interface)
  4507. return 0;
  4508. int32 amount = lua_interface->GetInt32Value(state);
  4509. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4510. WardInfo* ward = 0;
  4511. ZoneServer* zone = spell->caster->GetZone();
  4512. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4513. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4514. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  4515. ward = target->GetWard(spell->spell->GetSpellID());
  4516. if (ward) {
  4517. ward->DamageLeft += amount;
  4518. if (ward->DamageLeft > ward->BaseDamage)
  4519. ward->DamageLeft = ward->BaseDamage;
  4520. for (int32 i = 0; i < spell->targets.size(); i++) {
  4521. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  4522. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  4523. }
  4524. }
  4525. }
  4526. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4527. if (ward && spell->caster->IsPlayer())
  4528. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  4529. return 0;
  4530. }
  4531. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  4532. if (!lua_interface)
  4533. return 0;
  4534. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4535. if (!spell) {
  4536. lua_interface->LogError("LUA GetWardAmountLeft command error: this command can only be used in a spell script");
  4537. return 0;
  4538. }
  4539. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4540. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  4541. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  4542. if (ward) {
  4543. lua_interface->SetInt32Value(state, ward->DamageLeft);
  4544. return 1;
  4545. }
  4546. }
  4547. return 0;
  4548. }
  4549. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  4550. if (!lua_interface)
  4551. return 0;
  4552. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4553. ZoneServer* zone = spell->caster->GetZone();
  4554. Spawn* target = 0;
  4555. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4556. for (int32 i = 0; i < spell->targets.size(); i++) {
  4557. target = zone->GetSpawnByID(spell->targets.at(i));
  4558. if (target && target->IsEntity()) {
  4559. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4560. }
  4561. }
  4562. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4563. return 0;
  4564. }
  4565. int EQ2Emu_lua_Interrupt(lua_State* state)
  4566. {
  4567. if (!lua_interface)
  4568. return 0;
  4569. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  4570. Spawn* target = lua_interface->GetSpawn(state, 2);
  4571. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4572. if (!caster)
  4573. {
  4574. lua_interface->LogError("LUA Interrupt command error: caster is not a valid spawn");
  4575. return 0;
  4576. }
  4577. if (!target)
  4578. {
  4579. lua_interface->LogError("LUA Interrupt command error: target is not a valid spawn");
  4580. return 0;
  4581. }
  4582. if (!spell) {
  4583. lua_interface->LogError("LUA Interrupt command error: spell is not a valid spawn");
  4584. return 0;
  4585. }
  4586. if (!target->IsEntity() && !spell)
  4587. {
  4588. lua_interface->LogError("LUA Interrupt command error: Target is not an entity");
  4589. return 0;
  4590. }
  4591. if (!target && spell) {
  4592. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4593. for (int8 i = 0; i < spell->targets.size(); i++) {
  4594. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  4595. if (!target || !target->IsEntity())
  4596. continue;
  4597. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4598. }
  4599. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4600. }
  4601. else
  4602. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4603. return 0;
  4604. }
  4605. int EQ2Emu_lua_Stealth(lua_State* state) {
  4606. if (!lua_interface)
  4607. return 0;
  4608. int8 type = lua_interface->GetInt8Value(state);
  4609. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4610. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4611. if (!spell) {
  4612. lua_interface->LogError("LUA Stealth command error: must be used from spell script");
  4613. return 0;
  4614. }
  4615. ZoneServer* zone = spell->caster->GetZone();
  4616. if (spawn) {
  4617. if (spawn->IsEntity()) {
  4618. if (type == 1) {
  4619. ((Entity*)spawn)->AddStealthSpell(spell);
  4620. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4621. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4622. }
  4623. else if (type == 2) {
  4624. ((Entity*)spawn)->AddInvisSpell(spell);
  4625. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4626. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4627. }
  4628. return 0;
  4629. }
  4630. else {
  4631. lua_interface->LogError("LUA Stealth command error: target override is not Entity");
  4632. return 0;
  4633. }
  4634. }
  4635. else {
  4636. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4637. for (int32 i = 0; i < spell->targets.size(); i++) {
  4638. spawn = zone->GetSpawnByID(spell->targets.at(i));
  4639. if (!spawn || !spawn->IsEntity())
  4640. continue;
  4641. if (type == 1) {
  4642. ((Entity*)spawn)->AddStealthSpell(spell);
  4643. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4644. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4645. }
  4646. else if (type == 2) {
  4647. ((Entity*)spawn)->AddInvisSpell(spell);
  4648. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4649. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4650. }
  4651. else {
  4652. lua_interface->LogError("LUA Stealth command error: invalid stealth type given");
  4653. break;
  4654. }
  4655. }
  4656. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4657. }
  4658. return 0;
  4659. }
  4660. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  4661. if (!lua_interface)
  4662. return 0;
  4663. Spawn* spawn = lua_interface->GetSpawn(state);
  4664. if (!spawn) {
  4665. lua_interface->LogError("LUA IsStealthed command error: spawn is not valid");
  4666. return 0;
  4667. }
  4668. if (spawn->IsEntity()) {
  4669. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  4670. return 1;
  4671. }
  4672. else
  4673. lua_interface->LogError("LUA IsStealthed command error: spawn is not entity");
  4674. return 0;
  4675. }
  4676. int EQ2Emu_lua_IsInvis(lua_State* state) {
  4677. if (!lua_interface)
  4678. return 0;
  4679. Spawn* spawn = lua_interface->GetSpawn(state);
  4680. if (!spawn) {
  4681. lua_interface->LogError("LUA IsInvis command error: spawn is not valid");
  4682. return 0;
  4683. }
  4684. if (spawn->IsEntity()) {
  4685. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  4686. return 1;
  4687. }
  4688. else
  4689. lua_interface->LogError("LUA IsInvis command error: spawn is not entity");
  4690. return 0;
  4691. }
  4692. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  4693. if (!lua_interface)
  4694. return 0;
  4695. Spawn* player = lua_interface->GetSpawn(state);
  4696. int32 item_id = lua_interface->GetInt32Value(state, 2);
  4697. if (!player->IsPlayer()) {
  4698. lua_interface->LogError("LUA HasItemEquipped command error: spawn is not player");
  4699. return 0;
  4700. }
  4701. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  4702. return 1;
  4703. }
  4704. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  4705. if (!lua_interface)
  4706. return 0;
  4707. Spawn* player = lua_interface->GetSpawn(state);
  4708. int8 slot = lua_interface->GetInt8Value(state, 2);
  4709. if (!player) {
  4710. lua_interface->LogError("LUA GetEquippedItemBySlot command error: spawn is not valid");
  4711. return 0;
  4712. }
  4713. if (!player->IsPlayer()) {
  4714. lua_interface->LogError("LUA GetEquippedItemBySlot command error: spawn is not player");
  4715. return 0;
  4716. }
  4717. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  4718. if (!item) {
  4719. lua_interface->LogError("LUA GetEquippedItemBySlot command error: item was not found in slot");
  4720. return 0;
  4721. }
  4722. lua_interface->SetItemValue(state, item);
  4723. return 1;
  4724. }
  4725. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  4726. if (!lua_interface)
  4727. return 0;
  4728. Spawn* player = lua_interface->GetSpawn(state);
  4729. int32 id = lua_interface->GetInt32Value(state, 2);
  4730. if (!player) {
  4731. lua_interface->LogError("LUA GetEquippedItemByID command error: spawn is not valid");
  4732. return 0;
  4733. }
  4734. if (!player->IsPlayer()) {
  4735. lua_interface->LogError("LUA GetEquippedItemByID command error: spawn is not player");
  4736. return 0;
  4737. }
  4738. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  4739. if (!item) {
  4740. lua_interface->LogError("LUA GetEquippedItemByID command error: equipped item with used id not found");
  4741. return 0;
  4742. }
  4743. lua_interface->SetItemValue(state, item);
  4744. return 1;
  4745. }
  4746. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  4747. if (!lua_interface)
  4748. return 0;
  4749. Spawn* player = lua_interface->GetSpawn(state);
  4750. int32 id = lua_interface->GetInt32Value(state, 2);
  4751. int8 count = lua_interface->GetInt8Value(state, 3);
  4752. bool include_bank = lua_interface->GetInt8Value(state, 4);
  4753. if (!player) {
  4754. lua_interface->LogError("LUA GetItemByID command error: spawn is not valid");
  4755. return 0;
  4756. }
  4757. if (!player->IsPlayer()) {
  4758. lua_interface->LogError("LUA GetItemByID command error: spawn is not player");
  4759. return 0;
  4760. }
  4761. if (!count)
  4762. count = 1;
  4763. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  4764. if (!item) {
  4765. lua_interface->LogError("LUA GetItemByID command error: item with used id not found");
  4766. return 0;
  4767. }
  4768. lua_interface->SetItemValue(state, item);
  4769. return 1;
  4770. }
  4771. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  4772. if (!lua_interface)
  4773. return 0;
  4774. Spawn* spawn = lua_interface->GetSpawn(state);
  4775. int32 anim = lua_interface->GetInt32Value(state, 2);
  4776. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  4777. int8 type = lua_interface->GetInt8Value(state, 4);
  4778. if (!spawn) {
  4779. lua_interface->LogError("LUA PlayAnimation command error: spawn is not valid");
  4780. return 0;
  4781. }
  4782. if (spawn2) {
  4783. if (spawn2->IsPlayer()) {
  4784. if (type != 1 && type != 2)
  4785. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  4786. else
  4787. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  4788. return 0;
  4789. }
  4790. else {
  4791. lua_interface->LogError("LUA PlayAnimation command error: second spawn not a player");
  4792. return 0;
  4793. }
  4794. }
  4795. else
  4796. spawn->GetZone()->PlayAnimation(spawn, anim);
  4797. return 0;
  4798. }
  4799. int EQ2Emu_lua_IsPet(lua_State* state) {
  4800. if (!lua_interface)
  4801. return 0;
  4802. Spawn* spawn = lua_interface->GetSpawn(state);
  4803. if (!spawn) {
  4804. lua_interface->LogError("LUA IsPet command error: spawn is not valid");
  4805. return 0;
  4806. }
  4807. lua_interface->SetBooleanValue(state, spawn->IsPet());
  4808. return 1;
  4809. }
  4810. int EQ2Emu_lua_GetOwner(lua_State* state) {
  4811. if (!lua_interface)
  4812. return 0;
  4813. Spawn* spawn = lua_interface->GetSpawn(state);
  4814. if (!spawn) {
  4815. lua_interface->LogError("LUA GetOwner command error: spawn is not valid");
  4816. return 0;
  4817. }
  4818. if (!spawn->IsNPC()) {
  4819. lua_interface->LogError("LUA GetOwner command error: spawn is not a NPC");
  4820. return 0;
  4821. }
  4822. if (((NPC*)spawn)->GetOwner()) {
  4823. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  4824. return 1;
  4825. }
  4826. return 0;
  4827. }
  4828. int EQ2Emu_lua_SetTarget(lua_State* state) {
  4829. if (!lua_interface)
  4830. return 0;
  4831. Spawn* spawn = lua_interface->GetSpawn(state);
  4832. Spawn* target = lua_interface->GetSpawn(state, 2);
  4833. if (!spawn) {
  4834. lua_interface->LogError("LUA SetTarget command error: spawn is not valid");
  4835. return 0;
  4836. }
  4837. if (!spawn) {
  4838. lua_interface->LogError("LUA SetTarget command error: target is not valid");
  4839. return 0;
  4840. }
  4841. spawn->SetTarget(target);
  4842. return 0;
  4843. }
  4844. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  4845. if (!lua_interface)
  4846. return 0;
  4847. Spawn* spawn = lua_interface->GetSpawn(state);
  4848. bool val = lua_interface->GetBooleanValue(state, 2);
  4849. if (!spawn) {
  4850. lua_interface->LogError("LUA SetInCombat command error: spawn is not valid");
  4851. return 0;
  4852. }
  4853. if (!spawn->IsEntity()) {
  4854. lua_interface->LogError("LUA SetInCombat command error: spawn is not an entity");
  4855. return 0;
  4856. }
  4857. ((Entity*)spawn)->InCombat(val);
  4858. if (val) {
  4859. spawn->ClearRunningLocations();
  4860. spawn->CalculateRunningLocation(true);
  4861. }
  4862. return 0;
  4863. }
  4864. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  4865. if (!lua_interface)
  4866. return 0;
  4867. Spawn* spawn1 = lua_interface->GetSpawn(state);
  4868. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4869. if (!spawn1) {
  4870. lua_interface->LogError("LUA CompareSpawns command error: first spawn is not valid");
  4871. return 0;
  4872. }
  4873. if (!spawn2) {
  4874. lua_interface->LogError("LUA CompareSpawns command error: second spawn is not valid");
  4875. return 0;
  4876. }
  4877. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  4878. return 1;
  4879. }
  4880. int EQ2Emu_lua_Runback(lua_State* state) {
  4881. if (!lua_interface)
  4882. return 0;
  4883. Spawn* spawn = lua_interface->GetSpawn(state);
  4884. if (!spawn) {
  4885. lua_interface->LogError("LUA Runback command error: spawn is not valid");
  4886. return 0;
  4887. }
  4888. if (!spawn->IsNPC()) {
  4889. lua_interface->LogError("LUA Runback command error: spawn is not an NPC");
  4890. return 0;
  4891. }
  4892. ((NPC*)spawn)->Runback();
  4893. return 0;
  4894. }
  4895. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  4896. if (!lua_interface)
  4897. return 0;
  4898. Spawn* spawn = lua_interface->GetSpawn(state);
  4899. if (!spawn) {
  4900. lua_interface->LogError("LUA GetRunbackDistance command error: spawn is not valid");
  4901. return 0;
  4902. }
  4903. if (!spawn->IsNPC()) {
  4904. lua_interface->LogError("LUA GetRunbackDistance command error: spawn is not an NPC");
  4905. return 0;
  4906. }
  4907. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  4908. return 1;
  4909. }
  4910. int EQ2Emu_lua_IsCasting(lua_State* state) {
  4911. if (!lua_interface)
  4912. return 0;
  4913. Spawn* spawn = lua_interface->GetSpawn(state);
  4914. if (!spawn) {
  4915. lua_interface->LogError("LUA IsCasting command error: spawn is not valid");
  4916. return 0;
  4917. }
  4918. if (!spawn->IsEntity()) {
  4919. lua_interface->LogError("LUA IsCasting command error: spawn is not an entity");
  4920. return 0;
  4921. }
  4922. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  4923. return 1;
  4924. }
  4925. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  4926. if (!lua_interface)
  4927. return 0;
  4928. Spawn* spawn = lua_interface->GetSpawn(state);
  4929. if (!spawn) {
  4930. lua_interface->LogError("LUA IsMezzed command error: spawn is not valid");
  4931. return 0;
  4932. }
  4933. if (!spawn->IsEntity()) {
  4934. lua_interface->LogError("LUA IsMezzed command error: spawn is not an entity");
  4935. return 0;
  4936. }
  4937. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  4938. return 1;
  4939. }
  4940. int EQ2Emu_lua_IsStunned(lua_State* state) {
  4941. if (!lua_interface)
  4942. return 0;
  4943. Spawn* spawn = lua_interface->GetSpawn(state);
  4944. if (!spawn) {
  4945. lua_interface->LogError("LUA IsStunned command error: spawn is not valid");
  4946. return 0;
  4947. }
  4948. if (!spawn->IsEntity()) {
  4949. lua_interface->LogError("LUA IsStunned command error: spawn is not an entity");
  4950. return 0;
  4951. }
  4952. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  4953. return 1;
  4954. }
  4955. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  4956. if (!lua_interface)
  4957. return 0;
  4958. Spawn* spawn = lua_interface->GetSpawn(state);
  4959. if (!spawn) {
  4960. lua_interface->LogError("LUA IsMezzedOrStunned command error: spawn is not valid");
  4961. return 0;
  4962. }
  4963. if (!spawn->IsEntity()) {
  4964. lua_interface->LogError("LUA IsMezzedOrStunned command error: spawn is not an entity");
  4965. return 0;
  4966. }
  4967. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  4968. return 1;
  4969. }
  4970. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  4971. if (!lua_interface)
  4972. return 0;
  4973. Spawn* spawn = lua_interface->GetSpawn(state);
  4974. Spawn* target = lua_interface->GetSpawn(state, 2);
  4975. float distance = lua_interface->GetFloatValue(state, 3);
  4976. if (!spawn) {
  4977. lua_interface->LogError("LUA ProcessSpell command error: spawn is not valid");
  4978. return 0;
  4979. }
  4980. if (!target) {
  4981. lua_interface->LogError("LUA ProcessSpell command error: spawn is not an entity");
  4982. return 0;
  4983. }
  4984. if (!spawn->IsNPC()) {
  4985. lua_interface->LogError("LUA ProcessSpell command error: spawn is not an NPC");
  4986. return 0;
  4987. }
  4988. if (!target->IsEntity()) {
  4989. lua_interface->LogError("LUA ProcessSpell command error: target is not an entity");
  4990. return 0;
  4991. }
  4992. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  4993. return 1;
  4994. }
  4995. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  4996. if (!lua_interface)
  4997. return 0;
  4998. Spawn* spawn = lua_interface->GetSpawn(state);
  4999. Spawn* target = lua_interface->GetSpawn(state, 2);
  5000. float distance = lua_interface->GetFloatValue(state, 3);
  5001. if (!spawn) {
  5002. lua_interface->LogError("LUA ProcessMelee command error: spawn is not valid");
  5003. return 0;
  5004. }
  5005. if (!target) {
  5006. lua_interface->LogError("LUA ProcessMelee command error: target is not valid");
  5007. return 0;
  5008. }
  5009. if (!spawn->IsNPC()) {
  5010. lua_interface->LogError("LUA ProcessMelee command error: spawn is not an NPC");
  5011. return 0;
  5012. }
  5013. if (!target->IsEntity()) {
  5014. lua_interface->LogError("LUA ProcessMelee command error: target is not an entity");
  5015. return 0;
  5016. }
  5017. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5018. return 0;
  5019. }
  5020. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5021. if (!lua_interface)
  5022. return 0;
  5023. Spawn* spawn = lua_interface->GetSpawn(state);
  5024. if (!spawn) {
  5025. lua_interface->LogError("LUA HasRecovered command error: spawn is not valid");
  5026. return 0;
  5027. }
  5028. if (!spawn->IsNPC()) {
  5029. lua_interface->LogError("LUA HasRecovered command error: spawn is not an NPC");
  5030. return 0;
  5031. }
  5032. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5033. return 1;
  5034. }
  5035. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5036. if (!lua_interface)
  5037. return 0;
  5038. Spawn* spawn = lua_interface->GetSpawn(state);
  5039. if (!spawn) {
  5040. lua_interface->LogError("LUA GetEncounterSize command error: spawn is not valid");
  5041. return 0;
  5042. }
  5043. if (!spawn->IsNPC()) {
  5044. lua_interface->LogError("LUA GetEncounterSize command error: spawn is not an NPC");
  5045. return 0;
  5046. }
  5047. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5048. return 1;
  5049. }
  5050. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5051. if (!lua_interface)
  5052. return 0;
  5053. Spawn* spawn = lua_interface->GetSpawn(state);
  5054. if (!spawn) {
  5055. lua_interface->LogError("LUA GetMostHated command error: spawn is not valid");
  5056. return 0;
  5057. }
  5058. if (!spawn->IsNPC()) {
  5059. lua_interface->LogError("LUA GetMostHated command error: spawn is not an NPC");
  5060. return 0;
  5061. }
  5062. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5063. if (hated) {
  5064. lua_interface->SetSpawnValue(state, hated);
  5065. return 1;
  5066. }
  5067. return 0;
  5068. }
  5069. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5070. if (!lua_interface)
  5071. return 0;
  5072. Spawn* spawn = lua_interface->GetSpawn(state);
  5073. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5074. if (!spawn) {
  5075. lua_interface->LogError("LUA ClearHate command error: spawn is not valid");
  5076. return 0;
  5077. }
  5078. if (!spawn->IsNPC()) {
  5079. lua_interface->LogError("LUA ClearHate command error: spawn is not NPC");
  5080. return 0;
  5081. }
  5082. if (!hated) {
  5083. ((NPC*)spawn)->Brain()->ClearHate();
  5084. return 0;
  5085. }
  5086. else
  5087. {
  5088. if (!hated->IsEntity()) {
  5089. lua_interface->LogError("LUA ClearHate command error: second param is not entity");
  5090. return 0;
  5091. }
  5092. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5093. return 0;
  5094. }
  5095. return 0;
  5096. }
  5097. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5098. if (!lua_interface)
  5099. return 0;
  5100. Spawn* spawn = lua_interface->GetSpawn(state);
  5101. if (!spawn) {
  5102. lua_interface->LogError("LUA ClearEncounter command error: spawn is not valid");
  5103. return 0;
  5104. }
  5105. if (!spawn->IsNPC()) {
  5106. lua_interface->LogError("LUA ClearEncounter command error: spawn is not an NPC");
  5107. return 0;
  5108. }
  5109. ((NPC*)spawn)->Brain()->ClearEncounter();
  5110. return 0;
  5111. }
  5112. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5113. if (!lua_interface)
  5114. return 0;
  5115. Spawn* spawn = lua_interface->GetSpawn(state);
  5116. if (!spawn) {
  5117. lua_interface->LogError("LUA GetEncounter command error: Spawn is not valid");
  5118. return 0;
  5119. }
  5120. if (!spawn->IsNPC()) {
  5121. lua_interface->LogError("LUA GetEncounter command error: spawn is not a NPC");
  5122. return 0;
  5123. }
  5124. // Temp list to store hate list
  5125. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5126. if (encounterList->size() == 0) {
  5127. safe_delete(encounterList);
  5128. return 0;
  5129. }
  5130. lua_createtable(state, encounterList->size(), 0);
  5131. int newTable = lua_gettop(state);
  5132. for (int32 i = 0; i < encounterList->size(); i++) {
  5133. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5134. if (temp)
  5135. lua_interface->SetSpawnValue(state, temp);
  5136. lua_rawseti(state, newTable, i + 1);
  5137. }
  5138. safe_delete(encounterList);
  5139. return 1;
  5140. }
  5141. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5142. if (!lua_interface)
  5143. return 0;
  5144. Spawn* spawn = lua_interface->GetSpawn(state);
  5145. if (!spawn) {
  5146. lua_interface->LogError("LUA GetHateList command error: spawn is not valid");
  5147. return 0;
  5148. }
  5149. if (!spawn->IsNPC()) {
  5150. lua_interface->LogError("LUA GetHateList command error: spawn is not a NPC");
  5151. return 0;
  5152. }
  5153. // Temp list to store hate list
  5154. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5155. if (hateList->size() == 0) {
  5156. safe_delete(hateList);
  5157. return 0;
  5158. }
  5159. lua_createtable(state, hateList->size(), 0);
  5160. int newTable = lua_gettop(state);
  5161. for (int32 i = 0; i < hateList->size(); i++) {
  5162. lua_interface->SetSpawnValue(state, hateList->at(i));
  5163. lua_rawseti(state, newTable, i + 1);
  5164. }
  5165. safe_delete(hateList);
  5166. return 1;
  5167. }
  5168. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5169. if (!lua_interface)
  5170. return 0;
  5171. Spawn* spawn = lua_interface->GetSpawn(state);
  5172. if (!spawn) {
  5173. lua_interface->LogError("LUA HasGroup command error: spawn is not valid");
  5174. return 0;
  5175. }
  5176. if (spawn->IsPlayer()) {
  5177. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5178. lua_interface->SetBooleanValue(state, true);
  5179. else
  5180. lua_interface->SetBooleanValue(state, false);
  5181. return 1;
  5182. }
  5183. else {
  5184. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5185. return 1;
  5186. }
  5187. }
  5188. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5189. if (!lua_interface)
  5190. return 0;
  5191. Quest* quest = lua_interface->GetQuest(state);
  5192. if (!quest) {
  5193. lua_interface->LogError("LUA SetCompleteFlag command error: quest is not valid");
  5194. return 0;
  5195. }
  5196. quest->SetCompletedFlag(true);
  5197. return 0;
  5198. }
  5199. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5200. if (!lua_interface)
  5201. return 0;
  5202. Spawn* spawn = lua_interface->GetSpawn(state);
  5203. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5204. int8 tier = lua_interface->GetInt8Value(state, 3);
  5205. if (!spawn) {
  5206. lua_interface->LogError("LUA HasSpellEffect command error: spawn is not valid");
  5207. return 0;
  5208. }
  5209. if (!spawn->IsEntity()) {
  5210. lua_interface->LogError("LUA HasSpellEffect command error: spawn is not an entity");
  5211. return 0;
  5212. }
  5213. if (spellID == 0) {
  5214. lua_interface->LogError("LUA HasSpellEffect command error: spell id is not valid");
  5215. return 0;
  5216. }
  5217. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5218. if (effect) {
  5219. if (tier > 0) {
  5220. // If a tier was passed chec to see if it is the same as the effect
  5221. if (tier == effect->tier)
  5222. lua_interface->SetBooleanValue(state, true);
  5223. else
  5224. lua_interface->SetBooleanValue(state, false);
  5225. return 1;
  5226. }
  5227. else {
  5228. // Have an effect but no tier was passed so return true
  5229. lua_interface->SetBooleanValue(state, true);
  5230. }
  5231. return 1;
  5232. }
  5233. // no effect so return false
  5234. lua_interface->SetBooleanValue(state, false);
  5235. return 1;
  5236. }
  5237. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5238. if (!lua_interface)
  5239. return 0;
  5240. Spawn* spawn = lua_interface->GetSpawn(state);
  5241. int32 id = lua_interface->GetInt32Value(state, 2);
  5242. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5243. Spawn* spawn2 = 0;
  5244. vector<Spawn*> list;
  5245. if (!spawn) {
  5246. lua_interface->LogError("LUA AddSpawnIDAccess command error: spawn is not valid");
  5247. return 0;
  5248. }
  5249. //If zone not provided, use spawn's zone
  5250. if (!zone)
  5251. zone = spawn->GetZone();
  5252. list = zone->GetSpawnsByID(id);
  5253. if (list.size() == 0) {
  5254. lua_interface->LogError("LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns");
  5255. return 0;
  5256. }
  5257. vector<Spawn*>::iterator itr = list.begin();
  5258. for (int8 i = 0; i < list.size(); i++) {
  5259. spawn2 = itr[i];
  5260. if (spawn2)
  5261. spawn2->AddAllowAccessSpawn(spawn);
  5262. }
  5263. return 0;
  5264. }
  5265. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5266. if (!lua_interface)
  5267. return 0;
  5268. Spawn* spawn = lua_interface->GetSpawn(state);
  5269. int32 id = lua_interface->GetInt32Value(state, 2);
  5270. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5271. Spawn* spawn2 = 0;
  5272. if (!spawn) {
  5273. lua_interface->LogError("LUA RemoveSpawnIDAccess command error: spawn is not valid");
  5274. return 0;
  5275. }
  5276. //If zone not provided, use spawn's zone
  5277. if (!zone)
  5278. zone = spawn->GetZone();
  5279. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5280. vector<Spawn*>::iterator itr = list.begin();
  5281. if (list.size() == 0) {
  5282. lua_interface->LogError("LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns");
  5283. return 0;
  5284. }
  5285. for (int8 i = 0; i < list.size(); i++) {
  5286. spawn2 = itr[i];
  5287. if (spawn2)
  5288. spawn2->RemoveSpawnAccess(spawn);
  5289. }
  5290. return 0;
  5291. }
  5292. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5293. if (!lua_interface)
  5294. return 0;
  5295. Quest* quest = lua_interface->GetQuest(state);
  5296. if (!quest) {
  5297. lua_interface->LogError("LUA SetQuestYellow command error: quest is not valid");
  5298. return 0;
  5299. }
  5300. quest->SetYellowName(true);
  5301. return 0;
  5302. }
  5303. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5304. if (!lua_interface)
  5305. return 0;
  5306. Spawn* spawn = lua_interface->GetSpawn(state);
  5307. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5308. if (!spawn) {
  5309. lua_interface->LogError("LUA CanReceieveQuest command error: spawn is not valid");
  5310. return 0;
  5311. }
  5312. if (!spawn->IsPlayer()) {
  5313. lua_interface->LogError("LUA CanReceieveQuest command error: spawn is not player");
  5314. return 0;
  5315. }
  5316. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5317. return 1;
  5318. }
  5319. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5320. if (!lua_interface)
  5321. return 0;
  5322. Spawn* spawn = lua_interface->GetSpawn(state);
  5323. if (!spawn) {
  5324. lua_interface->LogError("LUA SetSuccessTimer command error: spawn is not valid");
  5325. return 0;
  5326. }
  5327. if (!spawn->IsPlayer()) {
  5328. lua_interface->LogError("LUA SetSuccessTimer command error: spawn is not a player");
  5329. return 0;
  5330. }
  5331. ZoneServer* zone = spawn->GetZone();
  5332. if (!zone) {
  5333. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn");
  5334. return 0;
  5335. }
  5336. Instance_Type iType = zone->GetInstanceType();
  5337. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5338. iType == GROUP_LOCKOUT_INSTANCE ||
  5339. iType == RAID_LOCKOUT_INSTANCE ||
  5340. iType == SOLO_PERSIST_INSTANCE ||
  5341. iType == GROUP_PERSIST_INSTANCE ||
  5342. iType == RAID_PERSIST_INSTANCE) {
  5343. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5344. if (data) {
  5345. // Check to see if the timer has already been set, if it has return out.
  5346. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  5347. return 0;
  5348. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  5349. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  5350. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5351. if (client) {
  5352. string time_msg = "";
  5353. int32 time = data->success_lockout_time;
  5354. int16 hour;
  5355. int8 min;
  5356. int8 sec;
  5357. hour = time / 3600;
  5358. time = time % 3600;
  5359. min = time / 60;
  5360. time = time % 60;
  5361. sec = time;
  5362. if (hour > 0) {
  5363. char temp[10];
  5364. sprintf(temp, " %i", hour);
  5365. time_msg.append(temp);
  5366. time_msg.append(" hour");
  5367. time_msg.append((hour > 1) ? "s" : "");
  5368. }
  5369. if (min > 0) {
  5370. char temp[5];
  5371. sprintf(temp, " %i", min);
  5372. time_msg.append(temp);
  5373. time_msg.append(" minute");
  5374. time_msg.append((min > 1) ? "s" : "");
  5375. }
  5376. // Only add seconds if minutes and hours are 0
  5377. if (hour == 0 && min == 0 && sec > 0) {
  5378. char temp[5];
  5379. sprintf(temp, " %i", sec);
  5380. time_msg.append(temp);
  5381. time_msg.append(" second");
  5382. time_msg.append((sec > 1) ? "s" : "");
  5383. }
  5384. 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());
  5385. }
  5386. }
  5387. else
  5388. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5389. }
  5390. else
  5391. lua_interface->LogError("LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance");
  5392. return 0;
  5393. }
  5394. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  5395. if (!lua_interface)
  5396. return 0;
  5397. Spawn* spawn = lua_interface->GetSpawn(state);
  5398. if (!spawn) {
  5399. lua_interface->LogError("LUA SetFailureTimer command error: spawn is not valid");
  5400. return 0;
  5401. }
  5402. if (!spawn->IsPlayer()) {
  5403. lua_interface->LogError("LUA SetFailureTimer command error: spawn is not a player");
  5404. return 0;
  5405. }
  5406. ZoneServer* zone = spawn->GetZone();
  5407. if (!zone) {
  5408. lua_interface->LogError("LUA SetFailureTimer command error: unable to get a valid zone for the given spawn");
  5409. return 0;
  5410. }
  5411. Instance_Type iType = zone->GetInstanceType();
  5412. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5413. iType == GROUP_LOCKOUT_INSTANCE ||
  5414. iType == RAID_LOCKOUT_INSTANCE ||
  5415. iType == SOLO_PERSIST_INSTANCE ||
  5416. iType == GROUP_PERSIST_INSTANCE ||
  5417. iType == RAID_PERSIST_INSTANCE) {
  5418. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5419. if (data) {
  5420. // Check to see if the timer has already been set, if it has return out.
  5421. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  5422. return 0;
  5423. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  5424. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  5425. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5426. if (client) {
  5427. string time_msg = "";
  5428. int32 time = data->failure_lockout_time;
  5429. int16 hour;
  5430. int8 min;
  5431. int8 sec;
  5432. hour = time / 3600;
  5433. time = time % 3600;
  5434. min = time / 60;
  5435. time = time % 60;
  5436. sec = time;
  5437. if (hour > 0) {
  5438. char temp[10];
  5439. sprintf(temp, " %i", hour);
  5440. time_msg.append(temp);
  5441. time_msg.append(" hour");
  5442. time_msg.append((hour > 1) ? "s" : "");
  5443. }
  5444. if (min > 0) {
  5445. char temp[5];
  5446. sprintf(temp, " %i", min);
  5447. time_msg.append(temp);
  5448. time_msg.append(" minute");
  5449. time_msg.append((min > 1) ? "s" : "");
  5450. }
  5451. // Only add seconds if minutes and hours are 0
  5452. if (hour == 0 && min == 0 && sec > 0) {
  5453. char temp[5];
  5454. sprintf(temp, " %i", sec);
  5455. time_msg.append(temp);
  5456. time_msg.append(" second");
  5457. time_msg.append((sec > 1) ? "s" : "");
  5458. }
  5459. 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());
  5460. }
  5461. }
  5462. else
  5463. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5464. }
  5465. else
  5466. lua_interface->LogError("LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance");
  5467. return 0;
  5468. }
  5469. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  5470. if (!lua_interface)
  5471. return 0;
  5472. Spawn* spawn = lua_interface->GetSpawn(state);
  5473. if (!spawn) {
  5474. lua_interface->LogError("LUA IsGroundSpawn command error: not a valid spawn");
  5475. return 0;
  5476. }
  5477. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  5478. return 1;
  5479. }
  5480. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  5481. if (!lua_interface)
  5482. return 0;
  5483. Spawn* player = lua_interface->GetSpawn(state);
  5484. Spawn* ground = lua_interface->GetSpawn(state, 2);
  5485. if (!player) {
  5486. lua_interface->LogError("LUA CanHarvest command error: not a valid spawn");
  5487. return 0;
  5488. }
  5489. if (!player->IsPlayer()) {
  5490. lua_interface->LogError("LUA CanHarvest command error: spawn is not a player");
  5491. return 0;
  5492. }
  5493. if (!ground) {
  5494. lua_interface->LogError("LUA CanHarvest command error: not a valid spawn");
  5495. return 0;
  5496. }
  5497. if (!ground->IsGroundSpawn()) {
  5498. lua_interface->LogError("LUA CanHarvest command error: spawn is not a ground spawn");
  5499. return 0;
  5500. }
  5501. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5502. if (!groundspawn_entries) {
  5503. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5504. return 0;
  5505. }
  5506. Skill* skill = 0;
  5507. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  5508. if (collection_skill == "Collecting")
  5509. skill = ((Player*)player)->GetSkillByName("Gathering");
  5510. else
  5511. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  5512. if (!skill) {
  5513. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  5514. return 0;
  5515. }
  5516. vector<GroundSpawnEntry*>::iterator itr;
  5517. GroundSpawnEntry* entry = 0;
  5518. bool can_harvest = false;
  5519. sint32 min_skill = -1;
  5520. // first, iterate through groundspawn_entries, discard tables player cannot use
  5521. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  5522. {
  5523. entry = *itr;
  5524. if (min_skill == -1 || entry->min_skill_level < min_skill)
  5525. min_skill = entry->min_skill_level;
  5526. // if player lacks skill, skip table
  5527. if (entry->min_skill_level > skill->current_val)
  5528. continue;
  5529. // if bonus, but player lacks level, skip table
  5530. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  5531. continue;
  5532. can_harvest = true;
  5533. break;
  5534. }
  5535. lua_interface->SetBooleanValue(state, can_harvest);
  5536. // If false, send the message to the client
  5537. if (!can_harvest) {
  5538. Client* client = player->GetZone()->GetClientBySpawn(player);
  5539. if (client) {
  5540. string msg = "You do not have enough skill to ";
  5541. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  5542. msg.append("gather");
  5543. else if (collection_skill == "Mining")
  5544. msg.append("mine");
  5545. else if (collection_skill == "Trapping")
  5546. msg.append("trap");
  5547. else if (collection_skill == "Foresting")
  5548. msg.append("forest");
  5549. else if (collection_skill == "Fishing")
  5550. msg.append("catch");
  5551. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  5552. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  5553. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  5554. }
  5555. }
  5556. return 1;
  5557. }
  5558. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  5559. if (!lua_interface)
  5560. return 0;
  5561. Spawn* player = lua_interface->GetSpawn(state);
  5562. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  5563. if (!player) {
  5564. lua_interface->LogError("LUA HasRecipeBook command error, Spawn is not valid");
  5565. return 0;
  5566. }
  5567. if (!player->IsPlayer()) {
  5568. lua_interface->LogError("LUA HasRecipeBook command error, Spawn is not a player");
  5569. return 0;
  5570. }
  5571. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  5572. lua_interface->SetBooleanValue(state, ret);
  5573. return 1;
  5574. }
  5575. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  5576. // Check to see if we have a valid lua_interface
  5577. if (!lua_interface)
  5578. return 0;
  5579. // Get the spawn that is getting the pet
  5580. Spawn* spawn = lua_interface->GetSpawn(state);
  5581. Spawn* target = lua_interface->GetSpawn(state, 2);
  5582. // Get the DB ID of the pet
  5583. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  5584. float x = lua_interface->GetFloatValue(state, 4);
  5585. float y = lua_interface->GetFloatValue(state, 5);
  5586. float z = lua_interface->GetFloatValue(state, 6);
  5587. // Get the spell that this command was called from
  5588. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5589. // Check to make sure the spawn pointer is valid
  5590. if (!spawn) {
  5591. lua_interface->LogError("LUA SummonDumbFirePet command error: Spawn is not valid");
  5592. return 0;
  5593. }
  5594. // Check to make sure the spawn is an entity
  5595. if (!spawn->IsEntity()) {
  5596. lua_interface->LogError("LUA SummonDumbFirePet command error: Spawn is not an entity");
  5597. return 0;
  5598. }
  5599. if (!target) {
  5600. lua_interface->LogError("LUA SummonDumbFirePet command error: target is not valid");
  5601. return 0;
  5602. }
  5603. if (!target->IsEntity()) {
  5604. lua_interface->LogError("LUA SummonDumbFirePet command error: target is not an entity");
  5605. return 0;
  5606. }
  5607. // Check to see if the DB ID for the pet is set
  5608. if (pet_id == 0) {
  5609. lua_interface->LogError("LUA SummonDumbFirePet command error: pet_id can not be set to 0");
  5610. return 0;
  5611. }
  5612. // Check to see if the pointer to the spell is valid
  5613. if (!luaspell) {
  5614. lua_interface->LogError("LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts");
  5615. return 0;
  5616. }
  5617. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5618. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5619. if (!pet) {
  5620. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  5621. return 0;
  5622. }
  5623. // Check to make sure the pet is an npc
  5624. if (!pet->IsNPC()) {
  5625. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  5626. return 0;
  5627. }
  5628. if (x == 0)
  5629. x = spawn->GetX();
  5630. if (y == 0)
  5631. y = spawn->GetY();
  5632. if (z == 0)
  5633. z = spawn->GetZ();
  5634. // Spawn the pet at the same location as the owner
  5635. pet->SetX(x);
  5636. pet->SetY(y);
  5637. pet->SetZ(z);
  5638. pet->SetLocation(spawn->GetLocation());
  5639. pet->SetHeading(spawn->GetHeading());
  5640. spawn->GetZone()->AddSpawn(pet);
  5641. /*
  5642. const char* spawn_script = world.GetSpawnScript(pet_id);
  5643. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5644. spawn->SetSpawnScript(string(spawn_script));
  5645. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5646. }*/
  5647. // Get a random pet name
  5648. string random_pet_name;
  5649. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5650. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5651. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5652. // Set the pets name
  5653. pet->SetName(random_pet_name.c_str());
  5654. // Set the level of the pet to the owners level
  5655. pet->SetLevel(spawn->GetLevel());
  5656. // Set the faction of the pet to the same faction as the owner
  5657. pet->SetFactionID(spawn->GetFactionID());
  5658. // Set the spawn as a pet
  5659. pet->SetPet(true);
  5660. // Give a pointer of the owner to the pet
  5661. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5662. // Set the pet type
  5663. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  5664. // Set the spell id used to create this pet
  5665. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5666. // Set the spell tier used to create this pet
  5667. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5668. // Set the pets spawn type to 6
  5669. pet->SetSpawnType(6);
  5670. // Set the pets brain
  5671. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  5672. // Check to see if the pet has a subtitle
  5673. if (strlen(pet->GetSubTitle()) > 0) {
  5674. // Add the players name to the front of the sub title
  5675. string pet_subtitle;
  5676. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5677. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5678. // Set the pets subtitle to the new one
  5679. pet->SetSubTitle(pet_subtitle.c_str());
  5680. }
  5681. // Set the pet as the return value for this function
  5682. lua_interface->SetSpawnValue(state, pet);
  5683. return 1;
  5684. }
  5685. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  5686. if (!lua_interface)
  5687. return 0;
  5688. Spawn* spawn = lua_interface->GetSpawn(state);
  5689. Spawn* player = lua_interface->GetSpawn(state, 2);
  5690. float max_distance = lua_interface->GetFloatValue(state, 3);
  5691. string type = lua_interface->GetStringValue(state, 4);
  5692. if (!spawn || (spawn && spawn->IsPlayer())) {
  5693. lua_interface->LogError("LUA SpawnMove command error: first param spawn is not valid or is player");
  5694. return 0;
  5695. }
  5696. if (!player || (player && !player->IsPlayer())) {
  5697. lua_interface->LogError("LUA SpawnMove command error: second param is not player");
  5698. return 0;
  5699. }
  5700. Client* client = 0;
  5701. if (player->GetZone())
  5702. client = player->GetZone()->GetClientBySpawn(player);
  5703. if (!client) {
  5704. lua_interface->LogError("LUA SpawnMove command error: could not find client");
  5705. return 0;
  5706. }
  5707. //Set max_distance to default if not set or not proper value
  5708. if (max_distance <= 0)
  5709. max_distance = 500;
  5710. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  5711. if (packet) {
  5712. float unknown2_3 = 0;
  5713. int8 placement_mode = 0;
  5714. if (type == "wall") {
  5715. placement_mode = 2;
  5716. unknown2_3 = 150;
  5717. }
  5718. else if (type == "ceiling")
  5719. placement_mode = 1;
  5720. packet->setDataByName("placement_mode", placement_mode);
  5721. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  5722. packet->setDataByName("model_type", spawn->GetModelType());
  5723. packet->setDataByName("unknown", 1); //size
  5724. packet->setDataByName("unknown2", 1); //size 2
  5725. packet->setDataByName("unknown2", .5, 1); //size 3
  5726. packet->setDataByName("unknown2", 3, 2);
  5727. packet->setDataByName("unknown2", unknown2_3, 3);
  5728. packet->setDataByName("max_distance", max_distance);
  5729. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  5730. client->QueuePacket(packet->serialize());
  5731. safe_delete(packet);
  5732. }
  5733. return 0;
  5734. }
  5735. int EQ2Emu_lua_GetItemType(lua_State* state) {
  5736. if (!lua_interface)
  5737. return 0;
  5738. Item* item = lua_interface->GetItem(state);
  5739. if (!item) {
  5740. lua_interface->LogError("LUA GetItemType command error: item pointer is not valid");
  5741. return 0;
  5742. }
  5743. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  5744. return 1;
  5745. }
  5746. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  5747. if (!lua_interface)
  5748. return 0;
  5749. Spawn* spawn = lua_interface->GetSpawn(state);
  5750. if (!spawn) {
  5751. lua_interface->LogError("LUA AddTransportSpawn command error: spawn is not valid");
  5752. return 0;
  5753. }
  5754. if (spawn->GetZone())
  5755. spawn->GetZone()->AddTransportSpawn(spawn);
  5756. return 0;
  5757. }
  5758. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  5759. if (!lua_interface)
  5760. return 0;
  5761. Skill* skill = lua_interface->GetSkill(state);
  5762. if (!skill) {
  5763. lua_interface->LogError("LUA GetSkillValue command error: skill is not valid");
  5764. return 0;
  5765. }
  5766. lua_interface->SetInt32Value(state, skill->current_val);
  5767. return 1;
  5768. }
  5769. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  5770. if (!lua_interface)
  5771. return 0;
  5772. Skill* skill = lua_interface->GetSkill(state);
  5773. if (!skill) {
  5774. lua_interface->LogError("LUA GetSkillMaxValue command error: skill is not valid");
  5775. return 0;
  5776. }
  5777. lua_interface->SetInt32Value(state, skill->max_val);
  5778. return 1;
  5779. }
  5780. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  5781. if (!lua_interface)
  5782. return 0;
  5783. Skill* skill = lua_interface->GetSkill(state);
  5784. if (!skill) {
  5785. lua_interface->LogError("LUA GetSkillName command error: skill is not valid");
  5786. return 0;
  5787. }
  5788. lua_interface->SetStringValue(state, skill->name.data.c_str());
  5789. return 1;
  5790. }
  5791. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  5792. if (!lua_interface)
  5793. return 0;
  5794. Skill* skill = lua_interface->GetSkill(state);
  5795. int16 value = lua_interface->GetInt16Value(state, 2);
  5796. if (!skill) {
  5797. lua_interface->LogError("LUA SetSkillMaxValue command error: skill is not valid");
  5798. return 0;
  5799. }
  5800. skill->max_val = value;
  5801. if (skill->max_val < skill->current_val)
  5802. skill->current_val = skill->max_val;
  5803. return 0;
  5804. }
  5805. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  5806. if (!lua_interface)
  5807. return 0;
  5808. Skill* skill = lua_interface->GetSkill(state);
  5809. int16 value = lua_interface->GetInt16Value(state, 2);
  5810. if (!skill) {
  5811. lua_interface->LogError("LUA SetSkillValue command error: skill is not valid");
  5812. return 0;
  5813. }
  5814. if (value > skill->max_val)
  5815. skill->current_val = skill->max_val;
  5816. else
  5817. skill->current_val = value;
  5818. return 0;
  5819. }
  5820. int EQ2Emu_lua_GetSkill(lua_State* state) {
  5821. if (!lua_interface)
  5822. return 0;
  5823. Spawn* spawn = lua_interface->GetSpawn(state);
  5824. string name = lua_interface->GetStringValue(state, 2);
  5825. if (!spawn) {
  5826. lua_interface->LogError("LUA GetSkill command error: spawn is not valid");
  5827. return 0;
  5828. }
  5829. if (!spawn->IsEntity()) {
  5830. lua_interface->LogError("LUA GetSkill command error: spawn is not a valid entity");
  5831. return 0;
  5832. }
  5833. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  5834. if (skill) {
  5835. lua_interface->SetSkillValue(state, skill);
  5836. return 1;
  5837. }
  5838. return 0;
  5839. }
  5840. int EQ2Emu_lua_AddProc(lua_State* state) {
  5841. if (!lua_interface)
  5842. return 0;
  5843. Spawn* spawn = lua_interface->GetSpawn(state);
  5844. int8 type = lua_interface->GetInt8Value(state, 2);
  5845. float chance = lua_interface->GetFloatValue(state, 3);
  5846. Item* item = lua_interface->GetItem(state, 4);
  5847. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  5848. LuaSpell* spell = 0;
  5849. if (!spawn && (!spell || !use_all_spelltargets)) {
  5850. lua_interface->LogError("LUA AddProc command error: spawn is not valid");
  5851. return 0;
  5852. }
  5853. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  5854. lua_interface->LogError("LUA AddProc command error: spawn is not a valid entity");
  5855. return 0;
  5856. }
  5857. if (!item)
  5858. spell = lua_interface->GetCurrentSpell(state);
  5859. if (!item && !spell) {
  5860. lua_interface->LogError("LUA AddProc command error: can only use with an item provided or inside a spell script");
  5861. return 0;
  5862. }
  5863. if (spell && use_all_spelltargets) {
  5864. Spawn* target;
  5865. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5866. for (int8 i = 0; i < spell->targets.size(); i++) {
  5867. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5868. if (!target || !target->IsEntity())
  5869. continue;
  5870. ((Entity*)target)->AddProc(type, chance, item, spell);
  5871. }
  5872. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5873. }
  5874. else
  5875. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  5876. return 0;
  5877. }
  5878. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  5879. if (!lua_interface)
  5880. return 0;
  5881. Spawn* spawn = lua_interface->GetSpawn(state);
  5882. Item* item = lua_interface->GetItem(state, 2);
  5883. LuaSpell* spell = 0;
  5884. if (!spawn) {
  5885. lua_interface->LogError("LUA RemoveProc command error: spawn is not valid");
  5886. return 0;
  5887. }
  5888. if (!spawn->IsEntity()) {
  5889. lua_interface->LogError("LUA RemoveProc command error: spawn is not a valid entity");
  5890. return 0;
  5891. }
  5892. if (!item)
  5893. spell = lua_interface->GetCurrentSpell(state);
  5894. if (!item && !spell) {
  5895. lua_interface->LogError("LUA RemoveProc command error: can only use with an item provided or inside a spell script");
  5896. return 0;
  5897. }
  5898. if (spell) {
  5899. Spawn* target;
  5900. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5901. for (int8 i = 0; i < spell->targets.size(); i++) {
  5902. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5903. if (!target || !target->IsEntity())
  5904. continue;
  5905. ((Entity*)target)->RemoveProc(item, spell);
  5906. }
  5907. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5908. spell->caster->RemoveProc(item, spell);
  5909. }
  5910. else
  5911. ((Entity*)spawn)->RemoveProc(item, spell);
  5912. return 0;
  5913. }
  5914. int EQ2Emu_lua_Knockback(lua_State* state) {
  5915. if (!lua_interface)
  5916. return 0;
  5917. Spawn* target_spawn = lua_interface->GetSpawn(state);
  5918. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5919. int32 duration = lua_interface->GetInt32Value(state, 3);
  5920. float vertical = lua_interface->GetFloatValue(state, 4);
  5921. float horizontal = lua_interface->GetFloatValue(state, 5);
  5922. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  5923. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5924. if (!target_spawn) {
  5925. lua_interface->LogError("LUA Knockback command error: target_spawn is not valid");
  5926. return 0;
  5927. }
  5928. if (!spawn) {
  5929. lua_interface->LogError("LUA Knockback command error: spawn is not valid");
  5930. return 0;
  5931. }
  5932. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  5933. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5934. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  5935. if (packet) {
  5936. packet->setDataByName("target_x", target_spawn->GetX());
  5937. packet->setDataByName("target_y", target_spawn->GetY());
  5938. packet->setDataByName("target_z", target_spawn->GetZ());
  5939. packet->setDataByName("vertical_movement", vertical);
  5940. packet->setDataByName("horizontal_movement", horizontal);
  5941. if (use_heading)
  5942. packet->setDataByName("use_player_heading", 1);
  5943. client->QueuePacket(packet->serialize());
  5944. }
  5945. safe_delete(packet);
  5946. }
  5947. return 0;
  5948. }
  5949. int EQ2Emu_lua_IsEpic(lua_State* state) {
  5950. if (!lua_interface)
  5951. return 0;
  5952. Spawn* spawn = lua_interface->GetSpawn(state);
  5953. if (!spawn) {
  5954. lua_interface->LogError("LUA IsEpic command error: spawn is not valid");
  5955. return 0;
  5956. }
  5957. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  5958. return 1;
  5959. }
  5960. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  5961. if (!lua_interface)
  5962. return 0;
  5963. Spawn* caster = lua_interface->GetSpawn(state);
  5964. Spawn* target = lua_interface->GetSpawn(state, 2);
  5965. string name = lua_interface->GetStringValue(state, 3);
  5966. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  5967. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  5968. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  5969. string success_msg = lua_interface->GetStringValue(state, 7);
  5970. string effect_msg = lua_interface->GetStringValue(state, 8);
  5971. if (!caster) {
  5972. lua_interface->LogError("LUA ProcDamage command error: caster is not a valid spawn");
  5973. return 0;
  5974. }
  5975. if (!caster->IsEntity()) {
  5976. lua_interface->LogError("LUA ProcDamage command error: caster is not an entity");
  5977. return 0;
  5978. }
  5979. if (!target) {
  5980. lua_interface->LogError("LUA ProcDamage command error: target is not a valid spawn");
  5981. return 0;
  5982. }
  5983. if (!target->IsEntity()) {
  5984. lua_interface->LogError("LUA ProcDamage command error: target is not an entity");
  5985. return 0;
  5986. }
  5987. if (name.length() == 0) {
  5988. lua_interface->LogError("LUA ProcDamage command error: name is empty");
  5989. return 0;
  5990. }
  5991. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  5992. return 0;
  5993. }
  5994. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  5995. if (!lua_interface)
  5996. return 0;
  5997. string name = lua_interface->GetStringValue(state);
  5998. if (name.length() == 0) {
  5999. lua_interface->LogError("LUA GetSkillIDByName command error: name param was not set");
  6000. return 0;
  6001. }
  6002. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6003. if (!skill) {
  6004. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6005. return 0;
  6006. }
  6007. lua_interface->SetInt32Value(state, skill->skill_id);
  6008. return 1;
  6009. }
  6010. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6011. if (!lua_interface)
  6012. return 0;
  6013. Spawn* spawn = lua_interface->GetSpawn(state);
  6014. if (!spawn) {
  6015. lua_interface->LogError("LUA IsHeroic command error: spawn is not valid");
  6016. return 0;
  6017. }
  6018. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6019. return 1;
  6020. }
  6021. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6022. if (!lua_interface)
  6023. return 0;
  6024. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6025. if (!luaspell) {
  6026. lua_interface->LogError("LUA LastSpellAttackHit command error: this must be called from a spellscript");
  6027. return 0;
  6028. }
  6029. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6030. return 1;
  6031. }
  6032. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6033. if (!lua_interface)
  6034. return 0;
  6035. Spawn* spawn = lua_interface->GetSpawn(state);
  6036. Spawn* target = lua_interface->GetSpawn(state, 2);
  6037. if (!spawn) {
  6038. lua_interface->LogError("LUA IsBehind command error: spawn is not valid");
  6039. return 0;
  6040. }
  6041. if (!spawn->IsEntity()) {
  6042. lua_interface->LogError("LUA IsBehind command error: spawn is not an entity");
  6043. return 0;
  6044. }
  6045. if (!target) {
  6046. lua_interface->LogError("LUA IsBehind command error: target is not valid");
  6047. return 0;
  6048. }
  6049. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6050. return 1;
  6051. }
  6052. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6053. if (!lua_interface)
  6054. return 0;
  6055. Spawn* spawn = lua_interface->GetSpawn(state);
  6056. Spawn* target = lua_interface->GetSpawn(state, 2);
  6057. if (!spawn) {
  6058. lua_interface->LogError("LUA IsFlanking command error: spawn is not valid");
  6059. return 0;
  6060. }
  6061. if (!spawn->IsEntity()) {
  6062. lua_interface->LogError("LUA IsFlanking command error: spawn is not an entity");
  6063. return 0;
  6064. }
  6065. if (!target) {
  6066. lua_interface->LogError("LUA IsFlanking command error: target is not valid");
  6067. return 0;
  6068. }
  6069. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6070. return 1;
  6071. }
  6072. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6073. if (!lua_interface)
  6074. return 0;
  6075. Item* item = lua_interface->GetItem(state);
  6076. if (!item) {
  6077. lua_interface->LogError("LUA GetItemCount command error: item not valid");
  6078. return 0;
  6079. }
  6080. lua_interface->SetInt32Value(state, item->details.count);
  6081. return 1;
  6082. }
  6083. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6084. if (!lua_interface)
  6085. return 0;
  6086. Item* item = lua_interface->GetItem(state);
  6087. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6088. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6089. if (!item) {
  6090. lua_interface->LogError("LUA SetItemCount command error: item not valid");
  6091. return 0;
  6092. }
  6093. if (!owner) {
  6094. lua_interface->LogError("LUA SetItemCount command error: spawn not valid");
  6095. return 0;
  6096. }
  6097. if (!owner->IsPlayer()) {
  6098. lua_interface->LogError("LUA SetItemCount command error: spawn is not a player");
  6099. return 0;
  6100. }
  6101. if (item->stack_count < new_count) {
  6102. lua_interface->LogError("LUA SetItemCount command error: new item count cannot be more than max stack count");
  6103. return 0;
  6104. }
  6105. if (new_count > 0) {
  6106. item->details.count = new_count;
  6107. item->save_needed = true;
  6108. }
  6109. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6110. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6111. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6112. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6113. else
  6114. {
  6115. lua_interface->LogError("LUA SetItemCount command error: could not remove item from player");
  6116. return 0;
  6117. }
  6118. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6119. if (!client)
  6120. return 0;
  6121. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6122. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6123. if (app)
  6124. client->QueuePacket(app);
  6125. return 0;
  6126. }
  6127. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6128. if (!lua_interface)
  6129. return 0;
  6130. int32 time = lua_interface->GetInt32Value(state);
  6131. string function = lua_interface->GetStringValue(state, 2);
  6132. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6133. Spawn* target = lua_interface->GetSpawn(state, 4);
  6134. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6135. if (time == 0) {
  6136. lua_interface->LogError("LUA AddSpellTimer command error: time must be set");
  6137. return 0;
  6138. }
  6139. if (function.length() == 0) {
  6140. lua_interface->LogError("LUA AddSpellTimer command error: function name must be set");
  6141. return 0;
  6142. }
  6143. if (!spell) {
  6144. lua_interface->LogError("LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script");
  6145. return 0;
  6146. }
  6147. SpellScriptTimer* timer = new SpellScriptTimer;
  6148. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6149. #ifdef WIN32
  6150. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6151. #else
  6152. bzero(timer, sizeof(SpellScriptTimer));
  6153. #endif*/
  6154. timer->caster = 0;
  6155. timer->deleteWhenDone = false;
  6156. timer->target = 0;
  6157. timer->time = Timer::GetCurrentTime2() + time;
  6158. timer->customFunction = function;
  6159. timer->spell = spell;
  6160. if (caster)
  6161. timer->caster = caster->GetID();
  6162. if (target)
  6163. timer->target = target->GetID();
  6164. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6165. return 0;
  6166. }
  6167. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6168. if (!lua_interface)
  6169. return 0;
  6170. float hp_perc = lua_interface->GetFloatValue(state);
  6171. float power_perc = lua_interface->GetFloatValue(state, 2);
  6172. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6173. Spawn* target = lua_interface->GetSpawn(state, 4);
  6174. string heal_name = lua_interface->GetStringValue(state, 5);
  6175. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6176. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6177. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6178. if (!spell) {
  6179. lua_interface->LogError("LUA command error: this function must be used in a spellscript");
  6180. return 0;
  6181. }
  6182. Entity* caster = spell->caster;
  6183. if (!caster) {
  6184. lua_interface->LogError("LUA command error: could not find caster");
  6185. return 0;
  6186. }
  6187. Client* client = 0;
  6188. PendingResurrection* rez = 0;
  6189. ZoneServer* zone = spell->caster->GetZone();
  6190. if (!target) {
  6191. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6192. if (spell->targets.size() > 0) {
  6193. vector<int32> spell_targets = spell->targets;
  6194. for (int8 i = 0; i < spell_targets.size(); i++) {
  6195. target = zone->GetSpawnByID(spell_targets.at(i));
  6196. if (!target)
  6197. continue;
  6198. if (!target->IsPlayer())
  6199. continue;
  6200. client = target->GetZone()->GetClientBySpawn(target);
  6201. if (!client)
  6202. continue;
  6203. rez = client->GetCurrentRez();
  6204. if (rez->active)
  6205. continue;
  6206. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6207. rez->active = true;
  6208. rez->caster = caster;
  6209. rez->expire_timer = new Timer;
  6210. int32 duration = spell->spell->GetSpellDuration();
  6211. rez->expire_timer->Start(duration * 100);
  6212. rez->hp_perc = hp_perc;
  6213. rez->mp_perc = power_perc;
  6214. rez->range = spell->spell->GetSpellData()->range;
  6215. rez->spell_name = spell->spell->GetName();
  6216. if (heal_name.length() > 0)
  6217. rez->heal_name = heal_name;
  6218. else
  6219. rez->heal_name = rez->spell_name;
  6220. rez->no_calcs = no_calcs;
  6221. rez->crit_mod = crit_mod;
  6222. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6223. if (send_window)
  6224. client->SendResurrectionWindow();
  6225. else {
  6226. target->GetZone()->ResurrectSpawn(target, client);
  6227. rez->should_delete = true;
  6228. }
  6229. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6230. }
  6231. }
  6232. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6233. }
  6234. else {
  6235. client = target->GetZone()->GetClientBySpawn(target);
  6236. if (!client)
  6237. return 0;
  6238. rez = client->GetCurrentRez();
  6239. if (rez->active)
  6240. return 0;
  6241. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6242. rez->active = true;
  6243. rez->caster = caster;
  6244. rez->expire_timer = new Timer;
  6245. int32 duration = spell->spell->GetSpellDuration();
  6246. rez->expire_timer->Start(duration * 100);
  6247. rez->hp_perc = hp_perc;
  6248. rez->mp_perc = power_perc;
  6249. rez->range = spell->spell->GetSpellData()->range;
  6250. rez->spell_name = spell->spell->GetName();
  6251. if (heal_name.length() > 0)
  6252. rez->heal_name = heal_name;
  6253. else
  6254. rez->heal_name = rez->spell_name;
  6255. rez->no_calcs = no_calcs;
  6256. rez->crit_mod = crit_mod;
  6257. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6258. if (send_window)
  6259. client->SendResurrectionWindow();
  6260. else {
  6261. target->GetZone()->ResurrectSpawn(target, client);
  6262. rez->should_delete = true;
  6263. }
  6264. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6265. }
  6266. return 0;
  6267. }
  6268. int EQ2Emu_lua_SetVision(lua_State* state) {
  6269. if (!lua_interface)
  6270. return 0;
  6271. Spawn* spawn = lua_interface->GetSpawn(state);
  6272. int8 vision = lua_interface->GetInt8Value(state, 2);
  6273. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6274. if (!spawn) {
  6275. lua_interface->LogError("LUA SetVision command error: spawn is not valid");
  6276. return 0;
  6277. }
  6278. if (!spawn->IsEntity()) {
  6279. lua_interface->LogError("LUA SetVision command error: spawn is not an entity");
  6280. return 0;
  6281. }
  6282. if (spell && spell->targets.size() > 0) {
  6283. ZoneServer* zone = spell->caster->GetZone();
  6284. for (int8 i = 0; i < spell->targets.size(); i++) {
  6285. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6286. if (target->IsEntity()) {
  6287. ((Entity*)target)->GetInfoStruct()->vision = vision;
  6288. if (target->IsPlayer())
  6289. ((Player*)target)->SetCharSheetChanged(true);
  6290. }
  6291. }
  6292. }
  6293. else {
  6294. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  6295. if (spawn->IsPlayer())
  6296. ((Player*)spawn)->SetCharSheetChanged(true);
  6297. }
  6298. return 0;
  6299. }
  6300. int EQ2Emu_lua_BlurVision(lua_State* state) {
  6301. if (!lua_interface)
  6302. return 0;
  6303. Spawn* spawn = lua_interface->GetSpawn(state);
  6304. float intensity = lua_interface->GetFloatValue(state, 2);
  6305. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6306. if (!spawn) {
  6307. lua_interface->LogError("LUA BlurVision command error: spawn is not valid");
  6308. return 0;
  6309. }
  6310. if (!spawn->IsEntity()) {
  6311. lua_interface->LogError("LUA BlurVision command error: spawn is not an entity");
  6312. return 0;
  6313. }
  6314. if (spell && spell->targets.size() > 0) {
  6315. ZoneServer* zone = spell->caster->GetZone();
  6316. for (int8 i = 0; i < spell->targets.size(); i++) {
  6317. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6318. if (target && target->IsEntity()) {
  6319. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  6320. if (target->IsPlayer())
  6321. ((Player*)target)->SetCharSheetChanged(true);
  6322. }
  6323. }
  6324. }
  6325. else {
  6326. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  6327. if (spawn->IsPlayer())
  6328. ((Player*)spawn)->SetCharSheetChanged(true);
  6329. }
  6330. return 0;
  6331. }
  6332. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  6333. if (!lua_interface)
  6334. return 0;
  6335. Spawn* spawn = lua_interface->GetSpawn(state);
  6336. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  6337. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6338. if (!spawn) {
  6339. lua_interface->LogError("LUA BreathUnderwater command error: spawn is not valid");
  6340. return 0;
  6341. }
  6342. if (!spawn->IsEntity()) {
  6343. lua_interface->LogError("LUA BreathUnderwater command error: spawn is not en entity");
  6344. return 0;
  6345. }
  6346. if (spell && spell->targets.size() > 0) {
  6347. ZoneServer* zone = spell->caster->GetZone();
  6348. for (int8 i = 0; i < spell->targets.size(); i++) {
  6349. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6350. if (target->IsEntity()) {
  6351. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6352. if (target->IsPlayer())
  6353. ((Player*)target)->SetCharSheetChanged(true);
  6354. }
  6355. }
  6356. }
  6357. else {
  6358. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6359. if (spawn->IsPlayer())
  6360. ((Player*)spawn)->SetCharSheetChanged(true);
  6361. }
  6362. return 0;
  6363. }
  6364. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  6365. if (!lua_interface)
  6366. return 0;
  6367. Item* item = lua_interface->GetItem(state);
  6368. int8 type = lua_interface->GetInt32Value(state, 2);
  6369. if (!item) {
  6370. lua_interface->LogError("LUA GetItemSkillReq command error: item not valid");
  6371. return 0;
  6372. }
  6373. if (type == 1)
  6374. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  6375. else if (type == 2)
  6376. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  6377. return 1;
  6378. }
  6379. int EQ2Emu_lua_SetSpeeedMultiplier(lua_State* state) {
  6380. if (!lua_interface)
  6381. return 0;
  6382. Spawn* target = lua_interface->GetSpawn(state);
  6383. float val = lua_interface->GetFloatValue(state, 2);
  6384. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6385. // Added from Gangrenous post
  6386. if (spell && spell->resisted)
  6387. return 0;
  6388. if (spell && spell->spell && spell->targets.size() > 0) {
  6389. ZoneServer* zone = spell->caster->GetZone();
  6390. for (int32 i = 0; i != spell->targets.size(); i++) {
  6391. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  6392. if (spawn && spawn->IsEntity()) {
  6393. ((Entity*)spawn)->SetSpeedMultiplier(val);
  6394. if (spawn->IsPlayer())
  6395. ((Player*)spawn)->SetCharSheetChanged(true);
  6396. }
  6397. }
  6398. }
  6399. else {
  6400. if (target && target->IsEntity()) {
  6401. ((Entity*)target)->SetSpeedMultiplier(val);
  6402. if (target->IsPlayer())
  6403. ((Player*)target)->SetCharSheetChanged(true);
  6404. }
  6405. }
  6406. return 0;
  6407. }
  6408. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  6409. if (!lua_interface)
  6410. return 0;
  6411. Spawn* spawn = lua_interface->GetSpawn(state);
  6412. int16 model = lua_interface->GetInt16Value(state, 2);
  6413. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6414. if (spell && spell->spell && spell->targets.size() > 0) {
  6415. ZoneServer* zone = spell->caster->GetZone();
  6416. for (int32 i = 0; i < spell->targets.size(); i++) {
  6417. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6418. if (target)
  6419. target->SetIllusionModel(model);
  6420. }
  6421. }
  6422. else {
  6423. if (!spawn) {
  6424. lua_interface->LogError("LUA SetIllusion command error: spawn is not valid");
  6425. return 0;
  6426. }
  6427. spawn->SetIllusionModel(model);
  6428. }
  6429. return 0;
  6430. }
  6431. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  6432. if (!lua_interface)
  6433. return 0;
  6434. Spawn* spawn = lua_interface->GetSpawn(state);
  6435. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6436. if (spell && spell->spell && spell->targets.size() > 0) {
  6437. ZoneServer* zone = spell->caster->GetZone();
  6438. for (int32 i = 0; i < spell->targets.size(); i++) {
  6439. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6440. if (target)
  6441. target->SetIllusionModel(0);
  6442. }
  6443. }
  6444. else {
  6445. if (!spawn) {
  6446. lua_interface->LogError("LUA ResetIllusion command error: spawn is not valid");
  6447. return 0;
  6448. }
  6449. spawn->SetIllusionModel(0);
  6450. }
  6451. return 0;
  6452. }
  6453. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  6454. if (!lua_interface)
  6455. return 0;
  6456. Spawn* caster = lua_interface->GetSpawn(state);
  6457. Spawn* target = lua_interface->GetSpawn(state, 2);
  6458. float chance = lua_interface->GetFloatValue(state, 3);
  6459. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6460. if (!caster) {
  6461. lua_interface->LogError("LUA AddThreatTransfer command error: caster is not a valid spawn");
  6462. return 0;
  6463. }
  6464. if (!caster->IsEntity()) {
  6465. lua_interface->LogError("LUA AddThreatTransfer command error: caster is not an entity");
  6466. return 0;
  6467. }
  6468. if (!target) {
  6469. lua_interface->LogError("LUA AddThreatTransfer command error: target is not a valid spawn");
  6470. return 0;
  6471. }
  6472. if (!target->IsEntity()) {
  6473. lua_interface->LogError("LUA AddThreatTransfer command error: target is not an entity");
  6474. return 0;
  6475. }
  6476. if (chance <= 0) {
  6477. lua_interface->LogError("LUA AddThreatTransfer command error: chance must be greater then 0%");
  6478. return 0;
  6479. }
  6480. if (!spell) {
  6481. lua_interface->LogError("LUA AddThreatTransfer command error: can only be used in a spell script");
  6482. return 0;
  6483. }
  6484. if (((Entity*)caster)->GetThreatTransfer()) {
  6485. return 0;
  6486. }
  6487. ThreatTransfer* transfer = new ThreatTransfer;
  6488. transfer->Target = target->GetID();
  6489. transfer->Amount = chance;
  6490. transfer->Spell = spell;
  6491. ((Entity*)caster)->SetThreatTransfer(transfer);
  6492. return 0;
  6493. }
  6494. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  6495. if (!lua_interface)
  6496. return 0;
  6497. Spawn* spawn = lua_interface->GetSpawn(state);
  6498. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6499. if (!spawn) {
  6500. lua_interface->LogError("LUA RemoveThreatTransfer command error: spawn is not valid");
  6501. return 0;
  6502. }
  6503. if (!spell) {
  6504. lua_interface->LogError("LUA RemoveThreatTransfer command error: can only be used in a spell script");
  6505. return 0;
  6506. }
  6507. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  6508. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  6509. safe_delete(transfer);
  6510. ((Entity*)spawn)->SetThreatTransfer(0);
  6511. }
  6512. return 0;
  6513. }
  6514. int EQ2Emu_lua_CureByType(lua_State* state) {
  6515. if (!lua_interface)
  6516. return 0;
  6517. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6518. if (!spell) {
  6519. lua_interface->LogError("LUA CureByType command error: can only be used in a spell script");
  6520. return 0;
  6521. }
  6522. int8 cure_count = lua_interface->GetInt8Value(state);
  6523. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6524. string cure_name = lua_interface->GetStringValue(state, 3);
  6525. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6526. Spawn* target = lua_interface->GetSpawn(state, 5);
  6527. if (target) {
  6528. if (!target->IsEntity()) {
  6529. lua_interface->LogError("LUA CureByType command error: spawn override must be entity if used");
  6530. return 0;
  6531. }
  6532. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6533. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6534. }
  6535. else {
  6536. ZoneServer* zone = spell->caster->GetZone();
  6537. vector<int32> targets = spell->targets;
  6538. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6539. for (int8 i = 0; i < targets.size(); i++) {
  6540. target = zone->GetSpawnByID(targets.at(i));
  6541. if (!target || !target->IsEntity())
  6542. continue;
  6543. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6544. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6545. }
  6546. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6547. }
  6548. return 0;
  6549. }
  6550. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  6551. if (!lua_interface)
  6552. return 0;
  6553. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6554. if (!spell) {
  6555. lua_interface->LogError("LUA CureByControlEffect command error: can only be used in a spell script");
  6556. return 0;
  6557. }
  6558. int8 cure_count = lua_interface->GetInt8Value(state);
  6559. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6560. string cure_name = lua_interface->GetStringValue(state, 3);
  6561. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6562. Spawn* target = lua_interface->GetSpawn(state, 5);
  6563. if (target) {
  6564. if (!target->IsEntity()) {
  6565. lua_interface->LogError("LUA CureByControlEffect command error: spawn override must be entity if used");
  6566. return 0;
  6567. }
  6568. if (((Entity*)target)->GetDetCount() > 0)
  6569. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6570. }
  6571. else {
  6572. ZoneServer* zone = spell->caster->GetZone();
  6573. vector<int32> targets = spell->targets;
  6574. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6575. for (int8 i = 0; i < targets.size(); i++) {
  6576. target = zone->GetSpawnByID(targets.at(i));
  6577. if (!target || !target->IsEntity())
  6578. continue;
  6579. if (((Entity*)target)->GetDetCount() > 0)
  6580. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6581. }
  6582. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6583. }
  6584. return 0;
  6585. }
  6586. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  6587. if (!lua_interface)
  6588. return 0;
  6589. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6590. if (!spell) {
  6591. lua_interface->LogError("LUA CancelSpell command error: can only be use in a spell script");
  6592. return 0;
  6593. }
  6594. if (!spell->caster) {
  6595. lua_interface->LogError("LUA CancelSpell command error: unable to get the caster of the spell");
  6596. return 0;
  6597. }
  6598. if (!spell->caster->GetZone()) {
  6599. lua_interface->LogError("LUA CancelSpell command error: unable to get the zone of the caster");
  6600. return 0;
  6601. }
  6602. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6603. return 0;
  6604. }
  6605. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  6606. if (!lua_interface)
  6607. return 0;
  6608. Spawn* spawn = lua_interface->GetSpawn(state);
  6609. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6610. if (!spell) {
  6611. lua_interface->LogError("LUA RemoveStealth command error: must be used from spell script");
  6612. return 0;
  6613. }
  6614. if (spawn && spawn->IsEntity())
  6615. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6616. else {
  6617. ZoneServer* zone = spell->caster->GetZone();
  6618. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6619. for (int32 i = 0; i < spell->targets.size(); i++) {
  6620. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6621. if (!spawn || !spawn->IsEntity())
  6622. continue;
  6623. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6624. }
  6625. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6626. }
  6627. return 0;
  6628. }
  6629. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  6630. if (!lua_interface)
  6631. return 0;
  6632. Spawn* spawn = lua_interface->GetSpawn(state);
  6633. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6634. if (!spell) {
  6635. lua_interface->LogError("LUA RemoveInvis command error: must be used from spell script");
  6636. return 0;
  6637. }
  6638. if (spawn && spawn->IsEntity())
  6639. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6640. else {
  6641. ZoneServer* zone = spell->caster->GetZone();
  6642. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6643. for (int32 i = 0; i < spell->targets.size(); i++) {
  6644. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6645. if (!spawn || !spawn->IsEntity())
  6646. continue;
  6647. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6648. }
  6649. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6650. }
  6651. return 0;
  6652. }
  6653. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  6654. if (!lua_interface)
  6655. return 0;
  6656. Spawn* caster = lua_interface->GetSpawn(state);
  6657. int8 class_id = lua_interface->GetInt8Value(state, 2);
  6658. if (!caster) {
  6659. lua_interface->LogError("LUA StartHeroicOpportunity command error: caster is not valid");
  6660. return 0;
  6661. }
  6662. if (!caster->IsPlayer()) {
  6663. lua_interface->LogError("LUA StartHeroicOpportunity command error: caster must be a player");
  6664. return 0;
  6665. }
  6666. Spawn* target = caster->GetTarget();
  6667. if (!target) {
  6668. lua_interface->LogError("LUA StartHeroicOpportunity command error: target is not valid");
  6669. return 0;
  6670. }
  6671. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  6672. if (!client) {
  6673. lua_interface->LogError("LUA StartHeroicOpportunity command error: unable to get a client for the given caster");
  6674. return 0;
  6675. }
  6676. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  6677. if (ho) {
  6678. ho->SetTarget(target->GetID());
  6679. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  6680. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  6681. if (((Entity*)caster)->GetGroupMemberInfo()) {
  6682. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6683. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  6684. deque<GroupMemberInfo*>::iterator itr;
  6685. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  6686. for (itr = members->begin(); itr != members->end(); itr++) {
  6687. if ((*itr)->client)
  6688. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  6689. }
  6690. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  6691. }
  6692. else
  6693. safe_delete(ho);
  6694. }
  6695. else {
  6696. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6697. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  6698. }
  6699. else
  6700. safe_delete(ho);
  6701. }
  6702. }
  6703. return 0;
  6704. }
  6705. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  6706. if (!lua_interface)
  6707. return 0;
  6708. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6709. if (!spell) {
  6710. lua_interface->LogError("LUA SetSpellTriggerCount command error: you must use this function in a spellscript!");
  6711. return 0;
  6712. }
  6713. int16 triggerCount = lua_interface->GetInt16Value(state);
  6714. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  6715. if (!triggerCount) {
  6716. lua_interface->LogError("LUA SetSpellTriggerCount command error: used trigger value equals zero!");
  6717. return 0;
  6718. }
  6719. spell->num_triggers = triggerCount;
  6720. spell->had_triggers = true;
  6721. spell->cancel_after_all_triggers = cancel_after_triggers;
  6722. return 0;
  6723. }
  6724. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  6725. if (!lua_interface)
  6726. return 0;
  6727. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6728. if (!spell) {
  6729. lua_interface->LogError("LUA GetSpellTriggerCount command error: you must use this function in a spellscript!");
  6730. return 0;
  6731. }
  6732. lua_interface->SetInt32Value(state, spell->num_triggers);
  6733. return 1;
  6734. }
  6735. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  6736. if (!lua_interface)
  6737. return 0;
  6738. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6739. if (!spell) {
  6740. lua_interface->LogError("LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!");
  6741. return 0;
  6742. }
  6743. int16 remove_count = lua_interface->GetInt16Value(state);
  6744. if (!remove_count)
  6745. remove_count = 1;
  6746. if (remove_count >= spell->num_triggers) {
  6747. spell->num_triggers = 0;
  6748. if (spell->cancel_after_all_triggers)
  6749. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6750. }
  6751. else {
  6752. spell->num_triggers -= remove_count;
  6753. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  6754. }
  6755. return 0;
  6756. }
  6757. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  6758. if (!lua_interface)
  6759. return 0;
  6760. Spawn* spawn = lua_interface->GetSpawn(state);
  6761. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  6762. if (!spawn) {
  6763. lua_interface->LogError("LUA CopySpawnAppearance command error: the first spawn used was not valid!");
  6764. return 0;
  6765. }
  6766. if (!copy_spawn) {
  6767. lua_interface->LogError("LUA CopySpawnAppearance command error: the second spawn used was not valid!");
  6768. return 0;
  6769. }
  6770. spawn->CopySpawnAppearance(copy_spawn);
  6771. return 0;
  6772. }
  6773. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  6774. if (!lua_interface)
  6775. return 0;
  6776. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6777. int8 type = lua_interface->GetInt8Value(state);
  6778. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6779. if (!spell) {
  6780. lua_interface->LogError("LUA AddImmunitySpell command error: This must be used in a spellscript");
  6781. return 0;
  6782. }
  6783. if (spawn) {
  6784. if (!spawn->IsEntity()) {
  6785. lua_interface->LogError("LUA AddImmunitySpell command error: The spawn provided is not an entity");
  6786. return 0;
  6787. }
  6788. Entity* entity = ((Entity*)spawn);
  6789. switch (type) {
  6790. case IMMUNITY_TYPE_AOE:
  6791. entity->AddAOEImmunity(spell);
  6792. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6793. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6794. break;
  6795. case IMMUNITY_TYPE_STUN:
  6796. entity->AddStunImmunity(spell);
  6797. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6798. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6799. break;
  6800. case IMMUNITY_TYPE_ROOT:
  6801. entity->AddRootImmunity(spell);
  6802. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6803. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6804. break;
  6805. case IMMUNITY_TYPE_DAZE:
  6806. entity->AddDazeImmunity(spell);
  6807. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6808. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6809. break;
  6810. case IMMUNITY_TYPE_FEAR:
  6811. entity->AddFearImmunity(spell);
  6812. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6813. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6814. break;
  6815. case IMMUNITY_TYPE_MEZ:
  6816. entity->AddMezImmunity(spell);
  6817. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6818. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6819. break;
  6820. case IMMUNITY_TYPE_STIFLE:
  6821. entity->AddStifleImmunity(spell);
  6822. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6823. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6824. break;
  6825. default:
  6826. lua_interface->LogError("LUA AddImmunitySpell command error: invalid immunity type");
  6827. }
  6828. }
  6829. else {
  6830. bool should_break = false;
  6831. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6832. for (int8 i = 0; i < spell->targets.size(); i++) {
  6833. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6834. if (!spawn || !spawn->IsEntity())
  6835. continue;
  6836. Entity* entity = ((Entity*)spawn);
  6837. switch (type) {
  6838. case IMMUNITY_TYPE_AOE:
  6839. entity->AddAOEImmunity(spell);
  6840. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6841. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6842. break;
  6843. case IMMUNITY_TYPE_STUN:
  6844. entity->AddStunImmunity(spell);
  6845. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6846. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6847. break;
  6848. case IMMUNITY_TYPE_ROOT:
  6849. entity->AddRootImmunity(spell);
  6850. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6851. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6852. break;
  6853. case IMMUNITY_TYPE_DAZE:
  6854. entity->AddDazeImmunity(spell);
  6855. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6856. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6857. break;
  6858. case IMMUNITY_TYPE_FEAR:
  6859. entity->AddFearImmunity(spell);
  6860. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6861. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6862. break;
  6863. case IMMUNITY_TYPE_MEZ:
  6864. entity->AddMezImmunity(spell);
  6865. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6866. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6867. break;
  6868. case IMMUNITY_TYPE_STIFLE:
  6869. entity->AddStifleImmunity(spell);
  6870. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6871. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6872. break;
  6873. default:
  6874. lua_interface->LogError("LUA AddImmunitySpell command error: invalid immunity type");
  6875. should_break = true;
  6876. }
  6877. if (should_break)
  6878. break;
  6879. }
  6880. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6881. }
  6882. return 0;
  6883. }
  6884. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  6885. if (!lua_interface)
  6886. return 0;
  6887. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6888. int8 type = lua_interface->GetInt8Value(state);
  6889. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6890. if (!spell) {
  6891. lua_interface->LogError("LUA RemoveImmunitySpell command error: This must be used in a spellscript");
  6892. return 0;
  6893. }
  6894. if (spawn) {
  6895. if (!spawn->IsEntity()) {
  6896. lua_interface->LogError("LUA RemoveImmunitySpell command error: The spawn provided is not an entity");
  6897. return 0;
  6898. }
  6899. Entity* entity = ((Entity*)spawn);
  6900. switch (type) {
  6901. case IMMUNITY_TYPE_AOE:
  6902. entity->RemoveAOEImmunity(spell);
  6903. break;
  6904. case IMMUNITY_TYPE_STUN:
  6905. entity->RemoveStunImmunity(spell);
  6906. break;
  6907. case IMMUNITY_TYPE_ROOT:
  6908. entity->RemoveRootImmunity(spell);
  6909. break;
  6910. case IMMUNITY_TYPE_DAZE:
  6911. entity->RemoveDazeImmunity(spell);
  6912. break;
  6913. case IMMUNITY_TYPE_FEAR:
  6914. entity->RemoveFearImmunity(spell);
  6915. break;
  6916. case IMMUNITY_TYPE_MEZ:
  6917. entity->RemoveMezImmunity(spell);
  6918. break;
  6919. case IMMUNITY_TYPE_STIFLE:
  6920. entity->RemoveStifleImmunity(spell);
  6921. break;
  6922. default:
  6923. lua_interface->LogError("LUA RemoveImmunitySpell command error: invalid immunity type");
  6924. }
  6925. }
  6926. else {
  6927. bool should_break = false;
  6928. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6929. for (int8 i = 0; i < spell->targets.size(); i++) {
  6930. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6931. if (!spawn || !spawn->IsEntity())
  6932. continue;
  6933. Entity* entity = ((Entity*)spawn);
  6934. switch (type) {
  6935. case IMMUNITY_TYPE_AOE:
  6936. entity->RemoveAOEImmunity(spell);
  6937. break;
  6938. case IMMUNITY_TYPE_STUN:
  6939. entity->RemoveStunImmunity(spell);
  6940. break;
  6941. case IMMUNITY_TYPE_ROOT:
  6942. entity->RemoveRootImmunity(spell);
  6943. break;
  6944. case IMMUNITY_TYPE_DAZE:
  6945. entity->RemoveDazeImmunity(spell);
  6946. break;
  6947. case IMMUNITY_TYPE_FEAR:
  6948. entity->RemoveFearImmunity(spell);
  6949. break;
  6950. case IMMUNITY_TYPE_MEZ:
  6951. entity->RemoveMezImmunity(spell);
  6952. break;
  6953. case IMMUNITY_TYPE_STIFLE:
  6954. entity->RemoveStifleImmunity(spell);
  6955. break;
  6956. default:
  6957. lua_interface->LogError("LUA RemoveImmunitySpell command error: invalid immunity type");
  6958. should_break = true;
  6959. }
  6960. if (should_break)
  6961. break;
  6962. }
  6963. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6964. }
  6965. return 0;
  6966. }
  6967. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  6968. if (!lua_interface)
  6969. return 0;
  6970. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6971. if (!spell) {
  6972. lua_interface->LogError("LUA SetSpellSnareValue command error: This can only be used in a spell script!");
  6973. return 0;
  6974. }
  6975. float snare = lua_interface->GetFloatValue(state);
  6976. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6977. // convert the val to the speed multipler value (100 - val)
  6978. float val = 100.0 - snare;
  6979. val /= 100.0;
  6980. if (spawn) {
  6981. if (!spawn->IsEntity()) {
  6982. lua_interface->LogError("LUA SetSpellSnareValue command error: spawn must be an entity.");
  6983. return 0;
  6984. }
  6985. ((Entity*)spawn)->SetSnareValue(spell, val);
  6986. }
  6987. else {
  6988. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6989. for (int8 i = 0; i < spell->targets.size(); i++) {
  6990. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6991. if (!spawn || !spawn->IsEntity())
  6992. continue;
  6993. ((Entity*)spawn)->SetSnareValue(spell, val);
  6994. }
  6995. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6996. }
  6997. return 0;
  6998. }
  6999. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7000. if (!lua_interface)
  7001. return 0;
  7002. Spawn* spawn = lua_interface->GetSpawn(state);
  7003. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7004. if (!spawn) {
  7005. lua_interface->LogError("LUA CheckRaceType command error: spawn is not valid");
  7006. return 0;
  7007. }
  7008. if (race_id == 0) {
  7009. lua_interface->LogError("LUA CheckRaceType command error: race id must be set");
  7010. return 0;
  7011. }
  7012. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7013. return 1;
  7014. }
  7015. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7016. if (!lua_interface)
  7017. return 0;
  7018. Spawn* spawn = lua_interface->GetSpawn(state);
  7019. if (!spawn) {
  7020. lua_interface->LogError("LUA GetRaceType command error: spawn is not valid");
  7021. return 0;
  7022. }
  7023. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7024. return 1;
  7025. }
  7026. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7027. if (!lua_interface)
  7028. return 0;
  7029. Spawn* spawn = lua_interface->GetSpawn(state);
  7030. if (!spawn) {
  7031. lua_interface->LogError("LUA GetRaceBaseType command error: spawn is not valid");
  7032. return 0;
  7033. }
  7034. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7035. return 1;
  7036. }
  7037. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7038. if (!lua_interface)
  7039. return 0;
  7040. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7041. if (!spell) {
  7042. lua_interface->LogError("LUA GetSpellName command error: this function must be used from a spell script!");
  7043. return 0;
  7044. }
  7045. lua_interface->SetStringValue(state, spell->spell->GetName());
  7046. return 1;
  7047. }
  7048. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7049. if (!lua_interface)
  7050. return 0;
  7051. Quest* quest = lua_interface->GetQuest(state);
  7052. if (!quest) {
  7053. lua_interface->LogError("LUA GetQuestFlags command error: quest is not valid.");
  7054. return 0;
  7055. }
  7056. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7057. return 1;
  7058. }
  7059. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7060. if (!lua_interface)
  7061. return 0;
  7062. Quest* quest = lua_interface->GetQuest(state);
  7063. int32 flags = lua_interface->GetInt32Value(state, 2);
  7064. if (!quest) {
  7065. lua_interface->LogError("LUA SetQuestFlags command error: quest is not valid.");
  7066. return 0;
  7067. }
  7068. quest->SetQuestFlags(flags);
  7069. return 0;
  7070. }
  7071. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7072. if (!lua_interface)
  7073. return 0;
  7074. Quest* quest = lua_interface->GetQuest(state);
  7075. Spawn* player = lua_interface->GetSpawn(state, 2);
  7076. int32 step = lua_interface->GetInt32Value(state, 3);
  7077. int32 duration = lua_interface->GetInt32Value(state, 4);
  7078. string action = lua_interface->GetStringValue(state, 5);
  7079. if (!quest) {
  7080. lua_interface->LogError("LUA SetQuestTimer command error: quest is not valid.");
  7081. return 0;
  7082. }
  7083. if (!player) {
  7084. lua_interface->LogError("LUA SetQuestTimer command error: player is not a valid spawn.");
  7085. return 0;
  7086. }
  7087. if (!player->IsPlayer()) {
  7088. lua_interface->LogError("LUA SetQuestTimer command error: player is not a valid player.");
  7089. return 0;
  7090. }
  7091. if (step == 0) {
  7092. lua_interface->LogError("LUA SetQuestTimer command error: step must be set.");
  7093. return 0;
  7094. }
  7095. if (duration == 0) {
  7096. lua_interface->LogError("LUA SetQuestTimer command error: duration must be set.");
  7097. return 0;
  7098. }
  7099. if (action.length() == 0) {
  7100. lua_interface->LogError("LUA SetQuestTimer command error: failed action must be set.");
  7101. return 0;
  7102. }
  7103. Client* client = player->GetZone()->GetClientBySpawn(player);
  7104. if (!client) {
  7105. lua_interface->LogError("LUA SetQuestTimer command error: failed to get a valid client pointer for the given player");
  7106. return 0;
  7107. }
  7108. quest->SetTimerStep(step);
  7109. quest->AddFailedAction(step, action);
  7110. quest->SetStepTimer(duration);
  7111. client->AddQuestTimer(quest->GetQuestID());
  7112. return 0;
  7113. }
  7114. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7115. if (!lua_interface)
  7116. return 0;
  7117. Quest* quest = lua_interface->GetQuest(state);
  7118. Spawn* player = lua_interface->GetSpawn(state, 2);
  7119. if (!quest) {
  7120. lua_interface->LogError("LUA SetQuestTimerComplete command error: quest is not valid.");
  7121. return 0;
  7122. }
  7123. if (!player) {
  7124. lua_interface->LogError("LUA SetQuestTimerComplete command error: player is not a valid spawn.");
  7125. return 0;
  7126. }
  7127. if (!player->IsPlayer()) {
  7128. lua_interface->LogError("LUA SetQuestTimerComplete command error: player is not a valid player.");
  7129. return 0;
  7130. }
  7131. Client* client = player->GetZone()->GetClientBySpawn(player);
  7132. if (!client) {
  7133. lua_interface->LogError("LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player");
  7134. return 0;
  7135. }
  7136. quest->SetTimerStep(0);
  7137. quest->SetStepTimer(0);
  7138. client->RemoveQuestTimer(quest->GetQuestID());
  7139. return 0;
  7140. }
  7141. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7142. if (!lua_interface)
  7143. return 0;
  7144. Spawn* player = lua_interface->GetSpawn(state);
  7145. Quest* quest = lua_interface->GetQuest(state, 2);
  7146. int32 step = lua_interface->GetInt32Value(state, 3);
  7147. if (!player) {
  7148. lua_interface->LogError("LUA RemoveQuestStep command error: player is not a valid spawn.");
  7149. return 0;
  7150. }
  7151. if (!player->IsPlayer()) {
  7152. lua_interface->LogError("LUA RemoveQuestStep command error: player is not a valid player.");
  7153. return 0;
  7154. }
  7155. if (!quest) {
  7156. lua_interface->LogError("LUA RemoveQuestStep command error: quest is not valid.");
  7157. return 0;
  7158. }
  7159. if (step == 0) {
  7160. lua_interface->LogError("LUA RemoveQuestStep command error: step must be set.");
  7161. return 0;
  7162. }
  7163. Client* client = player->GetZone()->GetClientBySpawn(player);
  7164. if (!client) {
  7165. lua_interface->LogError("LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.");
  7166. return 0;
  7167. }
  7168. if (quest->RemoveQuestStep(step, client)) {
  7169. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7170. client->GetCurrentZone()->SendQuestUpdates(client);
  7171. }
  7172. else
  7173. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7174. return 0;
  7175. }
  7176. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7177. if (!lua_interface)
  7178. return 0;
  7179. Quest* quest = lua_interface->GetQuest(state, 1);
  7180. int32 step = lua_interface->GetInt32Value(state, 2);
  7181. string desc = lua_interface->GetStringValue(state, 3);
  7182. string task_group = lua_interface->GetStringValue(state, 4);
  7183. if (!quest) {
  7184. lua_interface->LogError("LUA ResetQuestStep command error: quest is not valid.");
  7185. return 0;
  7186. }
  7187. if (step == 0) {
  7188. lua_interface->LogError("LUA ResetQuestStep command error: step must be set.");
  7189. return 0;
  7190. }
  7191. QuestStep* quest_step = quest->GetQuestStep(step);
  7192. if (!quest_step) {
  7193. lua_interface->LogError("LUA ResetQuestStep command error: unable to get a valid quest step.");
  7194. return 0;
  7195. }
  7196. quest_step->SetStepProgress(0);
  7197. quest_step->SetTaskGroup(task_group);
  7198. quest_step->SetDescription(desc);
  7199. return 0;
  7200. }
  7201. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7202. if (!lua_interface)
  7203. return 0;
  7204. Quest* quest = lua_interface->GetQuest(state);
  7205. int32 step = lua_interface->GetInt32Value(state, 2);
  7206. string action = lua_interface->GetStringValue(state, 3);
  7207. if (!quest) {
  7208. lua_interface->LogError("LUA AddQuestStepFailureAction command error: quest is not valid.");
  7209. return 0;
  7210. }
  7211. if (step == 0) {
  7212. lua_interface->LogError("LUA AddQuestStepFailureAction command error: step must be set.");
  7213. return 0;
  7214. }
  7215. if (action.length() == 0) {
  7216. lua_interface->LogError("LUA AddQuestStepFailureAction command error: action must be set.");
  7217. return 0;
  7218. }
  7219. quest->AddFailedAction(step, action);
  7220. return 0;
  7221. }
  7222. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  7223. if (!lua_interface)
  7224. return 0;
  7225. Spawn* player = lua_interface->GetSpawn(state);
  7226. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7227. int32 step = lua_interface->GetInt32Value(state, 3);
  7228. if (!player) {
  7229. lua_interface->LogError("LUA SetStepFailed command error: player is not a valid spawn.");
  7230. return 0;
  7231. }
  7232. if (!player->IsPlayer()) {
  7233. lua_interface->LogError("LUA SetStepFailed command error: player is not a valid player.");
  7234. return 0;
  7235. }
  7236. if (quest_id == 0) {
  7237. lua_interface->LogError("LUA SetStepFailed command error: quest_id must be set.");
  7238. return 0;
  7239. }
  7240. if (step == 0) {
  7241. lua_interface->LogError("LUA SetStepFailed command error: step must be set.");
  7242. return 0;
  7243. }
  7244. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  7245. if (!quest) {
  7246. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  7247. return 0;
  7248. }
  7249. quest->StepFailed(step);
  7250. return 0;
  7251. }
  7252. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  7253. if (!lua_interface)
  7254. return 0;
  7255. Spawn* player = lua_interface->GetSpawn(state);
  7256. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7257. if (!player) {
  7258. lua_interface->LogError("LUA GetQuestCompleteCount command error: player is not a valid spawn");
  7259. return 0;
  7260. }
  7261. if (!player->IsPlayer()) {
  7262. lua_interface->LogError("LUA GetQuestCompleteCount command error: player is not a valid player");
  7263. return 0;
  7264. }
  7265. if (quest_id == 0) {
  7266. lua_interface->LogError("LUA GetQuestCompleteCount command error: quest id is not valid");
  7267. return 0;
  7268. }
  7269. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  7270. if (!quest) {
  7271. lua_interface->SetInt32Value(state, 0);
  7272. return 1;
  7273. }
  7274. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  7275. return 1;
  7276. }
  7277. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  7278. if (!lua_interface)
  7279. return 0;
  7280. string name = lua_interface->GetStringValue(state);
  7281. string value = lua_interface->GetStringValue(state, 2);
  7282. string comment = lua_interface->GetStringValue(state, 3);
  7283. if (name.length() == 0) {
  7284. lua_interface->LogError("LUA SetServerVariable command error: name is not valid");
  7285. return 0;
  7286. }
  7287. if (value.length() == 0) {
  7288. lua_interface->LogError("LUA SetServerVariable command error: value is not valid");
  7289. return 0;
  7290. }
  7291. string varname = string("lua_").append(name);
  7292. Variable* var = variables.FindVariable(varname);
  7293. if (var)
  7294. var->SetValue(value.c_str());
  7295. else {
  7296. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  7297. variables.AddVariable(var);
  7298. }
  7299. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  7300. return 0;
  7301. }
  7302. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  7303. if (!lua_interface)
  7304. return 0;
  7305. string name = lua_interface->GetStringValue(state);
  7306. if (name.length() == 0) {
  7307. lua_interface->LogError("LUA GetServerVariable command error: name is not valid");
  7308. return 0;
  7309. }
  7310. string varname = string("lua_").append(name);
  7311. Variable* var = variables.FindVariable(varname);
  7312. if (var)
  7313. lua_interface->SetStringValue(state, var->GetValue());
  7314. else
  7315. lua_interface->SetStringValue(state, "NULL");
  7316. return 1;
  7317. }
  7318. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  7319. if (!lua_interface)
  7320. return 0;
  7321. Spawn* player = lua_interface->GetSpawn(state);
  7322. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7323. if (!player) {
  7324. lua_interface->LogError("LUA HasLanguage command error: player is not valid");
  7325. return 0;
  7326. }
  7327. if (!player->IsPlayer()) {
  7328. lua_interface->LogError("LUA HasLanguage command error: player is not a valid player");
  7329. return 0;
  7330. }
  7331. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  7332. return 1;
  7333. }
  7334. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  7335. if (!lua_interface)
  7336. return 0;
  7337. Spawn* player = lua_interface->GetSpawn(state);
  7338. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7339. if (!player) {
  7340. lua_interface->LogError("LUA AddLanguage command error: player is not valid");
  7341. return 0;
  7342. }
  7343. if (!player->IsPlayer()) {
  7344. lua_interface->LogError("LUA AddLanguage command error: player is not a valid player");
  7345. return 0;
  7346. }
  7347. Language* language = master_languages_list.GetLanguage(language_id);
  7348. if (language)
  7349. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  7350. return 0;
  7351. }
  7352. int EQ2Emu_lua_IsNight(lua_State* state) {
  7353. if (!lua_interface)
  7354. return 0;
  7355. ZoneServer* zone = lua_interface->GetZone(state);
  7356. if (!zone) {
  7357. lua_interface->LogError("LUA IsNight command error: zone is not valid");
  7358. return 0;
  7359. }
  7360. lua_interface->SetBooleanValue(state, zone->IsDusk());
  7361. return 1;
  7362. }
  7363. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  7364. if (!lua_interface)
  7365. return 0;
  7366. Spawn* spawn = lua_interface->GetSpawn(state);
  7367. if (!spawn) {
  7368. lua_interface->LogError("LUA AddMultiFloorLift command error: spawn is not valid");
  7369. return 0;
  7370. }
  7371. if (!spawn->IsWidget()) {
  7372. lua_interface->LogError("LUA AddMultiFloorLift command error: spawn is not a widget");
  7373. return 0;
  7374. }
  7375. ((Widget*)spawn)->SetMultiFloorLift(true);
  7376. if (spawn->GetZone())
  7377. spawn->GetZone()->AddTransportSpawn(spawn);
  7378. return 0;
  7379. }
  7380. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  7381. if (!lua_interface)
  7382. return 0;
  7383. Spawn* player = lua_interface->GetSpawn(state);
  7384. int32 path = lua_interface->GetInt32Value(state, 2);
  7385. if (!player) {
  7386. lua_interface->LogError("LUA StartAutoMount command error: spawn is not valid");
  7387. return 0;
  7388. }
  7389. if (!player->IsPlayer()) {
  7390. lua_interface->LogError("LUA StartAutoMount command error: spawn is not a player");
  7391. return 0;
  7392. }
  7393. if (path == 0) {
  7394. lua_interface->LogError("LUA StartAutoMount command error: path must be greater then zero");
  7395. return 0;
  7396. }
  7397. Client* client = player->GetZone()->GetClientBySpawn(player);
  7398. if (!client) {
  7399. lua_interface->LogError("LUA StartAutoMount command error: unable to get a client from the given player");
  7400. return 0;
  7401. }
  7402. client->SetPendingFlightPath(path);
  7403. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  7404. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  7405. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  7406. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", client->GetVersion());
  7407. if (packet) {
  7408. client->QueuePacket(packet->serialize());
  7409. safe_delete(packet);
  7410. }
  7411. return 0;
  7412. }
  7413. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  7414. if (!lua_interface)
  7415. return 0;
  7416. Spawn* player = lua_interface->GetSpawn(state);
  7417. if (!player) {
  7418. lua_interface->LogError("LUA EndAutoMount command error: spawn is not valid");
  7419. return 0;
  7420. }
  7421. if (!player->IsPlayer()) {
  7422. lua_interface->LogError("LUA EndAutoMount command error: spawn is not a player");
  7423. return 0;
  7424. }
  7425. Client* client = player->GetZone()->GetClientBySpawn(player);
  7426. if (!client) {
  7427. lua_interface->LogError("LUA EndAutoMount command error: unable to get a client from the given player");
  7428. return 0;
  7429. }
  7430. client->EndAutoMount();
  7431. return 0;
  7432. }
  7433. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  7434. if (!lua_interface)
  7435. return 0;
  7436. Spawn* player = lua_interface->GetSpawn(state);
  7437. if (!player) {
  7438. lua_interface->LogError("LUA IsOnAutoMount command error: spawn in not valid");
  7439. return 0;
  7440. }
  7441. if (!player->IsPlayer()) {
  7442. lua_interface->LogError("LUA IsOnAutoMount command error: spawn is not a player");
  7443. return 0;
  7444. }
  7445. Client* client = player->GetZone()->GetClientBySpawn(player);
  7446. if (!client) {
  7447. lua_interface->LogError("LUA IsOnAutoMount command error: unable to get a client from the given player");
  7448. return 0;
  7449. }
  7450. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  7451. return 1;
  7452. }
  7453. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  7454. if (!lua_interface)
  7455. return 0;
  7456. Spawn* player = lua_interface->GetSpawn(state);
  7457. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7458. int32 value = lua_interface->GetInt32Value(state, 3);
  7459. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7460. if (!player) {
  7461. lua_interface->LogError("LUA SetPlayerHistory command error: spawn is not valid");
  7462. return 0;
  7463. }
  7464. if (!player->IsPlayer()) {
  7465. lua_interface->LogError("LUA SetPlayerHistory command error: spawn is not a player");
  7466. return 0;
  7467. }
  7468. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  7469. return 0;
  7470. }
  7471. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  7472. if (!lua_interface)
  7473. return 0;
  7474. Spawn* player = lua_interface->GetSpawn(state);
  7475. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7476. if (!player) {
  7477. lua_interface->LogError("LUA GetPlayerHistory command error: spawn is not valid");
  7478. return 0;
  7479. }
  7480. if (!player->IsPlayer()) {
  7481. lua_interface->LogError("LUA GetPlayerHistory command error: spawn is not a player");
  7482. return 0;
  7483. }
  7484. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  7485. if (!hd)
  7486. return 0;
  7487. lua_interface->SetInt32Value(state, hd->Value);
  7488. lua_interface->SetInt32Value(state, hd->Value2);
  7489. return 2;
  7490. }
  7491. int EQ2Emu_lua_SetGridID(lua_State* state) {
  7492. if (!lua_interface)
  7493. return 0;
  7494. Spawn* spawn = lua_interface->GetSpawn(state);
  7495. int32 grid = lua_interface->GetInt32Value(state, 2);
  7496. if (!spawn) {
  7497. lua_interface->LogError("LUA SetGridID command error: spawn is not valid");
  7498. return 0;
  7499. }
  7500. if (grid == 0) {
  7501. lua_interface->LogError("LUA SetGridID command error: grid is not valid");
  7502. return 0;
  7503. }
  7504. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  7505. return 0;
  7506. }
  7507. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  7508. if (!lua_interface)
  7509. return 0;
  7510. Spawn* spawn = lua_interface->GetSpawn(state);
  7511. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7512. int32 value1 = lua_interface->GetInt32Value(state, 3);
  7513. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7514. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  7515. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  7516. if (!spawn) {
  7517. lua_interface->LogError("LUA SetRequiredHistory command error: spawn is not valid");
  7518. return 0;
  7519. }
  7520. //Add this quest to the list of required quests for this spawn
  7521. spawn->SetRequiredHistory(event_id, value1, value2);
  7522. //If private spawn value set
  7523. if (private_spawn) {
  7524. //Set the spawn to be private when not granted access via history
  7525. spawn->AddAllowAccessSpawn(spawn);
  7526. spawn->SetPrivateQuestSpawn(true);
  7527. }
  7528. //This value will override vis_flags in the vis packet
  7529. if (flag_override > 0)
  7530. spawn->SetQuestsRequiredOverride(flag_override);
  7531. return 0;
  7532. }
  7533. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  7534. if (!lua_interface)
  7535. return 0;
  7536. Spawn* player = lua_interface->GetSpawn(state);
  7537. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7538. int32 step_id = lua_interface->GetInt32Value(state, 3);
  7539. if (!player) {
  7540. lua_interface->LogError("LUA GetQuestStepProgress command error: spawn is not valid");
  7541. return 0;
  7542. }
  7543. if (!player->IsPlayer()) {
  7544. lua_interface->LogError("LUA GetQuestStepProgress command error: spawn is not a player");
  7545. return 0;
  7546. }
  7547. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  7548. return 1;
  7549. }
  7550. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  7551. if (!lua_interface)
  7552. return 0;
  7553. Spawn* player = lua_interface->GetSpawn(state);
  7554. int8 level = lua_interface->GetInt8Value(state, 2);
  7555. if (!player) {
  7556. lua_interface->LogError("LUA SetPlayerLevel command error: spawn is not valid");
  7557. return 0;
  7558. }
  7559. if (!player->IsPlayer()) {
  7560. lua_interface->LogError("LUA SetPlayerLevel command error: spawn is not a player");
  7561. return 0;
  7562. }
  7563. if (level == 0) {
  7564. lua_interface->LogError("LUA SetPlayerLevel command error: new level can't be 0");
  7565. return 0;
  7566. }
  7567. Client* client = player->GetZone()->GetClientBySpawn(player);
  7568. if (!client) {
  7569. lua_interface->LogError("LUA SetPlayerLevel command error: unable to get a client from the given spawn");
  7570. return 0;
  7571. }
  7572. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  7573. client->GetPlayer()->SetXP(1);
  7574. client->GetPlayer()->SetNeededXP();
  7575. return 0;
  7576. }
  7577. int EQ2Emu_lua_AddCoin(lua_State* state) {
  7578. if (!lua_interface)
  7579. return 0;
  7580. Spawn* player = lua_interface->GetSpawn(state);
  7581. int32 amount = lua_interface->GetInt32Value(state, 2);
  7582. if (!player) {
  7583. lua_interface->LogError("LUA AddCoin command error: spawn is not valid");
  7584. return 0;
  7585. }
  7586. if (!player->IsPlayer()) {
  7587. lua_interface->LogError("LUA AddCoin command error: spawn is not a player");
  7588. return 0;
  7589. }
  7590. if (amount == 0) {
  7591. lua_interface->LogError("LUA AddCoin command error: amount must be greater then 0");
  7592. return 0;
  7593. }
  7594. ((Player*)player)->AddCoins(amount);
  7595. return 0;
  7596. }
  7597. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  7598. if (!lua_interface)
  7599. return 0;
  7600. Spawn* player = lua_interface->GetSpawn(state);
  7601. int32 amount = lua_interface->GetInt32Value(state, 2);
  7602. if (!player) {
  7603. lua_interface->LogError("LUA RemoveCoin command error: spawn is not valid");
  7604. return 0;
  7605. }
  7606. if (!player->IsPlayer()) {
  7607. lua_interface->LogError("LUA RemoveCoin command error: spawn is not a player");
  7608. return 0;
  7609. }
  7610. if (amount == 0) {
  7611. lua_interface->LogError("LUA RemoveCoin command error: amount must be greater then 0");
  7612. return 0;
  7613. }
  7614. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  7615. return 1;
  7616. }
  7617. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  7618. if (!lua_interface)
  7619. return 0;
  7620. ZoneServer* zone = lua_interface->GetZone(state);
  7621. if (!zone) {
  7622. lua_interface->LogError("LUA GetPlayersInZone command error: zone is not valid");
  7623. return 0;
  7624. }
  7625. vector<Entity*> players = zone->GetPlayers();
  7626. if (players.size() == 0)
  7627. return 0;
  7628. lua_createtable(state, players.size(), 0);
  7629. int newTable = lua_gettop(state);
  7630. for (int32 i = 0; i < players.size(); i++) {
  7631. lua_interface->SetSpawnValue(state, players.at(i));
  7632. lua_rawseti(state, newTable, i + 1);
  7633. }
  7634. return 1;
  7635. }
  7636. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  7637. if (!lua_interface)
  7638. return 0;
  7639. ZoneServer* zone = lua_interface->GetZone(state, 1);
  7640. if (!zone) {
  7641. lua_interface->LogError("LUA GetPlayersInZone command error: zone is not valid");
  7642. return 0;
  7643. }
  7644. int32 group_id = lua_interface->GetInt32Value(state, 2);
  7645. //Map of <placement_id, location_id>
  7646. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  7647. map<int32, int32>::iterator itr;
  7648. vector<Spawn*> group;
  7649. for (itr = locs->begin(); itr != locs->end(); itr++) {
  7650. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  7651. if (!location) {
  7652. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  7653. return 0;
  7654. }
  7655. Spawn* spawn = 0;
  7656. if (location->entities[0]) {
  7657. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  7658. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  7659. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  7660. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  7661. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  7662. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  7663. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  7664. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  7665. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  7666. spawn = zone->AddSignSpawn(location, location->entities[0]);
  7667. if (spawn) {
  7668. const char* script = 0;
  7669. for (int x = 0; x < 3; x++) {
  7670. switch (x) {
  7671. case 0:
  7672. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  7673. break;
  7674. case 1:
  7675. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  7676. break;
  7677. case 2:
  7678. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  7679. break;
  7680. }
  7681. if (script && lua_interface->GetSpawnScript(script) != 0) {
  7682. spawn->SetSpawnScript(string(script));
  7683. break;
  7684. }
  7685. }
  7686. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7687. lua_interface->SetSpawnValue(state, spawn);
  7688. group.push_back(spawn);
  7689. }
  7690. else {
  7691. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  7692. safe_delete(spawn);
  7693. }
  7694. }
  7695. }
  7696. if (!group.empty()) {
  7697. lua_createtable(state, group.size(), 0);
  7698. int newTable = lua_gettop(state);
  7699. for (int32 i = 0; i < group.size(); i++) {
  7700. lua_interface->SetSpawnValue(state, group[i]);
  7701. lua_rawseti(state, newTable, i + 1);
  7702. }
  7703. }
  7704. else
  7705. lua_pushnil(state);
  7706. return 1;
  7707. }
  7708. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  7709. if (!lua_interface)
  7710. return 0;
  7711. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  7712. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  7713. int16 leeway = lua_interface->GetInt16Value(state, 3);
  7714. if (!spawn) {
  7715. lua_interface->LogError("LUA SetSpawnAnimation command error: spawn is not valid");
  7716. return 0;
  7717. }
  7718. if (anim_id == 0) {
  7719. lua_interface->LogError("LUA SetSpawnAnimation command error: anim_id is not valid");
  7720. return 0;
  7721. }
  7722. if (leeway == 0)
  7723. leeway = 5000;
  7724. spawn->SetSpawnAnim(anim_id);
  7725. spawn->SetSpawnAnimLeeway(leeway);
  7726. return 0;
  7727. }
  7728. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  7729. if (!lua_interface)
  7730. return 0;
  7731. Spawn* player = lua_interface->GetSpawn(state);
  7732. if (!player) {
  7733. return 0;
  7734. }
  7735. Client* client = player->GetZone()->GetClientBySpawn(player);
  7736. if (!client) {
  7737. return 0;
  7738. }
  7739. lua_interface->SetInt32Value(state, client->GetVersion());
  7740. return 1;
  7741. }
  7742. int EQ2Emu_lua_GetItemID(lua_State* state) {
  7743. if (!lua_interface)
  7744. return 0;
  7745. Item* item = lua_interface->GetItem(state);
  7746. if (!item) {
  7747. lua_interface->LogError("LUA GetItemID command error: item is not valid");
  7748. return 0;
  7749. }
  7750. lua_interface->SetInt32Value(state, item->details.item_id);
  7751. return 1;
  7752. }
  7753. int EQ2Emu_lua_IsEntity(lua_State* state) {
  7754. if (!lua_interface)
  7755. return 0;
  7756. Spawn* spawn = lua_interface->GetSpawn(state);
  7757. if (!spawn) {
  7758. lua_interface->LogError("LUA IsEntity command error: spawn is not valid");
  7759. return 0;
  7760. }
  7761. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  7762. return 1;
  7763. }
  7764. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  7765. if (!lua_interface)
  7766. return 0;
  7767. Spawn* spawn = lua_interface->GetSpawn(state);
  7768. if (!spawn) {
  7769. lua_interface->LogError("LUA GetOrigX command error: spawn is not valid");
  7770. return 0;
  7771. }
  7772. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  7773. return 1;
  7774. }
  7775. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  7776. if (!lua_interface)
  7777. return 0;
  7778. Spawn* spawn = lua_interface->GetSpawn(state);
  7779. if (!spawn) {
  7780. lua_interface->LogError("LUA GetOrigY command error: spawn is not valid");
  7781. return 0;
  7782. }
  7783. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  7784. return 1;
  7785. }
  7786. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  7787. if (!lua_interface)
  7788. return 0;
  7789. Spawn* spawn = lua_interface->GetSpawn(state);
  7790. if (!spawn) {
  7791. lua_interface->LogError("LUA GetOrigZ command error: spawn is not valid");
  7792. return 0;
  7793. }
  7794. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  7795. return 1;
  7796. }
  7797. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  7798. if (!lua_interface)
  7799. return 0;
  7800. Spawn* spawn = lua_interface->GetSpawn(state);
  7801. float pct = lua_interface->GetFloatValue(state, 2);
  7802. if (!spawn) {
  7803. lua_interface->LogError("LUA GetPCTOfHP command error: spawn is not valid");
  7804. return 0;
  7805. }
  7806. if (pct == 0) {
  7807. lua_interface->LogError("LUA GetPCTOfHP command error: pct is not valid");
  7808. return 0;
  7809. }
  7810. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  7811. lua_interface->SetInt32Value(state, amount);
  7812. return 1;
  7813. }
  7814. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  7815. if (!lua_interface)
  7816. return 0;
  7817. Spawn* spawn = lua_interface->GetSpawn(state);
  7818. float pct = lua_interface->GetFloatValue(state, 2);
  7819. if (!spawn) {
  7820. lua_interface->LogError("LUA GetPCTOfPower command error: spawn is not valid");
  7821. return 0;
  7822. }
  7823. if (pct == 0) {
  7824. lua_interface->LogError("LUA GetPCTOfPower command error: pct is not valid");
  7825. return 0;
  7826. }
  7827. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  7828. lua_interface->SetInt32Value(state, amount);
  7829. return 1;
  7830. }
  7831. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  7832. if (!lua_interface)
  7833. return 0;
  7834. Spawn* spawn = lua_interface->GetSpawn(state);
  7835. if (!spawn) {
  7836. lua_interface->LogError("LUA GetBoundZoneID command error: spawn is not valid");
  7837. return 0;
  7838. }
  7839. if (!spawn->IsPlayer()) {
  7840. lua_interface->LogError("LUA GetBoundZoneID command error: spawn is not a player");
  7841. return 0;
  7842. }
  7843. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  7844. return 1;
  7845. }
  7846. int EQ2Emu_lua_Evac(lua_State* state) {
  7847. if (!lua_interface)
  7848. return 0;
  7849. Spawn* target = lua_interface->GetSpawn(state);
  7850. if (target) {
  7851. float x = target->GetZone()->GetSafeX();
  7852. float y = target->GetZone()->GetSafeY();
  7853. float z = target->GetZone()->GetSafeZ();
  7854. float h = target->GetZone()->GetSafeHeading();
  7855. target->SetX(x);
  7856. target->SetY(y);
  7857. target->SetZ(z);
  7858. target->SetHeading(h);
  7859. target->SetSpawnOrigX(target->GetX());
  7860. target->SetSpawnOrigY(target->GetY());
  7861. target->SetSpawnOrigZ(target->GetZ());
  7862. target->SetSpawnOrigHeading(target->GetHeading());
  7863. if (target->IsPlayer()) {
  7864. Client* client = target->GetZone()->GetClientBySpawn(target);
  7865. if (client) {
  7866. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  7867. if (packet)
  7868. {
  7869. packet->setDataByName("x", x);
  7870. packet->setDataByName("y", y);
  7871. packet->setDataByName("z", z);
  7872. client->QueuePacket(packet->serialize());
  7873. safe_delete(packet);
  7874. }
  7875. }
  7876. }
  7877. }
  7878. else {
  7879. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7880. ZoneServer* zone = spell->caster->GetZone();
  7881. float x = spell->caster->GetZone()->GetSafeX();
  7882. float y = spell->caster->GetZone()->GetSafeY();
  7883. float z = spell->caster->GetZone()->GetSafeZ();
  7884. float h = spell->caster->GetZone()->GetSafeHeading();
  7885. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7886. for (int32 i = 0; i < spell->targets.size(); i++) {
  7887. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  7888. if (!target2)
  7889. continue;
  7890. target2->SetX(x);
  7891. target2->SetY(y);
  7892. target2->SetZ(z);
  7893. target2->SetHeading(h);
  7894. target2->SetSpawnOrigX(target2->GetX());
  7895. target2->SetSpawnOrigY(target2->GetY());
  7896. target2->SetSpawnOrigZ(target2->GetZ());
  7897. target2->SetSpawnOrigHeading(target2->GetHeading());
  7898. if (target2->IsPlayer()) {
  7899. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  7900. if (client) {
  7901. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  7902. if (packet)
  7903. {
  7904. packet->setDataByName("x", x);
  7905. packet->setDataByName("y", y);
  7906. packet->setDataByName("z", z);
  7907. client->QueuePacket(packet->serialize());
  7908. safe_delete(packet);
  7909. }
  7910. }
  7911. }
  7912. }
  7913. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7914. }
  7915. return 0;
  7916. }
  7917. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  7918. if (!lua_interface)
  7919. return 0;
  7920. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7921. if (!luaspell) {
  7922. lua_interface->LogError("LUA GetSpellTier command error: must be used in a spell script");
  7923. return 0;
  7924. }
  7925. int8 tier = luaspell->spell->GetSpellTier();
  7926. lua_interface->SetInt32Value(state, tier);
  7927. return 1;
  7928. }
  7929. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  7930. if (!lua_interface)
  7931. return 0;
  7932. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7933. if (!luaspell) {
  7934. lua_interface->LogError("LUA GetSpellID command error: must be used in a spell script");
  7935. return 0;
  7936. }
  7937. int32 spell_id = luaspell->spell->GetSpellID();
  7938. lua_interface->SetInt32Value(state, spell_id);
  7939. return 1;
  7940. }
  7941. int EQ2Emu_lua_ProcHate(lua_State* state) {
  7942. if (!lua_interface)
  7943. return 0;
  7944. Spawn* caster = lua_interface->GetSpawn(state);
  7945. Spawn* target = lua_interface->GetSpawn(state, 2);
  7946. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  7947. string spell_name = lua_interface->GetStringValue(state, 4);
  7948. if (!caster) {
  7949. lua_interface->LogError("LUA ProcHate command error: caster is not a valid spawn");
  7950. return 0;
  7951. }
  7952. if (!caster->IsEntity()) {
  7953. lua_interface->LogError("LUA ProcHate command error: caster is not an entity");
  7954. return 0;
  7955. }
  7956. if (!target) {
  7957. lua_interface->LogError("LUA ProcHate command error: target is not a valid spawn");
  7958. return 0;
  7959. }
  7960. if (!target->IsEntity()) {
  7961. lua_interface->LogError("LUA ProcHate command error: target is not an entity");
  7962. return 0;
  7963. }
  7964. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  7965. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  7966. return 0;
  7967. }