LuaFunctions.cpp 361 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. if (spawn) {
  156. const char* mp3 = 0;
  157. const char* text = 0;
  158. const char* emote = 0;
  159. if (mp3_string.length() > 0)
  160. mp3 = mp3_string.c_str();
  161. if (text_string.length() > 0)
  162. text = text_string.c_str();
  163. if (emote_string.length() > 0)
  164. emote = emote_string.c_str();
  165. Client* client = 0;
  166. if (player && player->IsPlayer())
  167. client = spawn->GetZone()->GetClientBySpawn(player);
  168. if (client) {
  169. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  170. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  171. }
  172. else
  173. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  174. }
  175. return 0;
  176. }
  177. int EQ2Emu_lua_PlaySound(lua_State* state) {
  178. if (!lua_interface)
  179. return 0;
  180. Spawn* spawn = lua_interface->GetSpawn(state);
  181. string sound_string = lua_interface->GetStringValue(state, 2);
  182. float x = lua_interface->GetFloatValue(state, 3);
  183. float y = lua_interface->GetFloatValue(state, 4);
  184. float z = lua_interface->GetFloatValue(state, 5);
  185. Spawn* player = lua_interface->GetSpawn(state, 6);
  186. if (spawn && sound_string.length() > 0) {
  187. Client* client = 0;
  188. if (player && player->IsPlayer())
  189. client = spawn->GetZone()->GetClientBySpawn(player);
  190. if (client)
  191. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  192. else
  193. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  194. }
  195. return 0;
  196. }
  197. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  202. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  203. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  204. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  205. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  206. if (!spawn) {
  207. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  208. return 0;
  209. }
  210. if (quest_id > 0) {
  211. //Add this quest to the list of required quests for this spawn
  212. spawn->SetQuestsRequired(quest_id, quest_step);
  213. //If private spawn value set
  214. if (private_spawn) {
  215. //Set the spawn to be private when not granted access through this quest
  216. spawn->AddAllowAccessSpawn(spawn);
  217. spawn->SetPrivateQuestSpawn(true);
  218. }
  219. //This value allows access after a quest step, or the whole quest has been completed
  220. if (continued_access)
  221. spawn->SetQuestsRequiredContinuedAccess(true);
  222. //This value will override vis_flags in the vis packet
  223. if (flag_override > 0)
  224. spawn->SetQuestsRequiredOverride(flag_override);
  225. }
  226. return 0;
  227. }
  228. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  229. if (!lua_interface)
  230. return 0;
  231. Spawn* spawn = lua_interface->GetSpawn(state);
  232. float max_distance = lua_interface->GetFloatValue(state, 2);
  233. string variable = lua_interface->GetStringValue(state, 3);
  234. string value = lua_interface->GetStringValue(state, 4);
  235. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  236. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  237. return 0;
  238. }
  239. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  240. if (!lua_interface)
  241. return 0;
  242. Client* client = 0;
  243. Spawn* player = lua_interface->GetSpawn(state);
  244. if (!player) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  246. return 0;
  247. }
  248. if (!player->IsPlayer()) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  250. return 0;
  251. }
  252. if (player->GetZone())
  253. client = player->GetZone()->GetClientBySpawn(player);
  254. if (!client) {
  255. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  256. return 0;
  257. }
  258. float intensity = lua_interface->GetFloatValue(state, 2);
  259. int8 direction = lua_interface->GetInt8Value(state, 3);
  260. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  261. if (packet) {
  262. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  263. v1 = *(float *)(a1 + 4);
  264. if ( v1 > 0.0 )
  265. v2 = fminf(v1, 1.0);
  266. else
  267. v2 = 0.1;
  268. */
  269. packet->setDataByName("intensity", intensity);
  270. if ( client->GetVersion() > 546 )
  271. packet->setDataByName("direction", direction);
  272. client->QueuePacket(packet->serialize());
  273. safe_delete(packet);
  274. }
  275. return 0;
  276. }
  277. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  278. if (!lua_interface)
  279. return 0;
  280. Spawn* dead = lua_interface->GetSpawn(state);
  281. Spawn* killer = lua_interface->GetSpawn(state, 2);
  282. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  283. if (dead && dead->Alive() && dead->GetZone())
  284. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  285. return 0;
  286. }
  287. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  288. if (!lua_interface)
  289. return 0;
  290. Spawn* spawn = lua_interface->GetSpawn(state);
  291. float max_distance = lua_interface->GetFloatValue(state, 2);
  292. bool include_players = lua_interface->GetInt8Value(state, 3);
  293. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  294. if (max_distance > 0 && spawn && spawn->GetZone())
  295. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  296. return 0;
  297. }
  298. int EQ2Emu_lua_Despawn(lua_State* state) {
  299. if (!lua_interface)
  300. return 0;
  301. Spawn* spawn = lua_interface->GetSpawn(state);
  302. int32 delay = lua_interface->GetInt32Value(state, 2);
  303. if (spawn && spawn->GetZone())
  304. spawn->GetZone()->Despawn(spawn, delay);
  305. return 0;
  306. }
  307. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* spawn = lua_interface->GetSpawn(state);
  311. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  312. if (spawn) {
  313. spawn->info_changed = true;
  314. spawn->SetShowHandIcon(displayHandIcon);
  315. }
  316. return 0;
  317. }
  318. //this function is used to force an update packet to be sent.
  319. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  320. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  321. if (!lua_interface)
  322. return 0;
  323. Spawn* spawn = lua_interface->GetSpawn(state);
  324. if (spawn) {
  325. spawn->vis_changed = true;
  326. }
  327. return 0;
  328. }
  329. //this function is used to force an update packet to be sent.
  330. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  331. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  332. if (!lua_interface)
  333. return 0;
  334. Spawn* spawn = lua_interface->GetSpawn(state);
  335. if (spawn) {
  336. spawn->info_changed = true;
  337. }
  338. return 0;
  339. }
  340. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int32 new_state = lua_interface->GetInt32Value(state, 2);
  345. if (spawn) {
  346. spawn->GetZone()->SendStateCommand(spawn, new_state);
  347. }
  348. return 0;
  349. }
  350. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  351. if (!lua_interface)
  352. return 0;
  353. Spawn* spawn = lua_interface->GetSpawn(state);
  354. string variable = lua_interface->GetStringValue(state, 2);
  355. string value = lua_interface->GetStringValue(state, 3);
  356. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  357. bool temporary_flag = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  358. int32 type = commands.GetSpawnSetType(variable);
  359. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  360. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  361. return 0;
  362. }
  363. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  364. if (!lua_interface)
  365. return 0;
  366. Spawn* spawn = lua_interface->GetSpawn(state);
  367. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  368. if (spawn && spawn_id > 0) {
  369. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  370. if (closest_spawn) {
  371. lua_interface->SetSpawnValue(state, closest_spawn);
  372. return 1;
  373. }
  374. }
  375. return 0;
  376. }
  377. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  381. int32 position = lua_interface->GetInt32Value(state, 2);
  382. if (spawnList) {
  383. if (spawnList->size() > position) {
  384. lua_interface->SetSpawnValue(state, spawnList->at(position));
  385. return 1;
  386. }
  387. else {
  388. return 0;
  389. }
  390. return spawnList->size();
  391. }
  392. return 0;
  393. }
  394. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  395. if (!lua_interface)
  396. return 0;
  397. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  398. if (spawnList) {
  399. return spawnList->size();
  400. }
  401. return 0;
  402. }
  403. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  404. if (!lua_interface)
  405. return 0;
  406. vector<Spawn*>* spawnList = new vector<Spawn*>();
  407. lua_interface->SetSpawnListValue(state, spawnList);
  408. return 1;
  409. }
  410. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  411. if (!lua_interface)
  412. return 0;
  413. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  414. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  415. if (spawnList) {
  416. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  417. if (it == spawnList->end())
  418. spawnList->push_back(spawn);
  419. }
  420. return 0;
  421. }
  422. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  423. if (!lua_interface)
  424. return 0;
  425. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  426. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  427. if (spawnList) {
  428. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  429. if(it != spawnList->end())
  430. spawnList->erase(it);
  431. }
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. if (spawn) {
  440. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  441. if (spawns.size() > 0) {
  442. vector<Spawn*>* spawnList = new vector<Spawn*>();
  443. vector<Spawn*>::iterator itr;
  444. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  445. spawnList->push_back(*itr);
  446. }
  447. lua_interface->SetSpawnListValue(state, spawnList);
  448. return 1;
  449. }
  450. }
  451. return 0;
  452. }
  453. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  454. if (!lua_interface)
  455. return 0;
  456. string variable_name = lua_interface->GetStringValue(state);
  457. Variable* var = variables.FindVariable(variable_name);
  458. if (var) {
  459. lua_interface->SetStringValue(state, var->GetValue());
  460. return 1;
  461. }
  462. return 0;
  463. }
  464. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  465. if (!lua_interface)
  466. return 0;
  467. int32 total_coins = lua_interface->GetInt32Value(state);
  468. if (total_coins == 0) {
  469. lua_interface->SetStringValue(state, "0 copper");
  470. return 1;
  471. }
  472. char tmp[64] = { 0 };
  473. string message = "";
  474. int32 val = 0;
  475. if (total_coins >= 1000000) {
  476. val = total_coins / 1000000;
  477. total_coins -= 1000000 * val;
  478. sprintf(tmp, " %u Platinum", val);
  479. message.append(tmp);
  480. memset(tmp, 0, 64);
  481. }
  482. if (total_coins >= 10000) {
  483. val = total_coins / 10000;
  484. total_coins -= 10000 * val;
  485. sprintf(tmp, " %u Gold", val);
  486. message.append(tmp);
  487. memset(tmp, 0, 64);
  488. }
  489. if (total_coins >= 100) {
  490. val = total_coins / 100;
  491. total_coins -= 100 * val;
  492. sprintf(tmp, " %u Silver", val);
  493. message.append(tmp);
  494. memset(tmp, 0, 64);
  495. }
  496. if (total_coins > 0) {
  497. sprintf(tmp, " %u Copper", (int32)total_coins);
  498. message.append(tmp);
  499. }
  500. lua_interface->SetStringValue(state, message.c_str());
  501. return 1;
  502. }
  503. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  504. ZoneServer* zone = lua_interface->GetZone(state);
  505. int32 group_id = lua_interface->GetInt32Value(state, 2);
  506. if (zone) {
  507. Spawn* spawn = zone->GetSpawnGroup(group_id);
  508. if (spawn) {
  509. lua_interface->SetSpawnValue(state, spawn);
  510. return 1;
  511. }
  512. }
  513. return 0;
  514. }
  515. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  516. ZoneServer* zone = lua_interface->GetZone(state);
  517. int32 location_id = lua_interface->GetInt32Value(state, 2);
  518. if (zone) {
  519. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  520. if (spawn) {
  521. lua_interface->SetSpawnValue(state, spawn);
  522. return 1;
  523. }
  524. }
  525. return 0;
  526. }
  527. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. if (spawn) {
  530. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  531. return 1;
  532. }
  533. return 0;
  534. }
  535. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  536. Spawn* spawn = lua_interface->GetSpawn(state);
  537. if (spawn) {
  538. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  539. return 1;
  540. }
  541. return 0;
  542. }
  543. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  544. Spawn* spawn = lua_interface->GetSpawn(state);
  545. if (spawn) {
  546. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  547. return 1;
  548. }
  549. return 0;
  550. }
  551. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  552. Spawn* spawn = lua_interface->GetSpawn(state);
  553. if (spawn) {
  554. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  555. return 1;
  556. }
  557. return 0;
  558. }
  559. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  560. Player* player = (Player*)lua_interface->GetSpawn(state);
  561. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  562. if (player && player->IsPlayer() && faction_id > 0) {
  563. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  564. return 1;
  565. }
  566. return 0;
  567. }
  568. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  569. if (!lua_interface)
  570. return 0;
  571. Spawn* spawn = lua_interface->GetSpawn(state);
  572. int32 value = lua_interface->GetInt32Value(state, 2);
  573. if (spawn) {
  574. spawn->SetFactionID(value);
  575. }
  576. return 0;
  577. }
  578. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  579. Spawn* spawn = lua_interface->GetSpawn(state);
  580. if (spawn) {
  581. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  582. return 1;
  583. }
  584. return 0;
  585. }
  586. int EQ2Emu_lua_GetGender(lua_State* state) {
  587. Spawn* spawn = lua_interface->GetSpawn(state);
  588. if (spawn) {
  589. lua_interface->SetInt32Value(state, spawn->GetGender());
  590. return 1;
  591. }
  592. return 0;
  593. }
  594. int EQ2Emu_lua_GetTarget(lua_State* state) {
  595. Spawn* spawn = lua_interface->GetSpawn(state);
  596. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  597. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  598. return 1;
  599. }
  600. return 0;
  601. }
  602. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  603. if (!lua_interface)
  604. return 0;
  605. Spawn* spawn = lua_interface->GetSpawn(state);
  606. string mp3_string = lua_interface->GetStringValue(state, 2);
  607. int32 key1 = lua_interface->GetInt32Value(state, 3);
  608. int32 key2 = lua_interface->GetInt32Value(state, 4);
  609. Spawn* player = lua_interface->GetSpawn(state, 5);
  610. if (spawn && mp3_string.length() > 0) {
  611. Client* client = 0;
  612. if (player && player->IsPlayer())
  613. client = spawn->GetZone()->GetClientBySpawn(player);
  614. if (client) {
  615. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  616. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  617. }
  618. else
  619. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  620. }
  621. return 0;
  622. }
  623. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  624. if (!lua_interface)
  625. return 0;
  626. Spawn* spawn = lua_interface->GetSpawn(state);
  627. if (spawn) {
  628. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  629. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  630. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  631. return 3;
  632. }
  633. return 0;
  634. }
  635. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  636. if (!lua_interface)
  637. return 0;
  638. Spawn* spawn = lua_interface->GetSpawn(state);
  639. if (spawn) {
  640. int32 item_id = lua_interface->GetInt32Value(state, 2);
  641. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  642. return 1;
  643. }
  644. return 0;
  645. }
  646. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  647. if (!lua_interface)
  648. return 0;
  649. Spawn* spawn = lua_interface->GetSpawn(state);
  650. if (spawn && spawn->IsEntity()) {
  651. int32 item_id = lua_interface->GetInt32Value(state, 2);
  652. int16 charges = lua_interface->GetInt16Value(state, 3);
  653. if (charges == 0)
  654. charges = 1;
  655. ((Entity*)spawn)->AddLootItem(item_id, charges);
  656. }
  657. return 0;
  658. }
  659. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  660. if (!lua_interface)
  661. return 0;
  662. Spawn* spawn = lua_interface->GetSpawn(state);
  663. if (spawn && spawn->IsEntity()) {
  664. int32 item_id = lua_interface->GetInt32Value(state, 2);
  665. spawn->LootItem(item_id);
  666. }
  667. return 0;
  668. }
  669. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  670. if (!lua_interface)
  671. return 0;
  672. Spawn* spawn = lua_interface->GetSpawn(state);
  673. if (spawn) {
  674. int32 val = lua_interface->GetInt32Value(state, 2);
  675. spawn->AddLootCoins(val);
  676. }
  677. return 0;
  678. }
  679. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  680. if (!lua_interface)
  681. return 0;
  682. Spawn* entity = lua_interface->GetSpawn(state);
  683. Spawn* player = lua_interface->GetSpawn(state, 2);
  684. if (entity && player && player->IsPlayer()) {
  685. int32 coins = lua_interface->GetInt32Value(state, 3);
  686. vector<Item*>* items = 0;
  687. int i = 0;
  688. int32 item_id = 0;
  689. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  690. if (items == 0)
  691. items = new vector<Item*>;
  692. if (master_item_list.GetItem(item_id))
  693. items->push_back(master_item_list.GetItem(item_id));
  694. i++;
  695. }
  696. Client* client = 0;
  697. client = player->GetZone()->GetClientBySpawn(player);
  698. if (client)
  699. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  700. if(coins > 0)
  701. entity->AddLootCoins(coins);
  702. safe_delete(items);
  703. }
  704. return 0;
  705. }
  706. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  707. if (!lua_interface)
  708. return 0;
  709. Spawn* entity = lua_interface->GetSpawn(state);
  710. Spawn* player = lua_interface->GetSpawn(state, 2);
  711. int32 item_id = lua_interface->GetInt32Value(state, 3);
  712. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  713. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  714. return 1;
  715. }
  716. return 0;
  717. }
  718. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  719. if (!lua_interface)
  720. return 0;
  721. Spawn* entity = lua_interface->GetSpawn(state);
  722. Spawn* player = lua_interface->GetSpawn(state, 2);
  723. if (entity && player && player->IsPlayer()) {
  724. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  725. return 1;
  726. }
  727. return 0;
  728. }
  729. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  730. if (!lua_interface)
  731. return 0;
  732. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  733. safe_delete(conversation);
  734. conversation = new vector<ConversationOption>();
  735. lua_interface->SetConversationValue(state, conversation);
  736. return 1;
  737. }
  738. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  739. if (!lua_interface)
  740. return 0;
  741. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  742. if (conversation) {
  743. ConversationOption conv_option;
  744. conv_option.option = lua_interface->GetStringValue(state, 2);
  745. conv_option.function = lua_interface->GetStringValue(state, 3);
  746. if (conv_option.option.length() > 0)
  747. conversation->push_back(conv_option);
  748. }
  749. return 0;
  750. }
  751. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  752. if (!lua_interface)
  753. return 0;
  754. Spawn* npc = lua_interface->GetSpawn(state);
  755. Spawn* player = lua_interface->GetSpawn(state, 2);
  756. if (npc && player && player->IsPlayer() && player->GetZone()) {
  757. Client* client = player->GetZone()->GetClientBySpawn(player);
  758. if (client) {
  759. int32 conversation_id = client->GetConversationID(npc, 0);
  760. client->CloseDialog(conversation_id);
  761. }
  762. }
  763. return 0;
  764. }
  765. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  766. if (!lua_interface)
  767. return 0;
  768. Item* item = lua_interface->GetItem(state);
  769. Spawn* player = lua_interface->GetSpawn(state, 2);
  770. if (item && player && player->IsPlayer() && player->GetZone()) {
  771. Client* client = player->GetZone()->GetClientBySpawn(player);
  772. if (client) {
  773. int32 conversation_id = client->GetConversationID(0, item);
  774. client->CloseDialog(conversation_id);
  775. }
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  783. Spawn* spawn = 0;
  784. Item* item = 0;
  785. int8 type = lua_interface->GetInt8Value(state, 2);
  786. if (type == 1 || type == 3)
  787. spawn = lua_interface->GetSpawn(state, 3);
  788. else if (type == 2 || type == 4)
  789. item = lua_interface->GetItem(state, 3);
  790. Spawn* player = lua_interface->GetSpawn(state, 4);
  791. string text = lua_interface->GetStringValue(state, 5);
  792. string mp3 = lua_interface->GetStringValue(state, 6);
  793. int32 key1 = lua_interface->GetInt32Value(state, 7);
  794. int32 key2 = lua_interface->GetInt32Value(state, 8);
  795. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  796. Client* client = player->GetZone()->GetClientBySpawn(player);
  797. if (client) {
  798. if (spawn) {
  799. // Need to do this so the function works the same as it did before
  800. if (type == 1)
  801. type++;
  802. if (mp3.length() > 0)
  803. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  804. else
  805. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  806. }
  807. else {
  808. if (mp3.length() > 0)
  809. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  810. else
  811. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  812. }
  813. }
  814. }
  815. safe_delete(conversation);
  816. lua_interface->SetConversationValue(state, NULL);
  817. return 0;
  818. }
  819. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  820. if(!lua_interface)
  821. return 0;
  822. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  823. Item* item = lua_interface->GetItem(state, 2);
  824. Spawn* player = lua_interface->GetSpawn(state, 3);
  825. string text = lua_interface->GetStringValue(state, 4);
  826. string mp3 = lua_interface->GetStringValue(state, 5);
  827. int32 key1 = lua_interface->GetInt32Value(state, 6);
  828. int32 key2 = lua_interface->GetInt32Value(state, 7);
  829. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  830. Client* client = player->GetZone()->GetClientBySpawn(player);
  831. if(client){
  832. if(mp3.length() > 0)
  833. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  834. else
  835. client->DisplayConversation(item, conversation, (char*)text.c_str());
  836. }
  837. safe_delete(conversation);
  838. }
  839. return 0;
  840. }*/
  841. int EQ2Emu_lua_StartConversation(lua_State* state) {
  842. if (!lua_interface)
  843. return 0;
  844. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  845. Spawn* source = lua_interface->GetSpawn(state, 2);
  846. Spawn* player = lua_interface->GetSpawn(state, 3);
  847. string text = lua_interface->GetStringValue(state, 4);
  848. string mp3 = lua_interface->GetStringValue(state, 5);
  849. int32 key1 = lua_interface->GetInt32Value(state, 6);
  850. int32 key2 = lua_interface->GetInt32Value(state, 7);
  851. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  852. Client* client = source->GetZone()->GetClientBySpawn(player);
  853. if (mp3.length() > 0)
  854. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  855. else
  856. client->DisplayConversation(source, 1, conversation, text.c_str());
  857. safe_delete(conversation);
  858. lua_interface->SetConversationValue(state, NULL);
  859. }
  860. else
  861. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  862. return 0;
  863. }
  864. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  865. if (!lua_interface)
  866. return 0;
  867. Spawn* spawn = lua_interface->GetSpawn(state);
  868. float distance = lua_interface->GetFloatValue(state, 2);
  869. string in_range_function = lua_interface->GetStringValue(state, 3);
  870. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  871. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  872. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  876. ZoneServer* zone = lua_interface->GetZone(state);
  877. float x = lua_interface->GetFloatValue(state, 2);
  878. float y = lua_interface->GetFloatValue(state, 3);
  879. float z = lua_interface->GetFloatValue(state, 4);
  880. float max_variation = lua_interface->GetFloatValue(state, 5);
  881. string in_range_function = lua_interface->GetStringValue(state, 6);
  882. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  883. if (zone && in_range_function.length() > 0)
  884. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  885. return 0;
  886. }
  887. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  888. if (!lua_interface)
  889. return 0;
  890. Spawn* spawn = lua_interface->GetSpawn(state);
  891. if (spawn && spawn->IsEntity()) {
  892. int32 val = lua_interface->GetInt32Value(state, 2);
  893. ((Entity*)spawn)->SetLootCoins(val);
  894. }
  895. return 0;
  896. }
  897. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  898. if (!lua_interface)
  899. return 0;
  900. Spawn* spawn = lua_interface->GetSpawn(state);
  901. if (spawn && spawn->IsEntity()) {
  902. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  903. return 1;
  904. }
  905. return 0;
  906. }
  907. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. Spawn* spawn = lua_interface->GetSpawn(state);
  911. float x = lua_interface->GetFloatValue(state, 2);
  912. float y = lua_interface->GetFloatValue(state, 3);
  913. float z = lua_interface->GetFloatValue(state, 4);
  914. float speed = lua_interface->GetFloatValue(state, 5);
  915. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  916. string function = lua_interface->GetStringValue(state, 7);
  917. if (spawn) {
  918. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  919. spawn->GetZone()->AddMovementNPC(spawn);
  920. }
  921. lua_interface->ResetFunctionStack(state);
  922. return 0;
  923. }
  924. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  925. if (!lua_interface)
  926. return 0;
  927. Spawn* spawn = lua_interface->GetSpawn(state);
  928. if (spawn) {
  929. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  930. return 1;
  931. }
  932. return 0;
  933. }
  934. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  935. if (!lua_interface)
  936. return 0;
  937. Spawn* spawn = lua_interface->GetSpawn(state);
  938. Spawn* target = lua_interface->GetSpawn(state, 2);
  939. if (spawn && target) {
  940. if (spawn->IsEntity())
  941. // ((Entity*)spawn)->FaceTarget(target);
  942. static_cast<Entity*>(spawn)->FaceTarget(target);
  943. }
  944. lua_interface->ResetFunctionStack(state);
  945. return 0;
  946. }
  947. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  948. if (!lua_interface)
  949. return 0;
  950. Spawn* spawn = lua_interface->GetSpawn(state);
  951. float x = lua_interface->GetFloatValue(state, 2);
  952. float y = lua_interface->GetFloatValue(state, 3);
  953. float z = lua_interface->GetFloatValue(state, 4);
  954. float speed = lua_interface->GetFloatValue(state, 5);
  955. string lua_function = lua_interface->GetStringValue(state, 6);
  956. bool more_points = lua_interface->GetBooleanValue(state, 7);
  957. if (spawn) {
  958. if (speed == 0)
  959. speed = spawn->GetSpeed();
  960. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  961. }
  962. lua_interface->ResetFunctionStack(state);
  963. return 0;
  964. }
  965. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  966. if (!lua_interface)
  967. return 0;
  968. Spawn* spawn = lua_interface->GetSpawn(state);
  969. if (spawn) {
  970. spawn->ClearRunningLocations();
  971. }
  972. return 0;
  973. }
  974. int EQ2Emu_lua_Say(lua_State* state) {
  975. if (!lua_interface)
  976. return 0;
  977. Spawn* spawn = lua_interface->GetSpawn(state);
  978. string message = lua_interface->GetStringValue(state, 2);
  979. Spawn* player = lua_interface->GetSpawn(state, 3);
  980. int32 language = lua_interface->GetInt32Value(state, 4);
  981. if (spawn && message.length() > 0) {
  982. Client* client = 0;
  983. if (player && player->IsPlayer())
  984. client = spawn->GetZone()->GetClientBySpawn(player);
  985. if (client)
  986. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  987. else
  988. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  989. }
  990. lua_interface->ResetFunctionStack(state);
  991. return 0;
  992. }
  993. int EQ2Emu_lua_Shout(lua_State* state) {
  994. if (!lua_interface)
  995. return 0;
  996. Spawn* spawn = lua_interface->GetSpawn(state);
  997. string message = lua_interface->GetStringValue(state, 2);
  998. Spawn* player = lua_interface->GetSpawn(state, 3);
  999. if (spawn && message.length() > 0) {
  1000. Client* client = 0;
  1001. if (player && player->IsPlayer())
  1002. client = spawn->GetZone()->GetClientBySpawn(player);
  1003. if (client)
  1004. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1005. else
  1006. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1007. }
  1008. lua_interface->ResetFunctionStack(state);
  1009. return 0;
  1010. }
  1011. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1012. if (!lua_interface)
  1013. return 0;
  1014. Spawn* spawn = lua_interface->GetSpawn(state);
  1015. string message = lua_interface->GetStringValue(state, 2);
  1016. Spawn* player = lua_interface->GetSpawn(state, 3);
  1017. if (spawn && message.length() > 0) {
  1018. Client* client = 0;
  1019. if (player && player->IsPlayer())
  1020. client = spawn->GetZone()->GetClientBySpawn(player);
  1021. if (client)
  1022. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1023. else
  1024. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1025. }
  1026. lua_interface->ResetFunctionStack(state);
  1027. return 0;
  1028. }
  1029. int EQ2Emu_lua_Emote(lua_State* state) {
  1030. if (!lua_interface)
  1031. return 0;
  1032. Spawn* spawn = lua_interface->GetSpawn(state);
  1033. string message = lua_interface->GetStringValue(state, 2);
  1034. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1035. Spawn* player = lua_interface->GetSpawn(state, 4);
  1036. char* to = 0;
  1037. if (spawn2)
  1038. to = spawn2->GetName();
  1039. if (spawn && message.length() > 0) {
  1040. Client* client = 0;
  1041. if (player && player->IsPlayer())
  1042. client = spawn->GetZone()->GetClientBySpawn(player);
  1043. if (client)
  1044. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1045. else
  1046. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1047. }
  1048. lua_interface->ResetFunctionStack(state);
  1049. return 0;
  1050. }
  1051. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1052. if (!lua_interface)
  1053. return 0;
  1054. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1055. if (!luaspell)
  1056. return 0;
  1057. Spawn* caster = luaspell->caster;
  1058. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1059. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1060. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1061. Spawn* target = lua_interface->GetSpawn(state, 4);
  1062. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1063. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1064. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1065. lua_interface->ResetFunctionStack(state);
  1066. boost::to_lower(heal_type);
  1067. if (caster && caster->IsEntity()) {
  1068. bool success = false;
  1069. luaspell->resisted = false;
  1070. if (target) {
  1071. float distance = caster->GetDistance(target, true);
  1072. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1073. success = true;
  1074. }
  1075. if (luaspell->targets.size() > 0) {
  1076. Spawn* target = 0;
  1077. ZoneServer* zone = luaspell->caster->GetZone();
  1078. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1079. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1080. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1081. float distance = caster->GetDistance(target, true);
  1082. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1083. }
  1084. }
  1085. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1086. success = true;
  1087. }
  1088. if (success) {
  1089. if (caster->GetZone())
  1090. caster->GetZone()->TriggerCharSheetTimer();
  1091. }
  1092. }
  1093. return 0;
  1094. }
  1095. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1096. if (!lua_interface)
  1097. return 0;
  1098. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1099. if (!luaspell)
  1100. return 0;
  1101. Spawn* caster = luaspell->caster;
  1102. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1103. float percentage = lua_interface->GetFloatValue(state, 2);
  1104. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1105. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1106. Spawn* target = lua_interface->GetSpawn(state, 5);
  1107. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1108. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1109. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1110. lua_interface->ResetFunctionStack(state);
  1111. boost::to_lower(heal_type);
  1112. int32 min_heal = 0, max_heal = 0;
  1113. if (caster && caster->IsEntity() && target) {
  1114. if(percentage <= 0.0f)
  1115. {
  1116. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1117. return 0;
  1118. }
  1119. if(heal_type == "power")
  1120. {
  1121. if(current_value)
  1122. {
  1123. if(caster_value)
  1124. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1125. else
  1126. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1127. }
  1128. else
  1129. {
  1130. if(caster_value)
  1131. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1132. else
  1133. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1134. }
  1135. }
  1136. else
  1137. {
  1138. if(current_value)
  1139. {
  1140. if(caster_value)
  1141. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1142. else
  1143. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1144. }
  1145. else
  1146. {
  1147. if(caster_value)
  1148. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1149. else
  1150. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1151. }
  1152. }
  1153. bool success = false;
  1154. luaspell->resisted = false;
  1155. if (target) {
  1156. float distance = caster->GetDistance(target, true);
  1157. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1158. success = true;
  1159. }
  1160. if (luaspell->targets.size() > 0) {
  1161. Spawn* target = 0;
  1162. ZoneServer* zone = luaspell->caster->GetZone();
  1163. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1164. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1165. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1166. float distance = caster->GetDistance(target, true);
  1167. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1168. }
  1169. }
  1170. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1171. success = true;
  1172. }
  1173. if (success) {
  1174. if (caster->GetZone())
  1175. caster->GetZone()->TriggerCharSheetTimer();
  1176. }
  1177. }
  1178. return 0;
  1179. }
  1180. int EQ2Emu_lua_AddItem(lua_State* state) {
  1181. if (!lua_interface)
  1182. return 0;
  1183. Spawn* spawn = lua_interface->GetSpawn(state);
  1184. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1185. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1186. // default of 1 quantity to add
  1187. if (quantity == 0)
  1188. quantity = 1;
  1189. if (spawn && spawn->IsPlayer()) {
  1190. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1191. if (client && item_id > 0) {
  1192. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1193. return 1;
  1194. }
  1195. }
  1196. lua_interface->SetBooleanValue(state, false);
  1197. return 1;
  1198. }
  1199. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1204. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1205. string location = lua_interface->GetStringValue(state, 4);
  1206. if (spawn && spawn->IsPlayer()) {
  1207. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1208. if (client && item_id > 0) {
  1209. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1210. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1211. else
  1212. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1213. if (send_messages) {
  1214. Item* item = master_item_list.GetItem(item_id);
  1215. if (item) {
  1216. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1217. string popup_text = "You receive " + item->name;
  1218. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1219. }
  1220. }
  1221. return 1;
  1222. }
  1223. }
  1224. lua_interface->SetBooleanValue(state, false);
  1225. return 1;
  1226. }
  1227. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1228. Spawn* spawn = lua_interface->GetSpawn(state);
  1229. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1230. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1231. // default of 1 to remove
  1232. if (quantity == 0)
  1233. quantity = 1;
  1234. Client* client;
  1235. Item* item;
  1236. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1237. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1238. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1239. if (client->RemoveItem(item, quantity)) {
  1240. lua_interface->SetBooleanValue(state, true);
  1241. return 1;
  1242. }
  1243. }
  1244. }
  1245. }
  1246. lua_interface->SetBooleanValue(state, false);
  1247. return 1;
  1248. }
  1249. int EQ2Emu_lua_HasItem(lua_State* state) {
  1250. Spawn* player = lua_interface->GetSpawn(state);
  1251. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1252. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1253. if (player && player->IsPlayer()) {
  1254. bool hasItem = false;
  1255. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1256. if (!hasItem)
  1257. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1258. lua_interface->SetBooleanValue(state, hasItem);
  1259. return 1;
  1260. }
  1261. lua_interface->SetBooleanValue(state, false);
  1262. return 1;
  1263. }
  1264. int EQ2Emu_lua_Spawn(lua_State* state) {
  1265. if (!lua_interface)
  1266. return 0;
  1267. ZoneServer* zone = lua_interface->GetZone(state);
  1268. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1269. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1270. float x = lua_interface->GetFloatValue(state, 4);
  1271. float y = lua_interface->GetFloatValue(state, 5);
  1272. float z = lua_interface->GetFloatValue(state, 6);
  1273. float heading = lua_interface->GetFloatValue(state, 7);
  1274. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1275. Spawn* spawn = zone->GetSpawn(spawn_id);
  1276. if (!spawn)
  1277. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1278. else {
  1279. spawn->SetX(x);
  1280. spawn->SetZ(z);
  1281. spawn->SetY(y,true,true);
  1282. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1283. spawn->SetHeading(heading);
  1284. if (restricted_npc)
  1285. spawn->AddAllowAccessSpawn(spawn);
  1286. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1287. bool scriptActive = false;
  1288. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1289. scriptActive = true;
  1290. spawn->SetSpawnScript(string(spawn_script));
  1291. }
  1292. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1293. zone->AddSpawn(spawn);
  1294. if (scriptActive) {
  1295. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1296. }
  1297. lua_interface->SetSpawnValue(state, spawn);
  1298. return 1;
  1299. }
  1300. }
  1301. else {
  1302. string output = "Invalid paramaters to LUA Spawn command: \n";
  1303. if (!zone)
  1304. output = output.append("\t").append("Missing zone reference. \n");
  1305. if (spawn_id == 0)
  1306. output = output.append("\t").append("Missing spawn_id.");
  1307. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1308. }
  1309. return 0;
  1310. }
  1311. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1312. if (!lua_interface)
  1313. return 0;
  1314. ZoneServer* zone = lua_interface->GetZone(state);
  1315. if (zone) {
  1316. lua_interface->SetStringValue(state, zone->GetZoneName());
  1317. return 1;
  1318. }
  1319. return 0;
  1320. }
  1321. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1322. if (!lua_interface)
  1323. return 0;
  1324. ZoneServer* zone = lua_interface->GetZone(state);
  1325. if (zone) {
  1326. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1327. return 1;
  1328. }
  1329. return 0;
  1330. }
  1331. int EQ2Emu_lua_GetZone(lua_State* state) {
  1332. if (!lua_interface)
  1333. return 0;
  1334. int32 zone_id = lua_interface->GetInt32Value(state);
  1335. ZoneServer* zone = 0;
  1336. if (zone_id > 0)
  1337. zone = zone_list.Get(zone_id);
  1338. else {
  1339. string zone_name = lua_interface->GetStringValue(state);
  1340. if (zone_name.length() > 0) {
  1341. zone = zone_list.Get(zone_name.c_str());
  1342. }
  1343. else {
  1344. Spawn* spawn = lua_interface->GetSpawn(state);
  1345. if (spawn)
  1346. zone = spawn->GetZone();
  1347. }
  1348. }
  1349. if (zone) {
  1350. lua_interface->SetZoneValue(state, zone);
  1351. return 1;
  1352. }
  1353. return 0;
  1354. }
  1355. int EQ2Emu_lua_AddHate(lua_State* state) {
  1356. Spawn* entity = lua_interface->GetSpawn(state);
  1357. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1358. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1359. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1360. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1361. if (entity && entity->IsEntity() && amount != 0) {
  1362. if (luaspell) {
  1363. ZoneServer* zone = luaspell->caster->GetZone();
  1364. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1365. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1366. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1367. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1368. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1369. if (send_packet)
  1370. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1371. }
  1372. }
  1373. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1374. }
  1375. else if (npc && npc->IsNPC() && npc->GetZone())
  1376. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1377. }
  1378. return 0;
  1379. }
  1380. int EQ2Emu_lua_Zone(lua_State* state) {
  1381. if (!lua_interface)
  1382. return 0;
  1383. ZoneServer* zone = lua_interface->GetZone(state);
  1384. Spawn* player = lua_interface->GetSpawn(state, 2);
  1385. Client* client = 0;
  1386. if (player && player->IsPlayer())
  1387. client = player->GetZone()->GetClientBySpawn(player);
  1388. float x = lua_interface->GetFloatValue(state, 3);
  1389. float y = lua_interface->GetFloatValue(state, 4);
  1390. float z = lua_interface->GetFloatValue(state, 5);
  1391. float heading = lua_interface->GetFloatValue(state, 6);
  1392. if (zone && client) {
  1393. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1394. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1395. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1396. {
  1397. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1398. return 0;
  1399. }
  1400. if (x != 0 || y != 0 || z != 0) {
  1401. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1402. player->SetX(x);
  1403. player->SetY(y);
  1404. player->SetZ(z);
  1405. player->SetHeading(heading);
  1406. client->Zone(zone->GetZoneName(), false);
  1407. }
  1408. else
  1409. client->Zone(zone->GetZoneName());
  1410. }
  1411. else
  1412. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1413. return 0;
  1414. }
  1415. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1416. if (!lua_interface)
  1417. return 0;
  1418. Spawn* spawn = lua_interface->GetSpawn(state);
  1419. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1420. if (spawn && spawn2)
  1421. spawn->AddAllowAccessSpawn(spawn2);
  1422. return 0;
  1423. }
  1424. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1425. if (!lua_interface)
  1426. return 0;
  1427. Spawn* target = lua_interface->GetSpawn(state);
  1428. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1429. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1430. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1431. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1432. if (!target) {
  1433. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1434. return 0;
  1435. }
  1436. if (!target->IsEntity()) {
  1437. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1438. return 0;
  1439. }
  1440. if (spell_id <= 0) {
  1441. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1442. return 0;
  1443. }
  1444. if (caster && !caster->IsEntity()) {
  1445. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1446. return 0;
  1447. }
  1448. if (spell_tier == 0)
  1449. spell_tier = 1;
  1450. if (!caster)
  1451. caster = target;
  1452. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1453. return 0;
  1454. }
  1455. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1456. if (!lua_interface)
  1457. return 0;
  1458. Spawn* target = lua_interface->GetSpawn(state);
  1459. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1460. if (!luaspell)
  1461. return 0;
  1462. Spawn* caster = luaspell->caster;
  1463. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1464. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1465. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1466. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1467. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1468. //lua_interface->ResetFunctionStack(state);
  1469. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1470. vector<int16> faction_req;
  1471. vector<int16> race_req;
  1472. int32 class_req = 0;
  1473. int32 i = 0;
  1474. int8 f = 0;
  1475. int8 r = 0;
  1476. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1477. if (class_id < 100) {
  1478. class_req += pow(2.0, double(class_id - 1));
  1479. }
  1480. else if (class_id > 100 && class_id < 1000) {
  1481. race_req.push_back(class_id);
  1482. r++;
  1483. }
  1484. else {
  1485. faction_req.push_back(class_id);
  1486. f++;
  1487. }
  1488. i++;
  1489. }
  1490. if (caster && caster->IsEntity()) {
  1491. bool race_match = false;
  1492. bool success = false;
  1493. luaspell->resisted = false;
  1494. if (luaspell->targets.size() > 0) {
  1495. ZoneServer* zone = luaspell->caster->GetZone();
  1496. Spawn* target = 0;
  1497. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1498. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1499. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1500. if (race_req.size() > 0) {
  1501. for (int8 i = 0; i < race_req.size(); i++) {
  1502. if (target->GetLuaRaceId() == race_req[i]) {
  1503. race_match = true;
  1504. }
  1505. }
  1506. }
  1507. else
  1508. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1509. if (race_match == true) {
  1510. float distance = caster->GetDistance(target, true);
  1511. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1512. }
  1513. }
  1514. }
  1515. success = true;
  1516. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1517. }
  1518. else if (target) {
  1519. //check class and race/faction here
  1520. if (race_req.size() > 0) {
  1521. for (int8 i = 0; i < race_req.size(); i++) {
  1522. if (target->GetLuaRaceId() == race_req[i]) {
  1523. race_match = true;
  1524. }
  1525. }
  1526. }
  1527. else
  1528. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1529. if (race_match == true) {
  1530. float distance = caster->GetDistance(target, true);
  1531. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1532. success = true;
  1533. }
  1534. }
  1535. if (success) {
  1536. Spell* spell = luaspell->spell;
  1537. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1538. ((Player*)caster)->InCombat(true);
  1539. if (caster->GetZone())
  1540. caster->GetZone()->TriggerCharSheetTimer();
  1541. }
  1542. }
  1543. }
  1544. return 0;
  1545. }
  1546. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1547. if (!lua_interface)
  1548. return 0;
  1549. Spawn* spawn = lua_interface->GetSpawn(state);
  1550. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1551. lua_interface->ResetFunctionStack(state);
  1552. if (spawn && value != 0) {
  1553. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1554. spawn->SetPower(spawn->GetTotalPower());
  1555. else
  1556. spawn->SetPower(spawn->GetPower() + value);
  1557. }
  1558. return 0;
  1559. }
  1560. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1561. if (!lua_interface)
  1562. return 0;
  1563. Spawn* spawn = lua_interface->GetSpawn(state);
  1564. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (spawn && value != 0) {
  1567. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1568. spawn->SetHP(spawn->GetTotalHP());
  1569. else
  1570. spawn->SetHP(spawn->GetHP() + value);
  1571. }
  1572. return 0;
  1573. }
  1574. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1575. if (!lua_interface)
  1576. return 0;
  1577. Spawn* spawn = lua_interface->GetSpawn(state);
  1578. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1579. lua_interface->ResetFunctionStack(state);
  1580. if (spawn && value != 0) {
  1581. spawn->SetPower(spawn->GetPower() + value);
  1582. if (value > spawn->GetTotalHPBase())
  1583. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1584. }
  1585. return 0;
  1586. }
  1587. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1588. if (!lua_interface)
  1589. return 0;
  1590. Spawn* spawn = lua_interface->GetSpawn(state);
  1591. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1592. lua_interface->ResetFunctionStack(state);
  1593. if (spawn && value != 0) {
  1594. spawn->SetHP(spawn->GetHP() + value);
  1595. if (value > spawn->GetTotalHPBase())
  1596. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1597. }
  1598. return 0;
  1599. }
  1600. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1601. if (!lua_interface)
  1602. return 0;
  1603. Spawn* spawn = lua_interface->GetSpawn(state);
  1604. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1605. lua_interface->ResetFunctionStack(state);
  1606. if (spawn) {
  1607. spawn->SetHP(value);
  1608. if (value > spawn->GetTotalHPBase())
  1609. spawn->SetTotalHP(value);
  1610. }
  1611. return 0;
  1612. }
  1613. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1614. if (!lua_interface)
  1615. return 0;
  1616. Spawn* spawn = lua_interface->GetSpawn(state);
  1617. float value = lua_interface->GetFloatValue(state, 2);
  1618. lua_interface->ResetFunctionStack(state);
  1619. if (spawn && spawn->IsEntity() && value > 0)
  1620. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1621. if (spawn->IsPlayer())
  1622. ((Player*)spawn)->SetCharSheetChanged(true);
  1623. return 0;
  1624. }
  1625. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1626. if (!lua_interface)
  1627. return 0;
  1628. Spawn* spawn = lua_interface->GetSpawn(state);
  1629. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1630. lua_interface->ResetFunctionStack(state);
  1631. if (spawn && spawn->IsEntity() && value > 0)
  1632. ((Entity*)spawn)->SetTotalHPBase(value);
  1633. return 0;
  1634. }
  1635. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1636. if (!lua_interface)
  1637. return 0;
  1638. Spawn* spawn = lua_interface->GetSpawn(state);
  1639. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1640. lua_interface->ResetFunctionStack(state);
  1641. if (spawn && value > 0) {
  1642. spawn->SetPower(value);
  1643. if (value > spawn->GetTotalPowerBase())
  1644. spawn->SetTotalPower(value);
  1645. }
  1646. return 0;
  1647. }
  1648. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1649. if (!lua_interface)
  1650. return 0;
  1651. Spawn* spawn = lua_interface->GetSpawn(state);
  1652. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1653. lua_interface->ResetFunctionStack(state);
  1654. if (spawn && spawn->IsEntity() && value > 0)
  1655. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1656. return 0;
  1657. }
  1658. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1659. if (!lua_interface)
  1660. return 0;
  1661. Spawn* spawn = lua_interface->GetSpawn(state);
  1662. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (spawn && spawn->IsEntity() && value > 0)
  1665. ((Entity*)spawn)->SetTotalPowerBase(value);
  1666. return 0;
  1667. }
  1668. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1669. if (!lua_interface)
  1670. return 0;
  1671. Spawn* spawn = lua_interface->GetSpawn(state);
  1672. float x = lua_interface->GetFloatValue(state, 2);
  1673. float y = lua_interface->GetFloatValue(state, 3);
  1674. float z = lua_interface->GetFloatValue(state, 4);
  1675. float heading = lua_interface->GetFloatValue(state, 5);
  1676. lua_interface->ResetFunctionStack(state);
  1677. if (spawn) {
  1678. spawn->SetX(x);
  1679. spawn->SetY(y);
  1680. spawn->SetZ(z);
  1681. if (heading != 0)
  1682. spawn->SetHeading(heading);
  1683. spawn->SetSpawnOrigX(spawn->GetX());
  1684. spawn->SetSpawnOrigY(spawn->GetY());
  1685. spawn->SetSpawnOrigZ(spawn->GetZ());
  1686. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1687. if (spawn->IsPlayer()) {
  1688. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1689. if (client) {
  1690. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1691. client->QueuePacket(packet);
  1692. }
  1693. }
  1694. }
  1695. return 0;
  1696. }
  1697. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1698. if (!lua_interface)
  1699. return 0;
  1700. Spawn* spawn = lua_interface->GetSpawn(state);
  1701. float value = lua_interface->GetFloatValue(state, 2);
  1702. lua_interface->ResetFunctionStack(state);
  1703. if (spawn) {
  1704. spawn->SetHeading(value);
  1705. if (spawn->IsPlayer()) {
  1706. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1707. if (client) {
  1708. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1709. client->QueuePacket(packet);
  1710. }
  1711. }
  1712. }
  1713. return 0;
  1714. }
  1715. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1716. if (!lua_interface)
  1717. return 0;
  1718. Spawn* spawn = lua_interface->GetSpawn(state);
  1719. int16 value = lua_interface->GetInt16Value(state, 2);
  1720. lua_interface->ResetFunctionStack(state);
  1721. if (spawn)
  1722. spawn->SetModelType(value);
  1723. return 0;
  1724. }
  1725. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1726. if (!lua_interface)
  1727. return 0;
  1728. Spawn* spawn = lua_interface->GetSpawn(state);
  1729. int8 value = lua_interface->GetInt8Value(state, 2);
  1730. lua_interface->ResetFunctionStack(state);
  1731. if (spawn) {
  1732. if (spawn->IsPlayer())
  1733. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1734. else
  1735. spawn->SetAdventureClass(value);
  1736. }
  1737. return 0;
  1738. }
  1739. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1740. if (!lua_interface)
  1741. return 0;
  1742. Spawn* spawn = lua_interface->GetSpawn(state);
  1743. int8 value = lua_interface->GetInt8Value(state, 2);
  1744. lua_interface->ResetFunctionStack(state);
  1745. if (spawn) {
  1746. spawn->SetTradeskillClass(value);
  1747. if (spawn->IsEntity()) {
  1748. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1749. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1750. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1751. }
  1752. if (spawn->IsPlayer())
  1753. ((Player*)spawn)->SetCharSheetChanged(true);
  1754. }
  1755. return 0;
  1756. }
  1757. int EQ2Emu_lua_SetMount(lua_State* state) {
  1758. if (!lua_interface)
  1759. return 0;
  1760. Spawn* spawn = lua_interface->GetSpawn(state);
  1761. int16 value = lua_interface->GetInt16Value(state, 2);
  1762. if (spawn && spawn->IsEntity()) {
  1763. ((Entity*)spawn)->SetMount(value);
  1764. EQ2_Color color;
  1765. color.red = 255;
  1766. color.green = 255;
  1767. color.blue = 255;
  1768. ((Entity*)spawn)->SetMountColor(&color);
  1769. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1770. }
  1771. return 0;
  1772. }
  1773. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1774. if (!lua_interface)
  1775. return 0;
  1776. Spawn* spawn = lua_interface->GetSpawn(state);
  1777. EQ2_Color mount_color;
  1778. EQ2_Color saddle_color;
  1779. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1780. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1781. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1782. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1783. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1784. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1785. if (spawn && spawn->IsEntity()) {
  1786. ((Entity*)spawn)->SetMountColor(&mount_color);
  1787. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1788. }
  1789. return 0;
  1790. }
  1791. int EQ2Emu_lua_GetMount(lua_State* state) {
  1792. if (!lua_interface)
  1793. return 0;
  1794. Spawn* spawn = lua_interface->GetSpawn(state);
  1795. if (spawn && spawn->IsEntity()) {
  1796. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1797. return 1;
  1798. }
  1799. return 0;
  1800. }
  1801. int EQ2Emu_lua_GetRace(lua_State* state) {
  1802. if (!lua_interface)
  1803. return 0;
  1804. Spawn* spawn = lua_interface->GetSpawn(state);
  1805. if (spawn)
  1806. {
  1807. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1808. lua_interface->SetInt32Value(state, spawn->GetRace());
  1809. return 1;
  1810. }
  1811. return 0;
  1812. }
  1813. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1814. if (!lua_interface)
  1815. return 0;
  1816. Spawn* spawn = lua_interface->GetSpawn(state);
  1817. if (spawn) {
  1818. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1819. return 1;
  1820. }
  1821. return 0;
  1822. }
  1823. int EQ2Emu_lua_GetClass(lua_State* state) {
  1824. Spawn* spawn = lua_interface->GetSpawn(state);
  1825. if (spawn) {
  1826. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1827. return 1;
  1828. }
  1829. return 0;
  1830. }
  1831. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1832. Spawn* spawn = lua_interface->GetSpawn(state);
  1833. if (spawn) {
  1834. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1835. return 1;
  1836. }
  1837. return 0;
  1838. }
  1839. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1840. if (!lua_interface)
  1841. return 0;
  1842. Spawn* spawn = lua_interface->GetSpawn(state);
  1843. float value = lua_interface->GetFloatValue(state, 2);
  1844. lua_interface->ResetFunctionStack(state);
  1845. if (spawn) {
  1846. spawn->SetSpeed(value);
  1847. ((Entity*)spawn)->SetSpeed(value);
  1848. if (spawn->IsPlayer()) {
  1849. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1850. if (client) {
  1851. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1852. if (packet) {
  1853. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1854. packet->setDataByName("speed", value);
  1855. packet->setDataByName("size", 0.51);
  1856. EQ2Packet* app = packet->serialize();
  1857. client->QueuePacket(app);
  1858. safe_delete(packet);
  1859. }
  1860. }
  1861. }
  1862. }
  1863. return 0;
  1864. }
  1865. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1866. if (!lua_interface)
  1867. return 0;
  1868. Spawn* spawn = lua_interface->GetSpawn(state);
  1869. const int16 type = lua_interface->GetInt16Value(state, 2);
  1870. const float value = lua_interface->GetFloatValue(state, 3);
  1871. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1872. int64 class_req = 0;
  1873. int32 class_id = 0;
  1874. vector<int16> faction_req;
  1875. vector<int16> race_req;
  1876. int32 i = 0;
  1877. int8 f = 0;
  1878. int8 r = 0;
  1879. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1880. if (class_id < 100) {
  1881. class_req += pow(2.0, double(class_id - 1));
  1882. }
  1883. else if (class_id > 100 && class_id < 1000) {
  1884. race_req.push_back(class_id);
  1885. r++;
  1886. }
  1887. else {
  1888. faction_req.push_back(class_id);
  1889. f++;
  1890. }
  1891. i++;
  1892. }
  1893. if (value != 0 && type >= 0) {
  1894. if (luaspell && luaspell->spell && luaspell->caster) {
  1895. ZoneServer* zone = luaspell->caster->GetZone();
  1896. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1897. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1898. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1899. if (target) {
  1900. if (target->IsPlayer()) {
  1901. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1902. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1903. if (((Player*)target)->GetGroupMemberInfo())
  1904. ((Player*)target)->UpdateGroupMemberInfo();
  1905. ((Player*)target)->SetCharSheetChanged(true);
  1906. }
  1907. else if (target->IsNPC())
  1908. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1909. else
  1910. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1911. }
  1912. }
  1913. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1914. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1915. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1916. }
  1917. else if (spawn && spawn->IsEntity()) {
  1918. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1919. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1920. if (spawn->IsPlayer())
  1921. ((Player*)spawn)->SetCharSheetChanged(true);
  1922. }
  1923. else
  1924. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1925. }
  1926. else
  1927. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1928. return 0;
  1929. }
  1930. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1931. if (!lua_interface)
  1932. return 0;
  1933. Spawn* spawn = lua_interface->GetSpawn(state);
  1934. int16 type = lua_interface->GetInt16Value(state, 2);
  1935. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1936. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1937. if (!spawn) {
  1938. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1939. return 0;
  1940. }
  1941. if (!spawn->IsEntity()) {
  1942. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1943. return 0;
  1944. }
  1945. if (value == 0) {
  1946. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1947. return 0;
  1948. }
  1949. if (!luaspell || !luaspell->spell) {
  1950. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1951. return 0;
  1952. }
  1953. int32 class_req = 0;
  1954. vector<int16> faction_req;
  1955. vector<int16> race_req;
  1956. int32 class_id = 0;
  1957. int32 i = 0;
  1958. int8 f = 0;
  1959. int8 r = 0;
  1960. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1961. if (class_id < 100) {
  1962. class_req += pow(2.0, double(class_id - 1));
  1963. }
  1964. else if (class_id > 100 && class_id < 1000) {
  1965. race_req.push_back(class_id);
  1966. r++;
  1967. }
  1968. else {
  1969. faction_req.push_back(class_id);
  1970. f++;
  1971. }
  1972. i++;
  1973. }
  1974. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1975. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1976. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1977. if (spawn->IsPlayer())
  1978. ((Player*)spawn)->SetCharSheetChanged(true);
  1979. return 0;
  1980. }
  1981. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1982. if (!lua_interface)
  1983. return 0;
  1984. Spawn* spawn = lua_interface->GetSpawn(state);
  1985. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1986. if (luaspell && luaspell->spell) {
  1987. ZoneServer* zone = luaspell->caster->GetZone();
  1988. Spawn* target = 0;
  1989. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1990. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1991. target = zone->GetSpawnByID(luaspell->targets[i]);
  1992. if (target && target->IsEntity()) {
  1993. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1994. if (target->IsPlayer())
  1995. ((Player*)target)->SetCharSheetChanged(true);
  1996. }
  1997. }
  1998. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1999. }
  2000. else if (spawn && spawn->IsEntity()) {
  2001. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2002. if (spawn->IsPlayer())
  2003. ((Player*)spawn)->SetCharSheetChanged(true);
  2004. }
  2005. return 0;
  2006. }
  2007. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2008. if (!lua_interface)
  2009. return 0;
  2010. Spawn* spawn = lua_interface->GetSpawn(state);
  2011. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2012. float value = lua_interface->GetFloatValue(state, 3);
  2013. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2014. if (value != 0) {
  2015. int32 spell_id = 0;
  2016. if (luaspell && luaspell->spell && luaspell->caster) {
  2017. spell_id = luaspell->spell->GetSpellID();
  2018. ZoneServer* zone = luaspell->caster->GetZone();
  2019. Spawn* target = 0;
  2020. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2021. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2022. target = zone->GetSpawnByID(luaspell->targets[i]);
  2023. if (target && target->Alive()) {
  2024. if (target->IsPlayer()) {
  2025. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2026. Client* client = target->GetZone()->GetClientBySpawn(target);
  2027. if (client) {
  2028. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2029. if (packet)
  2030. client->QueuePacket(packet);
  2031. }
  2032. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2033. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2034. }
  2035. else if (target->IsNPC()) {
  2036. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2037. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2038. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2039. }
  2040. else
  2041. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2042. }
  2043. }
  2044. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2045. }
  2046. else if (spawn) {
  2047. if (spawn->IsPlayer()) {
  2048. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2049. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2050. if (client) {
  2051. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2052. if (packet)
  2053. client->QueuePacket(packet);
  2054. }
  2055. }
  2056. else if (spawn->IsNPC())
  2057. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2058. else
  2059. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2060. }
  2061. }
  2062. else
  2063. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2064. return 0;
  2065. }
  2066. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2067. if (!lua_interface)
  2068. return 0;
  2069. Spawn* spawn = lua_interface->GetSpawn(state);
  2070. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2071. if (spawn && spawn->IsPlayer()) {
  2072. int32 spell_id = 0;
  2073. if (luaspell && luaspell->spell) {
  2074. spell_id = luaspell->spell->GetSpellID();
  2075. ZoneServer* zone = luaspell->caster->GetZone();
  2076. Spawn* target = 0;
  2077. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2078. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2079. target = zone->GetSpawnByID(luaspell->targets[i]);
  2080. if (target) {
  2081. if (target->IsPlayer()) {
  2082. ((Player*)target)->RemoveSkillBonus(spell_id);
  2083. Client* client = target->GetZone()->GetClientBySpawn(target);
  2084. if (client) {
  2085. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2086. if (packet)
  2087. client->QueuePacket(packet);
  2088. }
  2089. }
  2090. else if (target->IsNPC())
  2091. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2092. else
  2093. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2094. }
  2095. }
  2096. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2097. }
  2098. else if (spawn) {
  2099. if (spawn->IsPlayer()) {
  2100. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2101. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2102. if (client) {
  2103. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2104. if (packet)
  2105. client->QueuePacket(packet);
  2106. }
  2107. }
  2108. else if (spawn->IsNPC())
  2109. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2110. else
  2111. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2112. }
  2113. }
  2114. return 0;
  2115. }
  2116. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2117. if (!lua_interface)
  2118. return 0;
  2119. Spawn* spawn = lua_interface->GetSpawn(state);
  2120. int8 type = lua_interface->GetInt32Value(state, 2);
  2121. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2122. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2123. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2124. ZoneServer* zone = luaspell->caster->GetZone();
  2125. Spawn* target = 0;
  2126. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2127. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2128. target = zone->GetSpawnByID(luaspell->targets[i]);
  2129. if (target && target->IsEntity()) {
  2130. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2131. ((Entity*)target)->AddMezSpell(luaspell);
  2132. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2133. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2134. if (target->IsNPC())
  2135. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2136. }
  2137. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2138. ((Entity*)target)->AddStifleSpell(luaspell);
  2139. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2140. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2141. if (target->IsNPC())
  2142. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2143. }
  2144. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2145. ((Entity*)target)->AddDazeSpell(luaspell);
  2146. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2147. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2148. if (target->IsNPC())
  2149. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2150. }
  2151. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2152. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2153. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2154. ((Entity*)target)->AddStunSpell(luaspell);
  2155. if (target->IsNPC())
  2156. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2157. }
  2158. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2159. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2160. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2161. ((Entity*)target)->AddRootSpell(luaspell);
  2162. if (target->IsNPC())
  2163. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2164. }
  2165. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2166. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2167. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2168. ((Entity*)target)->AddFearSpell(luaspell);
  2169. if (target->IsNPC())
  2170. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2171. }
  2172. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2173. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2174. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2175. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2176. }
  2177. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2178. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2179. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2180. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2181. }
  2182. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2183. ((Entity*)target)->AddSnareSpell(luaspell);
  2184. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2185. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2186. if (target->IsNPC())
  2187. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2188. }
  2189. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2190. ((Entity*)target)->AddFlightSpell(luaspell);
  2191. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2192. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2193. }
  2194. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2195. ((Entity*)target)->AddGlideSpell(luaspell);
  2196. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2197. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2198. }
  2199. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2200. ((Entity*)target)->AddSafefallSpell(luaspell);
  2201. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2202. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2203. }
  2204. else
  2205. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2206. }
  2207. else
  2208. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2209. }
  2210. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2211. }
  2212. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2213. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2214. ((Entity*)spawn)->AddMezSpell(luaspell);
  2215. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2216. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2217. }
  2218. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2219. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2220. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2221. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2222. }
  2223. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2224. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2225. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2226. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2227. }
  2228. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2229. ((Entity*)spawn)->AddStunSpell(luaspell);
  2230. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2231. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2232. }
  2233. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2234. ((Entity*)spawn)->AddRootSpell(luaspell);
  2235. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2236. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2237. }
  2238. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2239. ((Entity*)spawn)->AddFearSpell(luaspell);
  2240. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2241. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2242. }
  2243. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2244. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2245. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2246. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2247. }
  2248. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2249. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2250. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2251. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2252. }
  2253. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2254. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2255. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2256. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2257. }
  2258. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2259. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2260. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2261. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2262. }
  2263. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2264. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2265. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2266. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2267. }
  2268. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2269. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2270. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2271. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2272. }
  2273. else
  2274. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2275. }
  2276. else
  2277. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2278. return 0;
  2279. }
  2280. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2281. if (!lua_interface)
  2282. return 0;
  2283. Spawn* spawn = lua_interface->GetSpawn(state);
  2284. int8 type = lua_interface->GetInt8Value(state, 2);
  2285. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2286. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2287. if (spawn && spawn->IsEntity()) {
  2288. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2289. ZoneServer* zone = luaspell->caster->GetZone();
  2290. Spawn* target = 0;
  2291. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2292. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2293. target = zone->GetSpawnByID(luaspell->targets[i]);
  2294. if (target) {
  2295. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2296. ((Entity*)target)->RemoveMezSpell(luaspell);
  2297. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2298. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2299. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2300. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2301. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2302. ((Entity*)target)->RemoveStunSpell(luaspell);
  2303. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2304. ((Entity*)target)->RemoveRootSpell(luaspell);
  2305. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2306. ((Entity*)target)->RemoveFearSpell(luaspell);
  2307. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2308. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2309. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2310. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2311. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2312. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2313. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2314. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2315. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2316. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2317. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2318. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2319. else
  2320. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2321. }
  2322. }
  2323. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2324. }
  2325. else if (only_remove_spawn) {
  2326. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2327. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2328. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2329. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2330. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2331. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2332. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2333. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2334. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2335. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2336. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2337. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2338. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2339. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2340. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2341. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2342. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2343. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2344. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2345. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2346. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2347. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2348. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2349. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2350. else
  2351. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2352. }
  2353. }
  2354. return 0;
  2355. }
  2356. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2357. if (!lua_interface)
  2358. return 0;
  2359. Spawn* spawn = lua_interface->GetSpawn(state);
  2360. int8 type = lua_interface->GetInt8Value(state, 2);
  2361. bool hasEffect = false;
  2362. if (!spawn)
  2363. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2364. else if (!spawn->IsEntity())
  2365. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2366. else if (type < CONTROL_MAX_EFFECTS)
  2367. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2368. else
  2369. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2370. lua_interface->SetBooleanValue(state, hasEffect);
  2371. return 1;
  2372. }
  2373. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2374. if (!lua_interface)
  2375. return 0;
  2376. Spawn* spawn = lua_interface->GetSpawn(state);
  2377. float distance = 0.0f;
  2378. if (!spawn)
  2379. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2380. else if (!spawn->IsNPC())
  2381. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2382. else
  2383. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2384. lua_interface->SetFloatValue(state, distance);
  2385. return 1;
  2386. }
  2387. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2388. if (!lua_interface)
  2389. return 0;
  2390. Spawn* spawn = lua_interface->GetSpawn(state);
  2391. float distance = 0.0f;
  2392. if (!spawn)
  2393. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2394. else if (!spawn->IsNPC())
  2395. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2396. else
  2397. distance = ((NPC*)spawn)->GetAggroRadius();
  2398. lua_interface->SetFloatValue(state, distance);
  2399. return 1;
  2400. }
  2401. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2402. if (!lua_interface)
  2403. return 0;
  2404. Spawn* spawn = lua_interface->GetSpawn(state);
  2405. float distance = lua_interface->GetFloatValue(state, 2);
  2406. bool override = lua_interface->GetBooleanValue(state, 3);
  2407. bool result = false;
  2408. lua_interface->ResetFunctionStack(state);
  2409. if (!spawn)
  2410. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2411. else if (!spawn->IsNPC())
  2412. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2413. else
  2414. {
  2415. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2416. result = true;
  2417. }
  2418. lua_interface->SetBooleanValue(state, result);
  2419. return 1;
  2420. }
  2421. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2422. if (!lua_interface)
  2423. return 0;
  2424. Spawn* spawn = lua_interface->GetSpawn(state);
  2425. int16 value = lua_interface->GetInt16Value(state, 2);
  2426. if (spawn && spawn->IsEntity()) {
  2427. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2428. if (spawn->IsPlayer())
  2429. ((Player*)spawn)->SetCharSheetChanged(true);
  2430. }
  2431. return 0;
  2432. }
  2433. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2434. if (!lua_interface)
  2435. return 0;
  2436. Spawn* spawn = lua_interface->GetSpawn(state);
  2437. int16 value = lua_interface->GetInt16Value(state, 2);
  2438. if (spawn && spawn->IsEntity()) {
  2439. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2440. if (spawn->IsPlayer())
  2441. ((Player*)spawn)->SetCharSheetChanged(true);
  2442. }
  2443. return 0;
  2444. }
  2445. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2446. if (!lua_interface)
  2447. return 0;
  2448. Spawn* spawn = lua_interface->GetSpawn(state);
  2449. int16 value = lua_interface->GetInt16Value(state, 2);
  2450. if (spawn && spawn->IsEntity()) {
  2451. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2452. if (spawn->IsPlayer())
  2453. ((Player*)spawn)->SetCharSheetChanged(true);
  2454. }
  2455. return 0;
  2456. }
  2457. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2458. if (!lua_interface)
  2459. return 0;
  2460. Spawn* spawn = lua_interface->GetSpawn(state);
  2461. int16 value = lua_interface->GetInt16Value(state, 2);
  2462. if (spawn && spawn->IsEntity()) {
  2463. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2464. if (spawn->IsPlayer())
  2465. ((Player*)spawn)->SetCharSheetChanged(true);
  2466. }
  2467. return 0;
  2468. }
  2469. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2470. if (!lua_interface)
  2471. return 0;
  2472. Spawn* spawn = lua_interface->GetSpawn(state);
  2473. int16 value = lua_interface->GetInt16Value(state, 2);
  2474. if (spawn && spawn->IsEntity()) {
  2475. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2476. if (spawn->IsPlayer())
  2477. ((Player*)spawn)->SetCharSheetChanged(true);
  2478. }
  2479. return 0;
  2480. }
  2481. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2482. if (!lua_interface)
  2483. return 0;
  2484. Spawn* spawn = lua_interface->GetSpawn(state);
  2485. int8 value = lua_interface->GetInt8Value(state, 2);
  2486. if (spawn && spawn->IsEntity()) {
  2487. ((Entity*)spawn)->SetDeity(value);
  2488. if (spawn->IsPlayer())
  2489. ((Player*)spawn)->SetCharSheetChanged(true);
  2490. }
  2491. lua_interface->ResetFunctionStack(state);
  2492. return 0;
  2493. }
  2494. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2495. if (!lua_interface)
  2496. return 0;
  2497. Spawn* spawn = lua_interface->GetSpawn(state);
  2498. if (spawn && spawn->IsEntity()) {
  2499. int8 deity = ((Entity*)spawn)->GetDeity();
  2500. lua_interface->SetInt32Value(state, deity);
  2501. return 1;
  2502. }
  2503. return 0;
  2504. }
  2505. int EQ2Emu_lua_SetInt(lua_State* state) {
  2506. if (!lua_interface)
  2507. return 0;
  2508. Spawn* spawn = lua_interface->GetSpawn(state);
  2509. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2510. if (spawn && spawn->IsEntity()) {
  2511. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2512. if (spawn->IsPlayer())
  2513. ((Player*)spawn)->SetCharSheetChanged(true);
  2514. }
  2515. return 0;
  2516. }
  2517. int EQ2Emu_lua_SetWis(lua_State* state) {
  2518. if (!lua_interface)
  2519. return 0;
  2520. Spawn* spawn = lua_interface->GetSpawn(state);
  2521. float value = lua_interface->GetFloatValue(state, 2);
  2522. if (spawn && spawn->IsEntity()) {
  2523. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2524. if (spawn->IsPlayer())
  2525. ((Player*)spawn)->SetCharSheetChanged(true);
  2526. }
  2527. return 0;
  2528. }
  2529. int EQ2Emu_lua_SetSta(lua_State* state) {
  2530. if (!lua_interface)
  2531. return 0;
  2532. Spawn* spawn = lua_interface->GetSpawn(state);
  2533. float value = lua_interface->GetFloatValue(state, 2);
  2534. if (spawn && spawn->IsEntity()) {
  2535. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2536. if (spawn->IsPlayer())
  2537. ((Player*)spawn)->SetCharSheetChanged(true);
  2538. }
  2539. return 0;
  2540. }
  2541. int EQ2Emu_lua_SetStr(lua_State* state) {
  2542. if (!lua_interface)
  2543. return 0;
  2544. Spawn* spawn = lua_interface->GetSpawn(state);
  2545. float value = lua_interface->GetFloatValue(state, 2);
  2546. if (spawn && spawn->IsEntity()) {
  2547. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2548. if (spawn->IsPlayer())
  2549. ((Player*)spawn)->SetCharSheetChanged(true);
  2550. }
  2551. return 0;
  2552. }
  2553. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2554. if (!lua_interface)
  2555. return 0;
  2556. Spawn* spawn = lua_interface->GetSpawn(state);
  2557. float value = lua_interface->GetFloatValue(state, 2);
  2558. if (spawn && spawn->IsEntity()) {
  2559. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2560. if (spawn->IsPlayer())
  2561. ((Player*)spawn)->SetCharSheetChanged(true);
  2562. }
  2563. return 0;
  2564. }
  2565. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2566. if (!lua_interface)
  2567. return 0;
  2568. Spawn* spawn = lua_interface->GetSpawn(state);
  2569. if (spawn) {
  2570. lua_interface->SetInt32Value(state, spawn->GetHP());
  2571. return 1;
  2572. }
  2573. return 0;
  2574. }
  2575. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2576. if (!lua_interface)
  2577. return 0;
  2578. Spawn* spawn = lua_interface->GetSpawn(state);
  2579. if (spawn) {
  2580. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2581. return 1;
  2582. }
  2583. return 0;
  2584. }
  2585. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2586. if (!lua_interface)
  2587. return 0;
  2588. Spawn* spawn = lua_interface->GetSpawn(state);
  2589. if (spawn) {
  2590. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2591. return 1;
  2592. }
  2593. return 0;
  2594. }
  2595. int EQ2Emu_lua_GetName(lua_State* state) {
  2596. if (!lua_interface)
  2597. return 0;
  2598. Spawn* spawn = lua_interface->GetSpawn(state);
  2599. if (spawn) {
  2600. lua_interface->SetStringValue(state, spawn->GetName());
  2601. return 1;
  2602. }
  2603. return 0;
  2604. }
  2605. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2606. Spawn* spawn = lua_interface->GetSpawn(state);
  2607. if (spawn) {
  2608. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2609. return 1;
  2610. }
  2611. return 0;
  2612. }
  2613. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2614. if (!lua_interface)
  2615. return 0;
  2616. Spawn* spawn = lua_interface->GetSpawn(state);
  2617. if (spawn) {
  2618. lua_interface->SetInt32Value(state, spawn->GetPower());
  2619. return 1;
  2620. }
  2621. return 0;
  2622. }
  2623. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2624. if (!lua_interface)
  2625. return 0;
  2626. Spawn* spawn = lua_interface->GetSpawn(state);
  2627. if (spawn) {
  2628. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2629. return 1;
  2630. }
  2631. return 0;
  2632. }
  2633. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2634. if (!lua_interface)
  2635. return 0;
  2636. Spawn* spawn = lua_interface->GetSpawn(state);
  2637. if (spawn) {
  2638. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2639. return 1;
  2640. }
  2641. return 0;
  2642. }
  2643. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2644. if (!lua_interface)
  2645. return 0;
  2646. Spawn* spawn = lua_interface->GetSpawn(state);
  2647. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2648. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2649. if (spawn && spawn2) {
  2650. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2651. lua_interface->SetFloatValue(state, distance);
  2652. return 1;
  2653. }
  2654. return 0;
  2655. }
  2656. int EQ2Emu_lua_GetX(lua_State* state) {
  2657. if (!lua_interface)
  2658. return 0;
  2659. Spawn* spawn = lua_interface->GetSpawn(state);
  2660. if (spawn) {
  2661. lua_interface->SetFloatValue(state, spawn->GetX());
  2662. return 1;
  2663. }
  2664. return 0;
  2665. }
  2666. int EQ2Emu_lua_GetY(lua_State* state) {
  2667. if (!lua_interface)
  2668. return 0;
  2669. Spawn* spawn = lua_interface->GetSpawn(state);
  2670. if (spawn) {
  2671. lua_interface->SetFloatValue(state, spawn->GetY());
  2672. return 1;
  2673. }
  2674. return 0;
  2675. }
  2676. int EQ2Emu_lua_GetZ(lua_State* state) {
  2677. if (!lua_interface)
  2678. return 0;
  2679. Spawn* spawn = lua_interface->GetSpawn(state);
  2680. if (spawn) {
  2681. lua_interface->SetFloatValue(state, spawn->GetZ());
  2682. return 1;
  2683. }
  2684. return 0;
  2685. }
  2686. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2687. if (!lua_interface)
  2688. return 0;
  2689. Spawn* spawn = lua_interface->GetSpawn(state);
  2690. if (spawn) {
  2691. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2692. return 1;
  2693. }
  2694. return 0;
  2695. }
  2696. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2697. if (!lua_interface)
  2698. return 0;
  2699. Spawn* spawn = lua_interface->GetSpawn(state);
  2700. if (spawn) {
  2701. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2702. return 1;
  2703. }
  2704. return 0;
  2705. }
  2706. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2707. if (!lua_interface)
  2708. return 0;
  2709. Spawn* spawn = lua_interface->GetSpawn(state);
  2710. if (spawn) {
  2711. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2712. return 1;
  2713. }
  2714. return 0;
  2715. }
  2716. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2717. if (!lua_interface)
  2718. return 0;
  2719. Spawn* spawn = lua_interface->GetSpawn(state);
  2720. if (spawn && spawn->IsEntity()) {
  2721. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2722. return 1;
  2723. }
  2724. return 0;
  2725. }
  2726. int EQ2Emu_lua_GetInt(lua_State* state) {
  2727. if (!lua_interface)
  2728. return 0;
  2729. Spawn* spawn = lua_interface->GetSpawn(state);
  2730. if (spawn && spawn->IsEntity()) {
  2731. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2732. return 1;
  2733. }
  2734. return 0;
  2735. }
  2736. int EQ2Emu_lua_GetWis(lua_State* state) {
  2737. if (!lua_interface)
  2738. return 0;
  2739. Spawn* spawn = lua_interface->GetSpawn(state);
  2740. if (spawn && spawn->IsEntity()) {
  2741. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2742. return 1;
  2743. }
  2744. return 0;
  2745. }
  2746. int EQ2Emu_lua_GetSta(lua_State* state) {
  2747. if (!lua_interface)
  2748. return 0;
  2749. Spawn* spawn = lua_interface->GetSpawn(state);
  2750. if (spawn && spawn->IsEntity()) {
  2751. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2752. return 1;
  2753. }
  2754. return 0;
  2755. }
  2756. int EQ2Emu_lua_GetStr(lua_State* state) {
  2757. if (!lua_interface)
  2758. return 0;
  2759. Spawn* spawn = lua_interface->GetSpawn(state);
  2760. if (spawn && spawn->IsEntity()) {
  2761. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2762. return 1;
  2763. }
  2764. return 0;
  2765. }
  2766. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2767. if (!lua_interface)
  2768. return 0;
  2769. Spawn* spawn = lua_interface->GetSpawn(state);
  2770. if (spawn && spawn->IsEntity()) {
  2771. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2772. return 1;
  2773. }
  2774. return 0;
  2775. }
  2776. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2777. if (!lua_interface)
  2778. return 0;
  2779. Spawn* spawn = lua_interface->GetSpawn(state);
  2780. if (spawn && spawn->IsEntity()) {
  2781. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2782. return 1;
  2783. }
  2784. return 0;
  2785. }
  2786. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2787. if (!lua_interface)
  2788. return 0;
  2789. Spawn* spawn = lua_interface->GetSpawn(state);
  2790. if (spawn && spawn->IsEntity()) {
  2791. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2792. return 1;
  2793. }
  2794. return 0;
  2795. }
  2796. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2797. if (!lua_interface)
  2798. return 0;
  2799. Spawn* spawn = lua_interface->GetSpawn(state);
  2800. if (spawn && spawn->IsEntity()) {
  2801. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2802. return 1;
  2803. }
  2804. return 0;
  2805. }
  2806. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2807. if (!lua_interface)
  2808. return 0;
  2809. Spawn* spawn = lua_interface->GetSpawn(state);
  2810. if (spawn && spawn->IsEntity()) {
  2811. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2812. return 1;
  2813. }
  2814. return 0;
  2815. }
  2816. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2817. if (!lua_interface)
  2818. return 0;
  2819. Spawn* spawn = lua_interface->GetSpawn(state);
  2820. if (spawn && spawn->IsEntity()) {
  2821. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2822. return 1;
  2823. }
  2824. return 0;
  2825. }
  2826. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2827. if (!lua_interface)
  2828. return 0;
  2829. Spawn* player = lua_interface->GetSpawn(state);
  2830. if (!player || !player->IsPlayer()) {
  2831. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2832. return 0;
  2833. }
  2834. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2835. if (quest_id <= 0) {
  2836. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2837. return 0;
  2838. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2839. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2840. return 0;
  2841. }
  2842. int32 step = lua_interface->GetInt32Value(state, 3);
  2843. if (step > 0) {
  2844. Client* client = player->GetZone()->GetClientBySpawn(player);
  2845. if (client)
  2846. client->AddPendingQuestUpdate(quest_id, step);
  2847. } else {
  2848. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2849. }
  2850. return 0;
  2851. }
  2852. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2853. Spawn* player = lua_interface->GetSpawn(state);
  2854. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2855. int32 step = lua_interface->GetInt32Value(state, 3);
  2856. int32 progress = lua_interface->GetInt32Value(state, 4);
  2857. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2858. Client* client = player->GetZone()->GetClientBySpawn(player);
  2859. if (client)
  2860. client->AddPendingQuestUpdate(quest_id, step, progress);
  2861. }
  2862. return 0;
  2863. }
  2864. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2865. if (!lua_interface)
  2866. return 0;
  2867. Spawn* player = lua_interface->GetSpawn(state);
  2868. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2869. if (player && player->IsPlayer() && quest_id > 0) {
  2870. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2871. return 1;
  2872. }
  2873. return 0;
  2874. }
  2875. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2876. if (!lua_interface)
  2877. return 0;
  2878. Spawn* player = lua_interface->GetSpawn(state);
  2879. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2880. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2881. if (player && player->IsPlayer() && quest_id > 0) {
  2882. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2883. return 1;
  2884. }
  2885. return 0;
  2886. }
  2887. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2888. if (!lua_interface)
  2889. return 0;
  2890. Spawn* player = lua_interface->GetSpawn(state);
  2891. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2892. if (player && player->IsPlayer() && quest_id > 0) {
  2893. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2894. return 1;
  2895. }
  2896. return 0;
  2897. }
  2898. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2899. if (!lua_interface)
  2900. return 0;
  2901. Quest* quest = lua_interface->GetQuest(state);
  2902. string name = lua_interface->GetStringValue(state, 2);
  2903. string type = lua_interface->GetStringValue(state, 3);
  2904. string zone = lua_interface->GetStringValue(state, 4);
  2905. int16 level = lua_interface->GetInt16Value(state, 5);
  2906. string description = lua_interface->GetStringValue(state, 6);
  2907. bool load = true;
  2908. if (!quest) {
  2909. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2910. load = false;
  2911. }
  2912. if (load && name.length() == 0) {
  2913. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2914. load = false;
  2915. }
  2916. if (load && type.length() == 0) {
  2917. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2918. load = false;
  2919. }
  2920. if (load && zone.length() == 0) {
  2921. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2922. load = false;
  2923. }
  2924. if (load && description.length() == 0) {
  2925. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2926. load = false;
  2927. }
  2928. if (load && level == 0) {
  2929. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2930. load = false;
  2931. }
  2932. if (load)
  2933. quest->RegisterQuest(name, type, zone, level, description);
  2934. return 0;
  2935. }
  2936. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2937. if (!lua_interface)
  2938. return 0;
  2939. Quest* quest = lua_interface->GetQuest(state);
  2940. if (quest) {
  2941. int8 level = lua_interface->GetInt16Value(state, 2);
  2942. quest->SetPrereqLevel(level);
  2943. }
  2944. return 0;
  2945. }
  2946. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2947. if (!lua_interface)
  2948. return 0;
  2949. Quest* quest = lua_interface->GetQuest(state);
  2950. if (quest) {
  2951. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2952. quest->AddPrereqQuest(quest_id);
  2953. }
  2954. return 0;
  2955. }
  2956. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2957. if (!lua_interface)
  2958. return 0;
  2959. Quest* quest = lua_interface->GetQuest(state);
  2960. if (quest) {
  2961. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2962. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2963. if (quantity == 0)
  2964. quantity = 1;
  2965. Item* master_item = master_item_list.GetItem(item_id);
  2966. if (master_item) {
  2967. Item* item = new Item(master_item);
  2968. item->details.count = quantity;
  2969. quest->AddPrereqItem(item);
  2970. }
  2971. }
  2972. return 0;
  2973. }
  2974. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2975. if (!lua_interface)
  2976. return 0;
  2977. Spawn* player = lua_interface->GetSpawn(state);
  2978. if(!player || !player->IsPlayer()) {
  2979. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  2980. return 0;
  2981. }
  2982. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2983. if (quest_id > 0) {
  2984. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2985. return 1;
  2986. } else {
  2987. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2988. }
  2989. return 0;
  2990. }
  2991. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2992. if (!lua_interface)
  2993. return 0;
  2994. Quest* quest = lua_interface->GetQuest(state);
  2995. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2996. if (quest && spawn_id > 0)
  2997. quest->SetQuestReturnNPC(spawn_id);
  2998. return 0;
  2999. }
  3000. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3001. if (!lua_interface)
  3002. return 0;
  3003. Spawn* spawn = lua_interface->GetSpawn(state);
  3004. if (!spawn) {
  3005. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3006. return 0;
  3007. }
  3008. int32 time = lua_interface->GetInt32Value(state, 2);
  3009. if (time <= 0) {
  3010. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3011. return 0;
  3012. }
  3013. string function = lua_interface->GetStringValue(state, 3);
  3014. if (function.length() == 0) {
  3015. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3016. return 0;
  3017. }
  3018. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3019. Spawn* player = lua_interface->GetSpawn(state, 5);
  3020. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3021. timer->timer = Timer::GetCurrentTime2() + time;
  3022. timer->function = function;
  3023. timer->spawn = spawn->GetID();
  3024. timer->player = player ? player->GetID() : 0;
  3025. if (max_count == 0)
  3026. max_count = 1;
  3027. timer->max_count = max_count;
  3028. timer->current_count = 0;
  3029. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Spawn* player = lua_interface->GetSpawn(state);
  3036. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3037. if (player && player->IsPlayer() && quest_id > 0) {
  3038. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3039. return 1;
  3040. }
  3041. return 0;
  3042. }
  3043. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3044. if (!lua_interface)
  3045. return 0;
  3046. Spawn* player = lua_interface->GetSpawn(state);
  3047. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3048. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3049. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3050. if (quest)
  3051. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3052. return 1;
  3053. }
  3054. return 0;
  3055. }
  3056. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3057. if (!lua_interface)
  3058. return 0;
  3059. Spawn* player = lua_interface->GetSpawn(state);
  3060. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3061. if (player && player->IsPlayer() && quest_id > 0) {
  3062. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3063. return 1;
  3064. }
  3065. return 0;
  3066. }
  3067. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3068. if (!lua_interface)
  3069. return 0;
  3070. Spawn* npc = lua_interface->GetSpawn(state);
  3071. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3072. if (npc && !npc->IsPlayer() && quest_id > 0)
  3073. npc->AddProvidedQuest(quest_id);
  3074. return 0;
  3075. }
  3076. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3077. if (!lua_interface)
  3078. return 0;
  3079. Spawn* npc = lua_interface->GetSpawn(state);
  3080. Spawn* player = lua_interface->GetSpawn(state, 2);
  3081. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3082. bool forced = lua_interface->GetBooleanValue(state, 4);
  3083. /* NPC is allowed to be null */
  3084. if (player && player->IsPlayer() && quest_id > 0) {
  3085. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3086. if (master_quest) {
  3087. Client* client = player->GetZone()->GetClientBySpawn(player);
  3088. if (!client) {
  3089. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3090. }
  3091. Quest* quest = new Quest(master_quest);
  3092. if (!quest) {
  3093. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3094. }
  3095. if (client && quest) {
  3096. if (npc)
  3097. quest->SetQuestGiver(npc->GetDatabaseID());
  3098. else
  3099. quest->SetQuestGiver(0);
  3100. client->AddPendingQuest(quest, forced);
  3101. }
  3102. }
  3103. else {
  3104. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3105. }
  3106. }
  3107. else {
  3108. lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
  3109. }
  3110. return 0;
  3111. }
  3112. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3113. if (!lua_interface)
  3114. return 0;
  3115. Quest* quest = lua_interface->GetQuest(state);
  3116. if (quest) {
  3117. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3118. quest->AddPrereqClass(class_id);
  3119. }
  3120. return 0;
  3121. }
  3122. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3123. if (!lua_interface)
  3124. return 0;
  3125. Quest* quest = lua_interface->GetQuest(state);
  3126. if (quest) {
  3127. int8 race = lua_interface->GetInt8Value(state, 2);
  3128. quest->AddPrereqRace(race);
  3129. }
  3130. return 0;
  3131. }
  3132. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3133. if (!lua_interface)
  3134. return 0;
  3135. Quest* quest = lua_interface->GetQuest(state);
  3136. if (quest) {
  3137. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3138. quest->AddPrereqModelType(model_type);
  3139. }
  3140. return 0;
  3141. }
  3142. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3143. if (!lua_interface)
  3144. return 0;
  3145. Quest* quest = lua_interface->GetQuest(state);
  3146. if (!quest) {
  3147. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3148. return 0;
  3149. }
  3150. int8 level = lua_interface->GetInt8Value(state, 2);
  3151. quest->SetPrereqTSLevel(level);
  3152. return 0;
  3153. }
  3154. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3155. if (!lua_interface)
  3156. return 0;
  3157. Quest* quest = lua_interface->GetQuest(state);
  3158. if (!quest) {
  3159. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3160. return 0;
  3161. }
  3162. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3163. quest->AddPrereqTradeskillClass(class_id);
  3164. return 0;
  3165. }
  3166. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3167. if (!lua_interface)
  3168. return 0;
  3169. Quest* quest = lua_interface->GetQuest(state);
  3170. if (quest) {
  3171. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3172. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3173. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3174. quest->AddPrereqFaction(faction_id, min, max);
  3175. }
  3176. return 0;
  3177. }
  3178. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3179. if (!lua_interface)
  3180. return 0;
  3181. Quest* quest = lua_interface->GetQuest(state);
  3182. if (quest) {
  3183. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3184. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3185. if (quantity == 0)
  3186. quantity = 1;
  3187. Item* master_item = master_item_list.GetItem(item_id);
  3188. if (master_item) {
  3189. Item* item = new Item(master_item);
  3190. item->details.count = quantity;
  3191. quest->AddSelectableRewardItem(item);
  3192. }
  3193. }
  3194. return 0;
  3195. }
  3196. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3197. if (!lua_interface)
  3198. return 0;
  3199. Quest* quest = lua_interface->GetQuest(state);
  3200. if (quest) {
  3201. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3202. vector<Item*>* items = quest->GetRewardItems();
  3203. if (items) {
  3204. vector<Item*>::iterator itr;
  3205. for (itr = items->begin(); itr != items->end(); itr++) {
  3206. if (*itr && (*itr)->details.item_id == item_id) {
  3207. lua_interface->SetBooleanValue(state, true);
  3208. return 1;
  3209. }
  3210. }
  3211. }
  3212. }
  3213. lua_interface->SetBooleanValue(state, false);
  3214. return 1;
  3215. }
  3216. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3217. if (!lua_interface)
  3218. return 0;
  3219. Quest* quest = lua_interface->GetQuest(state);
  3220. if (quest) {
  3221. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3222. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3223. if (quantity == 0)
  3224. quantity = 1;
  3225. Item* master_item = master_item_list.GetItem(item_id);
  3226. if (master_item) {
  3227. Item* item = new Item(master_item);
  3228. item->details.count = quantity;
  3229. quest->AddRewardItem(item);
  3230. }
  3231. }
  3232. return 0;
  3233. }
  3234. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3235. if (!lua_interface)
  3236. return 0;
  3237. Quest* quest = lua_interface->GetQuest(state);
  3238. if (quest) {
  3239. int32 copper = lua_interface->GetInt32Value(state, 2);
  3240. int32 silver = lua_interface->GetInt32Value(state, 3);
  3241. int32 gold = lua_interface->GetInt32Value(state, 4);
  3242. int32 plat = lua_interface->GetInt32Value(state, 5);
  3243. quest->AddRewardCoins(copper, silver, gold, plat);
  3244. }
  3245. return 0;
  3246. }
  3247. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3248. if (!lua_interface)
  3249. return 0;
  3250. Quest* quest = lua_interface->GetQuest(state);
  3251. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3252. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3253. if (quest && faction_id > 0 && amount != 0)
  3254. quest->AddRewardFaction(faction_id, amount);
  3255. return 0;
  3256. }
  3257. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3258. if (!lua_interface)
  3259. return 0;
  3260. Quest* quest = lua_interface->GetQuest(state);
  3261. if (quest) {
  3262. int32 status = lua_interface->GetInt32Value(state, 2);
  3263. quest->SetRewardStatus(status);
  3264. }
  3265. return 0;
  3266. }
  3267. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3268. if (!lua_interface)
  3269. return 0;
  3270. Quest* quest = lua_interface->GetQuest(state);
  3271. if (quest) {
  3272. string comment = lua_interface->GetStringValue(state, 2);
  3273. quest->SetRewardComment(comment);
  3274. }
  3275. return 0;
  3276. }
  3277. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3278. if (!lua_interface)
  3279. return 0;
  3280. Quest* quest = lua_interface->GetQuest(state);
  3281. if (quest) {
  3282. int32 exp = lua_interface->GetInt32Value(state, 2);
  3283. quest->SetRewardXP(exp);
  3284. }
  3285. return 0;
  3286. }
  3287. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3288. Quest* quest = lua_interface->GetQuest(state);
  3289. if (quest) {
  3290. int32 step = lua_interface->GetInt32Value(state, 2);
  3291. string description = lua_interface->GetStringValue(state, 3);
  3292. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3293. float percentage = lua_interface->GetFloatValue(state, 5);
  3294. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3295. int16 icon = lua_interface->GetInt16Value(state, 7);
  3296. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3297. const char* taskgroup = 0;
  3298. if (str_taskgroup.length() > 0)
  3299. taskgroup = str_taskgroup.c_str();
  3300. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3301. if (quest_step && icon && quantity > 0)
  3302. quest_step->SetIcon(icon);
  3303. }
  3304. return 0;
  3305. }
  3306. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3307. if (!lua_interface)
  3308. return 0;
  3309. Quest* quest = lua_interface->GetQuest(state);
  3310. if (quest) {
  3311. int32 step = lua_interface->GetInt32Value(state, 2);
  3312. string description = lua_interface->GetStringValue(state, 3);
  3313. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3314. float percentage = lua_interface->GetFloatValue(state, 5);
  3315. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3316. int16 icon = lua_interface->GetInt16Value(state, 7);
  3317. const char* taskgroup = 0;
  3318. if (str_taskgroup.length() > 0)
  3319. taskgroup = str_taskgroup.c_str();
  3320. int32 npc_id = 0;
  3321. vector<int32>* ids = 0;
  3322. int i = 0;
  3323. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3324. if (ids == 0)
  3325. ids = new vector<int32>;
  3326. ids->push_back(npc_id);
  3327. i++;
  3328. }
  3329. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3330. if (quest_step && icon > 0 && quantity > 0)
  3331. quest_step->SetIcon(icon);
  3332. if (quest->GetPlayer()) {
  3333. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3334. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3335. }
  3336. }
  3337. return 0;
  3338. }
  3339. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3340. if (!lua_interface)
  3341. return 0;
  3342. Quest* quest = lua_interface->GetQuest(state);
  3343. if (quest) {
  3344. int32 step = lua_interface->GetInt32Value(state, 2);
  3345. string description = lua_interface->GetStringValue(state, 3);
  3346. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3347. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3348. int16 icon = lua_interface->GetInt16Value(state, 6);
  3349. const char* taskgroup = 0;
  3350. if (str_taskgroup.length() > 0)
  3351. taskgroup = str_taskgroup.c_str();
  3352. int32 npc_id = 0;
  3353. vector<int32>* ids = 0;
  3354. int i = 0;
  3355. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3356. if (ids == 0)
  3357. ids = new vector<int32>;
  3358. ids->push_back(npc_id);
  3359. i++;
  3360. }
  3361. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3362. if (quest_step && icon > 0)
  3363. quest_step->SetIcon(icon);
  3364. if (quest->GetPlayer()) {
  3365. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3366. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3367. }
  3368. }
  3369. return 0;
  3370. }
  3371. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3372. if (!lua_interface)
  3373. return 0;
  3374. Quest* quest = lua_interface->GetQuest(state);
  3375. if (quest) {
  3376. int32 step = lua_interface->GetInt32Value(state, 2);
  3377. string description = lua_interface->GetStringValue(state, 3);
  3378. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3379. float percentage = lua_interface->GetFloatValue(state, 5);
  3380. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3381. int16 icon = lua_interface->GetInt16Value(state, 7);
  3382. const char* taskgroup = 0;
  3383. if (str_taskgroup.length() > 0)
  3384. taskgroup = str_taskgroup.c_str();
  3385. int32 item_id = 0;
  3386. vector<int32>* ids = 0;
  3387. int i = 0;
  3388. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3389. if (ids == 0)
  3390. ids = new vector<int32>;
  3391. ids->push_back(item_id);
  3392. i++;
  3393. }
  3394. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3395. if (quest_step && icon > 0 && quantity > 0)
  3396. quest_step->SetIcon(icon);
  3397. if (quest->GetPlayer()) {
  3398. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3399. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3400. }
  3401. }
  3402. return 0;
  3403. }
  3404. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3405. if (!lua_interface)
  3406. return 0;
  3407. Quest* quest = lua_interface->GetQuest(state);
  3408. if (quest) {
  3409. int32 step = lua_interface->GetInt32Value(state, 2);
  3410. string description = lua_interface->GetStringValue(state, 3);
  3411. float max_variation = lua_interface->GetFloatValue(state, 4);
  3412. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3413. int16 icon = lua_interface->GetInt16Value(state, 6);
  3414. const char* taskgroup = 0;
  3415. if (str_taskgroup.length() > 0)
  3416. taskgroup = str_taskgroup.c_str();
  3417. vector<Location>* locations = 0;
  3418. int i = 7;
  3419. while (true) {
  3420. Location loc;
  3421. loc.x = lua_interface->GetFloatValue(state, i);
  3422. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3423. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3424. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3425. break;
  3426. if (locations == 0)
  3427. locations = new vector<Location>;
  3428. locations->push_back(loc);
  3429. i += 3;
  3430. }
  3431. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3432. if (quest_step && icon > 0)
  3433. quest_step->SetIcon(icon);
  3434. if (quest->GetPlayer()) {
  3435. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3436. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3437. }
  3438. }
  3439. return 0;
  3440. }
  3441. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3442. if (!lua_interface)
  3443. return 0;
  3444. Quest* quest = lua_interface->GetQuest(state);
  3445. if (quest) {
  3446. int32 step = lua_interface->GetInt32Value(state, 2);
  3447. string description = lua_interface->GetStringValue(state, 3);
  3448. float max_variation = lua_interface->GetFloatValue(state, 4);
  3449. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3450. int16 icon = lua_interface->GetInt16Value(state, 6);
  3451. const char* taskgroup = 0;
  3452. if (str_taskgroup.length() > 0)
  3453. taskgroup = str_taskgroup.c_str();
  3454. vector<Location>* locations = 0;
  3455. int i = 7;
  3456. while (true) {
  3457. Location loc;
  3458. loc.x = lua_interface->GetFloatValue(state, i);
  3459. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3460. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3461. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3462. break;
  3463. if (locations == 0)
  3464. locations = new vector<Location>;
  3465. locations->push_back(loc);
  3466. i += 3;
  3467. }
  3468. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3469. if (quest_step && icon > 0)
  3470. quest_step->SetIcon(icon);
  3471. if (quest->GetPlayer()) {
  3472. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3473. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3474. }
  3475. }
  3476. return 0;
  3477. }
  3478. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3479. Quest* quest = lua_interface->GetQuest(state);
  3480. if (quest) {
  3481. int32 step = lua_interface->GetInt32Value(state, 2);
  3482. string description = lua_interface->GetStringValue(state, 3);
  3483. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3484. float percentage = lua_interface->GetFloatValue(state, 5);
  3485. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3486. int16 icon = lua_interface->GetInt16Value(state, 7);
  3487. const char* taskgroup = 0;
  3488. if (str_taskgroup.length() > 0)
  3489. taskgroup = str_taskgroup.c_str();
  3490. int32 spell_id = 0;
  3491. vector<int32>* ids = 0;
  3492. int i = 0;
  3493. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3494. if (ids == 0)
  3495. ids = new vector<int32>;
  3496. ids->push_back(spell_id);
  3497. i++;
  3498. }
  3499. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3500. if (quest_step && icon > 0 && quantity > 0)
  3501. quest_step->SetIcon(icon);
  3502. if (quest->GetPlayer()) {
  3503. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3504. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3505. }
  3506. }
  3507. return 0;
  3508. }
  3509. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3510. if (!lua_interface)
  3511. return 0;
  3512. Quest* quest = lua_interface->GetQuest(state);
  3513. if (quest) {
  3514. int32 step = lua_interface->GetInt32Value(state, 2);
  3515. string description = lua_interface->GetStringValue(state, 3);
  3516. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3517. float percentage = lua_interface->GetFloatValue(state, 5);
  3518. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3519. int16 icon = lua_interface->GetInt16Value(state, 7);
  3520. const char* taskgroup = 0;
  3521. if (str_taskgroup.length() > 0)
  3522. taskgroup = str_taskgroup.c_str();
  3523. int32 item_id = 0;
  3524. vector<int32>* ids = 0;
  3525. int i = 0;
  3526. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3527. if (ids == 0)
  3528. ids = new vector<int32>;
  3529. ids->push_back(item_id);
  3530. i++;
  3531. }
  3532. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3533. if (quest_step && icon > 0 && quantity > 0)
  3534. quest_step->SetIcon(icon);
  3535. if (quest->GetPlayer()) {
  3536. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3537. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3538. }
  3539. }
  3540. return 0;
  3541. }
  3542. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3543. if (!lua_interface)
  3544. return 0;
  3545. Quest* quest = lua_interface->GetQuest(state);
  3546. if (quest) {
  3547. int32 step = lua_interface->GetInt32Value(state, 2);
  3548. string description = lua_interface->GetStringValue(state, 3);
  3549. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3550. float percentage = lua_interface->GetFloatValue(state, 5);
  3551. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3552. int16 icon = lua_interface->GetInt16Value(state, 7);
  3553. const char* taskgroup = 0;
  3554. if (str_taskgroup.length() > 0)
  3555. taskgroup = str_taskgroup.c_str();
  3556. int32 item_id = 0;
  3557. vector<int32>* ids = 0;
  3558. int i = 0;
  3559. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3560. if (ids == 0)
  3561. ids = new vector<int32>;
  3562. ids->push_back(item_id);
  3563. i++;
  3564. }
  3565. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3566. if (quest_step && icon > 0 && quantity > 0)
  3567. quest_step->SetIcon(icon);
  3568. if (quest->GetPlayer()) {
  3569. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3570. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3571. }
  3572. }
  3573. return 0;
  3574. }
  3575. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3576. if (!lua_interface)
  3577. return 0;
  3578. Quest* quest = lua_interface->GetQuest(state);
  3579. if (quest) {
  3580. string action = lua_interface->GetStringValue(state, 2);
  3581. if (action.length() > 0)
  3582. quest->SetCompleteAction(action);
  3583. }
  3584. return 0;
  3585. }
  3586. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3587. if (!lua_interface)
  3588. return 0;
  3589. Quest* quest = lua_interface->GetQuest(state);
  3590. if (quest) {
  3591. int32 step = lua_interface->GetInt32Value(state, 2);
  3592. string action = lua_interface->GetStringValue(state, 3);
  3593. if (step > 0 && action.length() > 0)
  3594. quest->AddCompleteAction(step, action);
  3595. }
  3596. return 0;
  3597. }
  3598. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3599. if (!lua_interface)
  3600. return 0;
  3601. Quest* quest = lua_interface->GetQuest(state);
  3602. if (quest) {
  3603. int32 step = lua_interface->GetInt32Value(state, 2);
  3604. string action = lua_interface->GetStringValue(state, 3);
  3605. if (step > 0 && action.length() > 0)
  3606. quest->AddProgressAction(step, action);
  3607. }
  3608. return 0;
  3609. }
  3610. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3611. if (!lua_interface)
  3612. return 0;
  3613. Quest* quest = lua_interface->GetQuest(state);
  3614. string description = lua_interface->GetStringValue(state, 2);
  3615. if (quest && description.length() > 0)
  3616. quest->SetDescription(description);
  3617. return 0;
  3618. }
  3619. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3620. if (!lua_interface)
  3621. return 0;
  3622. Quest* quest = lua_interface->GetQuest(state);
  3623. string description = lua_interface->GetStringValue(state, 2);
  3624. if (quest && description.length() > 0)
  3625. quest->SetCompletedDescription(description);
  3626. return 0;
  3627. }
  3628. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3629. if (!lua_interface)
  3630. return 0;
  3631. Quest* quest = lua_interface->GetQuest(state);
  3632. int32 step = lua_interface->GetInt32Value(state, 2);
  3633. string description = lua_interface->GetStringValue(state, 3);
  3634. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3635. if (quest && step > 0 && description.length() > 0) {
  3636. quest->SetTaskGroupDescription(step, description, display_bullets);
  3637. if (quest->GetPlayer()) {
  3638. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3639. if (client)
  3640. client->SendQuestUpdateStep(quest, step, false);
  3641. }
  3642. }
  3643. return 0;
  3644. }
  3645. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3646. if (!lua_interface)
  3647. return 0;
  3648. Quest* quest = lua_interface->GetQuest(state);
  3649. int32 step = lua_interface->GetInt32Value(state, 2);
  3650. string description = lua_interface->GetStringValue(state, 3);
  3651. if (quest && step > 0 && description.length() > 0) {
  3652. quest->SetStepDescription(step, description);
  3653. if (quest->GetPlayer()) {
  3654. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3655. if (client)
  3656. client->SendQuestUpdateStepImmediately(quest, step);
  3657. }
  3658. }
  3659. return 0;
  3660. }
  3661. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3662. Quest* quest = lua_interface->GetQuest(state);
  3663. string zone = lua_interface->GetStringValue(state, 2);
  3664. if (quest && zone.length() > 0)
  3665. quest->SetZone(zone);
  3666. return 0;
  3667. }
  3668. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3669. if (!lua_interface)
  3670. return 0;
  3671. Quest* quest = lua_interface->GetQuest(state);
  3672. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3673. int32 coin = lua_interface->GetInt32Value(state, 3);
  3674. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3675. string rewards_str = lua_interface->GetStringValue(state, 5);
  3676. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3677. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3678. string text = lua_interface->GetStringValue(state, 8);
  3679. if (playerSpawn && playerSpawn->IsPlayer()) {
  3680. Player* player = (Player*)playerSpawn;
  3681. Client* client = player->GetZone()->GetClientBySpawn(player);
  3682. if (client) {
  3683. vector<Item*> reward_items;
  3684. vector<Item*> selectable_reward_items;
  3685. if (rewards_str.length() > 0) {
  3686. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3687. map<unsigned int, unsigned short>::iterator itr;
  3688. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3689. if (itr->first > 0) {
  3690. Item* item = new Item(master_item_list.GetItem(itr->first));
  3691. if (item) {
  3692. if (itr->second > 0)
  3693. item->details.count = itr->second;
  3694. reward_items.push_back(item);
  3695. }
  3696. }
  3697. }
  3698. }
  3699. if (select_rewards_str.length() > 0) {
  3700. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3701. map<unsigned int, unsigned short>::iterator itr;
  3702. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3703. if (itr->first > 0) {
  3704. Item* item = new Item(master_item_list.GetItem(itr->first));
  3705. if (item) {
  3706. if (itr->second > 0)
  3707. item->stack_count = itr->second;
  3708. selectable_reward_items.push_back(item);
  3709. }
  3710. }
  3711. }
  3712. }
  3713. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3714. const char* reward_type = "Quest Reward!";
  3715. if (!quest)
  3716. reward_type = "Reward!";
  3717. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3718. }
  3719. }
  3720. return 0;
  3721. }
  3722. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3723. if (!lua_interface)
  3724. return 0;
  3725. Quest* quest = lua_interface->GetQuest(state);
  3726. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3727. if (quest && spawn) {
  3728. if (spawn->IsPlayer()) {
  3729. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3730. if (client)
  3731. client->AddPendingQuestReward(quest);
  3732. }
  3733. }
  3734. return 0;
  3735. }
  3736. int EQ2Emu_lua_Harvest(lua_State* state) {
  3737. if (!lua_interface)
  3738. return 0;
  3739. Spawn* player = lua_interface->GetSpawn(state);
  3740. Spawn* node = lua_interface->GetSpawn(state, 2);
  3741. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3742. Client* client = player->GetZone()->GetClientBySpawn(player);
  3743. if (client) {
  3744. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3745. ((GroundSpawn*)node)->ProcessHarvest(client);
  3746. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3747. player->GetZone()->RemoveSpawn(node, true);
  3748. }
  3749. }
  3750. else if (player && player->IsPlayer()) {
  3751. Client* client = player->GetZone()->GetClientBySpawn(player);
  3752. if (client)
  3753. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3754. }
  3755. return 0;
  3756. }
  3757. int EQ2Emu_lua_Bind(lua_State* state) {
  3758. if (!lua_interface)
  3759. return 0;
  3760. Spawn* spawn = lua_interface->GetSpawn(state);
  3761. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3762. float x = lua_interface->GetFloatValue(state, 3);
  3763. float y = lua_interface->GetFloatValue(state, 4);
  3764. float z = lua_interface->GetFloatValue(state, 5);
  3765. float h = lua_interface->GetFloatValue(state, 6);
  3766. if (!spawn) {
  3767. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3768. return 0;
  3769. }
  3770. if (!spawn->IsPlayer()) {
  3771. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3772. return 0;
  3773. }
  3774. if (zone_id == 0) {
  3775. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3776. if (!client) {
  3777. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3778. return 0;
  3779. }
  3780. if (!client->Bind())
  3781. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3782. }
  3783. else {
  3784. Player* player = (Player*)spawn;
  3785. player->GetPlayerInfo()->SetBindZone(zone_id);
  3786. player->GetPlayerInfo()->SetBindX(x);
  3787. player->GetPlayerInfo()->SetBindY(y);
  3788. player->GetPlayerInfo()->SetBindZ(z);
  3789. player->GetPlayerInfo()->SetBindHeading(h);
  3790. }
  3791. return 0;
  3792. }
  3793. int EQ2Emu_lua_Gate(lua_State* state) {
  3794. if (!lua_interface)
  3795. return 0;
  3796. Spawn* spawn = lua_interface->GetSpawn(state);
  3797. if (spawn) {
  3798. if (spawn->IsPlayer()) {
  3799. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3800. if (client) {
  3801. if (!client->Gate())
  3802. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3803. }
  3804. }
  3805. }
  3806. return 0;
  3807. }
  3808. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3809. if (!lua_interface)
  3810. return 0;
  3811. bool ret = false;
  3812. Spawn* spawn = lua_interface->GetSpawn(state);
  3813. if (spawn) {
  3814. if (spawn->IsPlayer()) {
  3815. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3816. if (client)
  3817. ret = client->BindAllowed();
  3818. }
  3819. }
  3820. lua_interface->SetBooleanValue(state, ret);
  3821. return 1;
  3822. }
  3823. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3824. if (!lua_interface)
  3825. return 0;
  3826. bool ret = false;
  3827. Spawn* spawn = lua_interface->GetSpawn(state);
  3828. if (spawn) {
  3829. if (spawn->IsPlayer()) {
  3830. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3831. if (client)
  3832. ret = client->GateAllowed();
  3833. }
  3834. }
  3835. lua_interface->SetBooleanValue(state, ret);
  3836. return 1;
  3837. }
  3838. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3839. Spawn* spawn = lua_interface->GetSpawn(state);
  3840. if (spawn) {
  3841. lua_interface->SetBooleanValue(state, spawn->Alive());
  3842. return 1;
  3843. }
  3844. return 0;
  3845. }
  3846. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3847. if (!lua_interface)
  3848. return 0;
  3849. Spawn* spawn = lua_interface->GetSpawn(state);
  3850. if (spawn && spawn->IsEntity()) {
  3851. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3852. return 1;
  3853. }
  3854. return 0;
  3855. }
  3856. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3857. Spawn* spawn = lua_interface->GetSpawn(state);
  3858. string message = lua_interface->GetStringValue(state, 2);
  3859. string color_str = lua_interface->GetStringValue(state, 3);
  3860. int8 color = CHANNEL_NARRATIVE;
  3861. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3862. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3863. if (client) {
  3864. if (color_str.length() > 0) {
  3865. // leave for backwards compat, but all future should just use the number
  3866. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3867. color = CHANNEL_COLOR_RED;
  3868. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3869. color = CHANNEL_COLOR_YELLOW;
  3870. else
  3871. {
  3872. // use a number to specify the channel as per Commands/Commands.h defines
  3873. color = (int8)atoul(color_str.c_str());
  3874. }
  3875. }
  3876. client->SimpleMessage(color, message.c_str());
  3877. }
  3878. }
  3879. return 0;
  3880. }
  3881. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3882. Spawn* spawn = lua_interface->GetSpawn(state);
  3883. string message = lua_interface->GetStringValue(state, 2);
  3884. int8 red = lua_interface->GetInt8Value(state, 3);
  3885. int8 green = lua_interface->GetInt8Value(state, 4);
  3886. int8 blue = lua_interface->GetInt8Value(state, 5);
  3887. if (!spawn) {
  3888. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3889. return 0;
  3890. }
  3891. int32 words = ::CountWordsInString(message.c_str());
  3892. if (words < 5)
  3893. words = 5;
  3894. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3895. if (client)
  3896. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3897. return 0;
  3898. }
  3899. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3900. Spawn* spawn = lua_interface->GetSpawn(state);
  3901. int8 param = lua_interface->GetInt8Value(state, 2);
  3902. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3903. int8 value = lua_interface->GetInt8Value(state, 4);
  3904. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3905. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3906. if (client) {
  3907. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3908. switch (param) {
  3909. case 1: {
  3910. packet->setDataByName("parameter1", param_value);
  3911. break;
  3912. }
  3913. case 2: {
  3914. packet->setDataByName("parameter2", param_value);
  3915. break;
  3916. }
  3917. case 3: {
  3918. packet->setDataByName("parameter3", param_value);
  3919. break;
  3920. }
  3921. case 4: {
  3922. packet->setDataByName("parameter4", param_value);
  3923. break;
  3924. }
  3925. case 5: {
  3926. packet->setDataByName("parameter5", param_value);
  3927. break;
  3928. }
  3929. }
  3930. packet->setDataByName("value", value);
  3931. client->QueuePacket(packet->serialize());
  3932. safe_delete(packet);
  3933. }
  3934. }
  3935. return 0;
  3936. }
  3937. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3938. Spawn* spawn = lua_interface->GetSpawn(state);
  3939. if (spawn && spawn->IsPlayer()) {
  3940. if (((Player*)spawn)->GetIsTracking())
  3941. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3942. else
  3943. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3944. }
  3945. return 0;
  3946. }
  3947. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3948. Spawn* player = lua_interface->GetSpawn(state);
  3949. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3950. string name = lua_interface->GetStringValue(state, 3);
  3951. float distance = lua_interface->GetFloatValue(state, 4);
  3952. string command = lua_interface->GetStringValue(state, 5);
  3953. string error_text = lua_interface->GetStringValue(state, 6);
  3954. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3955. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3956. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3957. if (spawn) {
  3958. if (distance == 0)
  3959. distance = 10.0f;
  3960. if (command.length() == 0)
  3961. command = name;
  3962. if (command.length() < 1 && name.length() < 1)
  3963. {
  3964. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3965. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3966. spawn->RemovePrimaryCommands();
  3967. }
  3968. else
  3969. {
  3970. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3971. }
  3972. }
  3973. return 0;
  3974. }
  3975. int EQ2Emu_lua_HasSpell(lua_State* state) {
  3976. if (!lua_interface)
  3977. return 0;
  3978. Spawn* player = lua_interface->GetSpawn(state);
  3979. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3980. int16 tier = lua_interface->GetInt16Value(state, 3);
  3981. if (player && player->IsPlayer()) {
  3982. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  3983. return 1;
  3984. }
  3985. return 0;
  3986. }
  3987. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3988. if (!lua_interface)
  3989. return 0;
  3990. Spawn* player = lua_interface->GetSpawn(state);
  3991. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3992. int16 tier = lua_interface->GetInt16Value(state, 3);
  3993. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3994. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  3995. bool add_to_hotbar = true;
  3996. if (num_args > 4) {
  3997. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  3998. }
  3999. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4000. if (player && spell && player->IsPlayer()) {
  4001. Client* client = player->GetClient();
  4002. if (client) {
  4003. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4004. {
  4005. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4006. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4007. client->GetPlayer()->UnlockSpell(spell);
  4008. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4009. }
  4010. else
  4011. {
  4012. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4013. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4014. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4015. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4016. client->GetPlayer()->UnlockSpell(spell);
  4017. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4018. }
  4019. //if (client ) {
  4020. // ((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);
  4021. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4022. if (outapp)
  4023. client->QueuePacket(outapp);
  4024. }
  4025. }
  4026. return 0;
  4027. }
  4028. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4029. if (!lua_interface)
  4030. return 0;
  4031. Spawn* player = lua_interface->GetSpawn(state);
  4032. if (player && player->IsPlayer()) {
  4033. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4034. return 1;
  4035. }
  4036. return 0;
  4037. }
  4038. int EQ2Emu_lua_Attack(lua_State* state) {
  4039. if (lua_interface) {
  4040. Spawn* npc = lua_interface->GetSpawn(state);
  4041. Spawn* player = lua_interface->GetSpawn(state, 2);
  4042. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4043. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4044. }
  4045. return 0;
  4046. }
  4047. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4048. if (lua_interface) {
  4049. Spawn* target = lua_interface->GetSpawn(state);
  4050. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4051. if (target && target->GetZone())
  4052. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4053. }
  4054. return 0;
  4055. }
  4056. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4057. Spawn* player;
  4058. if (lua_interface) {
  4059. player = lua_interface->GetSpawn(state);
  4060. if (player && player->IsPlayer()) {
  4061. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4062. return 1;
  4063. }
  4064. }
  4065. return 0;
  4066. }
  4067. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4068. Spawn* player;
  4069. Client* client;
  4070. if (lua_interface) {
  4071. player = lua_interface->GetSpawn(state);
  4072. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4073. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4074. client->HandInCollections();
  4075. }
  4076. return 0;
  4077. }
  4078. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4079. Spawn* widget;
  4080. if (lua_interface) {
  4081. widget = lua_interface->GetSpawn(state);
  4082. if (widget && widget->IsWidget())
  4083. ((Widget*)widget)->HandleUse(nullptr, "");
  4084. }
  4085. return 0;
  4086. }
  4087. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4088. Spawn* spawn = 0;
  4089. int32 primary_list = 0;
  4090. int32 secondary_list = 0;
  4091. if (lua_interface) {
  4092. spawn = lua_interface->GetSpawn(state);
  4093. primary_list = lua_interface->GetInt32Value(state, 2);
  4094. secondary_list = lua_interface->GetInt32Value(state, 3);
  4095. if (!spawn->IsNPC()) {
  4096. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4097. return 0;
  4098. }
  4099. NPC* npc = (NPC*)spawn;
  4100. npc->SetPrimarySpellList(primary_list);
  4101. npc->SetSecondarySpellList(secondary_list);
  4102. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4103. }
  4104. return 0;
  4105. }
  4106. int EQ2Emu_lua_GetPet(lua_State* state) {
  4107. if (!lua_interface)
  4108. return 0;
  4109. Spawn* spawn = lua_interface->GetSpawn(state);
  4110. if (spawn) {
  4111. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4112. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4113. return 1;
  4114. }
  4115. }
  4116. return 0;
  4117. }
  4118. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4119. if (!lua_interface)
  4120. return 0;
  4121. Spawn* spawn = lua_interface->GetSpawn(state);
  4122. if (spawn) {
  4123. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4124. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4125. return 1;
  4126. }
  4127. }
  4128. return 0;
  4129. }
  4130. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4131. if (!lua_interface)
  4132. return 0;
  4133. Spawn* spawn = lua_interface->GetSpawn(state);
  4134. if (spawn) {
  4135. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4136. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4137. return 1;
  4138. }
  4139. }
  4140. return 0;
  4141. }
  4142. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4143. if (!lua_interface)
  4144. return 0;
  4145. Spawn* spawn = lua_interface->GetSpawn(state);
  4146. if (spawn) {
  4147. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4148. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4149. return 1;
  4150. }
  4151. }
  4152. return 0;
  4153. }
  4154. int EQ2Emu_lua_Charm(lua_State* state) {
  4155. if (!lua_interface)
  4156. return 0;
  4157. Spawn* owner = lua_interface->GetSpawn(state);
  4158. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4159. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4160. if (!luaspell) {
  4161. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4162. return 0;
  4163. }
  4164. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4165. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4166. pet->SetPet(true);
  4167. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4168. ((NPC*)pet)->SetOwner((Entity*)owner);
  4169. // If owner is player and player does not have a summoned pet set the players charsheet
  4170. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4171. Player* player = (Player*)owner;
  4172. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4173. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4174. player->GetInfoStruct()->set_pet_movement(2);
  4175. player->GetInfoStruct()->set_pet_behavior(3);
  4176. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4177. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4178. // Make sure the values get sent to the client
  4179. player->SetCharSheetChanged(true);
  4180. }
  4181. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4182. pet->SetSpawnScript("");
  4183. // Set faction to the same as the owner
  4184. pet->SetFactionID(owner->GetFactionID());
  4185. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4186. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4187. // Clear hate list
  4188. ((NPC*)pet)->Brain()->ClearHate();
  4189. // Set the brain to a pet brain
  4190. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4191. }
  4192. return 0;
  4193. }
  4194. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4195. if (!lua_interface)
  4196. return 0;
  4197. Spawn* spawn = lua_interface->GetSpawn(state);
  4198. if (!spawn) {
  4199. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4200. return 0;
  4201. }
  4202. vector<Spawn*> groupMembers;
  4203. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4204. groupMembers = *spawn->GetSpawnGroup();
  4205. }
  4206. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4207. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4208. deque<GroupMemberInfo*>::iterator itr;
  4209. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4210. if (group)
  4211. {
  4212. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4213. deque<GroupMemberInfo*>* members = group->GetMembers();
  4214. GroupMemberInfo* info = 0;
  4215. for (itr = members->begin(); itr != members->end(); itr++) {
  4216. info = *itr;
  4217. if (info->client)
  4218. groupMembers.push_back(info->client->GetPlayer());
  4219. }
  4220. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4221. }
  4222. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4223. }
  4224. else
  4225. return 0;
  4226. lua_createtable(state, groupMembers.size(), 0);
  4227. int newTable = lua_gettop(state);
  4228. for (int32 i = 0; i < groupMembers.size(); i++) {
  4229. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4230. lua_rawseti(state, newTable, i + 1);
  4231. }
  4232. return 1;
  4233. }
  4234. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4235. if (!lua_interface)
  4236. return 0;
  4237. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4238. lua_interface->SetOptionWindowValue(state, option_window);
  4239. return 1;
  4240. }
  4241. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4242. if (!lua_interface)
  4243. return 0;
  4244. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4245. if (option_window) {
  4246. OptionWindowOption option_window_option;
  4247. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4248. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4249. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4250. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4251. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4252. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4253. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4254. option_window->push_back(option_window_option);
  4255. }
  4256. return 0;
  4257. }
  4258. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4259. if (!lua_interface)
  4260. return 0;
  4261. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4262. Spawn* player = lua_interface->GetSpawn(state, 2);
  4263. string window_title = lua_interface->GetStringValue(state, 3);
  4264. string cancel_command = lua_interface->GetStringValue(state, 4);
  4265. Client* client = player->GetZone()->GetClientBySpawn(player);
  4266. if (option_window && window_title.length() > 0 && client) {
  4267. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4268. if (!packet)
  4269. return 0;
  4270. packet->setDataByName("title_text", window_title.c_str());
  4271. if (cancel_command.length() > 0)
  4272. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4273. packet->setArrayLengthByName("num_selections", option_window->size());
  4274. vector<OptionWindowOption>::iterator itr;
  4275. int8 i = 0;
  4276. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4277. OptionWindowOption opt = *itr;
  4278. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4279. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4280. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4281. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4282. if (opt.optionCommand.length() > 0)
  4283. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4284. if (opt.optionConfirmTitle.length() > 0)
  4285. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4286. i++;
  4287. }
  4288. client->QueuePacket(packet->serialize());
  4289. safe_delete(option_window);
  4290. safe_delete(packet);
  4291. }
  4292. return 0;
  4293. }
  4294. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4295. if (!lua_interface)
  4296. return 0;
  4297. Spawn* spawn = lua_interface->GetSpawn(state);
  4298. if (spawn) {
  4299. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4300. return 1;
  4301. }
  4302. else
  4303. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4304. return 0;
  4305. }
  4306. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4307. if (!lua_interface)
  4308. return 0;
  4309. Spawn* spawn = lua_interface->GetSpawn(state);
  4310. if (spawn) {
  4311. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4312. return 1;
  4313. }
  4314. else
  4315. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4316. return 0;
  4317. }
  4318. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4319. if (!lua_interface)
  4320. return 0;
  4321. Spawn* spawn = lua_interface->GetSpawn(state);
  4322. if (spawn) {
  4323. int8 class_id = spawn->GetTradeskillClass();
  4324. // Need to add 42 for the offset in the array
  4325. class_id += 44;
  4326. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4327. return 1;
  4328. }
  4329. else
  4330. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4331. return 0;
  4332. }
  4333. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4334. if (!lua_interface)
  4335. return 0;
  4336. Spawn* spawn = lua_interface->GetSpawn(state);
  4337. int16 level = lua_interface->GetInt8Value(state, 2);
  4338. if (spawn) {
  4339. if (spawn->IsPlayer())
  4340. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4341. else
  4342. spawn->SetTSLevel(level);
  4343. }
  4344. else
  4345. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4346. return 0;
  4347. }
  4348. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4349. if (!lua_interface)
  4350. return 0;
  4351. Spawn* spawn = lua_interface->GetSpawn(state);
  4352. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4353. if (spawn) {
  4354. spawn->SetAttackable(attackable);
  4355. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4356. }
  4357. return 0;
  4358. }
  4359. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4360. // Check to see if we have a valid lua_interface
  4361. if (!lua_interface)
  4362. return 0;
  4363. // Get the spawn that is getting the pet
  4364. Spawn* spawn = lua_interface->GetSpawn(state);
  4365. // Get the DB ID of the pet
  4366. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4367. // The max level the pet can gain
  4368. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4369. // Get the spell that this command was called from
  4370. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4371. // Check to make sure the spawn pointer is valid
  4372. if (!spawn) {
  4373. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4374. return 0;
  4375. }
  4376. // Check to make sure the spawn is an entity
  4377. if (!spawn->IsEntity()) {
  4378. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4379. return 0;
  4380. }
  4381. // Check to make sure the spawn doesn't already have a pet of this type
  4382. if (((Entity*)spawn)->GetPet()) {
  4383. if (spawn->IsPlayer()) {
  4384. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4385. if (client)
  4386. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4387. }
  4388. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4389. return 0;
  4390. }
  4391. // Check to see if the DB ID for the pet is set
  4392. if (pet_id == 0) {
  4393. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4394. return 0;
  4395. }
  4396. // Check to see if the pointer to the spell is valid
  4397. if (!luaspell) {
  4398. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4399. return 0;
  4400. }
  4401. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4402. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4403. if (!pet) {
  4404. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4405. return 0;
  4406. }
  4407. // Check to make sure the pet is an npc
  4408. if (!pet->IsNPC()) {
  4409. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4410. return 0;
  4411. }
  4412. // Spawn the pet at the same location as the owner
  4413. pet->SetX(spawn->GetX());
  4414. pet->SetY(spawn->GetY());
  4415. pet->SetZ(spawn->GetZ());
  4416. pet->SetLocation(spawn->GetLocation());
  4417. pet->SetHeading(spawn->GetHeading());
  4418. spawn->GetZone()->AddSpawn(pet);
  4419. /*
  4420. const char* spawn_script = world.GetSpawnScript(pet_id);
  4421. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4422. spawn->SetSpawnScript(string(spawn_script));
  4423. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4424. }*/
  4425. // Get a random pet name
  4426. string random_pet_name;
  4427. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4428. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4429. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4430. // If player set various values for the char sheet (pet window)
  4431. if (spawn->IsPlayer()) {
  4432. Player* player = (Player*)spawn;
  4433. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4434. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4435. player->GetInfoStruct()->set_pet_movement(2);
  4436. player->GetInfoStruct()->set_pet_behavior(3);
  4437. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4438. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4439. // Make sure the values get sent to the client
  4440. player->SetCharSheetChanged(true);
  4441. }
  4442. // Set the pets name
  4443. pet->SetName(random_pet_name.c_str());
  4444. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4445. if (max_level > 0)
  4446. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4447. else
  4448. pet->SetLevel(spawn->GetLevel());
  4449. // Set the max level this pet can reach
  4450. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4451. // Set the faction of the pet to the same faction as the owner
  4452. pet->SetFactionID(spawn->GetFactionID());
  4453. // Set the spawn as a pet
  4454. pet->SetPet(true);
  4455. // Give a pointer of the owner to the pet
  4456. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4457. // Give a pointer of the pet to the owner
  4458. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4459. // Set the pet type
  4460. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4461. // Set the spell id used to create this pet
  4462. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4463. // Set the spell tier used to create this pet
  4464. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4465. // Set the pets spawn type to 6
  4466. pet->SetSpawnType(6);
  4467. // Set the pets brain
  4468. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4469. // Check to see if the pet has a subtitle
  4470. if (strlen(pet->GetSubTitle()) > 0) {
  4471. // Add the players name to the front of the sub title
  4472. string pet_subtitle;
  4473. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4474. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4475. // Set the pets subtitle to the new one
  4476. pet->SetSubTitle(pet_subtitle.c_str());
  4477. }
  4478. // Add the "Pet Options" entity command to the pet
  4479. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4480. // Set the pet as the return value for this function
  4481. lua_interface->SetSpawnValue(state, pet);
  4482. return 1;
  4483. }
  4484. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4485. if (!lua_interface)
  4486. return 0;
  4487. Spawn* spawn = lua_interface->GetSpawn(state);
  4488. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4489. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4490. if (!spawn) {
  4491. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4492. return 0;
  4493. }
  4494. if (!spawn->IsEntity()) {
  4495. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4496. return 0;
  4497. }
  4498. if (((Entity*)spawn)->GetDeityPet()) {
  4499. if (spawn->IsPlayer()) {
  4500. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4501. if (client)
  4502. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4503. }
  4504. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4505. return 0;
  4506. }
  4507. if (pet_id == 0) {
  4508. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4509. return 0;
  4510. }
  4511. if (!luaspell) {
  4512. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4513. return 0;
  4514. }
  4515. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4516. if (!pet) {
  4517. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4518. return 0;
  4519. }
  4520. if (!pet->IsNPC()) {
  4521. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4522. return 0;
  4523. }
  4524. pet->SetX(spawn->GetX());
  4525. pet->SetY(spawn->GetY());
  4526. pet->SetZ(spawn->GetZ());
  4527. pet->SetLocation(spawn->GetLocation());
  4528. pet->SetHeading(spawn->GetHeading());
  4529. spawn->GetZone()->AddSpawn(pet);
  4530. string random_pet_name;
  4531. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4532. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4533. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4534. pet->SetName(random_pet_name.c_str());
  4535. pet->SetLevel(spawn->GetLevel());
  4536. pet->SetFactionID(spawn->GetFactionID());
  4537. pet->SetPet(true);
  4538. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4539. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4540. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4541. pet->SetSpawnType(6);
  4542. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4543. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4544. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4545. if (strlen(pet->GetSubTitle()) > 0) {
  4546. string pet_subtitle;
  4547. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4548. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4549. pet->SetSubTitle(pet_subtitle.c_str());
  4550. }
  4551. // deity and cosmetic pets are not attackable
  4552. pet->SetAttackable(false);
  4553. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4554. lua_interface->SetSpawnValue(state, pet);
  4555. return 1;
  4556. }
  4557. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4558. if (!lua_interface)
  4559. return 0;
  4560. Spawn* spawn = lua_interface->GetSpawn(state);
  4561. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4562. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4563. if (!spawn) {
  4564. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4565. return 0;
  4566. }
  4567. if (!spawn->IsEntity()) {
  4568. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4569. return 0;
  4570. }
  4571. if (((Entity*)spawn)->GetCosmeticPet()) {
  4572. if (spawn->IsPlayer()) {
  4573. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4574. if (client)
  4575. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4576. }
  4577. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4578. return 0;
  4579. }
  4580. if (pet_id == 0) {
  4581. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4582. return 0;
  4583. }
  4584. if (!luaspell) {
  4585. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4586. return 0;
  4587. }
  4588. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4589. if (!pet) {
  4590. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4591. return 0;
  4592. }
  4593. if (!pet->IsNPC()) {
  4594. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4595. return 0;
  4596. }
  4597. pet->SetX(spawn->GetX());
  4598. pet->SetY(spawn->GetY());
  4599. pet->SetZ(spawn->GetZ());
  4600. pet->SetLocation(spawn->GetLocation());
  4601. pet->SetHeading(spawn->GetHeading());
  4602. spawn->GetZone()->AddSpawn(pet);
  4603. string random_pet_name;
  4604. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4605. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4606. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4607. pet->SetName(random_pet_name.c_str());
  4608. pet->SetLevel(spawn->GetLevel());
  4609. pet->SetFactionID(spawn->GetFactionID());
  4610. pet->SetPet(true);
  4611. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4612. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4613. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4614. pet->SetSpawnType(6);
  4615. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4616. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4617. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4618. if (strlen(pet->GetSubTitle()) > 0) {
  4619. string pet_subtitle;
  4620. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4621. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4622. pet->SetSubTitle(pet_subtitle.c_str());
  4623. }
  4624. pet->SetAttackable(false);
  4625. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4626. lua_interface->SetSpawnValue(state, pet);
  4627. return 1;
  4628. }
  4629. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4630. if (!lua_interface)
  4631. return 0;
  4632. Spawn* spawn = lua_interface->GetSpawn(state);
  4633. if (!spawn) {
  4634. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4635. return 0;
  4636. }
  4637. if (!spawn->IsPet()) {
  4638. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4639. return 0;
  4640. }
  4641. if (!((NPC*)spawn)->IsDismissing())
  4642. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4643. return 0;
  4644. }
  4645. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4646. if (!lua_interface)
  4647. return 0;
  4648. Quest* quest = lua_interface->GetQuest(state);
  4649. if (!quest) {
  4650. lua_interface->LogError("%s: LUA SetQuestFeatherColor command error: valid quest not found, SetQuestFeatherColor can only be called from a quest script", lua_interface->GetScriptName(state));
  4651. return 0;
  4652. }
  4653. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4654. if (feather_color > 0)
  4655. quest->SetFeatherColor(feather_color);
  4656. return 0;
  4657. }
  4658. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4659. if (!lua_interface)
  4660. return 0;
  4661. Spawn* spawn = lua_interface->GetSpawn(state);
  4662. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4663. if (!spawn) {
  4664. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4665. return 0;
  4666. }
  4667. if (!spawn2) {
  4668. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4669. return 0;
  4670. }
  4671. spawn->RemoveSpawnAccess(spawn2);
  4672. return 0;
  4673. }
  4674. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4675. if (!lua_interface)
  4676. return 0;
  4677. ZoneServer* zone = lua_interface->GetZone(state);
  4678. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4679. if (!zone) {
  4680. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4681. return 0;
  4682. }
  4683. if (location_id == 0) {
  4684. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4685. return 0;
  4686. }
  4687. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4688. if (!location) {
  4689. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4690. return 0;
  4691. }
  4692. Spawn* spawn = 0;
  4693. if (location->entities[0]) {
  4694. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4695. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4696. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4697. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4698. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4699. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4700. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4701. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4702. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4703. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4704. if (spawn) {
  4705. const char* script = 0;
  4706. for (int x = 0; x < 3; x++) {
  4707. switch (x) {
  4708. case 0:
  4709. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4710. break;
  4711. case 1:
  4712. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4713. break;
  4714. case 2:
  4715. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4716. break;
  4717. }
  4718. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4719. spawn->SetSpawnScript(string(script));
  4720. break;
  4721. }
  4722. }
  4723. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4724. lua_interface->SetSpawnValue(state, spawn);
  4725. return 1;
  4726. }
  4727. else {
  4728. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4729. safe_delete(spawn);
  4730. }
  4731. }
  4732. return 0;
  4733. }
  4734. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4735. if (!lua_interface)
  4736. return 0;
  4737. Spawn* caster = lua_interface->GetSpawn(state);
  4738. Spawn* target = lua_interface->GetSpawn(state, 2);
  4739. int32 id = lua_interface->GetInt32Value(state, 3);
  4740. string command = lua_interface->GetStringValue(state, 4);
  4741. if (!caster) {
  4742. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4743. return 0;
  4744. }
  4745. if (!target) {
  4746. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4747. return 0;
  4748. }
  4749. if (!caster->IsPlayer()) {
  4750. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4751. return 0;
  4752. }
  4753. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4754. if (!entity_command) {
  4755. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid EntityCommand with the given ID (%u) and name (%s)", lua_interface->GetScriptName(state), id, command.c_str());
  4756. return 0;
  4757. }
  4758. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4759. if (!client) {
  4760. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4761. return 0;
  4762. }
  4763. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4764. return 0;
  4765. }
  4766. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4767. if (!lua_interface)
  4768. return 0;
  4769. Spawn* spawn = lua_interface->GetSpawn(state);
  4770. if (!spawn) {
  4771. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4772. return 0;
  4773. }
  4774. if (!spawn->IsNPC()) {
  4775. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4776. return 0;
  4777. }
  4778. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4779. return 0;
  4780. }
  4781. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4782. if (!lua_interface)
  4783. return 0;
  4784. Spawn* spawn = lua_interface->GetSpawn(state);
  4785. int16 tick = lua_interface->GetInt16Value(state, 2);
  4786. if (!spawn) {
  4787. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4788. return 0;
  4789. }
  4790. if (!spawn->IsNPC()) {
  4791. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4792. return 0;
  4793. }
  4794. if (tick < 20) {
  4795. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4796. return 0;
  4797. }
  4798. ((NPC*)spawn)->Brain()->SetTick(tick);
  4799. return 0;
  4800. }
  4801. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4802. if (!lua_interface)
  4803. return 0;
  4804. Spawn* spawn = lua_interface->GetSpawn(state);
  4805. Spawn* target = lua_interface->GetSpawn(state, 2);
  4806. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4807. if (!spawn) {
  4808. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4809. return 0;
  4810. }
  4811. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4812. spawn->SetFollowTarget(target, follow_distance);
  4813. return 0;
  4814. }
  4815. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4816. if (!lua_interface)
  4817. return 0;
  4818. Spawn* spawn = lua_interface->GetSpawn(state);
  4819. if (!spawn) {
  4820. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4821. return 0;
  4822. }
  4823. Spawn* target = spawn->GetFollowTarget();
  4824. if (target) {
  4825. lua_interface->SetSpawnValue(state, target);
  4826. return 1;
  4827. }
  4828. return 0;
  4829. }
  4830. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4831. if (!lua_interface)
  4832. return 0;
  4833. Spawn* spawn = lua_interface->GetSpawn(state);
  4834. if (!spawn) {
  4835. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4836. return 0;
  4837. }
  4838. if (spawn->following)
  4839. spawn->following = false;
  4840. else
  4841. spawn->following = true;
  4842. return 0;
  4843. }
  4844. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4845. if (!lua_interface)
  4846. return 0;
  4847. Spawn* spawn = lua_interface->GetSpawn(state);
  4848. if (!spawn) {
  4849. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4850. return 0;
  4851. }
  4852. lua_interface->SetBooleanValue(state, spawn->following);
  4853. return 1;
  4854. }
  4855. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4856. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4857. // I will attempt to explain how this function works for future refrence
  4858. // Fist lets make sure lua_interface is valid, if not return out
  4859. if (!lua_interface)
  4860. return 0;
  4861. // Next we grab the first 2 params same as we usually would
  4862. Spawn* spawn = lua_interface->GetSpawn(state);
  4863. string var = lua_interface->GetStringValue(state, 2);
  4864. // 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
  4865. // 1 = Spawn
  4866. // 2 = Zone
  4867. // 3 = Item
  4868. // 4 = Quest
  4869. // 5 = String
  4870. // 6 = nil (null)
  4871. int8 dataType = 0;
  4872. // Define pointers for each potential type
  4873. Spawn* spawnVal = 0;
  4874. ZoneServer* zone = 0;
  4875. Item* item = 0;
  4876. Quest* quest = 0;
  4877. string val;
  4878. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4879. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4880. // options window are also light user data be we do not handle those.
  4881. // We check with lua_islightuserdata(lua_State*, index)
  4882. if (lua_islightuserdata(state, 3)) {
  4883. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4884. // and convert it to LUAUserData*
  4885. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4886. // Check to make sure the data we got is valid, if not give an error
  4887. if (!data || !data->IsCorrectlyInitialized()) {
  4888. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4889. }
  4890. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4891. else if (data->IsSpawn()) {
  4892. spawnVal = data->spawn;
  4893. dataType = 1;
  4894. }
  4895. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4896. else if (data->IsZone()) {
  4897. zone = data->zone;
  4898. dataType = 2;
  4899. }
  4900. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4901. else if (data->IsItem()) {
  4902. item = data->item;
  4903. dataType = 3;
  4904. }
  4905. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4906. else if (data->IsQuest()) {
  4907. quest = data->quest;
  4908. dataType = 4;
  4909. }
  4910. }
  4911. // Wasn't light user data, check if it is nil(null)
  4912. else if (lua_isnil(state, 3)) {
  4913. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4914. dataType = 6;
  4915. }
  4916. // Wasn't light user data or nil (null), must be a string
  4917. else {
  4918. // Set the string and dataType variable
  4919. val = lua_interface->GetStringValue(state, 3);
  4920. dataType = 5;
  4921. }
  4922. // We now have all the params, lets check to make sure they are valid
  4923. if (!spawn) {
  4924. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4925. return 0;
  4926. }
  4927. if (var.length() == 0) {
  4928. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4929. return 0;
  4930. }
  4931. if (dataType == 0) {
  4932. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4933. return 0;
  4934. }
  4935. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4936. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4937. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4938. switch (dataType) {
  4939. case 1:
  4940. // 1 = Spawn
  4941. spawn->AddTempVariable(var, spawnVal);
  4942. break;
  4943. case 2:
  4944. // 2 = Zone
  4945. spawn->AddTempVariable(var, zone);
  4946. break;
  4947. case 3:
  4948. // 3 = Item
  4949. spawn->AddTempVariable(var, item);
  4950. break;
  4951. case 4:
  4952. // 4 = Quest
  4953. spawn->AddTempVariable(var, quest);
  4954. break;
  4955. case 5:
  4956. // 5 = String
  4957. spawn->AddTempVariable(var, val);
  4958. break;
  4959. case 6:
  4960. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4961. spawn->DeleteTempVariable(var);
  4962. break;
  4963. }
  4964. // And we are done so return out
  4965. return 0;
  4966. }
  4967. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4968. if (!lua_interface)
  4969. return 0;
  4970. Spawn* spawn = lua_interface->GetSpawn(state);
  4971. string var = lua_interface->GetStringValue(state, 2);
  4972. if (!spawn) {
  4973. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4974. return 0;
  4975. }
  4976. if (var.length() == 0) {
  4977. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4978. return 0;
  4979. }
  4980. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4981. int8 type = spawn->GetTempVariableType(var);
  4982. Spawn* spawn2 = 0;
  4983. ZoneServer* zone = 0;
  4984. Item* item = 0;
  4985. Quest* quest = 0;
  4986. // Set the lua function return value based on the type of data the variable contains
  4987. switch (type) {
  4988. case 1:
  4989. spawn2 = spawn->GetTempVariableSpawn(var);
  4990. if (!spawn2)
  4991. return 0;
  4992. lua_interface->SetSpawnValue(state, spawn2);
  4993. break;
  4994. case 2:
  4995. zone = spawn->GetTempVariableZone(var);
  4996. if (!zone)
  4997. return 0;
  4998. lua_interface->SetZoneValue(state, zone);
  4999. break;
  5000. case 3:
  5001. item = spawn->GetTempVariableItem(var);
  5002. if (!item)
  5003. return 0;
  5004. lua_interface->SetItemValue(state, item);
  5005. break;
  5006. case 4:
  5007. quest = spawn->GetTempVariableQuest(var);
  5008. if (!quest)
  5009. return 0;
  5010. lua_interface->SetQuestValue(state, quest);
  5011. break;
  5012. case 5:
  5013. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5014. break;
  5015. default:
  5016. // Not a valid type then the variable was not set so return out
  5017. return 0;
  5018. }
  5019. // Return value was set so return out
  5020. return 1;
  5021. }
  5022. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5023. {
  5024. if (!lua_interface)
  5025. return 0;
  5026. Quest* quest = lua_interface->GetQuest(state);
  5027. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5028. string description = lua_interface->GetStringValue(state, 3);
  5029. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5030. if (!quest) {
  5031. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5032. lua_interface->SetBooleanValue(state, false);
  5033. return 1;
  5034. }
  5035. if (!spawn) {
  5036. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5037. lua_interface->SetBooleanValue(state, false);
  5038. return 1;
  5039. }
  5040. if (!spawn->IsPlayer()) {
  5041. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5042. lua_interface->SetBooleanValue(state, false);
  5043. return 1;
  5044. }
  5045. if (item_id == 0) {
  5046. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5047. lua_interface->SetBooleanValue(state, false);
  5048. return 1;
  5049. }
  5050. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5051. if (!client) {
  5052. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5053. lua_interface->SetBooleanValue(state, false);
  5054. return 1;
  5055. }
  5056. Item* item = master_item_list.GetItem(item_id);
  5057. if (!item) {
  5058. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5059. lua_interface->SetBooleanValue(state, false);
  5060. return 1;
  5061. }
  5062. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  5063. if (packet) {
  5064. packet->setDataByName("title", "Quest Reward!");
  5065. packet->setDataByName("name", quest->GetName());
  5066. packet->setDataByName("description", description.c_str());
  5067. packet->setDataByName("level", quest->GetLevel());
  5068. packet->setArrayLengthByName("num_rewards", 1);
  5069. packet->setArrayDataByName("reward_id", item->details.item_id);
  5070. if (client->GetVersion() < 860)
  5071. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  5072. else if (client->GetVersion() < 1193)
  5073. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  5074. else
  5075. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  5076. client->QueuePacket(packet->serialize());
  5077. safe_delete(packet);
  5078. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  5079. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  5080. return 1;
  5081. }
  5082. lua_interface->SetBooleanValue(state, false);
  5083. return 1;
  5084. }
  5085. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5086. if (!lua_interface)
  5087. return 0;
  5088. Quest* quest = lua_interface->GetQuest(state);
  5089. if (!quest) {
  5090. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5091. return 0;
  5092. }
  5093. quest->SetRepeatable(true);
  5094. return 0;
  5095. }
  5096. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5097. if (!lua_interface)
  5098. return 0;
  5099. Spawn* spawn = lua_interface->GetSpawn(state);
  5100. if (!spawn) {
  5101. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5102. return 0;
  5103. }
  5104. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5105. string ret = classes.GetClassNameCase(base_class);
  5106. if (ret.length() > 0) {
  5107. lua_interface->SetStringValue(state, ret.c_str());
  5108. return 1;
  5109. }
  5110. return 0;
  5111. }
  5112. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5113. if (!lua_interface)
  5114. return 0;
  5115. Spawn* player = lua_interface->GetSpawn(state);
  5116. if (player && player->IsPlayer()) {
  5117. Client* client = player->GetClient();
  5118. if (client)
  5119. client->SendWaypoints();
  5120. }
  5121. return 0;
  5122. }
  5123. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5124. if (!lua_interface)
  5125. return 0;
  5126. Spawn* player = lua_interface->GetSpawn(state);
  5127. string name = lua_interface->GetStringValue(state, 2);
  5128. int32 type = lua_interface->GetInt32Value(state, 3);
  5129. if (type == 0)
  5130. type = 2;
  5131. if (name.length() > 0) {
  5132. if (player && player->IsPlayer()) {
  5133. Client* client = player->GetClient();
  5134. if (client)
  5135. client->AddWaypoint(name, type);
  5136. }
  5137. }
  5138. return 0;
  5139. }
  5140. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5141. if (!lua_interface)
  5142. return 0;
  5143. Spawn* player = lua_interface->GetSpawn(state);
  5144. string name = lua_interface->GetStringValue(state, 2);
  5145. if (name.length() > 0) {
  5146. if (player && player->IsPlayer()) {
  5147. Client* client = player->GetClient();
  5148. if (client)
  5149. client->RemoveWaypoint(name);
  5150. }
  5151. }
  5152. return 0;
  5153. }
  5154. int EQ2Emu_lua_AddWard(lua_State* state) {
  5155. if (!lua_interface)
  5156. return 0;
  5157. int32 damage = lua_interface->GetInt32Value(state);
  5158. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5159. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5160. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5161. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5162. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5163. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5164. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5165. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5166. bool ward_was_added = false;
  5167. ZoneServer* zone = spell->caster->GetZone();
  5168. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5169. for (int32 i = 0; i < spell->targets.size(); i++) {
  5170. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5171. if (!target)
  5172. continue;
  5173. if (target->IsEntity()) {
  5174. // If the ward is already active remove it
  5175. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5176. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5177. // Create new ward info
  5178. WardInfo* ward = new WardInfo;
  5179. ward->Spell = spell;
  5180. ward->BaseDamage = damage;
  5181. ward->DamageLeft = damage;
  5182. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5183. ward->keepWard = keepWard;
  5184. ward->WardType = wardType;
  5185. if (damageAbsorptionPercent > 100)
  5186. damageAbsorptionPercent = 100;
  5187. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5188. if (damageAbsorptionMaxHealthPercent > 100)
  5189. damageAbsorptionMaxHealthPercent = 100;
  5190. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5191. ward->RedirectDamagePercent = redirectDamagePercent;
  5192. ward->LastRedirectDamage = 0;
  5193. ward->LastAbsorbedDamage = 0;
  5194. ward->HitCount = 0;
  5195. spell->num_triggers = maxHitCount;
  5196. spell->had_triggers = true;
  5197. spell->cancel_after_all_triggers = false;
  5198. ward->MaxHitCount = maxHitCount;
  5199. if (wardType == WARD_TYPE_MAGICAL)
  5200. ward->DamageType = damageTypes;
  5201. // Add the ward to the entity
  5202. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5203. ward_was_added = true;
  5204. }
  5205. }
  5206. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5207. if (ward_was_added && spell->caster->IsPlayer()) {
  5208. spell->had_dmg_remaining = true;
  5209. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5210. }
  5211. return 0;
  5212. }
  5213. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5214. if (!lua_interface)
  5215. return 0;
  5216. int32 amount = lua_interface->GetInt32Value(state);
  5217. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5218. WardInfo* ward = 0;
  5219. ZoneServer* zone = spell->caster->GetZone();
  5220. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5221. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5222. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5223. ward = target->GetWard(spell->spell->GetSpellID());
  5224. if (ward) {
  5225. ward->DamageLeft += amount;
  5226. if (ward->DamageLeft > ward->BaseDamage)
  5227. ward->DamageLeft = ward->BaseDamage;
  5228. for (int32 i = 0; i < spell->targets.size(); i++) {
  5229. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5230. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5231. }
  5232. }
  5233. }
  5234. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5235. if (ward && spell->caster->IsPlayer())
  5236. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5237. return 0;
  5238. }
  5239. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5240. if (!lua_interface)
  5241. return 0;
  5242. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5243. if (!spell) {
  5244. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5245. return 0;
  5246. }
  5247. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5248. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5249. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5250. if (ward) {
  5251. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5252. return 1;
  5253. }
  5254. }
  5255. return 0;
  5256. }
  5257. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5258. if (!lua_interface)
  5259. return 0;
  5260. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5261. if (!spell) {
  5262. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5263. return 0;
  5264. }
  5265. string type = lua_interface->GetStringValue(state, 2);
  5266. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5267. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5268. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5269. if (ward) {
  5270. if (boost::iequals(type, "damageleft"))
  5271. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5272. else if (boost::iequals(type, "basedamage"))
  5273. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5274. else if (boost::iequals(type, "keepward"))
  5275. lua_interface->SetBooleanValue(state, ward->keepWard);
  5276. else if (boost::iequals(type, "wardtype"))
  5277. lua_interface->SetInt32Value(state, ward->WardType);
  5278. else if (boost::iequals(type, "dmgabsorptionpct"))
  5279. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5280. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5281. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5282. else if (boost::iequals(type, "redirectdamagepercent"))
  5283. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5284. else if (boost::iequals(type, "lastredirectdamage"))
  5285. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5286. else if (boost::iequals(type, "lastabsorbeddamage"))
  5287. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5288. else if (boost::iequals(type, "hitcount"))
  5289. lua_interface->SetInt32Value(state, ward->HitCount);
  5290. else if (boost::iequals(type, "maxhitcount"))
  5291. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5292. else
  5293. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5294. return 1;
  5295. }
  5296. }
  5297. return 0;
  5298. }
  5299. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5300. if (!lua_interface)
  5301. return 0;
  5302. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5303. ZoneServer* zone = spell->caster->GetZone();
  5304. Spawn* target = 0;
  5305. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5306. for (int32 i = 0; i < spell->targets.size(); i++) {
  5307. target = zone->GetSpawnByID(spell->targets.at(i));
  5308. if (target && target->IsEntity()) {
  5309. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5310. }
  5311. }
  5312. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5313. return 0;
  5314. }
  5315. int EQ2Emu_lua_Interrupt(lua_State* state)
  5316. {
  5317. if (!lua_interface)
  5318. return 0;
  5319. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5320. Spawn* target = lua_interface->GetSpawn(state, 2);
  5321. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5322. if (!caster)
  5323. {
  5324. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5325. return 0;
  5326. }
  5327. if (!target)
  5328. {
  5329. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5330. return 0;
  5331. }
  5332. if (!spell) {
  5333. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5334. return 0;
  5335. }
  5336. if (!target->IsEntity() && !spell)
  5337. {
  5338. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5339. return 0;
  5340. }
  5341. if (!target && spell) {
  5342. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5343. for (int8 i = 0; i < spell->targets.size(); i++) {
  5344. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5345. if (!target || !target->IsEntity())
  5346. continue;
  5347. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5348. }
  5349. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5350. }
  5351. else
  5352. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5353. return 0;
  5354. }
  5355. int EQ2Emu_lua_Stealth(lua_State* state) {
  5356. if (!lua_interface)
  5357. return 0;
  5358. int8 type = lua_interface->GetInt8Value(state);
  5359. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5360. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5361. if (!spell) {
  5362. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5363. return 0;
  5364. }
  5365. ZoneServer* zone = spell->caster->GetZone();
  5366. if (spawn) {
  5367. if (spawn->IsEntity()) {
  5368. if (type == 1) {
  5369. ((Entity*)spawn)->AddStealthSpell(spell);
  5370. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5371. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5372. }
  5373. else if (type == 2) {
  5374. ((Entity*)spawn)->AddInvisSpell(spell);
  5375. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5376. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5377. }
  5378. return 0;
  5379. }
  5380. else {
  5381. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5382. return 0;
  5383. }
  5384. }
  5385. else {
  5386. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5387. for (int32 i = 0; i < spell->targets.size(); i++) {
  5388. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5389. if (!spawn || !spawn->IsEntity())
  5390. continue;
  5391. if (type == 1) {
  5392. ((Entity*)spawn)->AddStealthSpell(spell);
  5393. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5394. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5395. }
  5396. else if (type == 2) {
  5397. ((Entity*)spawn)->AddInvisSpell(spell);
  5398. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5399. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5400. }
  5401. else {
  5402. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5403. break;
  5404. }
  5405. }
  5406. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5407. }
  5408. return 0;
  5409. }
  5410. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5411. if (!lua_interface)
  5412. return 0;
  5413. Spawn* spawn = lua_interface->GetSpawn(state);
  5414. if (!spawn) {
  5415. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5416. return 0;
  5417. }
  5418. if (spawn->IsEntity()) {
  5419. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5420. return 1;
  5421. }
  5422. else
  5423. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5424. return 0;
  5425. }
  5426. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5427. if (!lua_interface)
  5428. return 0;
  5429. Spawn* spawn = lua_interface->GetSpawn(state);
  5430. if (!spawn) {
  5431. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5432. return 0;
  5433. }
  5434. if (spawn->IsEntity()) {
  5435. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5436. return 1;
  5437. }
  5438. else
  5439. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5440. return 0;
  5441. }
  5442. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5443. if (!lua_interface)
  5444. return 0;
  5445. Spawn* player = lua_interface->GetSpawn(state);
  5446. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5447. lua_interface->ResetFunctionStack(state);
  5448. if (!player->IsPlayer()) {
  5449. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5450. return 0;
  5451. }
  5452. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5453. return 1;
  5454. }
  5455. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5456. if (!lua_interface)
  5457. return 0;
  5458. Spawn* player = lua_interface->GetSpawn(state);
  5459. int8 slot = lua_interface->GetInt8Value(state, 2);
  5460. lua_interface->ResetFunctionStack(state);
  5461. if (!player) {
  5462. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5463. return 0;
  5464. }
  5465. if (!player->IsPlayer()) {
  5466. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5467. return 0;
  5468. }
  5469. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5470. if (!item) {
  5471. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5472. return 0;
  5473. }
  5474. lua_interface->SetItemValue(state, item);
  5475. return 1;
  5476. }
  5477. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5478. if (!lua_interface)
  5479. return 0;
  5480. Spawn* player = lua_interface->GetSpawn(state);
  5481. int32 id = lua_interface->GetInt32Value(state, 2);
  5482. lua_interface->ResetFunctionStack(state);
  5483. if (!player) {
  5484. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5485. return 0;
  5486. }
  5487. if (!player->IsPlayer()) {
  5488. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5492. if (!item) {
  5493. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5494. return 0;
  5495. }
  5496. lua_interface->SetItemValue(state, item);
  5497. return 1;
  5498. }
  5499. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5500. if (!lua_interface)
  5501. return 0;
  5502. Spawn* spawn = lua_interface->GetSpawn(state);
  5503. int8 slot = lua_interface->GetInt8Value(state, 2);
  5504. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5505. lua_interface->ResetFunctionStack(state);
  5506. if (!spawn) {
  5507. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5508. return 0;
  5509. }
  5510. if (!spawn->IsEntity()) {
  5511. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5512. return 0;
  5513. }
  5514. Item* item = master_item_list.GetItem(item_id);
  5515. if (!item) {
  5516. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5517. return 0;
  5518. }
  5519. Item* copy = new Item(item);
  5520. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5521. if(result)
  5522. {
  5523. ((Entity*)spawn)->SetEquipment(copy, slot);
  5524. spawn->vis_changed = true;
  5525. if(spawn->IsPlayer())
  5526. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5527. }
  5528. else
  5529. {
  5530. safe_delete(copy);
  5531. }
  5532. lua_interface->SetBooleanValue(state, result);
  5533. return 1;
  5534. }
  5535. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5536. if (!lua_interface)
  5537. return 0;
  5538. Spawn* spawn = lua_interface->GetSpawn(state);
  5539. int8 slot = lua_interface->GetInt8Value(state, 2);
  5540. Item* item = lua_interface->GetItem(state, 3);
  5541. lua_interface->ResetFunctionStack(state);
  5542. if (!spawn) {
  5543. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5544. return 0;
  5545. }
  5546. if (!spawn->IsEntity()) {
  5547. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5548. return 0;
  5549. }
  5550. if (!item) {
  5551. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5552. return 0;
  5553. }
  5554. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5555. if(result)
  5556. {
  5557. ((Entity*)spawn)->SetEquipment(item, slot);
  5558. spawn->vis_changed = true;
  5559. if(spawn->IsPlayer())
  5560. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5561. }
  5562. lua_interface->SetBooleanValue(state, result);
  5563. return 1;
  5564. }
  5565. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5566. if (!lua_interface)
  5567. return 0;
  5568. Spawn* spawn = lua_interface->GetSpawn(state);
  5569. int8 slot = lua_interface->GetInt8Value(state, 2);
  5570. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5571. lua_interface->ResetFunctionStack(state);
  5572. if (!spawn) {
  5573. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5574. return 0;
  5575. }
  5576. if (!spawn->IsEntity()) {
  5577. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5578. return 0;
  5579. }
  5580. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5581. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5582. spawn->vis_changed = true;
  5583. if(spawn->IsPlayer())
  5584. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5585. lua_interface->SetBooleanValue(state, true);
  5586. return 1;
  5587. }
  5588. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5589. if (!lua_interface)
  5590. return 0;
  5591. Spawn* spawn = lua_interface->GetSpawn(state);
  5592. int8 slot = lua_interface->GetInt8Value(state, 2);
  5593. int16 type = lua_interface->GetInt16Value(state, 3);
  5594. int8 r = lua_interface->GetInt8Value(state, 4);
  5595. int8 g = lua_interface->GetInt8Value(state, 5);
  5596. int8 b = lua_interface->GetInt8Value(state, 6);
  5597. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5598. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5599. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5600. lua_interface->ResetFunctionStack(state);
  5601. if (!spawn) {
  5602. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5603. return 0;
  5604. }
  5605. if (!spawn->IsEntity()) {
  5606. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5607. return 0;
  5608. }
  5609. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5610. spawn->vis_changed = true;
  5611. lua_interface->SetBooleanValue(state, true);
  5612. return 1;
  5613. }
  5614. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5615. if (!lua_interface)
  5616. return 0;
  5617. Spawn* player = lua_interface->GetSpawn(state);
  5618. int32 id = lua_interface->GetInt32Value(state, 2);
  5619. int8 count = lua_interface->GetInt8Value(state, 3);
  5620. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5621. lua_interface->ResetFunctionStack(state);
  5622. if (!player) {
  5623. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5624. return 0;
  5625. }
  5626. if (!player->IsPlayer()) {
  5627. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5628. return 0;
  5629. }
  5630. if (!count)
  5631. count = 1;
  5632. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5633. if (!item) {
  5634. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5635. return 0;
  5636. }
  5637. lua_interface->SetItemValue(state, item);
  5638. return 1;
  5639. }
  5640. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5641. if (!lua_interface)
  5642. return 0;
  5643. Spawn* spawn = lua_interface->GetSpawn(state);
  5644. int32 anim = lua_interface->GetInt32Value(state, 2);
  5645. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5646. int8 type = lua_interface->GetInt8Value(state, 4);
  5647. if (!spawn) {
  5648. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5649. return 0;
  5650. }
  5651. if (spawn2) {
  5652. if (spawn2->IsPlayer()) {
  5653. if (type != 1 && type != 2)
  5654. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5655. else
  5656. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5657. return 0;
  5658. }
  5659. else {
  5660. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5661. return 0;
  5662. }
  5663. }
  5664. else
  5665. spawn->GetZone()->PlayAnimation(spawn, anim);
  5666. return 0;
  5667. }
  5668. int EQ2Emu_lua_IsPet(lua_State* state) {
  5669. if (!lua_interface)
  5670. return 0;
  5671. Spawn* spawn = lua_interface->GetSpawn(state);
  5672. if (!spawn) {
  5673. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5674. return 0;
  5675. }
  5676. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5677. return 1;
  5678. }
  5679. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5680. if (!lua_interface)
  5681. return 0;
  5682. Spawn* spawn = lua_interface->GetSpawn(state);
  5683. if (!spawn) {
  5684. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5685. return 0;
  5686. }
  5687. if (!spawn->IsNPC()) {
  5688. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5689. return 0;
  5690. }
  5691. if (((NPC*)spawn)->GetOwner()) {
  5692. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5693. return 1;
  5694. }
  5695. return 0;
  5696. }
  5697. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5698. if (!lua_interface)
  5699. return 0;
  5700. Spawn* spawn = lua_interface->GetSpawn(state);
  5701. Spawn* target = lua_interface->GetSpawn(state, 2);
  5702. if (!spawn) {
  5703. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5704. return 0;
  5705. }
  5706. if (!spawn) {
  5707. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5708. return 0;
  5709. }
  5710. spawn->SetTarget(target);
  5711. return 0;
  5712. }
  5713. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5714. if (!lua_interface)
  5715. return 0;
  5716. Spawn* spawn = lua_interface->GetSpawn(state);
  5717. bool val = lua_interface->GetBooleanValue(state, 2);
  5718. if (!spawn) {
  5719. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5720. return 0;
  5721. }
  5722. if (!spawn->IsEntity()) {
  5723. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5724. return 0;
  5725. }
  5726. ((Entity*)spawn)->InCombat(val);
  5727. if (val) {
  5728. spawn->ClearRunningLocations();
  5729. spawn->CalculateRunningLocation(true);
  5730. }
  5731. return 0;
  5732. }
  5733. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5734. if (!lua_interface)
  5735. return 0;
  5736. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5737. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5738. if (!spawn1) {
  5739. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5740. return 0;
  5741. }
  5742. if (!spawn2) {
  5743. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5744. return 0;
  5745. }
  5746. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5747. return 1;
  5748. }
  5749. int EQ2Emu_lua_Runback(lua_State* state) {
  5750. if (!lua_interface)
  5751. return 0;
  5752. Spawn* spawn = lua_interface->GetSpawn(state);
  5753. if (!spawn) {
  5754. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5755. return 0;
  5756. }
  5757. if (!spawn->IsNPC()) {
  5758. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5759. return 0;
  5760. }
  5761. ((NPC*)spawn)->Runback();
  5762. return 0;
  5763. }
  5764. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5765. if (!lua_interface)
  5766. return 0;
  5767. Spawn* spawn = lua_interface->GetSpawn(state);
  5768. if (!spawn) {
  5769. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5770. return 0;
  5771. }
  5772. if (!spawn->IsNPC()) {
  5773. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5774. return 0;
  5775. }
  5776. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5777. return 1;
  5778. }
  5779. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5780. if (!lua_interface)
  5781. return 0;
  5782. Spawn* spawn = lua_interface->GetSpawn(state);
  5783. if (!spawn) {
  5784. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5785. return 0;
  5786. }
  5787. if (!spawn->IsEntity()) {
  5788. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5789. return 0;
  5790. }
  5791. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5792. return 1;
  5793. }
  5794. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5795. if (!lua_interface)
  5796. return 0;
  5797. Spawn* spawn = lua_interface->GetSpawn(state);
  5798. if (!spawn) {
  5799. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5800. return 0;
  5801. }
  5802. if (!spawn->IsEntity()) {
  5803. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5804. return 0;
  5805. }
  5806. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5807. return 1;
  5808. }
  5809. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5810. if (!lua_interface)
  5811. return 0;
  5812. Spawn* spawn = lua_interface->GetSpawn(state);
  5813. if (!spawn) {
  5814. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5815. return 0;
  5816. }
  5817. if (!spawn->IsEntity()) {
  5818. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5819. return 0;
  5820. }
  5821. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5822. return 1;
  5823. }
  5824. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5825. if (!lua_interface)
  5826. return 0;
  5827. Spawn* spawn = lua_interface->GetSpawn(state);
  5828. if (!spawn) {
  5829. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5830. return 0;
  5831. }
  5832. if (!spawn->IsEntity()) {
  5833. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5834. return 0;
  5835. }
  5836. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5837. return 1;
  5838. }
  5839. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5840. if (!lua_interface)
  5841. return 0;
  5842. Spawn* spawn = lua_interface->GetSpawn(state);
  5843. Spawn* target = lua_interface->GetSpawn(state, 2);
  5844. float distance = lua_interface->GetFloatValue(state, 3);
  5845. if (!spawn) {
  5846. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5847. return 0;
  5848. }
  5849. if (!target) {
  5850. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5851. return 0;
  5852. }
  5853. if (!spawn->IsNPC()) {
  5854. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5855. return 0;
  5856. }
  5857. if (!target->IsEntity()) {
  5858. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5859. return 0;
  5860. }
  5861. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5862. return 1;
  5863. }
  5864. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5865. if (!lua_interface)
  5866. return 0;
  5867. Spawn* spawn = lua_interface->GetSpawn(state);
  5868. Spawn* target = lua_interface->GetSpawn(state, 2);
  5869. float distance = lua_interface->GetFloatValue(state, 3);
  5870. if (!spawn) {
  5871. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5872. return 0;
  5873. }
  5874. if (!target) {
  5875. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5876. return 0;
  5877. }
  5878. if (!spawn->IsNPC()) {
  5879. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5880. return 0;
  5881. }
  5882. if (!target->IsEntity()) {
  5883. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5887. return 0;
  5888. }
  5889. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5890. if (!lua_interface)
  5891. return 0;
  5892. Spawn* spawn = lua_interface->GetSpawn(state);
  5893. if (!spawn) {
  5894. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5895. return 0;
  5896. }
  5897. if (!spawn->IsNPC()) {
  5898. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5899. return 0;
  5900. }
  5901. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5902. return 1;
  5903. }
  5904. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5905. if (!lua_interface)
  5906. return 0;
  5907. Spawn* spawn = lua_interface->GetSpawn(state);
  5908. if (!spawn) {
  5909. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5910. return 0;
  5911. }
  5912. if (!spawn->IsNPC()) {
  5913. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5914. return 0;
  5915. }
  5916. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5917. return 1;
  5918. }
  5919. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5920. if (!lua_interface)
  5921. return 0;
  5922. Spawn* spawn = lua_interface->GetSpawn(state);
  5923. if (!spawn) {
  5924. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5925. return 0;
  5926. }
  5927. if (!spawn->IsNPC()) {
  5928. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5929. return 0;
  5930. }
  5931. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5932. if (hated) {
  5933. lua_interface->SetSpawnValue(state, hated);
  5934. return 1;
  5935. }
  5936. return 0;
  5937. }
  5938. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5939. if (!lua_interface)
  5940. return 0;
  5941. Spawn* spawn = lua_interface->GetSpawn(state);
  5942. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5943. if (!spawn) {
  5944. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5945. return 0;
  5946. }
  5947. if (!spawn->IsNPC()) {
  5948. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. if (!hated) {
  5952. ((NPC*)spawn)->Brain()->ClearHate();
  5953. return 0;
  5954. }
  5955. else
  5956. {
  5957. if (!hated->IsEntity()) {
  5958. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5959. return 0;
  5960. }
  5961. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5962. return 0;
  5963. }
  5964. return 0;
  5965. }
  5966. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5967. if (!lua_interface)
  5968. return 0;
  5969. Spawn* spawn = lua_interface->GetSpawn(state);
  5970. if (!spawn) {
  5971. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5972. return 0;
  5973. }
  5974. if (!spawn->IsNPC()) {
  5975. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5976. return 0;
  5977. }
  5978. ((NPC*)spawn)->Brain()->ClearEncounter();
  5979. return 0;
  5980. }
  5981. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5982. if (!lua_interface)
  5983. return 0;
  5984. Spawn* spawn = lua_interface->GetSpawn(state);
  5985. if (!spawn) {
  5986. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5987. return 0;
  5988. }
  5989. if (!spawn->IsNPC()) {
  5990. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5991. return 0;
  5992. }
  5993. // Temp list to store hate list
  5994. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5995. if (encounterList->size() == 0) {
  5996. safe_delete(encounterList);
  5997. return 0;
  5998. }
  5999. lua_createtable(state, encounterList->size(), 0);
  6000. int newTable = lua_gettop(state);
  6001. for (int32 i = 0; i < encounterList->size(); i++) {
  6002. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6003. if (temp)
  6004. lua_interface->SetSpawnValue(state, temp);
  6005. lua_rawseti(state, newTable, i + 1);
  6006. }
  6007. safe_delete(encounterList);
  6008. return 1;
  6009. }
  6010. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6011. if (!lua_interface)
  6012. return 0;
  6013. Spawn* spawn = lua_interface->GetSpawn(state);
  6014. if (!spawn) {
  6015. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6016. return 0;
  6017. }
  6018. if (!spawn->IsNPC()) {
  6019. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6020. return 0;
  6021. }
  6022. // Temp list to store hate list
  6023. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6024. if (hateList->size() == 0) {
  6025. safe_delete(hateList);
  6026. return 0;
  6027. }
  6028. lua_createtable(state, hateList->size(), 0);
  6029. int newTable = lua_gettop(state);
  6030. for (int32 i = 0; i < hateList->size(); i++) {
  6031. lua_interface->SetSpawnValue(state, hateList->at(i));
  6032. lua_rawseti(state, newTable, i + 1);
  6033. }
  6034. safe_delete(hateList);
  6035. return 1;
  6036. }
  6037. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6038. if (!lua_interface)
  6039. return 0;
  6040. Spawn* spawn = lua_interface->GetSpawn(state);
  6041. if (!spawn) {
  6042. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6043. return 0;
  6044. }
  6045. if (spawn->IsPlayer()) {
  6046. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6047. lua_interface->SetBooleanValue(state, true);
  6048. else
  6049. lua_interface->SetBooleanValue(state, false);
  6050. return 1;
  6051. }
  6052. else {
  6053. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6054. return 1;
  6055. }
  6056. }
  6057. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6058. if (!lua_interface)
  6059. return 0;
  6060. Quest* quest = lua_interface->GetQuest(state);
  6061. if (!quest) {
  6062. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6063. return 0;
  6064. }
  6065. quest->SetCompletedFlag(true);
  6066. return 0;
  6067. }
  6068. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6069. if (!lua_interface)
  6070. return 0;
  6071. Spawn* spawn = lua_interface->GetSpawn(state);
  6072. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6073. int8 tier = lua_interface->GetInt8Value(state, 3);
  6074. if (!spawn) {
  6075. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6076. return 0;
  6077. }
  6078. if (!spawn->IsEntity()) {
  6079. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6080. return 0;
  6081. }
  6082. if (spellID == 0) {
  6083. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6084. return 0;
  6085. }
  6086. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6087. if (effect) {
  6088. if (tier > 0) {
  6089. // If a tier was passed chec to see if it is the same as the effect
  6090. if (tier == effect->tier)
  6091. lua_interface->SetBooleanValue(state, true);
  6092. else
  6093. lua_interface->SetBooleanValue(state, false);
  6094. return 1;
  6095. }
  6096. else {
  6097. // Have an effect but no tier was passed so return true
  6098. lua_interface->SetBooleanValue(state, true);
  6099. }
  6100. return 1;
  6101. }
  6102. // no effect so return false
  6103. lua_interface->SetBooleanValue(state, false);
  6104. return 1;
  6105. }
  6106. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6107. if (!lua_interface)
  6108. return 0;
  6109. Spawn* spawn = lua_interface->GetSpawn(state);
  6110. int32 id = lua_interface->GetInt32Value(state, 2);
  6111. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6112. Spawn* spawn2 = 0;
  6113. vector<Spawn*> list;
  6114. if (!spawn) {
  6115. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6116. return 0;
  6117. }
  6118. //If zone not provided, use spawn's zone
  6119. if (!zone)
  6120. zone = spawn->GetZone();
  6121. list = zone->GetSpawnsByID(id);
  6122. if (list.size() == 0) {
  6123. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6124. return 0;
  6125. }
  6126. vector<Spawn*>::iterator itr = list.begin();
  6127. for (int8 i = 0; i < list.size(); i++) {
  6128. spawn2 = itr[i];
  6129. if (spawn2)
  6130. spawn2->AddAllowAccessSpawn(spawn);
  6131. }
  6132. return 0;
  6133. }
  6134. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6135. if (!lua_interface)
  6136. return 0;
  6137. Spawn* spawn = lua_interface->GetSpawn(state);
  6138. int32 id = lua_interface->GetInt32Value(state, 2);
  6139. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6140. Spawn* spawn2 = 0;
  6141. if (!spawn) {
  6142. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6143. return 0;
  6144. }
  6145. //If zone not provided, use spawn's zone
  6146. if (!zone)
  6147. zone = spawn->GetZone();
  6148. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6149. vector<Spawn*>::iterator itr = list.begin();
  6150. if (list.size() == 0) {
  6151. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6152. return 0;
  6153. }
  6154. for (int8 i = 0; i < list.size(); i++) {
  6155. spawn2 = itr[i];
  6156. if (spawn2)
  6157. spawn2->RemoveSpawnAccess(spawn);
  6158. }
  6159. return 0;
  6160. }
  6161. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6162. if (!lua_interface)
  6163. return 0;
  6164. Quest* quest = lua_interface->GetQuest(state);
  6165. if (!quest) {
  6166. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6167. return 0;
  6168. }
  6169. quest->SetYellowName(true);
  6170. return 0;
  6171. }
  6172. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6173. if (!lua_interface)
  6174. return 0;
  6175. Spawn* spawn = lua_interface->GetSpawn(state);
  6176. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6177. if (!spawn) {
  6178. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6179. return 0;
  6180. }
  6181. if (!spawn->IsPlayer()) {
  6182. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6183. return 0;
  6184. }
  6185. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6186. return 1;
  6187. }
  6188. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6189. if (!lua_interface)
  6190. return 0;
  6191. Spawn* spawn = lua_interface->GetSpawn(state);
  6192. if (!spawn) {
  6193. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6194. return 0;
  6195. }
  6196. if (!spawn->IsPlayer()) {
  6197. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6198. return 0;
  6199. }
  6200. ZoneServer* zone = spawn->GetZone();
  6201. if (!zone) {
  6202. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6203. return 0;
  6204. }
  6205. Instance_Type iType = zone->GetInstanceType();
  6206. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6207. iType == GROUP_LOCKOUT_INSTANCE ||
  6208. iType == RAID_LOCKOUT_INSTANCE ||
  6209. iType == SOLO_PERSIST_INSTANCE ||
  6210. iType == GROUP_PERSIST_INSTANCE ||
  6211. iType == RAID_PERSIST_INSTANCE) {
  6212. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6213. if (data) {
  6214. // Check to see if the timer has already been set, if it has return out.
  6215. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6216. return 0;
  6217. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6218. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6219. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6220. if (client) {
  6221. string time_msg = "";
  6222. int32 time = data->success_lockout_time;
  6223. int16 hour;
  6224. int8 min;
  6225. int8 sec;
  6226. hour = time / 3600;
  6227. time = time % 3600;
  6228. min = time / 60;
  6229. time = time % 60;
  6230. sec = time;
  6231. if (hour > 0) {
  6232. char temp[10];
  6233. sprintf(temp, " %i", hour);
  6234. time_msg.append(temp);
  6235. time_msg.append(" hour");
  6236. time_msg.append((hour > 1) ? "s" : "");
  6237. }
  6238. if (min > 0) {
  6239. char temp[5];
  6240. sprintf(temp, " %i", min);
  6241. time_msg.append(temp);
  6242. time_msg.append(" minute");
  6243. time_msg.append((min > 1) ? "s" : "");
  6244. }
  6245. // Only add seconds if minutes and hours are 0
  6246. if (hour == 0 && min == 0 && sec > 0) {
  6247. char temp[5];
  6248. sprintf(temp, " %i", sec);
  6249. time_msg.append(temp);
  6250. time_msg.append(" second");
  6251. time_msg.append((sec > 1) ? "s" : "");
  6252. }
  6253. 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());
  6254. }
  6255. }
  6256. else
  6257. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6258. }
  6259. else
  6260. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6261. return 0;
  6262. }
  6263. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6264. if (!lua_interface)
  6265. return 0;
  6266. Spawn* spawn = lua_interface->GetSpawn(state);
  6267. if (!spawn) {
  6268. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6269. return 0;
  6270. }
  6271. if (!spawn->IsPlayer()) {
  6272. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6273. return 0;
  6274. }
  6275. ZoneServer* zone = spawn->GetZone();
  6276. if (!zone) {
  6277. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6278. return 0;
  6279. }
  6280. Instance_Type iType = zone->GetInstanceType();
  6281. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6282. iType == GROUP_LOCKOUT_INSTANCE ||
  6283. iType == RAID_LOCKOUT_INSTANCE ||
  6284. iType == SOLO_PERSIST_INSTANCE ||
  6285. iType == GROUP_PERSIST_INSTANCE ||
  6286. iType == RAID_PERSIST_INSTANCE) {
  6287. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6288. if (data) {
  6289. // Check to see if the timer has already been set, if it has return out.
  6290. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6291. return 0;
  6292. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6293. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6294. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6295. if (client) {
  6296. string time_msg = "";
  6297. int32 time = data->failure_lockout_time;
  6298. int16 hour;
  6299. int8 min;
  6300. int8 sec;
  6301. hour = time / 3600;
  6302. time = time % 3600;
  6303. min = time / 60;
  6304. time = time % 60;
  6305. sec = time;
  6306. if (hour > 0) {
  6307. char temp[10];
  6308. sprintf(temp, " %i", hour);
  6309. time_msg.append(temp);
  6310. time_msg.append(" hour");
  6311. time_msg.append((hour > 1) ? "s" : "");
  6312. }
  6313. if (min > 0) {
  6314. char temp[5];
  6315. sprintf(temp, " %i", min);
  6316. time_msg.append(temp);
  6317. time_msg.append(" minute");
  6318. time_msg.append((min > 1) ? "s" : "");
  6319. }
  6320. // Only add seconds if minutes and hours are 0
  6321. if (hour == 0 && min == 0 && sec > 0) {
  6322. char temp[5];
  6323. sprintf(temp, " %i", sec);
  6324. time_msg.append(temp);
  6325. time_msg.append(" second");
  6326. time_msg.append((sec > 1) ? "s" : "");
  6327. }
  6328. 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());
  6329. }
  6330. }
  6331. else
  6332. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6333. }
  6334. else
  6335. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6336. return 0;
  6337. }
  6338. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6339. if (!lua_interface)
  6340. return 0;
  6341. Spawn* spawn = lua_interface->GetSpawn(state);
  6342. if (!spawn) {
  6343. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6344. return 0;
  6345. }
  6346. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6347. return 1;
  6348. }
  6349. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6350. if (!lua_interface)
  6351. return 0;
  6352. Spawn* player = lua_interface->GetSpawn(state);
  6353. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6354. if (!player) {
  6355. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6356. return 0;
  6357. }
  6358. if (!player->IsPlayer()) {
  6359. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6360. return 0;
  6361. }
  6362. if (!ground) {
  6363. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6364. return 0;
  6365. }
  6366. if (!ground->IsGroundSpawn()) {
  6367. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6368. return 0;
  6369. }
  6370. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6371. if (!groundspawn_entries) {
  6372. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6373. return 0;
  6374. }
  6375. Skill* skill = 0;
  6376. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6377. if (collection_skill == "Collecting")
  6378. skill = ((Player*)player)->GetSkillByName("Gathering");
  6379. else
  6380. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6381. if (!skill) {
  6382. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6383. return 0;
  6384. }
  6385. vector<GroundSpawnEntry*>::iterator itr;
  6386. GroundSpawnEntry* entry = 0;
  6387. bool can_harvest = false;
  6388. sint32 min_skill = -1;
  6389. // first, iterate through groundspawn_entries, discard tables player cannot use
  6390. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6391. {
  6392. entry = *itr;
  6393. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6394. min_skill = entry->min_skill_level;
  6395. // if player lacks skill, skip table
  6396. if (entry->min_skill_level > skill->current_val)
  6397. continue;
  6398. // if bonus, but player lacks level, skip table
  6399. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6400. continue;
  6401. can_harvest = true;
  6402. break;
  6403. }
  6404. lua_interface->SetBooleanValue(state, can_harvest);
  6405. // If false, send the message to the client
  6406. if (!can_harvest) {
  6407. Client* client = player->GetZone()->GetClientBySpawn(player);
  6408. if (client) {
  6409. string msg = "You do not have enough skill to ";
  6410. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6411. msg.append("gather");
  6412. else if (collection_skill == "Mining")
  6413. msg.append("mine");
  6414. else if (collection_skill == "Trapping")
  6415. msg.append("trap");
  6416. else if (collection_skill == "Foresting")
  6417. msg.append("forest");
  6418. else if (collection_skill == "Fishing")
  6419. msg.append("catch");
  6420. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6421. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  6422. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6423. }
  6424. }
  6425. return 1;
  6426. }
  6427. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6428. if (!lua_interface)
  6429. return 0;
  6430. Spawn* player = lua_interface->GetSpawn(state);
  6431. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6432. if (!player) {
  6433. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6434. return 0;
  6435. }
  6436. if (!player->IsPlayer()) {
  6437. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6438. return 0;
  6439. }
  6440. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6441. lua_interface->SetBooleanValue(state, ret);
  6442. return 1;
  6443. }
  6444. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6445. // Check to see if we have a valid lua_interface
  6446. if (!lua_interface)
  6447. return 0;
  6448. // Get the spawn that is getting the pet
  6449. Spawn* spawn = lua_interface->GetSpawn(state);
  6450. Spawn* target = lua_interface->GetSpawn(state, 2);
  6451. // Get the DB ID of the pet
  6452. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6453. float x = lua_interface->GetFloatValue(state, 4);
  6454. float y = lua_interface->GetFloatValue(state, 5);
  6455. float z = lua_interface->GetFloatValue(state, 6);
  6456. // Get the spell that this command was called from
  6457. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6458. // Check to make sure the spawn pointer is valid
  6459. if (!spawn) {
  6460. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6461. return 0;
  6462. }
  6463. // Check to make sure the spawn is an entity
  6464. if (!spawn->IsEntity()) {
  6465. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6466. return 0;
  6467. }
  6468. if (!target) {
  6469. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6470. return 0;
  6471. }
  6472. if (!target->IsEntity()) {
  6473. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6474. return 0;
  6475. }
  6476. // Check to see if the DB ID for the pet is set
  6477. if (pet_id == 0) {
  6478. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6479. return 0;
  6480. }
  6481. // Check to see if the pointer to the spell is valid
  6482. if (!luaspell) {
  6483. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6484. return 0;
  6485. }
  6486. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6487. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6488. if (!pet) {
  6489. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6490. return 0;
  6491. }
  6492. // Check to make sure the pet is an npc
  6493. if (!pet->IsNPC()) {
  6494. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6495. return 0;
  6496. }
  6497. if (x == 0)
  6498. x = spawn->GetX();
  6499. if (y == 0)
  6500. y = spawn->GetY();
  6501. if (z == 0)
  6502. z = spawn->GetZ();
  6503. // Spawn the pet at the same location as the owner
  6504. pet->SetX(x);
  6505. pet->SetY(y);
  6506. pet->SetZ(z);
  6507. pet->SetLocation(spawn->GetLocation());
  6508. pet->SetHeading(spawn->GetHeading());
  6509. spawn->GetZone()->AddSpawn(pet);
  6510. /*
  6511. const char* spawn_script = world.GetSpawnScript(pet_id);
  6512. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6513. spawn->SetSpawnScript(string(spawn_script));
  6514. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6515. }*/
  6516. // Get a random pet name
  6517. string random_pet_name;
  6518. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6519. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6520. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6521. // Set the pets name
  6522. pet->SetName(random_pet_name.c_str());
  6523. // Set the level of the pet to the owners level
  6524. pet->SetLevel(spawn->GetLevel());
  6525. // Set the faction of the pet to the same faction as the owner
  6526. pet->SetFactionID(spawn->GetFactionID());
  6527. // Set the spawn as a pet
  6528. pet->SetPet(true);
  6529. // Give a pointer of the owner to the pet
  6530. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6531. // Set the pet type
  6532. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6533. // Set the spell id used to create this pet
  6534. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6535. // Set the spell tier used to create this pet
  6536. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6537. // Set the pets spawn type to 6
  6538. pet->SetSpawnType(6);
  6539. // Set the pets brain
  6540. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6541. // Check to see if the pet has a subtitle
  6542. if (strlen(pet->GetSubTitle()) > 0) {
  6543. // Add the players name to the front of the sub title
  6544. string pet_subtitle;
  6545. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6546. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6547. // Set the pets subtitle to the new one
  6548. pet->SetSubTitle(pet_subtitle.c_str());
  6549. }
  6550. // Set the pet as the return value for this function
  6551. lua_interface->SetSpawnValue(state, pet);
  6552. return 1;
  6553. }
  6554. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6555. if (!lua_interface)
  6556. return 0;
  6557. Spawn* spawn = lua_interface->GetSpawn(state);
  6558. Spawn* player = lua_interface->GetSpawn(state, 2);
  6559. float max_distance = lua_interface->GetFloatValue(state, 3);
  6560. string type = lua_interface->GetStringValue(state, 4);
  6561. if (!spawn || (spawn && spawn->IsPlayer())) {
  6562. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6563. return 0;
  6564. }
  6565. if (!player || (player && !player->IsPlayer())) {
  6566. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6567. return 0;
  6568. }
  6569. Client* client = 0;
  6570. if (player->GetZone())
  6571. client = player->GetZone()->GetClientBySpawn(player);
  6572. if (!client) {
  6573. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6574. return 0;
  6575. }
  6576. //Set max_distance to default if not set or not proper value
  6577. if (max_distance <= 0)
  6578. max_distance = 500;
  6579. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6580. if (packet) {
  6581. float unknown2_3 = 0;
  6582. int8 placement_mode = 0;
  6583. if (type == "wall") {
  6584. placement_mode = 2;
  6585. unknown2_3 = 150;
  6586. }
  6587. else if (type == "ceiling")
  6588. placement_mode = 1;
  6589. packet->setDataByName("placement_mode", placement_mode);
  6590. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6591. packet->setDataByName("model_type", spawn->GetModelType());
  6592. packet->setDataByName("unknown", 1); //size
  6593. packet->setDataByName("unknown2", 1); //size 2
  6594. packet->setDataByName("unknown2", .5, 1); //size 3
  6595. packet->setDataByName("unknown2", 3, 2);
  6596. packet->setDataByName("unknown2", unknown2_3, 3);
  6597. packet->setDataByName("max_distance", max_distance);
  6598. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6599. client->QueuePacket(packet->serialize());
  6600. safe_delete(packet);
  6601. }
  6602. return 0;
  6603. }
  6604. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6605. if (!lua_interface)
  6606. return 0;
  6607. Item* item = lua_interface->GetItem(state);
  6608. if (!item) {
  6609. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6610. return 0;
  6611. }
  6612. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6613. return 1;
  6614. }
  6615. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6616. if (!lua_interface)
  6617. return 0;
  6618. Spawn* spawn = lua_interface->GetSpawn(state);
  6619. if (!spawn) {
  6620. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6621. return 0;
  6622. }
  6623. if (spawn->GetZone())
  6624. spawn->GetZone()->AddTransportSpawn(spawn);
  6625. return 0;
  6626. }
  6627. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6628. if (!lua_interface)
  6629. return 0;
  6630. Skill* skill = lua_interface->GetSkill(state);
  6631. if (!skill) {
  6632. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6633. return 0;
  6634. }
  6635. lua_interface->SetInt32Value(state, skill->current_val);
  6636. return 1;
  6637. }
  6638. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6639. if (!lua_interface)
  6640. return 0;
  6641. Skill* skill = lua_interface->GetSkill(state);
  6642. if (!skill) {
  6643. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6644. return 0;
  6645. }
  6646. lua_interface->SetInt32Value(state, skill->max_val);
  6647. return 1;
  6648. }
  6649. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6650. if (!lua_interface)
  6651. return 0;
  6652. Skill* skill = lua_interface->GetSkill(state);
  6653. if (!skill) {
  6654. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6655. return 0;
  6656. }
  6657. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6658. return 1;
  6659. }
  6660. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6661. if (!lua_interface)
  6662. return 0;
  6663. Skill* skill = lua_interface->GetSkill(state);
  6664. int16 value = lua_interface->GetInt16Value(state, 2);
  6665. if (!skill) {
  6666. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6667. return 0;
  6668. }
  6669. skill->max_val = value;
  6670. if (skill->max_val < skill->current_val)
  6671. skill->current_val = skill->max_val;
  6672. return 0;
  6673. }
  6674. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6675. if (!lua_interface)
  6676. return 0;
  6677. Skill* skill = lua_interface->GetSkill(state);
  6678. int16 value = lua_interface->GetInt16Value(state, 2);
  6679. if (!skill) {
  6680. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6681. return 0;
  6682. }
  6683. if (value > skill->max_val)
  6684. skill->current_val = skill->max_val;
  6685. else
  6686. skill->current_val = value;
  6687. return 0;
  6688. }
  6689. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6690. if (!lua_interface)
  6691. return 0;
  6692. Spawn* player = lua_interface->GetSpawn(state);
  6693. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6694. if (skill_id > 0 && player && player->IsPlayer()) {
  6695. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6696. return 1;
  6697. }
  6698. return 0;
  6699. }
  6700. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6701. if (!lua_interface)
  6702. return 0;
  6703. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6704. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6705. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6706. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6707. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6708. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6709. if (player_spawn && player_spawn->IsPlayer()) {
  6710. Player* player = (Player*)player_spawn;
  6711. bool added = false;
  6712. if (!player->skill_list.HasSkill(skill_id)) {
  6713. player->AddSkill(skill_id, current_val, max_val, true);
  6714. added = true;
  6715. }
  6716. if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
  6717. Client* client = player->GetClient();
  6718. if (client) {
  6719. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6720. if (packet)
  6721. client->QueuePacket(packet);
  6722. }
  6723. }
  6724. if (added) {
  6725. lua_interface->SetBooleanValue(state, true);
  6726. return 1;
  6727. }
  6728. }
  6729. else {
  6730. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6731. }
  6732. }
  6733. else {
  6734. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6735. }
  6736. lua_interface->SetBooleanValue(state, false);
  6737. return 1;
  6738. }
  6739. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6740. if (!lua_interface)
  6741. return 0;
  6742. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6743. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6744. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6745. if (skill_id > 0) {
  6746. if (player_spawn && player_spawn->IsPlayer()) {
  6747. Player* player = (Player*)player_spawn;
  6748. if (player->skill_list.HasSkill(skill_id)) {
  6749. player->RemovePlayerSkill(skill_id);
  6750. if (!more_to_remove) {
  6751. Client* client = player->GetClient();
  6752. if (client) {
  6753. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6754. if (packet)
  6755. client->QueuePacket(packet);
  6756. }
  6757. }
  6758. }
  6759. }
  6760. else {
  6761. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6762. }
  6763. }
  6764. else {
  6765. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6766. }
  6767. return 0;
  6768. }
  6769. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6770. if (!lua_interface)
  6771. return 0;
  6772. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6773. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6774. int16 amount = lua_interface->GetInt8Value(state, 3);
  6775. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6776. if (amount > 0 && skill_type < 100) {
  6777. if (player_spawn && player_spawn->IsPlayer()) {
  6778. Player* player = (Player*)player_spawn;
  6779. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6780. if (!more_to_increase) {
  6781. Client* client = player->GetClient();
  6782. if (client) {
  6783. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6784. if (packet)
  6785. client->QueuePacket(packet);
  6786. }
  6787. }
  6788. }
  6789. else {
  6790. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6791. }
  6792. }
  6793. else {
  6794. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6795. }
  6796. return 0;
  6797. }
  6798. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6799. if (!lua_interface)
  6800. return 0;
  6801. Spawn* spawn = lua_interface->GetSpawn(state);
  6802. string name = lua_interface->GetStringValue(state, 2);
  6803. if (!spawn) {
  6804. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6805. return 0;
  6806. }
  6807. if (!spawn->IsEntity()) {
  6808. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6809. return 0;
  6810. }
  6811. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6812. if (skill) {
  6813. lua_interface->SetSkillValue(state, skill);
  6814. return 1;
  6815. }
  6816. return 0;
  6817. }
  6818. int EQ2Emu_lua_AddProc(lua_State* state) {
  6819. if (!lua_interface)
  6820. return 0;
  6821. Spawn* spawn = lua_interface->GetSpawn(state);
  6822. int8 type = lua_interface->GetInt8Value(state, 2);
  6823. float chance = lua_interface->GetFloatValue(state, 3);
  6824. Item* item = lua_interface->GetItem(state, 4);
  6825. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6826. LuaSpell* spell = 0;
  6827. if (!spawn && (!spell || !use_all_spelltargets)) {
  6828. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6829. return 0;
  6830. }
  6831. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6832. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6833. return 0;
  6834. }
  6835. if (!item)
  6836. spell = lua_interface->GetCurrentSpell(state);
  6837. if (!item && !spell) {
  6838. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6839. return 0;
  6840. }
  6841. if (spell && use_all_spelltargets) {
  6842. Spawn* target;
  6843. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6844. for (int8 i = 0; i < spell->targets.size(); i++) {
  6845. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6846. if (!target || !target->IsEntity())
  6847. continue;
  6848. ((Entity*)target)->AddProc(type, chance, item, spell);
  6849. }
  6850. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6851. }
  6852. else
  6853. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6854. return 0;
  6855. }
  6856. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6857. if (!lua_interface)
  6858. return 0;
  6859. Spawn* spawn = lua_interface->GetSpawn(state);
  6860. Item* item = lua_interface->GetItem(state, 2);
  6861. LuaSpell* spell = 0;
  6862. if (!spawn) {
  6863. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6864. return 0;
  6865. }
  6866. if (!spawn->IsEntity()) {
  6867. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6868. return 0;
  6869. }
  6870. if (!item)
  6871. spell = lua_interface->GetCurrentSpell(state);
  6872. if (!item && !spell) {
  6873. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6874. return 0;
  6875. }
  6876. if (spell) {
  6877. Spawn* target;
  6878. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6879. for (int8 i = 0; i < spell->targets.size(); i++) {
  6880. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6881. if (!target || !target->IsEntity())
  6882. continue;
  6883. ((Entity*)target)->RemoveProc(item, spell);
  6884. }
  6885. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6886. spell->caster->RemoveProc(item, spell);
  6887. }
  6888. else
  6889. ((Entity*)spawn)->RemoveProc(item, spell);
  6890. return 0;
  6891. }
  6892. int EQ2Emu_lua_Knockback(lua_State* state) {
  6893. if (!lua_interface)
  6894. return 0;
  6895. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6896. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6897. int32 duration = lua_interface->GetInt32Value(state, 3);
  6898. float vertical = lua_interface->GetFloatValue(state, 4);
  6899. float horizontal = lua_interface->GetFloatValue(state, 5);
  6900. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6901. if (!target_spawn) {
  6902. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6903. return 0;
  6904. }
  6905. if (!spawn) {
  6906. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6907. return 0;
  6908. }
  6909. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6910. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6911. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6912. if (packet) {
  6913. packet->setDataByName("target_x", target_spawn->GetX());
  6914. packet->setDataByName("target_y", target_spawn->GetY());
  6915. packet->setDataByName("target_z", target_spawn->GetZ());
  6916. packet->setDataByName("vertical_movement", vertical);
  6917. packet->setDataByName("horizontal_movement", horizontal);
  6918. if (use_heading)
  6919. packet->setDataByName("use_player_heading", 1);
  6920. client->QueuePacket(packet->serialize());
  6921. }
  6922. safe_delete(packet);
  6923. }
  6924. return 0;
  6925. }
  6926. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6927. if (!lua_interface)
  6928. return 0;
  6929. Spawn* spawn = lua_interface->GetSpawn(state);
  6930. if (!spawn) {
  6931. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6932. return 0;
  6933. }
  6934. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6935. return 1;
  6936. }
  6937. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6938. if (!lua_interface)
  6939. return 0;
  6940. Spawn* caster = lua_interface->GetSpawn(state);
  6941. Spawn* target = lua_interface->GetSpawn(state, 2);
  6942. string name = lua_interface->GetStringValue(state, 3);
  6943. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6944. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6945. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6946. string success_msg = lua_interface->GetStringValue(state, 7);
  6947. string effect_msg = lua_interface->GetStringValue(state, 8);
  6948. if (!caster) {
  6949. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6950. return 0;
  6951. }
  6952. if (!caster->IsEntity()) {
  6953. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6954. return 0;
  6955. }
  6956. if (!target) {
  6957. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6958. return 0;
  6959. }
  6960. if (!target->IsEntity()) {
  6961. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6962. return 0;
  6963. }
  6964. if (name.length() == 0) {
  6965. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6966. return 0;
  6967. }
  6968. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6969. return 0;
  6970. }
  6971. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6972. if (!lua_interface)
  6973. return 0;
  6974. string name = lua_interface->GetStringValue(state);
  6975. if (name.length() == 0) {
  6976. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6977. return 0;
  6978. }
  6979. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6980. if (!skill) {
  6981. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6982. return 0;
  6983. }
  6984. lua_interface->SetInt32Value(state, skill->skill_id);
  6985. return 1;
  6986. }
  6987. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6988. if (!lua_interface)
  6989. return 0;
  6990. Spawn* spawn = lua_interface->GetSpawn(state);
  6991. if (!spawn) {
  6992. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6996. return 1;
  6997. }
  6998. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6999. if (!lua_interface)
  7000. return 0;
  7001. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7002. if (!luaspell) {
  7003. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7004. return 0;
  7005. }
  7006. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7007. return 1;
  7008. }
  7009. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7010. if (!lua_interface)
  7011. return 0;
  7012. Spawn* spawn = lua_interface->GetSpawn(state);
  7013. Spawn* target = lua_interface->GetSpawn(state, 2);
  7014. if (!spawn) {
  7015. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7016. return 0;
  7017. }
  7018. if (!spawn->IsEntity()) {
  7019. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7020. return 0;
  7021. }
  7022. if (!target) {
  7023. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7024. return 0;
  7025. }
  7026. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7027. return 1;
  7028. }
  7029. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7030. if (!lua_interface)
  7031. return 0;
  7032. Spawn* spawn = lua_interface->GetSpawn(state);
  7033. Spawn* target = lua_interface->GetSpawn(state, 2);
  7034. if (!spawn) {
  7035. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7036. return 0;
  7037. }
  7038. if (!spawn->IsEntity()) {
  7039. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7040. return 0;
  7041. }
  7042. if (!target) {
  7043. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7044. return 0;
  7045. }
  7046. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7047. return 1;
  7048. }
  7049. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7050. if (!lua_interface)
  7051. return 0;
  7052. Item* item = lua_interface->GetItem(state);
  7053. if (!item) {
  7054. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7055. return 0;
  7056. }
  7057. lua_interface->SetInt32Value(state, item->details.count);
  7058. return 1;
  7059. }
  7060. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7061. if (!lua_interface)
  7062. return 0;
  7063. Item* item = lua_interface->GetItem(state);
  7064. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7065. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7066. if (!item) {
  7067. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7068. return 0;
  7069. }
  7070. if (!owner) {
  7071. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7072. return 0;
  7073. }
  7074. if (!owner->IsPlayer()) {
  7075. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7076. return 0;
  7077. }
  7078. if (item->stack_count < new_count) {
  7079. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7080. return 0;
  7081. }
  7082. if (new_count > 0) {
  7083. item->details.count = new_count;
  7084. item->save_needed = true;
  7085. }
  7086. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7087. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7088. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7089. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7090. else
  7091. {
  7092. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7093. return 0;
  7094. }
  7095. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7096. if (!client)
  7097. return 0;
  7098. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7099. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  7100. if (app)
  7101. client->QueuePacket(app);
  7102. return 0;
  7103. }
  7104. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7105. if (!lua_interface)
  7106. return 0;
  7107. int32 time = lua_interface->GetInt32Value(state);
  7108. string function = lua_interface->GetStringValue(state, 2);
  7109. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7110. Spawn* target = lua_interface->GetSpawn(state, 4);
  7111. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7112. if (time == 0) {
  7113. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7114. return 0;
  7115. }
  7116. if (function.length() == 0) {
  7117. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7118. return 0;
  7119. }
  7120. if (!spell) {
  7121. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7122. return 0;
  7123. }
  7124. SpellScriptTimer* timer = new SpellScriptTimer;
  7125. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7126. #ifdef WIN32
  7127. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7128. #else
  7129. bzero(timer, sizeof(SpellScriptTimer));
  7130. #endif*/
  7131. timer->caster = 0;
  7132. timer->deleteWhenDone = false;
  7133. timer->target = 0;
  7134. timer->time = Timer::GetCurrentTime2() + time;
  7135. timer->customFunction = function;
  7136. timer->spell = spell;
  7137. if (caster)
  7138. timer->caster = caster->GetID();
  7139. if (target)
  7140. timer->target = target->GetID();
  7141. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7142. return 0;
  7143. }
  7144. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7145. if (!lua_interface)
  7146. return 0;
  7147. float hp_perc = lua_interface->GetFloatValue(state);
  7148. float power_perc = lua_interface->GetFloatValue(state, 2);
  7149. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7150. Spawn* target = lua_interface->GetSpawn(state, 4);
  7151. string heal_name = lua_interface->GetStringValue(state, 5);
  7152. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7153. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7154. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7155. if (!spell) {
  7156. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7157. return 0;
  7158. }
  7159. Entity* caster = spell->caster;
  7160. if (!caster) {
  7161. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7162. return 0;
  7163. }
  7164. Client* client = 0;
  7165. PendingResurrection* rez = 0;
  7166. ZoneServer* zone = spell->caster->GetZone();
  7167. if (!target) {
  7168. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7169. if (spell->targets.size() > 0) {
  7170. vector<int32> spell_targets = spell->targets;
  7171. for (int8 i = 0; i < spell_targets.size(); i++) {
  7172. target = zone->GetSpawnByID(spell_targets.at(i));
  7173. if (!target)
  7174. continue;
  7175. if (!target->IsPlayer())
  7176. continue;
  7177. client = target->GetZone()->GetClientBySpawn(target);
  7178. if (!client)
  7179. continue;
  7180. rez = client->GetCurrentRez();
  7181. if (rez->active)
  7182. continue;
  7183. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7184. rez->active = true;
  7185. rez->caster = caster;
  7186. rez->expire_timer = new Timer;
  7187. int32 duration = spell->spell->GetSpellDuration();
  7188. rez->expire_timer->Start(duration * 100);
  7189. rez->hp_perc = hp_perc;
  7190. rez->mp_perc = power_perc;
  7191. rez->range = spell->spell->GetSpellData()->range;
  7192. rez->spell_name = spell->spell->GetName();
  7193. if (heal_name.length() > 0)
  7194. rez->heal_name = heal_name;
  7195. else
  7196. rez->heal_name = rez->spell_name;
  7197. rez->no_calcs = no_calcs;
  7198. rez->crit_mod = crit_mod;
  7199. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7200. if (send_window)
  7201. client->SendResurrectionWindow();
  7202. else {
  7203. target->GetZone()->ResurrectSpawn(target, client);
  7204. rez->should_delete = true;
  7205. }
  7206. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7207. }
  7208. }
  7209. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7210. }
  7211. else {
  7212. client = target->GetZone()->GetClientBySpawn(target);
  7213. if (!client)
  7214. return 0;
  7215. rez = client->GetCurrentRez();
  7216. if (rez->active)
  7217. return 0;
  7218. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7219. rez->active = true;
  7220. rez->caster = caster;
  7221. rez->expire_timer = new Timer;
  7222. int32 duration = spell->spell->GetSpellDuration();
  7223. rez->expire_timer->Start(duration * 100);
  7224. rez->hp_perc = hp_perc;
  7225. rez->mp_perc = power_perc;
  7226. rez->range = spell->spell->GetSpellData()->range;
  7227. rez->spell_name = spell->spell->GetName();
  7228. if (heal_name.length() > 0)
  7229. rez->heal_name = heal_name;
  7230. else
  7231. rez->heal_name = rez->spell_name;
  7232. rez->no_calcs = no_calcs;
  7233. rez->crit_mod = crit_mod;
  7234. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7235. if (send_window)
  7236. client->SendResurrectionWindow();
  7237. else {
  7238. target->GetZone()->ResurrectSpawn(target, client);
  7239. rez->should_delete = true;
  7240. }
  7241. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7242. }
  7243. return 0;
  7244. }
  7245. int EQ2Emu_lua_SetVision(lua_State* state) {
  7246. if (!lua_interface)
  7247. return 0;
  7248. Spawn* spawn = lua_interface->GetSpawn(state);
  7249. int8 vision = lua_interface->GetInt8Value(state, 2);
  7250. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7251. if (!spawn) {
  7252. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7253. return 0;
  7254. }
  7255. if (!spawn->IsEntity()) {
  7256. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7257. return 0;
  7258. }
  7259. if (spell && spell->targets.size() > 0) {
  7260. ZoneServer* zone = spell->caster->GetZone();
  7261. for (int8 i = 0; i < spell->targets.size(); i++) {
  7262. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7263. if (target->IsEntity()) {
  7264. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7265. if (target->IsPlayer())
  7266. ((Player*)target)->SetCharSheetChanged(true);
  7267. }
  7268. }
  7269. }
  7270. else {
  7271. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7272. if (spawn->IsPlayer())
  7273. ((Player*)spawn)->SetCharSheetChanged(true);
  7274. }
  7275. return 0;
  7276. }
  7277. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7278. if (!lua_interface)
  7279. return 0;
  7280. Spawn* spawn = lua_interface->GetSpawn(state);
  7281. float intensity = lua_interface->GetFloatValue(state, 2);
  7282. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7283. if (!spawn) {
  7284. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7285. return 0;
  7286. }
  7287. if (!spawn->IsEntity()) {
  7288. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7289. return 0;
  7290. }
  7291. if (spell && spell->targets.size() > 0) {
  7292. ZoneServer* zone = spell->caster->GetZone();
  7293. for (int8 i = 0; i < spell->targets.size(); i++) {
  7294. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7295. if (target && target->IsEntity()) {
  7296. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7297. if (target->IsPlayer())
  7298. ((Player*)target)->SetCharSheetChanged(true);
  7299. }
  7300. }
  7301. }
  7302. else {
  7303. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7304. if (spawn->IsPlayer())
  7305. ((Player*)spawn)->SetCharSheetChanged(true);
  7306. }
  7307. return 0;
  7308. }
  7309. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7310. if (!lua_interface)
  7311. return 0;
  7312. Spawn* spawn = lua_interface->GetSpawn(state);
  7313. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7314. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7315. if (!spawn) {
  7316. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7317. return 0;
  7318. }
  7319. if (!spawn->IsEntity()) {
  7320. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7321. return 0;
  7322. }
  7323. if (spell && spell->targets.size() > 0) {
  7324. ZoneServer* zone = spell->caster->GetZone();
  7325. for (int8 i = 0; i < spell->targets.size(); i++) {
  7326. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7327. if (target->IsEntity()) {
  7328. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7329. if (target->IsPlayer())
  7330. ((Player*)target)->SetCharSheetChanged(true);
  7331. }
  7332. }
  7333. }
  7334. else {
  7335. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7336. if (spawn->IsPlayer())
  7337. ((Player*)spawn)->SetCharSheetChanged(true);
  7338. }
  7339. return 0;
  7340. }
  7341. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7342. if (!lua_interface)
  7343. return 0;
  7344. Item* item = lua_interface->GetItem(state);
  7345. int8 type = lua_interface->GetInt32Value(state, 2);
  7346. if (!item) {
  7347. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7348. return 0;
  7349. }
  7350. if (type == 1)
  7351. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7352. else if (type == 2)
  7353. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7354. return 1;
  7355. }
  7356. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7357. if (!lua_interface)
  7358. return 0;
  7359. Spawn* target = lua_interface->GetSpawn(state);
  7360. float val = lua_interface->GetFloatValue(state, 2);
  7361. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7362. // Added from Gangrenous post
  7363. if (spell && spell->resisted)
  7364. return 0;
  7365. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7366. if (val > 1.0f)
  7367. val = 1.0f - (val / 100.0f);
  7368. if (spell && spell->spell && spell->targets.size() > 0) {
  7369. ZoneServer* zone = spell->caster->GetZone();
  7370. for (int32 i = 0; i != spell->targets.size(); i++) {
  7371. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7372. if (spawn && spawn->IsEntity()) {
  7373. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7374. if (spawn->IsPlayer())
  7375. ((Player*)spawn)->SetCharSheetChanged(true);
  7376. }
  7377. }
  7378. }
  7379. else {
  7380. if (target && target->IsEntity()) {
  7381. ((Entity*)target)->SetSpeedMultiplier(val);
  7382. if (target->IsPlayer())
  7383. ((Player*)target)->SetCharSheetChanged(true);
  7384. }
  7385. }
  7386. return 0;
  7387. }
  7388. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7389. if (!lua_interface)
  7390. return 0;
  7391. Spawn* spawn = lua_interface->GetSpawn(state);
  7392. int16 model = lua_interface->GetInt16Value(state, 2);
  7393. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7394. if (spell && spell->spell && spell->targets.size() > 0) {
  7395. ZoneServer* zone = spell->caster->GetZone();
  7396. for (int32 i = 0; i < spell->targets.size(); i++) {
  7397. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7398. if (target)
  7399. target->SetIllusionModel(model);
  7400. }
  7401. }
  7402. else {
  7403. if (!spawn) {
  7404. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7405. return 0;
  7406. }
  7407. spawn->SetIllusionModel(model);
  7408. }
  7409. return 0;
  7410. }
  7411. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7412. if (!lua_interface)
  7413. return 0;
  7414. Spawn* spawn = lua_interface->GetSpawn(state);
  7415. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7416. if (spell && spell->spell && spell->targets.size() > 0) {
  7417. ZoneServer* zone = spell->caster->GetZone();
  7418. for (int32 i = 0; i < spell->targets.size(); i++) {
  7419. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7420. if (target)
  7421. target->SetIllusionModel(0);
  7422. }
  7423. }
  7424. else {
  7425. if (!spawn) {
  7426. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7427. return 0;
  7428. }
  7429. spawn->SetIllusionModel(0);
  7430. }
  7431. return 0;
  7432. }
  7433. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7434. if (!lua_interface)
  7435. return 0;
  7436. Spawn* caster = lua_interface->GetSpawn(state);
  7437. Spawn* target = lua_interface->GetSpawn(state, 2);
  7438. float chance = lua_interface->GetFloatValue(state, 3);
  7439. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7440. if (!caster) {
  7441. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7442. return 0;
  7443. }
  7444. if (!caster->IsEntity()) {
  7445. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7446. return 0;
  7447. }
  7448. if (!target) {
  7449. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7450. return 0;
  7451. }
  7452. if (!target->IsEntity()) {
  7453. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7454. return 0;
  7455. }
  7456. if (chance <= 0) {
  7457. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7458. return 0;
  7459. }
  7460. if (!spell) {
  7461. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7462. return 0;
  7463. }
  7464. if (((Entity*)caster)->GetThreatTransfer()) {
  7465. return 0;
  7466. }
  7467. ThreatTransfer* transfer = new ThreatTransfer;
  7468. transfer->Target = target->GetID();
  7469. transfer->Amount = chance;
  7470. transfer->Spell = spell;
  7471. ((Entity*)caster)->SetThreatTransfer(transfer);
  7472. return 0;
  7473. }
  7474. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7475. if (!lua_interface)
  7476. return 0;
  7477. Spawn* spawn = lua_interface->GetSpawn(state);
  7478. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7479. if (!spawn) {
  7480. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7481. return 0;
  7482. }
  7483. if (!spell) {
  7484. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7485. return 0;
  7486. }
  7487. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7488. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7489. ((Entity*)spawn)->SetThreatTransfer(0);
  7490. safe_delete(transfer);
  7491. }
  7492. return 0;
  7493. }
  7494. int EQ2Emu_lua_CureByType(lua_State* state) {
  7495. if (!lua_interface)
  7496. return 0;
  7497. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7498. if (!spell) {
  7499. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7500. return 0;
  7501. }
  7502. int8 cure_count = lua_interface->GetInt8Value(state);
  7503. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7504. string cure_name = lua_interface->GetStringValue(state, 3);
  7505. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7506. Spawn* target = lua_interface->GetSpawn(state, 5);
  7507. if (target) {
  7508. if (!target->IsEntity()) {
  7509. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7510. return 0;
  7511. }
  7512. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7513. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7514. }
  7515. else {
  7516. ZoneServer* zone = spell->caster->GetZone();
  7517. vector<int32> targets = spell->targets;
  7518. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7519. for (int8 i = 0; i < targets.size(); i++) {
  7520. target = zone->GetSpawnByID(targets.at(i));
  7521. if (!target || !target->IsEntity())
  7522. continue;
  7523. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7524. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7525. }
  7526. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7527. }
  7528. return 0;
  7529. }
  7530. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7531. if (!lua_interface)
  7532. return 0;
  7533. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7534. if (!spell) {
  7535. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7536. return 0;
  7537. }
  7538. int8 cure_count = lua_interface->GetInt8Value(state);
  7539. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7540. string cure_name = lua_interface->GetStringValue(state, 3);
  7541. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7542. Spawn* target = lua_interface->GetSpawn(state, 5);
  7543. if (target) {
  7544. if (!target->IsEntity()) {
  7545. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7546. return 0;
  7547. }
  7548. if (((Entity*)target)->GetDetCount() > 0)
  7549. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7550. }
  7551. else {
  7552. ZoneServer* zone = spell->caster->GetZone();
  7553. vector<int32> targets = spell->targets;
  7554. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7555. for (int8 i = 0; i < targets.size(); i++) {
  7556. target = zone->GetSpawnByID(targets.at(i));
  7557. if (!target || !target->IsEntity())
  7558. continue;
  7559. if (((Entity*)target)->GetDetCount() > 0)
  7560. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7561. }
  7562. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7563. }
  7564. return 0;
  7565. }
  7566. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7567. if (!lua_interface)
  7568. return 0;
  7569. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7570. if (!spell) {
  7571. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7572. return 0;
  7573. }
  7574. if (!spell->caster) {
  7575. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7576. return 0;
  7577. }
  7578. if (!spell->caster->GetZone()) {
  7579. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7580. return 0;
  7581. }
  7582. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7583. return 0;
  7584. }
  7585. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7586. if (!lua_interface)
  7587. return 0;
  7588. Spawn* spawn = lua_interface->GetSpawn(state);
  7589. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7590. if (!spell) {
  7591. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7592. return 0;
  7593. }
  7594. if (spawn && spawn->IsEntity())
  7595. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7596. else {
  7597. ZoneServer* zone = spell->caster->GetZone();
  7598. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7599. for (int32 i = 0; i < spell->targets.size(); i++) {
  7600. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7601. if (!spawn || !spawn->IsEntity())
  7602. continue;
  7603. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7604. }
  7605. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7606. }
  7607. return 0;
  7608. }
  7609. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7610. if (!lua_interface)
  7611. return 0;
  7612. Spawn* spawn = lua_interface->GetSpawn(state);
  7613. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7614. if (!spell) {
  7615. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7616. return 0;
  7617. }
  7618. if (spawn && spawn->IsEntity())
  7619. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7620. else {
  7621. ZoneServer* zone = spell->caster->GetZone();
  7622. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7623. for (int32 i = 0; i < spell->targets.size(); i++) {
  7624. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7625. if (!spawn || !spawn->IsEntity())
  7626. continue;
  7627. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7628. }
  7629. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7630. }
  7631. return 0;
  7632. }
  7633. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7634. if (!lua_interface)
  7635. return 0;
  7636. Spawn* caster = lua_interface->GetSpawn(state);
  7637. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7638. if (!caster) {
  7639. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7640. return 0;
  7641. }
  7642. if (!caster->IsPlayer()) {
  7643. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7644. return 0;
  7645. }
  7646. Spawn* target = caster->GetTarget();
  7647. if (!target) {
  7648. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7649. return 0;
  7650. }
  7651. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7652. if (!client) {
  7653. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7654. return 0;
  7655. }
  7656. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7657. if (ho) {
  7658. ho->SetTarget(target->GetID());
  7659. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7660. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7661. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7662. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7663. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7664. deque<GroupMemberInfo*>::iterator itr;
  7665. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7666. if (group)
  7667. {
  7668. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7669. deque<GroupMemberInfo*>* members = group->GetMembers();
  7670. for (itr = members->begin(); itr != members->end(); itr++) {
  7671. if ((*itr)->client)
  7672. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7673. }
  7674. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7675. }
  7676. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7677. }
  7678. else
  7679. safe_delete(ho);
  7680. }
  7681. else {
  7682. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7683. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7684. }
  7685. else
  7686. safe_delete(ho);
  7687. }
  7688. }
  7689. return 0;
  7690. }
  7691. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7692. if (!lua_interface)
  7693. return 0;
  7694. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7695. if (!spell) {
  7696. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7697. return 0;
  7698. }
  7699. int16 triggerCount = lua_interface->GetInt16Value(state);
  7700. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7701. if (!triggerCount) {
  7702. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7703. return 0;
  7704. }
  7705. spell->num_triggers = triggerCount;
  7706. spell->had_triggers = true;
  7707. spell->cancel_after_all_triggers = cancel_after_triggers;
  7708. return 0;
  7709. }
  7710. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7711. if (!lua_interface)
  7712. return 0;
  7713. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7714. if (!spell) {
  7715. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7716. return 0;
  7717. }
  7718. lua_interface->SetInt32Value(state, spell->num_triggers);
  7719. return 1;
  7720. }
  7721. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7722. if (!lua_interface)
  7723. return 0;
  7724. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7725. if (!spell) {
  7726. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7727. return 0;
  7728. }
  7729. int16 remove_count = lua_interface->GetInt16Value(state);
  7730. if (!remove_count)
  7731. remove_count = 1;
  7732. if (remove_count >= spell->num_triggers) {
  7733. spell->num_triggers = 0;
  7734. if (spell->cancel_after_all_triggers)
  7735. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7736. }
  7737. else {
  7738. spell->num_triggers -= remove_count;
  7739. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7740. }
  7741. return 0;
  7742. }
  7743. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7744. if (!lua_interface)
  7745. return 0;
  7746. Spawn* spawn = lua_interface->GetSpawn(state);
  7747. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7748. if (!spawn) {
  7749. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7750. return 0;
  7751. }
  7752. if (!copy_spawn) {
  7753. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7754. return 0;
  7755. }
  7756. spawn->CopySpawnAppearance(copy_spawn);
  7757. return 0;
  7758. }
  7759. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7760. Spawn* spawn = lua_interface->GetSpawn(state);
  7761. int8 type = lua_interface->GetInt8Value(state, 2);
  7762. if (!spawn) {
  7763. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7764. return 0;
  7765. }
  7766. else if (!spawn->IsEntity()) {
  7767. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7768. return 0;
  7769. }
  7770. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7771. return 1;
  7772. }
  7773. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7774. if (!lua_interface)
  7775. return 0;
  7776. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7777. int8 type = lua_interface->GetInt8Value(state);
  7778. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7779. if (!spell) {
  7780. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7781. return 0;
  7782. }
  7783. if (spawn) {
  7784. if (!spawn->IsEntity()) {
  7785. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7786. return 0;
  7787. }
  7788. Entity* entity = ((Entity*)spawn);
  7789. entity->AddImmunity(spell, type);
  7790. }
  7791. else {
  7792. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7793. for (int8 i = 0; i < spell->targets.size(); i++) {
  7794. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7795. if (!spawn || !spawn->IsEntity())
  7796. continue;
  7797. Entity* entity = ((Entity*)spawn);
  7798. entity->AddImmunity(spell, type);
  7799. }
  7800. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7801. }
  7802. return 0;
  7803. }
  7804. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7805. if (!lua_interface)
  7806. return 0;
  7807. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7808. int8 type = lua_interface->GetInt8Value(state);
  7809. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7810. if (!spell) {
  7811. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7812. return 0;
  7813. }
  7814. if (spawn) {
  7815. if (!spawn->IsEntity()) {
  7816. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7817. return 0;
  7818. }
  7819. Entity* entity = ((Entity*)spawn);
  7820. entity->RemoveImmunity(spell, type);
  7821. }
  7822. else {
  7823. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7824. for (int8 i = 0; i < spell->targets.size(); i++) {
  7825. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7826. if (!spawn || !spawn->IsEntity())
  7827. continue;
  7828. Entity* entity = ((Entity*)spawn);
  7829. entity->RemoveImmunity(spell, type);
  7830. }
  7831. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7832. }
  7833. return 0;
  7834. }
  7835. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7836. if (!lua_interface)
  7837. return 0;
  7838. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7839. if (!spell) {
  7840. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7841. return 0;
  7842. }
  7843. float snare = lua_interface->GetFloatValue(state);
  7844. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7845. // convert the val to the speed multipler value (100 - val)
  7846. float val = 100.0 - snare;
  7847. val /= 100.0;
  7848. if (spawn) {
  7849. if (!spawn->IsEntity()) {
  7850. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7851. return 0;
  7852. }
  7853. ((Entity*)spawn)->SetSnareValue(spell, val);
  7854. }
  7855. else {
  7856. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7857. for (int8 i = 0; i < spell->targets.size(); i++) {
  7858. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7859. if (!spawn || !spawn->IsEntity())
  7860. continue;
  7861. ((Entity*)spawn)->SetSnareValue(spell, val);
  7862. }
  7863. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7864. }
  7865. return 0;
  7866. }
  7867. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7868. if (!lua_interface)
  7869. return 0;
  7870. Spawn* spawn = lua_interface->GetSpawn(state);
  7871. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7872. if (!spawn) {
  7873. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7874. return 0;
  7875. }
  7876. if (race_id == 0) {
  7877. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7878. return 0;
  7879. }
  7880. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7881. return 1;
  7882. }
  7883. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7884. if (!lua_interface)
  7885. return 0;
  7886. Spawn* spawn = lua_interface->GetSpawn(state);
  7887. if (!spawn) {
  7888. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7889. return 0;
  7890. }
  7891. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7892. return 1;
  7893. }
  7894. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7895. if (!lua_interface)
  7896. return 0;
  7897. Spawn* spawn = lua_interface->GetSpawn(state);
  7898. if (!spawn) {
  7899. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7900. return 0;
  7901. }
  7902. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7903. return 1;
  7904. }
  7905. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7906. if (!lua_interface)
  7907. return 0;
  7908. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7909. if (!spell) {
  7910. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7911. return 0;
  7912. }
  7913. lua_interface->SetStringValue(state, spell->spell->GetName());
  7914. return 1;
  7915. }
  7916. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7917. if (!lua_interface)
  7918. return 0;
  7919. Quest* quest = lua_interface->GetQuest(state);
  7920. if (!quest) {
  7921. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7922. return 0;
  7923. }
  7924. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7925. return 1;
  7926. }
  7927. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7928. if (!lua_interface)
  7929. return 0;
  7930. Quest* quest = lua_interface->GetQuest(state);
  7931. int32 flags = lua_interface->GetInt32Value(state, 2);
  7932. if (!quest) {
  7933. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7934. return 0;
  7935. }
  7936. quest->SetQuestFlags(flags);
  7937. return 0;
  7938. }
  7939. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7940. if (!lua_interface)
  7941. return 0;
  7942. Quest* quest = lua_interface->GetQuest(state);
  7943. Spawn* player = lua_interface->GetSpawn(state, 2);
  7944. int32 step = lua_interface->GetInt32Value(state, 3);
  7945. int32 duration = lua_interface->GetInt32Value(state, 4);
  7946. string action = lua_interface->GetStringValue(state, 5);
  7947. if (!quest) {
  7948. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7949. return 0;
  7950. }
  7951. if (!player) {
  7952. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7953. return 0;
  7954. }
  7955. if (!player->IsPlayer()) {
  7956. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7957. return 0;
  7958. }
  7959. if (step == 0) {
  7960. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7961. return 0;
  7962. }
  7963. if (duration == 0) {
  7964. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7965. return 0;
  7966. }
  7967. if (action.length() == 0) {
  7968. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7969. return 0;
  7970. }
  7971. Client* client = player->GetZone()->GetClientBySpawn(player);
  7972. if (!client) {
  7973. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7974. return 0;
  7975. }
  7976. quest->SetTimerStep(step);
  7977. quest->AddFailedAction(step, action);
  7978. quest->SetStepTimer(duration);
  7979. client->AddQuestTimer(quest->GetQuestID());
  7980. return 0;
  7981. }
  7982. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7983. if (!lua_interface)
  7984. return 0;
  7985. Quest* quest = lua_interface->GetQuest(state);
  7986. Spawn* player = lua_interface->GetSpawn(state, 2);
  7987. if (!quest) {
  7988. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7989. return 0;
  7990. }
  7991. if (!player) {
  7992. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7993. return 0;
  7994. }
  7995. if (!player->IsPlayer()) {
  7996. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7997. return 0;
  7998. }
  7999. Client* client = player->GetZone()->GetClientBySpawn(player);
  8000. if (!client) {
  8001. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8002. return 0;
  8003. }
  8004. quest->SetTimerStep(0);
  8005. quest->SetStepTimer(0);
  8006. client->RemoveQuestTimer(quest->GetQuestID());
  8007. return 0;
  8008. }
  8009. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8010. if (!lua_interface)
  8011. return 0;
  8012. Spawn* player = lua_interface->GetSpawn(state);
  8013. Quest* quest = lua_interface->GetQuest(state, 2);
  8014. int32 step = lua_interface->GetInt32Value(state, 3);
  8015. if (!player) {
  8016. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8017. return 0;
  8018. }
  8019. if (!player->IsPlayer()) {
  8020. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8021. return 0;
  8022. }
  8023. if (!quest) {
  8024. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8025. return 0;
  8026. }
  8027. if (step == 0) {
  8028. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8029. return 0;
  8030. }
  8031. Client* client = player->GetZone()->GetClientBySpawn(player);
  8032. if (!client) {
  8033. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8034. return 0;
  8035. }
  8036. if (quest->RemoveQuestStep(step, client)) {
  8037. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8038. client->GetCurrentZone()->SendQuestUpdates(client);
  8039. }
  8040. else
  8041. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8042. return 0;
  8043. }
  8044. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8045. if (!lua_interface)
  8046. return 0;
  8047. Quest* quest = lua_interface->GetQuest(state, 1);
  8048. int32 step = lua_interface->GetInt32Value(state, 2);
  8049. string desc = lua_interface->GetStringValue(state, 3);
  8050. string task_group = lua_interface->GetStringValue(state, 4);
  8051. if (!quest) {
  8052. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8053. return 0;
  8054. }
  8055. if (step == 0) {
  8056. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8057. return 0;
  8058. }
  8059. QuestStep* quest_step = quest->GetQuestStep(step);
  8060. if (!quest_step) {
  8061. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8062. return 0;
  8063. }
  8064. quest_step->SetStepProgress(0);
  8065. quest_step->SetTaskGroup(task_group);
  8066. quest_step->SetDescription(desc);
  8067. return 0;
  8068. }
  8069. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8070. if (!lua_interface)
  8071. return 0;
  8072. Quest* quest = lua_interface->GetQuest(state);
  8073. int32 step = lua_interface->GetInt32Value(state, 2);
  8074. string action = lua_interface->GetStringValue(state, 3);
  8075. if (!quest) {
  8076. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8077. return 0;
  8078. }
  8079. if (step == 0) {
  8080. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8081. return 0;
  8082. }
  8083. if (action.length() == 0) {
  8084. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8085. return 0;
  8086. }
  8087. quest->AddFailedAction(step, action);
  8088. return 0;
  8089. }
  8090. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8091. if (!lua_interface)
  8092. return 0;
  8093. Spawn* player = lua_interface->GetSpawn(state);
  8094. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8095. int32 step = lua_interface->GetInt32Value(state, 3);
  8096. if (!player) {
  8097. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8098. return 0;
  8099. }
  8100. if (!player->IsPlayer()) {
  8101. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8102. return 0;
  8103. }
  8104. if (quest_id == 0) {
  8105. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8106. return 0;
  8107. }
  8108. if (step == 0) {
  8109. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8110. return 0;
  8111. }
  8112. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8113. if (!quest) {
  8114. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8115. return 0;
  8116. }
  8117. quest->StepFailed(step);
  8118. return 0;
  8119. }
  8120. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8121. if (!lua_interface)
  8122. return 0;
  8123. Spawn* player = lua_interface->GetSpawn(state);
  8124. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8125. if (!player) {
  8126. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8127. return 0;
  8128. }
  8129. if (!player->IsPlayer()) {
  8130. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8131. return 0;
  8132. }
  8133. if (quest_id == 0) {
  8134. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8135. return 0;
  8136. }
  8137. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8138. if (!quest) {
  8139. lua_interface->SetInt32Value(state, 0);
  8140. return 1;
  8141. }
  8142. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8143. return 1;
  8144. }
  8145. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8146. if (!lua_interface)
  8147. return 0;
  8148. string name = lua_interface->GetStringValue(state);
  8149. string value = lua_interface->GetStringValue(state, 2);
  8150. string comment = lua_interface->GetStringValue(state, 3);
  8151. if (name.length() == 0) {
  8152. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8153. return 0;
  8154. }
  8155. if (value.length() == 0) {
  8156. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8157. return 0;
  8158. }
  8159. string varname = string("lua_").append(name);
  8160. Variable* var = variables.FindVariable(varname);
  8161. if (var)
  8162. var->SetValue(value.c_str());
  8163. else {
  8164. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8165. variables.AddVariable(var);
  8166. }
  8167. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8168. return 0;
  8169. }
  8170. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8171. if (!lua_interface)
  8172. return 0;
  8173. string name = lua_interface->GetStringValue(state);
  8174. if (name.length() == 0) {
  8175. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8176. return 0;
  8177. }
  8178. string varname = string("lua_").append(name);
  8179. Variable* var = variables.FindVariable(varname);
  8180. if (var)
  8181. lua_interface->SetStringValue(state, var->GetValue());
  8182. else
  8183. lua_interface->SetStringValue(state, "NULL");
  8184. return 1;
  8185. }
  8186. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8187. if (!lua_interface)
  8188. return 0;
  8189. Spawn* player = lua_interface->GetSpawn(state);
  8190. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8191. if (!player) {
  8192. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8193. return 0;
  8194. }
  8195. if (!player->IsPlayer()) {
  8196. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8197. return 0;
  8198. }
  8199. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8200. return 1;
  8201. }
  8202. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8203. if (!lua_interface)
  8204. return 0;
  8205. Spawn* player = lua_interface->GetSpawn(state);
  8206. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8207. if (!player) {
  8208. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8209. return 0;
  8210. }
  8211. if (!player->IsPlayer()) {
  8212. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8213. return 0;
  8214. }
  8215. Language* language = master_languages_list.GetLanguage(language_id);
  8216. if (language)
  8217. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8218. return 0;
  8219. }
  8220. int EQ2Emu_lua_IsNight(lua_State* state) {
  8221. if (!lua_interface)
  8222. return 0;
  8223. ZoneServer* zone = lua_interface->GetZone(state);
  8224. if (!zone) {
  8225. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8226. return 0;
  8227. }
  8228. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8229. return 1;
  8230. }
  8231. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8232. if (!lua_interface)
  8233. return 0;
  8234. Spawn* spawn = lua_interface->GetSpawn(state);
  8235. if (!spawn) {
  8236. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8237. return 0;
  8238. }
  8239. if (!spawn->IsWidget()) {
  8240. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8241. return 0;
  8242. }
  8243. ((Widget*)spawn)->SetMultiFloorLift(true);
  8244. if (spawn->GetZone())
  8245. spawn->GetZone()->AddTransportSpawn(spawn);
  8246. return 0;
  8247. }
  8248. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8249. if (!lua_interface)
  8250. return 0;
  8251. Spawn* player = lua_interface->GetSpawn(state);
  8252. int32 path = lua_interface->GetInt32Value(state, 2);
  8253. if (!player) {
  8254. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8255. return 0;
  8256. }
  8257. if (!player->IsPlayer()) {
  8258. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8259. return 0;
  8260. }
  8261. if (path == 0) {
  8262. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8263. return 0;
  8264. }
  8265. Client* client = player->GetZone()->GetClientBySpawn(player);
  8266. if (!client) {
  8267. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8268. return 0;
  8269. }
  8270. client->SendFlightAutoMount(path);
  8271. return 0;
  8272. }
  8273. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8274. if (!lua_interface)
  8275. return 0;
  8276. Spawn* player = lua_interface->GetSpawn(state);
  8277. if (!player) {
  8278. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8279. return 0;
  8280. }
  8281. if (!player->IsPlayer()) {
  8282. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8283. return 0;
  8284. }
  8285. Client* client = player->GetZone()->GetClientBySpawn(player);
  8286. if (!client) {
  8287. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8288. return 0;
  8289. }
  8290. client->EndAutoMount();
  8291. return 0;
  8292. }
  8293. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8294. if (!lua_interface)
  8295. return 0;
  8296. Spawn* player = lua_interface->GetSpawn(state);
  8297. if (!player) {
  8298. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8299. return 0;
  8300. }
  8301. if (!player->IsPlayer()) {
  8302. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8303. return 0;
  8304. }
  8305. Client* client = player->GetZone()->GetClientBySpawn(player);
  8306. if (!client) {
  8307. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8308. return 0;
  8309. }
  8310. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8311. return 1;
  8312. }
  8313. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8314. if (!lua_interface)
  8315. return 0;
  8316. Spawn* player = lua_interface->GetSpawn(state);
  8317. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8318. int32 value = lua_interface->GetInt32Value(state, 3);
  8319. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8320. if (!player) {
  8321. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (!player->IsPlayer()) {
  8325. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8329. return 0;
  8330. }
  8331. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8332. if (!lua_interface)
  8333. return 0;
  8334. Spawn* player = lua_interface->GetSpawn(state);
  8335. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8336. if (!player) {
  8337. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8338. return 0;
  8339. }
  8340. if (!player->IsPlayer()) {
  8341. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8342. return 0;
  8343. }
  8344. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8345. if (!hd)
  8346. return 0;
  8347. lua_interface->SetInt32Value(state, hd->Value);
  8348. lua_interface->SetInt32Value(state, hd->Value2);
  8349. return 2;
  8350. }
  8351. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8352. if (!lua_interface)
  8353. return 0;
  8354. Spawn* spawn = lua_interface->GetSpawn(state);
  8355. int32 grid = lua_interface->GetInt32Value(state, 2);
  8356. if (!spawn) {
  8357. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8358. return 0;
  8359. }
  8360. if (grid == 0) {
  8361. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8362. return 0;
  8363. }
  8364. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8365. return 0;
  8366. }
  8367. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8368. if (!lua_interface)
  8369. return 0;
  8370. Spawn* spawn = lua_interface->GetSpawn(state);
  8371. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8372. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8373. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8374. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8375. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8376. if (!spawn) {
  8377. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8378. return 0;
  8379. }
  8380. //Add this quest to the list of required quests for this spawn
  8381. spawn->SetRequiredHistory(event_id, value1, value2);
  8382. //If private spawn value set
  8383. if (private_spawn) {
  8384. //Set the spawn to be private when not granted access via history
  8385. spawn->AddAllowAccessSpawn(spawn);
  8386. spawn->SetPrivateQuestSpawn(true);
  8387. }
  8388. //This value will override vis_flags in the vis packet
  8389. if (flag_override > 0)
  8390. spawn->SetQuestsRequiredOverride(flag_override);
  8391. return 0;
  8392. }
  8393. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8394. if (!lua_interface)
  8395. return 0;
  8396. Spawn* player = lua_interface->GetSpawn(state);
  8397. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8398. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8399. if (!player) {
  8400. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8401. return 0;
  8402. }
  8403. if (!player->IsPlayer()) {
  8404. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8405. return 0;
  8406. }
  8407. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8408. return 1;
  8409. }
  8410. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8411. if (!lua_interface)
  8412. return 0;
  8413. Spawn* player = lua_interface->GetSpawn(state);
  8414. int8 level = lua_interface->GetInt8Value(state, 2);
  8415. if (!player) {
  8416. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8417. return 0;
  8418. }
  8419. if (!player->IsPlayer()) {
  8420. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8421. return 0;
  8422. }
  8423. if (level == 0) {
  8424. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8425. return 0;
  8426. }
  8427. Client* client = player->GetZone()->GetClientBySpawn(player);
  8428. if (!client) {
  8429. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8430. return 0;
  8431. }
  8432. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8433. return 0;
  8434. }
  8435. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8436. if (!lua_interface)
  8437. return 0;
  8438. Spawn* player = lua_interface->GetSpawn(state);
  8439. int32 amount = lua_interface->GetInt32Value(state, 2);
  8440. if (!player) {
  8441. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8442. return 0;
  8443. }
  8444. if (!player->IsPlayer()) {
  8445. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8446. return 0;
  8447. }
  8448. if (amount == 0) {
  8449. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8450. return 0;
  8451. }
  8452. ((Player*)player)->AddCoins(amount);
  8453. return 0;
  8454. }
  8455. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8456. if (!lua_interface)
  8457. return 0;
  8458. Spawn* player = lua_interface->GetSpawn(state);
  8459. int32 amount = lua_interface->GetInt32Value(state, 2);
  8460. if (!player) {
  8461. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8462. return 0;
  8463. }
  8464. if (!player->IsPlayer()) {
  8465. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8466. return 0;
  8467. }
  8468. if (amount == 0) {
  8469. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8470. return 0;
  8471. }
  8472. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8473. return 1;
  8474. }
  8475. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8476. if (!lua_interface)
  8477. return 0;
  8478. ZoneServer* zone = lua_interface->GetZone(state);
  8479. if (!zone) {
  8480. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8481. return 0;
  8482. }
  8483. vector<Entity*> players = zone->GetPlayers();
  8484. if (players.size() == 0)
  8485. return 0;
  8486. lua_createtable(state, players.size(), 0);
  8487. int newTable = lua_gettop(state);
  8488. for (int32 i = 0; i < players.size(); i++) {
  8489. lua_interface->SetSpawnValue(state, players.at(i));
  8490. lua_rawseti(state, newTable, i + 1);
  8491. }
  8492. return 1;
  8493. }
  8494. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8495. if (!lua_interface)
  8496. return 0;
  8497. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8498. if (!zone) {
  8499. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8500. return 0;
  8501. }
  8502. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8503. //Map of <placement_id, location_id>
  8504. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8505. map<int32, int32>::iterator itr;
  8506. vector<Spawn*> group;
  8507. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8508. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8509. if (!location) {
  8510. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8511. return 0;
  8512. }
  8513. Spawn* spawn = 0;
  8514. if (location->entities[0]) {
  8515. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8516. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8517. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8518. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8519. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8520. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8521. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8522. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8523. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8524. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8525. if (spawn) {
  8526. const char* script = 0;
  8527. for (int x = 0; x < 3; x++) {
  8528. switch (x) {
  8529. case 0:
  8530. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8531. break;
  8532. case 1:
  8533. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8534. break;
  8535. case 2:
  8536. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8537. break;
  8538. }
  8539. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8540. spawn->SetSpawnScript(string(script));
  8541. break;
  8542. }
  8543. }
  8544. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8545. lua_interface->SetSpawnValue(state, spawn);
  8546. group.push_back(spawn);
  8547. }
  8548. else {
  8549. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8550. safe_delete(spawn);
  8551. }
  8552. }
  8553. }
  8554. if (!group.empty()) {
  8555. lua_createtable(state, group.size(), 0);
  8556. int newTable = lua_gettop(state);
  8557. for (int32 i = 0; i < group.size(); i++) {
  8558. lua_interface->SetSpawnValue(state, group[i]);
  8559. lua_rawseti(state, newTable, i + 1);
  8560. }
  8561. }
  8562. else
  8563. lua_pushnil(state);
  8564. return 1;
  8565. }
  8566. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8567. if (!lua_interface)
  8568. return 0;
  8569. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8570. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8571. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8572. if (!spawn) {
  8573. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8574. return 0;
  8575. }
  8576. if (anim_id == 0) {
  8577. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8578. return 0;
  8579. }
  8580. if (leeway == 0)
  8581. leeway = 5000;
  8582. spawn->SetSpawnAnim(anim_id);
  8583. spawn->SetSpawnAnimLeeway(leeway);
  8584. return 0;
  8585. }
  8586. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8587. if (!lua_interface)
  8588. return 0;
  8589. Spawn* player = lua_interface->GetSpawn(state);
  8590. if (!player) {
  8591. return 0;
  8592. }
  8593. Client* client = player->GetZone()->GetClientBySpawn(player);
  8594. if (!client) {
  8595. return 0;
  8596. }
  8597. lua_interface->SetInt32Value(state, client->GetVersion());
  8598. return 1;
  8599. }
  8600. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8601. if (!lua_interface)
  8602. return 0;
  8603. Item* item = lua_interface->GetItem(state);
  8604. if (!item) {
  8605. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8606. return 0;
  8607. }
  8608. lua_interface->SetInt32Value(state, item->details.item_id);
  8609. return 1;
  8610. }
  8611. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8612. if (!lua_interface)
  8613. return 0;
  8614. Spawn* spawn = lua_interface->GetSpawn(state);
  8615. if (!spawn) {
  8616. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8617. return 0;
  8618. }
  8619. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8620. return 1;
  8621. }
  8622. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8623. if (!lua_interface)
  8624. return 0;
  8625. Spawn* spawn = lua_interface->GetSpawn(state);
  8626. if (!spawn) {
  8627. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8628. return 0;
  8629. }
  8630. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8631. return 1;
  8632. }
  8633. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8634. if (!lua_interface)
  8635. return 0;
  8636. Spawn* spawn = lua_interface->GetSpawn(state);
  8637. if (!spawn) {
  8638. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8639. return 0;
  8640. }
  8641. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8642. return 1;
  8643. }
  8644. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8645. if (!lua_interface)
  8646. return 0;
  8647. Spawn* spawn = lua_interface->GetSpawn(state);
  8648. if (!spawn) {
  8649. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8650. return 0;
  8651. }
  8652. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8653. return 1;
  8654. }
  8655. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8656. if (!lua_interface)
  8657. return 0;
  8658. Spawn* spawn = lua_interface->GetSpawn(state);
  8659. float pct = lua_interface->GetFloatValue(state, 2);
  8660. if (!spawn) {
  8661. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8662. return 0;
  8663. }
  8664. if (pct == 0) {
  8665. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8666. return 0;
  8667. }
  8668. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8669. lua_interface->SetInt32Value(state, amount);
  8670. return 1;
  8671. }
  8672. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8673. if (!lua_interface)
  8674. return 0;
  8675. Spawn* spawn = lua_interface->GetSpawn(state);
  8676. float pct = lua_interface->GetFloatValue(state, 2);
  8677. if (!spawn) {
  8678. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8679. return 0;
  8680. }
  8681. if (pct == 0) {
  8682. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8683. return 0;
  8684. }
  8685. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8686. lua_interface->SetInt32Value(state, amount);
  8687. return 1;
  8688. }
  8689. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8690. if (!lua_interface)
  8691. return 0;
  8692. Spawn* spawn = lua_interface->GetSpawn(state);
  8693. if (!spawn) {
  8694. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8695. return 0;
  8696. }
  8697. if (!spawn->IsPlayer()) {
  8698. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8699. return 0;
  8700. }
  8701. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8702. return 1;
  8703. }
  8704. int EQ2Emu_lua_Evac(lua_State* state) {
  8705. if (!lua_interface)
  8706. return 0;
  8707. Spawn* target = lua_interface->GetSpawn(state);
  8708. if (target) {
  8709. float x = target->GetZone()->GetSafeX();
  8710. float y = target->GetZone()->GetSafeY();
  8711. float z = target->GetZone()->GetSafeZ();
  8712. float h = target->GetZone()->GetSafeHeading();
  8713. target->SetX(x);
  8714. target->SetY(y);
  8715. target->SetZ(z);
  8716. target->SetHeading(h);
  8717. target->SetSpawnOrigX(target->GetX());
  8718. target->SetSpawnOrigY(target->GetY());
  8719. target->SetSpawnOrigZ(target->GetZ());
  8720. target->SetSpawnOrigHeading(target->GetHeading());
  8721. if (target->IsPlayer()) {
  8722. Client* client = target->GetZone()->GetClientBySpawn(target);
  8723. if (client) {
  8724. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8725. if (packet)
  8726. {
  8727. packet->setDataByName("x", x);
  8728. packet->setDataByName("y", y);
  8729. packet->setDataByName("z", z);
  8730. client->QueuePacket(packet->serialize());
  8731. safe_delete(packet);
  8732. }
  8733. }
  8734. }
  8735. }
  8736. else {
  8737. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8738. ZoneServer* zone = spell->caster->GetZone();
  8739. float x = spell->caster->GetZone()->GetSafeX();
  8740. float y = spell->caster->GetZone()->GetSafeY();
  8741. float z = spell->caster->GetZone()->GetSafeZ();
  8742. float h = spell->caster->GetZone()->GetSafeHeading();
  8743. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8744. for (int32 i = 0; i < spell->targets.size(); i++) {
  8745. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8746. if (!target2)
  8747. continue;
  8748. target2->SetX(x);
  8749. target2->SetY(y);
  8750. target2->SetZ(z);
  8751. target2->SetHeading(h);
  8752. target2->SetSpawnOrigX(target2->GetX());
  8753. target2->SetSpawnOrigY(target2->GetY());
  8754. target2->SetSpawnOrigZ(target2->GetZ());
  8755. target2->SetSpawnOrigHeading(target2->GetHeading());
  8756. if (target2->IsPlayer()) {
  8757. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8758. if (client) {
  8759. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8760. if (packet)
  8761. {
  8762. packet->setDataByName("x", x);
  8763. packet->setDataByName("y", y);
  8764. packet->setDataByName("z", z);
  8765. client->QueuePacket(packet->serialize());
  8766. safe_delete(packet);
  8767. }
  8768. }
  8769. }
  8770. }
  8771. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8772. }
  8773. return 0;
  8774. }
  8775. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8776. if (!lua_interface)
  8777. return 0;
  8778. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8779. if (!luaspell) {
  8780. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8781. return 0;
  8782. }
  8783. int8 tier = luaspell->spell->GetSpellTier();
  8784. lua_interface->SetInt32Value(state, tier);
  8785. return 1;
  8786. }
  8787. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8788. if (!lua_interface)
  8789. return 0;
  8790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8791. if (!luaspell) {
  8792. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8793. return 0;
  8794. }
  8795. int32 spell_id = luaspell->spell->GetSpellID();
  8796. lua_interface->SetInt32Value(state, spell_id);
  8797. return 1;
  8798. }
  8799. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8800. if (!lua_interface)
  8801. return 0;
  8802. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8803. if (!spawn) {
  8804. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8805. return 0;
  8806. }
  8807. if (!spawn->IsPlayer()) {
  8808. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8809. return 0;
  8810. }
  8811. ZoneServer* zone = spawn->GetZone();
  8812. if (!zone) {
  8813. return 0;
  8814. }
  8815. Client* client = zone->GetClientBySpawn(spawn);
  8816. if (!client) {
  8817. return 0;
  8818. }
  8819. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8820. return 0;
  8821. }
  8822. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8823. if (!lua_interface)
  8824. return 0;
  8825. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8826. if (!spawn) {
  8827. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8828. return 0;
  8829. }
  8830. if (!spawn->IsPlayer()) {
  8831. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. ZoneServer* zone = spawn->GetZone();
  8835. if (!zone) {
  8836. return 0;
  8837. }
  8838. Client* client = zone->GetClientBySpawn(spawn);
  8839. if (!client) {
  8840. return 0;
  8841. }
  8842. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8843. return 0;
  8844. }
  8845. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8846. if (!lua_interface)
  8847. return 0;
  8848. Spawn* caster = lua_interface->GetSpawn(state);
  8849. Spawn* target = lua_interface->GetSpawn(state, 2);
  8850. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8851. string spell_name = lua_interface->GetStringValue(state, 4);
  8852. if (!caster) {
  8853. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8854. return 0;
  8855. }
  8856. if (!caster->IsEntity()) {
  8857. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8858. return 0;
  8859. }
  8860. if (!target) {
  8861. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8862. return 0;
  8863. }
  8864. if (!target->IsEntity()) {
  8865. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8866. return 0;
  8867. }
  8868. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8869. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8870. return 0;
  8871. }
  8872. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8873. if (!lua_interface)
  8874. return 0;
  8875. Spawn* player = lua_interface->GetSpawn(state);
  8876. int32 amount = lua_interface->GetInt32Value(state, 2);
  8877. if (player && player->IsPlayer() && amount > 0) {
  8878. ((Player*)player)->AddXP(amount);
  8879. ((Player*)player)->SetCharSheetChanged(true);
  8880. Client* client = player->GetZone()->GetClientBySpawn(player);
  8881. if (client) {
  8882. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8883. }
  8884. }
  8885. return 0;
  8886. }
  8887. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8888. if (!lua_interface)
  8889. return 0;
  8890. Spawn* player = lua_interface->GetSpawn(state);
  8891. int8 type = lua_interface->GetInt8Value(state, 2);
  8892. string text = lua_interface->GetStringValue(state, 3);
  8893. Client* client = 0;
  8894. if (player && player->IsPlayer())
  8895. client = player->GetZone()->GetClientBySpawn(player);
  8896. if (!client || text.length() == 0) {
  8897. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8898. return 0;
  8899. }
  8900. client->SimpleMessage(type, text.c_str());
  8901. return 0;
  8902. }
  8903. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8904. if (!lua_interface)
  8905. return 0;
  8906. Spawn* player = lua_interface->GetSpawn(state);
  8907. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8908. Client* client = 0;
  8909. if (player && player->IsPlayer())
  8910. client = player->GetZone()->GetClientBySpawn(player);
  8911. if (!client || !spawn) {
  8912. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8913. return 0;
  8914. }
  8915. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8916. if (!items) {
  8917. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8918. return 0;
  8919. }
  8920. client->Loot(spawn->GetLootCoins(), items, spawn);
  8921. return 0;
  8922. }
  8923. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8924. if (!lua_interface)
  8925. return 0;
  8926. Spawn* spawnref = lua_interface->GetSpawn(state);
  8927. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8928. if (spawn_id > 0 && spawnref) {
  8929. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8930. if (spawns.size() == 0) {
  8931. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8932. return 0;
  8933. }
  8934. Spawn* spawn = 0;
  8935. int16 index = MakeRandomInt(0, spawns.size());
  8936. if (index >= spawns.size() || index < 0)
  8937. index = 0;
  8938. spawn = spawns[index];
  8939. lua_interface->SetSpawnValue(state, spawn);
  8940. return 1;
  8941. }
  8942. else {
  8943. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8944. }
  8945. return 0;
  8946. }
  8947. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8948. Spawn* player = lua_interface->GetSpawn(state);
  8949. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8950. string name = lua_interface->GetStringValue(state, 3);
  8951. float distance = lua_interface->GetFloatValue(state, 4);
  8952. string command = lua_interface->GetStringValue(state, 5);
  8953. string error_text = lua_interface->GetStringValue(state, 6);
  8954. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8955. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8956. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8957. if (distance == 0)
  8958. distance = 10.0f;
  8959. if (command.length() == 0)
  8960. command = name;
  8961. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8962. if (spawns.size() == 0) {
  8963. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8964. return 0;
  8965. }
  8966. Spawn* spawn = 0;
  8967. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  8968. spawn = *itr;
  8969. if (spawn) {
  8970. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  8971. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  8972. }
  8973. }
  8974. }
  8975. return 0;
  8976. }
  8977. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  8978. if (!lua_interface)
  8979. return 0;
  8980. Client* client = 0;
  8981. Spawn* player = lua_interface->GetSpawn(state);
  8982. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  8983. if (player && player->IsPlayer() && player->GetZone())
  8984. client = player->GetZone()->GetClientBySpawn(player);
  8985. else{
  8986. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  8987. return 0;
  8988. }
  8989. if (client) {
  8990. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8991. if (packet) {
  8992. packet->setDataByName("goal_num", goal_num);
  8993. client->QueuePacket(packet->serialize());
  8994. safe_delete(packet);
  8995. }
  8996. }
  8997. return 0;
  8998. }
  8999. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9000. if (!lua_interface)
  9001. return 0;
  9002. Client* client = 0;
  9003. Spawn* player = lua_interface->GetSpawn(state);
  9004. if (player && player->IsPlayer() && player->GetZone())
  9005. client = player->GetZone()->GetClientBySpawn(player);
  9006. else {
  9007. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9008. return 0;
  9009. }
  9010. if (client) {
  9011. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9012. }
  9013. return 0;
  9014. }
  9015. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9016. if (!lua_interface)
  9017. return 0;
  9018. Client* client = 0;
  9019. Spawn* player = lua_interface->GetSpawn(state);
  9020. float duration = lua_interface->GetFloatValue(state, 2);
  9021. string text = lua_interface->GetStringValue(state, 3);
  9022. string voice = lua_interface->GetStringValue(state, 4);
  9023. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9024. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9025. string signal = lua_interface->GetStringValue(state, 7);
  9026. string goal1 = lua_interface->GetStringValue(state, 8);
  9027. string task1 = lua_interface->GetStringValue(state, 9);
  9028. string goal2 = lua_interface->GetStringValue(state, 10);
  9029. string task2 = lua_interface->GetStringValue(state, 11);
  9030. string goal3 = lua_interface->GetStringValue(state, 12);
  9031. string task3 = lua_interface->GetStringValue(state, 13);
  9032. string goal4 = lua_interface->GetStringValue(state, 14);
  9033. string task4 = lua_interface->GetStringValue(state, 15);
  9034. if (!player) {
  9035. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9036. return 0;
  9037. }
  9038. if (!player->IsPlayer()) {
  9039. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9040. return 0;
  9041. }
  9042. else
  9043. client = ((Player*)player)->GetClient();
  9044. if (!client) {
  9045. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9046. return 0;
  9047. }
  9048. if (text.length() == 0) {
  9049. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9050. return 0;
  9051. }
  9052. if (duration >= 0 && duration < 2)
  9053. duration = 2;
  9054. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9055. if (packet) {
  9056. packet->setDataByName("open_seconds_max", duration);
  9057. packet->setDataByName("text", text.c_str());
  9058. packet->setDataByName("voice", voice.c_str());
  9059. int8 num_goals = 1;
  9060. if (task2.length() > 0)
  9061. num_goals++;
  9062. if (task3.length() > 0)
  9063. num_goals++;
  9064. if (task4.length() > 0)
  9065. num_goals++;
  9066. packet->setArrayLengthByName("num_goals", num_goals);
  9067. for (int8 i = 0; i < num_goals; i++) {
  9068. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9069. }
  9070. if (goal1.length() > 0)
  9071. packet->setArrayDataByName("goal_text", goal1.c_str());
  9072. if (goal2.length() > 0)
  9073. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9074. if (goal3.length() > 0)
  9075. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9076. if (goal4.length() > 0)
  9077. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9078. packet->setSubArrayDataByName("task_text", task1.c_str());
  9079. if (task2.length() > 0)
  9080. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9081. if (task3.length() > 0)
  9082. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9083. if (task4.length() > 0)
  9084. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9085. packet->setDataByName("complete_sound", "click");
  9086. packet->setDataByName("signal", signal.c_str());
  9087. packet->setDataByName("voice_key1", voice_key1);
  9088. packet->setDataByName("voice_key2", voice_key2);
  9089. client->QueuePacket(packet->serialize());
  9090. safe_delete(packet);
  9091. }
  9092. return 0;
  9093. }
  9094. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9095. if (!lua_interface)
  9096. return 0;
  9097. Client* client = 0;
  9098. Spawn* player = lua_interface->GetSpawn(state);
  9099. string window = lua_interface->GetStringValue(state, 2);
  9100. int8 show = lua_interface->GetInt8Value(state, 3);
  9101. if (!player) {
  9102. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9103. return 0;
  9104. }
  9105. if (!player->IsPlayer()) {
  9106. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9107. return 0;
  9108. }
  9109. else
  9110. client = ((Player*)player)->GetClient();
  9111. if (!client) {
  9112. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9113. return 0;
  9114. }
  9115. if (window.length() == 0) {
  9116. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9117. return 0;
  9118. }
  9119. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9120. if (packet) {
  9121. packet->setDataByName("window", window.c_str());
  9122. packet->setDataByName("show", show);
  9123. client->QueuePacket(packet->serialize());
  9124. safe_delete(packet);
  9125. }
  9126. return 0;
  9127. }
  9128. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9129. //See GameEvents.txt for options that can be used for this function
  9130. if (!lua_interface)
  9131. return 0;
  9132. Client* client = 0;
  9133. Spawn* player = lua_interface->GetSpawn(state);
  9134. string event_name = lua_interface->GetStringValue(state, 2);
  9135. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9136. if (!player || !player->IsPlayer()) {
  9137. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9138. return 0;
  9139. }
  9140. if (player->GetZone())
  9141. client = player->GetZone()->GetClientBySpawn(player);
  9142. if (!client) {
  9143. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9144. return 0;
  9145. }
  9146. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9147. if (packet) {
  9148. packet->setDataByName("event_name", event_name.c_str());
  9149. packet->setDataByName("enabled", enabled);
  9150. client->QueuePacket(packet->serialize());
  9151. safe_delete(packet);
  9152. }
  9153. return 0;
  9154. }
  9155. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9156. if (!lua_interface)
  9157. return 0;
  9158. Spawn* player = lua_interface->GetSpawn(state);
  9159. if (player && player->IsPlayer()) {
  9160. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9161. return 1;
  9162. }
  9163. return 0;
  9164. }
  9165. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9166. if (!lua_interface)
  9167. return 0;
  9168. Spawn* player = lua_interface->GetSpawn(state);
  9169. int8 step = lua_interface->GetInt8Value(state, 2);
  9170. if (player && player->IsPlayer() && step > 0) {
  9171. ((Player*)player)->SetTutorialStep(step);
  9172. }
  9173. return 0;
  9174. }
  9175. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9176. if (!lua_interface)
  9177. return 0;
  9178. Client* client = 0;
  9179. Spawn* player = lua_interface->GetSpawn(state);
  9180. string window = lua_interface->GetStringValue(state, 2);
  9181. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9182. if (!player) {
  9183. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9184. return 0;
  9185. }
  9186. if (!player->IsPlayer()) {
  9187. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9188. return 0;
  9189. }
  9190. else
  9191. client = ((Player*)player)->GetClient();
  9192. if (!client) {
  9193. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9194. return 0;
  9195. }
  9196. if (window.length() == 0) {
  9197. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9198. return 0;
  9199. }
  9200. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9201. if (packet) {
  9202. packet->setDataByName("window", window.c_str());
  9203. packet->setDataByName("flash_seconds", flash_seconds);
  9204. client->QueuePacket(packet->serialize());
  9205. safe_delete(packet);
  9206. }
  9207. return 0;
  9208. }
  9209. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9210. if (!lua_interface)
  9211. return 0;
  9212. Spawn* spawn = lua_interface->GetSpawn(state);
  9213. Spawn* target = lua_interface->GetSpawn(state, 2);
  9214. if (spawn && target)
  9215. return spawn->CheckLoS(target);
  9216. return 0;
  9217. }
  9218. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9219. if (!lua_interface)
  9220. return 0;
  9221. Spawn* spawn = lua_interface->GetSpawn(state);
  9222. float x = lua_interface->GetFloatValue(state, 2);
  9223. float y = lua_interface->GetFloatValue(state, 3);
  9224. float z = lua_interface->GetFloatValue(state, 4);
  9225. if (spawn)
  9226. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9227. return 0;
  9228. }
  9229. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9230. if (!lua_interface)
  9231. return 0;
  9232. ZoneServer* zone = lua_interface->GetZone(state);
  9233. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9234. if (zone)
  9235. zone->SetExpansionFlag(xpackFlag);
  9236. return 0;
  9237. }
  9238. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9239. if (!lua_interface)
  9240. return 0;
  9241. ZoneServer* zone = lua_interface->GetZone(state);
  9242. if (zone) {
  9243. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9244. return 1;
  9245. }
  9246. return 0;
  9247. }
  9248. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9249. if (!lua_interface)
  9250. return 0;
  9251. ZoneServer* zone = lua_interface->GetZone(state);
  9252. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9253. if (zone)
  9254. zone->SetHolidayFlag(holidayFlag);
  9255. return 0;
  9256. }
  9257. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9258. if (!lua_interface)
  9259. return 0;
  9260. ZoneServer* zone = lua_interface->GetZone(state);
  9261. if (zone) {
  9262. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9263. return 1;
  9264. }
  9265. return 0;
  9266. }
  9267. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9268. if (!lua_interface)
  9269. return 0;
  9270. Spawn* spawn = lua_interface->GetSpawn(state);
  9271. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9272. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9273. float distance = lua_interface->GetFloatValue(state, 4);
  9274. string in_range_function = lua_interface->GetStringValue(state, 5);
  9275. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9276. if (spawn && distance > 0 && in_range_function.length() > 0)
  9277. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9278. return 0;
  9279. }
  9280. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9281. if (!lua_interface)
  9282. return 0;
  9283. Spawn* spawn = lua_interface->GetSpawn(state);
  9284. Spawn* target = lua_interface->GetSpawn(state, 2);
  9285. if (spawn && target)
  9286. {
  9287. if (spawn->IsPlayer() && target->IsEntity())
  9288. {
  9289. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9290. return 1;
  9291. }
  9292. else if (spawn->IsEntity() && target->IsEntity())
  9293. {
  9294. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9295. return 1;
  9296. }
  9297. }
  9298. return 0;
  9299. }
  9300. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9301. if (!lua_interface)
  9302. return 0;
  9303. Spawn* spawn = lua_interface->GetSpawn(state);
  9304. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9305. if (spawn && spawn->IsEntity())
  9306. {
  9307. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9308. if (spawn->IsPlayer())
  9309. {
  9310. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9311. if (client)
  9312. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9313. }
  9314. }
  9315. return 0;
  9316. }
  9317. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9318. if (!lua_interface)
  9319. return 0;
  9320. Spawn* spawn = lua_interface->GetSpawn(state);
  9321. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9322. if (spawn && spawn->IsEntity())
  9323. {
  9324. ((Entity*)spawn)->SetSeeHideSpell(val);
  9325. if (spawn->IsPlayer())
  9326. {
  9327. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9328. if (client)
  9329. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9330. }
  9331. }
  9332. return 0;
  9333. }
  9334. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9335. {
  9336. if (!lua_interface)
  9337. return 0;
  9338. Spawn* player = lua_interface->GetSpawn(state);
  9339. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9340. string command = lua_interface->GetStringValue(state, 3);
  9341. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9342. if (spawn && player && player->IsPlayer())
  9343. {
  9344. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9345. bool res = false;
  9346. if (cmd)
  9347. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9348. lua_interface->SetBooleanValue(state, res);
  9349. return 1;
  9350. }
  9351. return 0;
  9352. }
  9353. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9354. {
  9355. if (!lua_interface)
  9356. return 0;
  9357. Spawn* spawn = lua_interface->GetSpawn(state);
  9358. string command = lua_interface->GetStringValue(state, 2);
  9359. if (spawn && command.length() > 0)
  9360. spawn->RemovePrimaryEntityCommand(command.c_str());
  9361. return 0;
  9362. }
  9363. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9364. if (!lua_interface)
  9365. return 0;
  9366. Spawn* spawn = lua_interface->GetSpawn(state);
  9367. float distance = lua_interface->GetFloatValue(state, 2);
  9368. string command = lua_interface->GetStringValue(state, 3);
  9369. Spawn* player = lua_interface->GetSpawn(state, 4);
  9370. if (spawn) {
  9371. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9372. }
  9373. return 0;
  9374. }
  9375. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9376. if (!lua_interface)
  9377. return 0;
  9378. Spawn* spawn = lua_interface->GetSpawn(state);
  9379. Spawn* player = lua_interface->GetSpawn(state, 2);
  9380. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9381. if (spawn && player && transport_id && player->IsPlayer()) {
  9382. Client* client = 0;
  9383. if (player && player->IsPlayer())
  9384. client = player->GetZone()->GetClientBySpawn(player);
  9385. if (!client)
  9386. return 0;
  9387. vector<TransportDestination*> destinations;
  9388. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9389. if (destinations.size())
  9390. {
  9391. client->SetTemporaryTransportID(transport_id);
  9392. client->ProcessTeleport(spawn, &destinations, transport_id);
  9393. }
  9394. else
  9395. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9396. }
  9397. return 0;
  9398. }
  9399. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9400. if (!lua_interface)
  9401. return 0;
  9402. Spawn* player = lua_interface->GetSpawn(state);
  9403. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9404. if (player && player->IsPlayer()) {
  9405. Client* client = 0;
  9406. if (player && player->IsPlayer())
  9407. client = player->GetZone()->GetClientBySpawn(player);
  9408. if (!client)
  9409. return 0;
  9410. client->SetTemporaryTransportID(transport_id);
  9411. }
  9412. return 0;
  9413. }
  9414. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9415. if (!lua_interface)
  9416. return 0;
  9417. Spawn* player = lua_interface->GetSpawn(state);
  9418. if (player && player->IsPlayer()) {
  9419. Client* client = 0;
  9420. if (player && player->IsPlayer())
  9421. client = player->GetZone()->GetClientBySpawn(player);
  9422. if (!client)
  9423. return 0;
  9424. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9425. return 1;
  9426. }
  9427. return 0;
  9428. }
  9429. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9430. if (!lua_interface)
  9431. return 0;
  9432. Spawn* spawn = lua_interface->GetSpawn(state);
  9433. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9434. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9435. if (!spawn) {
  9436. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9437. return 0;
  9438. }
  9439. if (!spawn->IsEntity()) {
  9440. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9441. return 0;
  9442. }
  9443. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9444. {
  9445. lua_interface->LogError("%s: LUA SetAlignment command error: alignment value beyond supported min: %i and max: %i", lua_interface->GetScriptName(state), SCHAR_MIN, SCHAR_MAX);
  9446. return 0;
  9447. }
  9448. if (spell && spell->targets.size() > 0) {
  9449. ZoneServer* zone = spell->caster->GetZone();
  9450. for (int8 i = 0; i < spell->targets.size(); i++) {
  9451. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9452. if (target->IsEntity()) {
  9453. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9454. if (target->IsPlayer())
  9455. ((Player*)target)->SetCharSheetChanged(true);
  9456. }
  9457. }
  9458. }
  9459. else {
  9460. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9461. if (spawn->IsPlayer())
  9462. ((Player*)spawn)->SetCharSheetChanged(true);
  9463. }
  9464. return 0;
  9465. }
  9466. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9467. if (!lua_interface)
  9468. return 0;
  9469. Spawn* spawn = lua_interface->GetSpawn(state);
  9470. if (!spawn) {
  9471. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9472. return 0;
  9473. }
  9474. if (!spawn->IsEntity()) {
  9475. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9476. return 0;
  9477. }
  9478. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9479. return 1;
  9480. }
  9481. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9482. if (!lua_interface)
  9483. return 0;
  9484. int32 spell_id = lua_interface->GetInt32Value(state);
  9485. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9486. if (spell_id > 0) {
  9487. if (spell_tier == 0)
  9488. spell_tier = 1;
  9489. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9490. LuaSpell* lua_spell = 0;
  9491. if (lua_interface)
  9492. lua_spell = lua_interface->GetSpell(spell->GetSpellData()->lua_script.c_str());
  9493. if (!lua_spell)
  9494. return 0;
  9495. lua_spell->spell = new Spell(spell);
  9496. lua_interface->AddCustomSpell(lua_spell);
  9497. lua_interface->SetSpellValue(state, lua_spell);
  9498. return 1;
  9499. }
  9500. return 0;
  9501. }
  9502. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9503. if (!lua_interface)
  9504. return 0;
  9505. LuaSpell* spell = lua_interface->GetSpell(state);
  9506. string field = lua_interface->GetStringValue(state, 2);
  9507. if (!spell) {
  9508. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9509. return 0;
  9510. }
  9511. if (!spell->spell || !spell->spell->GetSpellData()) {
  9512. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9513. return 0;
  9514. }
  9515. boost::to_lower(field);
  9516. return spell->spell->GetSpellData(state, field);
  9517. }
  9518. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9519. if (!lua_interface)
  9520. return 0;
  9521. LuaSpell* spell = lua_interface->GetSpell(state);
  9522. string field = lua_interface->GetStringValue(state, 2);
  9523. int8 fieldArg = 3; // field value after the initial set
  9524. if (!spell) {
  9525. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9526. return 0;
  9527. }
  9528. if (!spell->spell || !spell->spell->GetSpellData()) {
  9529. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9530. return 0;
  9531. }
  9532. boost::to_lower(field);
  9533. bool valSet = false;
  9534. spell->spell->SetSpellData(state, field, fieldArg);
  9535. return valSet;
  9536. }
  9537. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9538. if (!lua_interface)
  9539. return 0;
  9540. LuaSpell* spell = lua_interface->GetSpell(state);
  9541. int8 idx = lua_interface->GetInt32Value(state, 2);
  9542. if (!spell) {
  9543. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9544. return 0;
  9545. }
  9546. if (!spell->spell || !spell->spell->GetSpellData()) {
  9547. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9548. return 0;
  9549. }
  9550. if (spell->spell->lua_data.size() <= idx)
  9551. {
  9552. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9553. return 0;
  9554. }
  9555. bool setVal = true;
  9556. LUAData* data = spell->spell->lua_data[idx];
  9557. switch (data->type)
  9558. {
  9559. case 0:
  9560. {
  9561. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9562. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9563. data->int_value = value;
  9564. data->int_value2 = value2;
  9565. break;
  9566. }
  9567. case 1:
  9568. {
  9569. float value = lua_interface->GetFloatValue(state, 3);
  9570. float value2 = lua_interface->GetFloatValue(state, 4);
  9571. data->float_value = value;
  9572. data->float_value2 = value2;
  9573. break;
  9574. }
  9575. case 2:
  9576. {
  9577. bool value = lua_interface->GetBooleanValue(state, 3);
  9578. data->bool_value = value;
  9579. break;
  9580. }
  9581. case 3:
  9582. {
  9583. string value = lua_interface->GetStringValue(state, 3);
  9584. string value2 = lua_interface->GetStringValue(state, 4);
  9585. data->string_value = value;
  9586. data->string_value2 = value2;
  9587. break;
  9588. }
  9589. default:
  9590. setVal = false;
  9591. }
  9592. return setVal;
  9593. }
  9594. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9595. if (!lua_interface)
  9596. return 0;
  9597. LuaSpell* spell = lua_interface->GetSpell(state);
  9598. int8 idx = lua_interface->GetInt32Value(state, 2);
  9599. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9600. if (!spell) {
  9601. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9602. return 0;
  9603. }
  9604. if (!spell->spell || !spell->spell->GetSpellData()) {
  9605. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9606. return 0;
  9607. }
  9608. if (spell->spell->lua_data.size() <= idx)
  9609. {
  9610. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9611. return 0;
  9612. }
  9613. bool setVal = true;
  9614. LUAData* data = spell->spell->lua_data[idx];
  9615. switch (data->type)
  9616. {
  9617. case 0:
  9618. {
  9619. if(!secondfield)
  9620. lua_interface->SetSInt32Value(state, data->int_value);
  9621. else
  9622. lua_interface->SetSInt32Value(state, data->int_value2);
  9623. break;
  9624. }
  9625. case 1:
  9626. {
  9627. if (!secondfield)
  9628. lua_interface->SetFloatValue(state, data->float_value);
  9629. else
  9630. lua_interface->SetFloatValue(state, data->float_value2);
  9631. break;
  9632. }
  9633. case 2:
  9634. {
  9635. lua_interface->SetBooleanValue(state, data->bool_value);
  9636. break;
  9637. }
  9638. case 3:
  9639. {
  9640. if (!secondfield)
  9641. lua_interface->SetStringValue(state, data->string_value.c_str());
  9642. else
  9643. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9644. break;
  9645. }
  9646. default:
  9647. setVal = false;
  9648. }
  9649. return setVal;
  9650. }
  9651. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9652. if (!lua_interface)
  9653. return 0;
  9654. LuaSpell* spell = lua_interface->GetSpell(state);
  9655. int8 idx = lua_interface->GetInt32Value(state, 2);
  9656. string field = lua_interface->GetStringValue(state, 3);
  9657. boost::to_lower(field);
  9658. if (!spell) {
  9659. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9660. return 0;
  9661. }
  9662. if (!spell->spell || !spell->spell->GetSpellData()) {
  9663. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9664. return 0;
  9665. }
  9666. if (spell->spell->effects.size() <= idx)
  9667. {
  9668. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9669. return 0;
  9670. }
  9671. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9672. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9673. if (field == "description")
  9674. effect->description = string(lua_interface->GetStringValue(state, 4));
  9675. else if (field == "bullet")
  9676. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9677. else if (field == "percentage")
  9678. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9679. else // no match
  9680. return 0;
  9681. return 1;
  9682. }
  9683. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9684. if (!lua_interface)
  9685. return 0;
  9686. LuaSpell* spell = lua_interface->GetSpell(state);
  9687. int8 idx = lua_interface->GetInt32Value(state, 2);
  9688. string field = lua_interface->GetStringValue(state, 3);
  9689. boost::to_lower(field);
  9690. if (!spell) {
  9691. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9692. return 0;
  9693. }
  9694. if (!spell->spell || !spell->spell->GetSpellData()) {
  9695. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9696. return 0;
  9697. }
  9698. if (spell->spell->effects.size() <= idx)
  9699. {
  9700. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9701. return 0;
  9702. }
  9703. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9704. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9705. if (field == "description")
  9706. lua_interface->SetStringValue(state, effect->description.c_str());
  9707. else if (field == "bullet")
  9708. lua_interface->SetInt32Value(state, effect->subbullet);
  9709. else if (field == "percentage")
  9710. lua_interface->SetInt32Value(state, effect->percentage);
  9711. else // no match
  9712. return 0;
  9713. return 1;
  9714. }
  9715. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9716. if (!lua_interface)
  9717. return 0;
  9718. LuaSpell* spell = lua_interface->GetSpell(state);
  9719. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9720. Spawn* target = lua_interface->GetSpawn(state, 3);
  9721. if (!target) {
  9722. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9723. return 0;
  9724. }
  9725. if (!target->IsEntity()) {
  9726. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9727. return 0;
  9728. }
  9729. if (!spell) {
  9730. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9731. return 0;
  9732. }
  9733. if (caster && !caster->IsEntity()) {
  9734. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9735. return 0;
  9736. }
  9737. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9738. return 0;
  9739. }
  9740. int EQ2Emu_lua_InWater(lua_State* state) {
  9741. if (!lua_interface)
  9742. return 0;
  9743. Spawn* spawn = lua_interface->GetSpawn(state);
  9744. lua_interface->ResetFunctionStack(state);
  9745. if (spawn) {
  9746. lua_interface->SetBooleanValue(state, spawn->InWater());
  9747. return 1;
  9748. }
  9749. return 0;
  9750. }
  9751. int EQ2Emu_lua_InLava(lua_State* state) {
  9752. if (!lua_interface)
  9753. return 0;
  9754. Spawn* spawn = lua_interface->GetSpawn(state);
  9755. lua_interface->ResetFunctionStack(state);
  9756. if (spawn) {
  9757. lua_interface->SetBooleanValue(state, spawn->InLava());
  9758. return 1;
  9759. }
  9760. return 0;
  9761. }
  9762. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9763. if (!lua_interface)
  9764. return 0;
  9765. Spawn* attacker = lua_interface->GetSpawn(state);
  9766. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9767. int8 type = lua_interface->GetInt8Value(state, 3);
  9768. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9769. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9770. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9771. string spell_name = lua_interface->GetStringValue(state, 7);
  9772. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9773. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9774. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9775. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9776. lua_interface->ResetFunctionStack(state);
  9777. if (!attacker) {
  9778. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9779. return 0;
  9780. }
  9781. if (!attacker->IsEntity()) {
  9782. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9783. return 0;
  9784. }
  9785. if (!victim) {
  9786. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9787. return 0;
  9788. }
  9789. if (!victim->IsEntity()) {
  9790. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9791. return 0;
  9792. }
  9793. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9794. return 0;
  9795. }
  9796. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9797. if (!lua_interface)
  9798. return 0;
  9799. Spawn* spawn = lua_interface->GetSpawn(state);
  9800. lua_interface->ResetFunctionStack(state);
  9801. if (spawn) {
  9802. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9803. return 1;
  9804. }
  9805. return 0;
  9806. }
  9807. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9808. if (!lua_interface)
  9809. return 0;
  9810. Spawn* spawn = lua_interface->GetSpawn(state);
  9811. bool invul = lua_interface->GetBooleanValue(state, 2);
  9812. lua_interface->ResetFunctionStack(state);
  9813. if (spawn) {
  9814. spawn->SetInvulnerable(invul);
  9815. }
  9816. return 0;
  9817. }
  9818. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9819. if (!lua_interface)
  9820. return 0;
  9821. string category = lua_interface->GetStringValue(state);
  9822. string name = lua_interface->GetStringValue(state, 2);
  9823. lua_interface->ResetFunctionStack(state);
  9824. Rule *ret = 0;
  9825. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9826. lua_interface->SetInt32Value(state, ret->GetInt32());
  9827. return 1;
  9828. }
  9829. lua_interface->LogError("%s: LUA GetRuleFlag Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9830. return 0;
  9831. }
  9832. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  9833. if (!lua_interface)
  9834. return 0;
  9835. Spawn* spawn = lua_interface->GetSpawn(state);
  9836. string type = lua_interface->GetStringValue(state, 2);
  9837. lua_interface->ResetFunctionStack(state);
  9838. if (spawn) {
  9839. int res = 1;
  9840. boost::to_lower(type);
  9841. if(type == "assigned_aa")
  9842. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  9843. else if ( type == "unassigned_aa")
  9844. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  9845. else if ( type == "assigned_tradeskill_aa")
  9846. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  9847. else if ( type == "unassigned_tradeskill_aa")
  9848. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  9849. else if ( type == "assigned_prestige_aa")
  9850. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  9851. else if ( type == "unassigned_prestige_aa")
  9852. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  9853. else if ( type == "assigned_tradeskill_prestige_aa")
  9854. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  9855. else if ( type == "unassigned_tradeskill_prestige_aa")
  9856. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  9857. else
  9858. res = 0;
  9859. return res;
  9860. }
  9861. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  9862. return 0;
  9863. }
  9864. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  9865. if (!lua_interface)
  9866. return 0;
  9867. Spawn* spawn = lua_interface->GetSpawn(state);
  9868. string type = lua_interface->GetStringValue(state, 2);
  9869. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9870. lua_interface->ResetFunctionStack(state);
  9871. if (spawn) {
  9872. boost::to_lower(type);
  9873. if(type == "assigned_aa")
  9874. spawn->SetAssignedAA((sint16)value);
  9875. else if ( type == "unassigned_aa")
  9876. spawn->SetUnassignedAA((sint16)value);
  9877. else if ( type == "assigned_tradeskill_aa")
  9878. spawn->SetTradeskillAA((sint16)value);
  9879. else if ( type == "unassigned_tradeskill_aa")
  9880. spawn->SetUnassignedTradeskillAA((sint16)value);
  9881. else if ( type == "assigned_prestige_aa")
  9882. spawn->SetPrestigeAA((sint16)value);
  9883. else if ( type == "unassigned_prestige_aa")
  9884. spawn->SetUnassignedPrestigeAA((sint16)value);
  9885. else if ( type == "assigned_tradeskill_prestige_aa")
  9886. spawn->SetTradeskillPrestigeAA((sint16)value);
  9887. else if ( type == "unassigned_tradeskill_prestige_aa")
  9888. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  9889. if(spawn->IsPlayer())
  9890. ((Player*)spawn)->SetCharSheetChanged(true);
  9891. }
  9892. return 0;
  9893. }
  9894. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  9895. if (!lua_interface)
  9896. return 0;
  9897. string titleName = lua_interface->GetStringValue(state);
  9898. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  9899. lua_interface->ResetFunctionStack(state);
  9900. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  9901. lua_interface->SetSInt32Value(state, index);
  9902. return 1;
  9903. }
  9904. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  9905. if (!lua_interface)
  9906. return 0;
  9907. Spawn* spawn = lua_interface->GetSpawn(state);
  9908. string titleName = lua_interface->GetStringValue(state, 2);
  9909. lua_interface->ResetFunctionStack(state);
  9910. if(!spawn->IsPlayer())
  9911. {
  9912. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  9913. lua_interface->SetSInt32Value(state, -1);
  9914. return 1;
  9915. }
  9916. Player* player = (Player*)spawn;
  9917. // check if player already has the title, don't need to add twice
  9918. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  9919. if ( playerHasTitle)
  9920. {
  9921. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  9922. return 1;
  9923. }
  9924. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  9925. if(!title)
  9926. {
  9927. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9928. lua_interface->SetSInt32Value(state, -1);
  9929. return 1;
  9930. }
  9931. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  9932. if(returnIdx < 0)
  9933. {
  9934. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9935. }
  9936. lua_interface->SetSInt32Value(state, returnIdx);
  9937. player->GetClient()->SendTitleUpdate();
  9938. return 1;
  9939. }
  9940. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  9941. if (!lua_interface)
  9942. return 0;
  9943. Spawn* spawn = lua_interface->GetSpawn(state);
  9944. string titleName = lua_interface->GetStringValue(state, 2);
  9945. lua_interface->ResetFunctionStack(state);
  9946. if(!spawn->IsPlayer())
  9947. {
  9948. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  9949. return 0;
  9950. }
  9951. Player* player = (Player*)spawn;
  9952. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  9953. if(!title)
  9954. {
  9955. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9956. return 0;
  9957. }
  9958. if(title->GetPrefix())
  9959. {
  9960. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title with name '%s' is not valid as a suffix, only prefix", lua_interface->GetScriptName(state), titleName.c_str());
  9961. return 0;
  9962. }
  9963. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  9964. player->GetClient()->SendTitleUpdate();
  9965. return 1;
  9966. }
  9967. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  9968. if (!lua_interface)
  9969. return 0;
  9970. Spawn* spawn = lua_interface->GetSpawn(state);
  9971. string titleName = lua_interface->GetStringValue(state, 2);
  9972. lua_interface->ResetFunctionStack(state);
  9973. if(!spawn->IsPlayer())
  9974. {
  9975. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  9976. return 0;
  9977. }
  9978. Player* player = (Player*)spawn;
  9979. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  9980. if(!title)
  9981. {
  9982. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9983. return 0;
  9984. }
  9985. if(!title->GetPrefix())
  9986. {
  9987. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title with name '%s' is not valid as a prefix, only suffix", lua_interface->GetScriptName(state), titleName.c_str());
  9988. return 0;
  9989. }
  9990. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  9991. player->GetClient()->SendTitleUpdate();
  9992. return 1;
  9993. }
  9994. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  9995. if (!lua_interface)
  9996. return 0;
  9997. Spawn* spawn = lua_interface->GetSpawn(state);
  9998. lua_interface->ResetFunctionStack(state);
  9999. if(!spawn->IsPlayer())
  10000. {
  10001. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10002. return 0;
  10003. }
  10004. Player* player = (Player*)spawn;
  10005. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10006. player->GetClient()->SendTitleUpdate();
  10007. return 1;
  10008. }
  10009. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10010. if (!lua_interface)
  10011. return 0;
  10012. Spawn* spawn = lua_interface->GetSpawn(state);
  10013. lua_interface->ResetFunctionStack(state);
  10014. if(!spawn->IsPlayer())
  10015. {
  10016. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10017. return 0;
  10018. }
  10019. Player* player = (Player*)spawn;
  10020. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10021. player->GetClient()->SendTitleUpdate();
  10022. return 1;
  10023. }
  10024. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10025. if (!lua_interface)
  10026. return 0;
  10027. Spawn* spawn = lua_interface->GetSpawn(state);
  10028. string field = lua_interface->GetStringValue(state, 2);
  10029. lua_interface->ResetFunctionStack(state);
  10030. if(!spawn || !spawn->IsEntity())
  10031. {
  10032. lua_interface->LogError("%s: LUA GetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10033. return 0;
  10034. }
  10035. Entity* ent = (Entity*)spawn;
  10036. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10037. return 1;
  10038. }
  10039. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10040. if (!lua_interface)
  10041. return 0;
  10042. Spawn* spawn = lua_interface->GetSpawn(state);
  10043. string field = lua_interface->GetStringValue(state, 2);
  10044. lua_interface->ResetFunctionStack(state);
  10045. if(!spawn || !spawn->IsEntity())
  10046. {
  10047. lua_interface->LogError("%s: LUA GetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10048. return 0;
  10049. }
  10050. Entity* ent = (Entity*)spawn;
  10051. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10052. return 1;
  10053. }
  10054. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10055. if (!lua_interface)
  10056. return 0;
  10057. Spawn* spawn = lua_interface->GetSpawn(state);
  10058. string field = lua_interface->GetStringValue(state, 2);
  10059. lua_interface->ResetFunctionStack(state);
  10060. if(!spawn || !spawn->IsEntity())
  10061. {
  10062. lua_interface->LogError("%s: LUA GetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10063. return 0;
  10064. }
  10065. Entity* ent = (Entity*)spawn;
  10066. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10067. return 1;
  10068. }
  10069. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10070. if (!lua_interface)
  10071. return 0;
  10072. Spawn* spawn = lua_interface->GetSpawn(state);
  10073. string field = lua_interface->GetStringValue(state, 2);
  10074. lua_interface->ResetFunctionStack(state);
  10075. if(!spawn || !spawn->IsEntity())
  10076. {
  10077. lua_interface->LogError("%s: LUA GetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10078. return 0;
  10079. }
  10080. Entity* ent = (Entity*)spawn;
  10081. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10082. return 1;
  10083. }
  10084. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10085. if (!lua_interface)
  10086. return 0;
  10087. Spawn* spawn = lua_interface->GetSpawn(state);
  10088. string field = lua_interface->GetStringValue(state, 2);
  10089. string value = lua_interface->GetStringValue(state, 3);
  10090. lua_interface->ResetFunctionStack(state);
  10091. if(!spawn || !spawn->IsEntity())
  10092. {
  10093. lua_interface->LogError("%s: LUA SetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10094. return 0;
  10095. }
  10096. Entity* ent = (Entity*)spawn;
  10097. bool set_ = ent->SetInfoStructString(field, value);
  10098. lua_interface->SetBooleanValue(state, set_);
  10099. return 1;
  10100. }
  10101. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10102. if (!lua_interface)
  10103. return 0;
  10104. Spawn* spawn = lua_interface->GetSpawn(state);
  10105. string field = lua_interface->GetStringValue(state, 2);
  10106. int64 value = lua_interface->GetInt64Value(state, 3);
  10107. lua_interface->ResetFunctionStack(state);
  10108. if(!spawn || !spawn->IsEntity())
  10109. {
  10110. lua_interface->LogError("%s: LUA SetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10111. return 0;
  10112. }
  10113. Entity* ent = (Entity*)spawn;
  10114. bool set_ = ent->SetInfoStructUInt(field, value);
  10115. lua_interface->SetBooleanValue(state, set_);
  10116. return 1;
  10117. }
  10118. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10119. if (!lua_interface)
  10120. return 0;
  10121. Spawn* spawn = lua_interface->GetSpawn(state);
  10122. string field = lua_interface->GetStringValue(state, 2);
  10123. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10124. lua_interface->ResetFunctionStack(state);
  10125. if(!spawn || !spawn->IsEntity())
  10126. {
  10127. lua_interface->LogError("%s: LUA SetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10128. return 0;
  10129. }
  10130. Entity* ent = (Entity*)spawn;
  10131. bool set_ = ent->SetInfoStructSInt(field, value);
  10132. lua_interface->SetBooleanValue(state, set_);
  10133. return 1;
  10134. }
  10135. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10136. if (!lua_interface)
  10137. return 0;
  10138. Spawn* spawn = lua_interface->GetSpawn(state);
  10139. string field = lua_interface->GetStringValue(state, 2);
  10140. float value = lua_interface->GetFloatValue(state, 3);
  10141. lua_interface->ResetFunctionStack(state);
  10142. if(!spawn || !spawn->IsEntity())
  10143. {
  10144. lua_interface->LogError("%s: LUA SetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10145. return 0;
  10146. }
  10147. Entity* ent = (Entity*)spawn;
  10148. bool set_ = ent->SetInfoStructFloat(field, value);
  10149. lua_interface->SetBooleanValue(state, set_);
  10150. return 1;
  10151. }
  10152. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10153. if (!lua_interface)
  10154. return 0;
  10155. Spawn* spawn = lua_interface->GetSpawn(state);
  10156. bool value = lua_interface->GetBooleanValue(state, 2);
  10157. lua_interface->ResetFunctionStack(state);
  10158. if(!spawn || !spawn->IsPlayer())
  10159. {
  10160. lua_interface->LogError("%s: LUA SetCharSheetChanged command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  10161. return 0;
  10162. }
  10163. ((Player*)spawn)->SetCharSheetChanged(value);
  10164. return 0;
  10165. }
  10166. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10167. if (!lua_interface)
  10168. return 0;
  10169. Spawn* spawn = lua_interface->GetSpawn(state);
  10170. std::string fromName = lua_interface->GetStringValue(state, 2);
  10171. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10172. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10173. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10174. int32 copper = lua_interface->GetInt32Value(state, 6);
  10175. int32 silver = lua_interface->GetInt32Value(state, 7);
  10176. int32 gold = lua_interface->GetInt32Value(state, 8);
  10177. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10178. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10179. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10180. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10181. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10182. lua_interface->ResetFunctionStack(state);
  10183. if(!spawn || !spawn->IsPlayer())
  10184. {
  10185. lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  10186. lua_interface->SetBooleanValue(state, false);
  10187. return 1;
  10188. }
  10189. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10190. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10191. lua_interface->SetBooleanValue(state, true);
  10192. return 1;
  10193. }
  10194. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10195. if (!lua_interface)
  10196. return 0;
  10197. int32 char_id = lua_interface->GetInt32Value(state);
  10198. std::string fromName = lua_interface->GetStringValue(state, 2);
  10199. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10200. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10201. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10202. int32 copper = lua_interface->GetInt32Value(state, 6);
  10203. int32 silver = lua_interface->GetInt32Value(state, 7);
  10204. int32 gold = lua_interface->GetInt32Value(state, 8);
  10205. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10206. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10207. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10208. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10209. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10210. lua_interface->ResetFunctionStack(state);
  10211. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10212. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10213. lua_interface->SetBooleanValue(state, true);
  10214. return 1;
  10215. }
  10216. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10217. Spawn* widget;
  10218. if (lua_interface) {
  10219. widget = lua_interface->GetSpawn(state);
  10220. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10221. lua_interface->ResetFunctionStack(state);
  10222. if (widget && widget->IsWidget())
  10223. {
  10224. ((Widget*)widget)->OpenDoor();
  10225. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10226. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10227. }
  10228. else
  10229. lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10230. }
  10231. return 0;
  10232. }
  10233. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10234. Spawn* widget;
  10235. if (lua_interface) {
  10236. widget = lua_interface->GetSpawn(state);
  10237. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10238. lua_interface->ResetFunctionStack(state);
  10239. if (widget && widget->IsWidget())
  10240. {
  10241. ((Widget*)widget)->CloseDoor();
  10242. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10243. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10244. }
  10245. else
  10246. lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10247. }
  10248. return 0;
  10249. }
  10250. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10251. if (!lua_interface)
  10252. return 0;
  10253. Spawn* widget = lua_interface->GetSpawn(state);
  10254. if (widget && widget->IsWidget())
  10255. {
  10256. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10257. return 1;
  10258. }
  10259. return 0;
  10260. }