LuaFunctions.cpp 369 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045
  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_GetCharacterID(lua_State* state) {
  935. if (!lua_interface)
  936. return 0;
  937. Spawn* spawn = lua_interface->GetSpawn(state);
  938. if (spawn && spawn->IsPlayer()) {
  939. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  940. return 1;
  941. }
  942. lua_interface->SetInt32Value(state, 0);
  943. return 1;
  944. }
  945. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  946. if (!lua_interface)
  947. return 0;
  948. Spawn* spawn = lua_interface->GetSpawn(state);
  949. Spawn* target = lua_interface->GetSpawn(state, 2);
  950. if (spawn && target) {
  951. if (spawn->IsEntity())
  952. // ((Entity*)spawn)->FaceTarget(target);
  953. static_cast<Entity*>(spawn)->FaceTarget(target);
  954. }
  955. lua_interface->ResetFunctionStack(state);
  956. return 0;
  957. }
  958. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  959. if (!lua_interface)
  960. return 0;
  961. Spawn* spawn = lua_interface->GetSpawn(state);
  962. float x = lua_interface->GetFloatValue(state, 2);
  963. float y = lua_interface->GetFloatValue(state, 3);
  964. float z = lua_interface->GetFloatValue(state, 4);
  965. float speed = lua_interface->GetFloatValue(state, 5);
  966. string lua_function = lua_interface->GetStringValue(state, 6);
  967. bool more_points = lua_interface->GetBooleanValue(state, 7);
  968. if (spawn) {
  969. if (speed == 0)
  970. speed = spawn->GetSpeed();
  971. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  972. }
  973. lua_interface->ResetFunctionStack(state);
  974. return 0;
  975. }
  976. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  977. if (!lua_interface)
  978. return 0;
  979. Spawn* spawn = lua_interface->GetSpawn(state);
  980. if (spawn) {
  981. spawn->ClearRunningLocations();
  982. }
  983. return 0;
  984. }
  985. int EQ2Emu_lua_Say(lua_State* state) {
  986. if (!lua_interface)
  987. return 0;
  988. Spawn* spawn = lua_interface->GetSpawn(state);
  989. string message = lua_interface->GetStringValue(state, 2);
  990. Spawn* player = lua_interface->GetSpawn(state, 3);
  991. int32 language = lua_interface->GetInt32Value(state, 4);
  992. if (spawn && message.length() > 0) {
  993. Client* client = 0;
  994. if (player && player->IsPlayer())
  995. client = spawn->GetZone()->GetClientBySpawn(player);
  996. if (client)
  997. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  998. else
  999. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1000. }
  1001. lua_interface->ResetFunctionStack(state);
  1002. return 0;
  1003. }
  1004. int EQ2Emu_lua_Shout(lua_State* state) {
  1005. if (!lua_interface)
  1006. return 0;
  1007. Spawn* spawn = lua_interface->GetSpawn(state);
  1008. string message = lua_interface->GetStringValue(state, 2);
  1009. Spawn* player = lua_interface->GetSpawn(state, 3);
  1010. if (spawn && message.length() > 0) {
  1011. Client* client = 0;
  1012. if (player && player->IsPlayer())
  1013. client = spawn->GetZone()->GetClientBySpawn(player);
  1014. if (client)
  1015. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1016. else
  1017. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1018. }
  1019. lua_interface->ResetFunctionStack(state);
  1020. return 0;
  1021. }
  1022. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1023. if (!lua_interface)
  1024. return 0;
  1025. Spawn* spawn = lua_interface->GetSpawn(state);
  1026. string message = lua_interface->GetStringValue(state, 2);
  1027. Spawn* player = lua_interface->GetSpawn(state, 3);
  1028. if (spawn && message.length() > 0) {
  1029. Client* client = 0;
  1030. if (player && player->IsPlayer())
  1031. client = spawn->GetZone()->GetClientBySpawn(player);
  1032. if (client)
  1033. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1034. else
  1035. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1036. }
  1037. lua_interface->ResetFunctionStack(state);
  1038. return 0;
  1039. }
  1040. int EQ2Emu_lua_Emote(lua_State* state) {
  1041. if (!lua_interface)
  1042. return 0;
  1043. Spawn* spawn = lua_interface->GetSpawn(state);
  1044. string message = lua_interface->GetStringValue(state, 2);
  1045. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1046. Spawn* player = lua_interface->GetSpawn(state, 4);
  1047. char* to = 0;
  1048. if (spawn2)
  1049. to = spawn2->GetName();
  1050. if (spawn && message.length() > 0) {
  1051. Client* client = 0;
  1052. if (player && player->IsPlayer())
  1053. client = spawn->GetZone()->GetClientBySpawn(player);
  1054. if (client)
  1055. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1056. else
  1057. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1058. }
  1059. lua_interface->ResetFunctionStack(state);
  1060. return 0;
  1061. }
  1062. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1063. if (!lua_interface)
  1064. return 0;
  1065. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1066. if (!luaspell)
  1067. return 0;
  1068. Spawn* caster = luaspell->caster;
  1069. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1070. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1071. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1072. Spawn* target = lua_interface->GetSpawn(state, 4);
  1073. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1074. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1075. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1076. lua_interface->ResetFunctionStack(state);
  1077. boost::to_lower(heal_type);
  1078. if (caster && caster->IsEntity()) {
  1079. bool success = false;
  1080. luaspell->resisted = false;
  1081. if (target) {
  1082. float distance = caster->GetDistance(target, true);
  1083. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1084. success = true;
  1085. }
  1086. if (luaspell->targets.size() > 0) {
  1087. Spawn* target = 0;
  1088. ZoneServer* zone = luaspell->caster->GetZone();
  1089. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1090. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1091. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1092. float distance = caster->GetDistance(target, true);
  1093. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1094. }
  1095. }
  1096. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1097. success = true;
  1098. }
  1099. if (success) {
  1100. if (caster->GetZone())
  1101. caster->GetZone()->TriggerCharSheetTimer();
  1102. }
  1103. }
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1110. if (!luaspell)
  1111. return 0;
  1112. Spawn* caster = luaspell->caster;
  1113. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1114. float percentage = lua_interface->GetFloatValue(state, 2);
  1115. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1116. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1117. Spawn* target = lua_interface->GetSpawn(state, 5);
  1118. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1119. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1120. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1121. lua_interface->ResetFunctionStack(state);
  1122. boost::to_lower(heal_type);
  1123. int32 min_heal = 0, max_heal = 0;
  1124. if (caster && caster->IsEntity() && target) {
  1125. if(percentage <= 0.0f)
  1126. {
  1127. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1128. return 0;
  1129. }
  1130. if(heal_type == "power")
  1131. {
  1132. if(current_value)
  1133. {
  1134. if(caster_value)
  1135. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1136. else
  1137. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1138. }
  1139. else
  1140. {
  1141. if(caster_value)
  1142. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1143. else
  1144. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1145. }
  1146. }
  1147. else
  1148. {
  1149. if(current_value)
  1150. {
  1151. if(caster_value)
  1152. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1153. else
  1154. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1155. }
  1156. else
  1157. {
  1158. if(caster_value)
  1159. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1160. else
  1161. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1162. }
  1163. }
  1164. bool success = false;
  1165. luaspell->resisted = false;
  1166. if (target) {
  1167. float distance = caster->GetDistance(target, true);
  1168. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1169. success = true;
  1170. }
  1171. if (luaspell->targets.size() > 0) {
  1172. Spawn* target = 0;
  1173. ZoneServer* zone = luaspell->caster->GetZone();
  1174. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1175. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1176. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1177. float distance = caster->GetDistance(target, true);
  1178. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1179. }
  1180. }
  1181. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1182. success = true;
  1183. }
  1184. if (success) {
  1185. if (caster->GetZone())
  1186. caster->GetZone()->TriggerCharSheetTimer();
  1187. }
  1188. }
  1189. return 0;
  1190. }
  1191. int EQ2Emu_lua_AddItem(lua_State* state) {
  1192. if (!lua_interface)
  1193. return 0;
  1194. Spawn* spawn = lua_interface->GetSpawn(state);
  1195. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1196. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1197. // default of 1 quantity to add
  1198. if (quantity == 0)
  1199. quantity = 1;
  1200. if (spawn && spawn->IsPlayer()) {
  1201. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1202. if (client && item_id > 0) {
  1203. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1204. return 1;
  1205. }
  1206. }
  1207. lua_interface->SetBooleanValue(state, false);
  1208. return 1;
  1209. }
  1210. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1211. if (!lua_interface)
  1212. return 0;
  1213. Spawn* spawn = lua_interface->GetSpawn(state);
  1214. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1215. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1216. string location = lua_interface->GetStringValue(state, 4);
  1217. if (spawn && spawn->IsPlayer()) {
  1218. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1219. if (client && item_id > 0) {
  1220. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1221. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1222. else
  1223. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1224. if (send_messages) {
  1225. Item* item = master_item_list.GetItem(item_id);
  1226. if (item) {
  1227. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1228. string popup_text = "You receive " + item->name;
  1229. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1230. }
  1231. }
  1232. return 1;
  1233. }
  1234. }
  1235. lua_interface->SetBooleanValue(state, false);
  1236. return 1;
  1237. }
  1238. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1239. Spawn* spawn = lua_interface->GetSpawn(state);
  1240. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1241. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1242. // default of 1 to remove
  1243. if (quantity == 0)
  1244. quantity = 1;
  1245. Client* client;
  1246. Item* item;
  1247. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1248. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1249. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1250. if (client->RemoveItem(item, quantity)) {
  1251. lua_interface->SetBooleanValue(state, true);
  1252. return 1;
  1253. }
  1254. }
  1255. }
  1256. }
  1257. lua_interface->SetBooleanValue(state, false);
  1258. return 1;
  1259. }
  1260. int EQ2Emu_lua_HasItem(lua_State* state) {
  1261. Spawn* player = lua_interface->GetSpawn(state);
  1262. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1263. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1264. if (player && player->IsPlayer()) {
  1265. bool hasItem = false;
  1266. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1267. if (!hasItem)
  1268. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1269. lua_interface->SetBooleanValue(state, hasItem);
  1270. return 1;
  1271. }
  1272. lua_interface->SetBooleanValue(state, false);
  1273. return 1;
  1274. }
  1275. int EQ2Emu_lua_Spawn(lua_State* state) {
  1276. if (!lua_interface)
  1277. return 0;
  1278. ZoneServer* zone = lua_interface->GetZone(state);
  1279. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1280. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1281. float x = lua_interface->GetFloatValue(state, 4);
  1282. float y = lua_interface->GetFloatValue(state, 5);
  1283. float z = lua_interface->GetFloatValue(state, 6);
  1284. float heading = lua_interface->GetFloatValue(state, 7);
  1285. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1286. Spawn* spawn = zone->GetSpawn(spawn_id);
  1287. if (!spawn)
  1288. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1289. else {
  1290. spawn->SetX(x);
  1291. spawn->SetZ(z);
  1292. spawn->SetY(y,true,true);
  1293. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1294. spawn->SetHeading(heading);
  1295. if (restricted_npc)
  1296. spawn->AddAllowAccessSpawn(spawn);
  1297. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1298. bool scriptActive = false;
  1299. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1300. scriptActive = true;
  1301. spawn->SetSpawnScript(string(spawn_script));
  1302. }
  1303. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1304. zone->AddSpawn(spawn);
  1305. if (scriptActive) {
  1306. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1307. }
  1308. lua_interface->SetSpawnValue(state, spawn);
  1309. return 1;
  1310. }
  1311. }
  1312. else {
  1313. string output = "Invalid paramaters to LUA Spawn command: \n";
  1314. if (!zone)
  1315. output = output.append("\t").append("Missing zone reference. \n");
  1316. if (spawn_id == 0)
  1317. output = output.append("\t").append("Missing spawn_id.");
  1318. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1319. }
  1320. return 0;
  1321. }
  1322. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1323. if (!lua_interface)
  1324. return 0;
  1325. ZoneServer* zone = lua_interface->GetZone(state);
  1326. if (zone) {
  1327. lua_interface->SetStringValue(state, zone->GetZoneName());
  1328. return 1;
  1329. }
  1330. return 0;
  1331. }
  1332. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1333. if (!lua_interface)
  1334. return 0;
  1335. ZoneServer* zone = lua_interface->GetZone(state);
  1336. if (zone) {
  1337. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1338. return 1;
  1339. }
  1340. return 0;
  1341. }
  1342. int EQ2Emu_lua_GetZone(lua_State* state) {
  1343. if (!lua_interface)
  1344. return 0;
  1345. int32 zone_id = lua_interface->GetInt32Value(state);
  1346. ZoneServer* zone = 0;
  1347. if (zone_id > 0)
  1348. zone = zone_list.Get(zone_id);
  1349. else {
  1350. string zone_name = lua_interface->GetStringValue(state);
  1351. if (zone_name.length() > 0) {
  1352. zone = zone_list.Get(zone_name.c_str());
  1353. }
  1354. else {
  1355. Spawn* spawn = lua_interface->GetSpawn(state);
  1356. if (spawn)
  1357. zone = spawn->GetZone();
  1358. }
  1359. }
  1360. if (zone) {
  1361. lua_interface->SetZoneValue(state, zone);
  1362. return 1;
  1363. }
  1364. return 0;
  1365. }
  1366. int EQ2Emu_lua_AddHate(lua_State* state) {
  1367. Spawn* entity = lua_interface->GetSpawn(state);
  1368. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1369. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1370. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1371. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1372. if (entity && entity->IsEntity() && amount != 0) {
  1373. if (luaspell) {
  1374. ZoneServer* zone = luaspell->caster->GetZone();
  1375. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1376. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1377. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1378. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1379. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1380. if (send_packet)
  1381. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1382. }
  1383. }
  1384. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1385. }
  1386. else if (npc && npc->IsNPC() && npc->GetZone())
  1387. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1388. }
  1389. return 0;
  1390. }
  1391. int EQ2Emu_lua_Zone(lua_State* state) {
  1392. if (!lua_interface)
  1393. return 0;
  1394. ZoneServer* zone = lua_interface->GetZone(state);
  1395. Spawn* player = lua_interface->GetSpawn(state, 2);
  1396. Client* client = 0;
  1397. if (player && player->IsPlayer())
  1398. client = player->GetZone()->GetClientBySpawn(player);
  1399. float x = lua_interface->GetFloatValue(state, 3);
  1400. float y = lua_interface->GetFloatValue(state, 4);
  1401. float z = lua_interface->GetFloatValue(state, 5);
  1402. float heading = lua_interface->GetFloatValue(state, 6);
  1403. if (zone && client) {
  1404. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1405. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1406. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1407. {
  1408. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1409. return 0;
  1410. }
  1411. if (x != 0 || y != 0 || z != 0) {
  1412. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1413. player->SetX(x);
  1414. player->SetY(y);
  1415. player->SetZ(z);
  1416. player->SetHeading(heading);
  1417. client->Zone(zone->GetZoneName(), false);
  1418. }
  1419. else
  1420. client->Zone(zone->GetZoneName());
  1421. }
  1422. else
  1423. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1424. return 0;
  1425. }
  1426. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1427. if (!lua_interface)
  1428. return 0;
  1429. Spawn* spawn = lua_interface->GetSpawn(state);
  1430. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1431. if (spawn && spawn2)
  1432. spawn->AddAllowAccessSpawn(spawn2);
  1433. return 0;
  1434. }
  1435. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1436. if (!lua_interface)
  1437. return 0;
  1438. Spawn* target = lua_interface->GetSpawn(state);
  1439. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1440. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1441. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1442. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1443. if (!target) {
  1444. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1445. return 0;
  1446. }
  1447. if (!target->IsEntity()) {
  1448. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1449. return 0;
  1450. }
  1451. if (spell_id <= 0) {
  1452. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1453. return 0;
  1454. }
  1455. if (caster && !caster->IsEntity()) {
  1456. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1457. return 0;
  1458. }
  1459. if (spell_tier == 0)
  1460. spell_tier = 1;
  1461. if (!caster)
  1462. caster = target;
  1463. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1464. return 0;
  1465. }
  1466. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1467. if (!lua_interface)
  1468. return 0;
  1469. Spawn* target = lua_interface->GetSpawn(state);
  1470. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1471. if (!luaspell)
  1472. return 0;
  1473. Spawn* caster = luaspell->caster;
  1474. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1475. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1476. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1477. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1478. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1479. //lua_interface->ResetFunctionStack(state);
  1480. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1481. vector<int16> faction_req;
  1482. vector<int16> race_req;
  1483. int32 class_req = 0;
  1484. int32 i = 0;
  1485. int8 f = 0;
  1486. int8 r = 0;
  1487. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1488. if (class_id < 100) {
  1489. class_req += pow(2.0, double(class_id - 1));
  1490. }
  1491. else if (class_id > 100 && class_id < 1000) {
  1492. race_req.push_back(class_id);
  1493. r++;
  1494. }
  1495. else {
  1496. faction_req.push_back(class_id);
  1497. f++;
  1498. }
  1499. i++;
  1500. }
  1501. if (caster && caster->IsEntity()) {
  1502. bool race_match = false;
  1503. bool success = false;
  1504. luaspell->resisted = false;
  1505. if (luaspell->targets.size() > 0) {
  1506. ZoneServer* zone = luaspell->caster->GetZone();
  1507. Spawn* target = 0;
  1508. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1509. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1510. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1511. if (race_req.size() > 0) {
  1512. for (int8 i = 0; i < race_req.size(); i++) {
  1513. if (target->GetLuaRaceId() == race_req[i]) {
  1514. race_match = true;
  1515. }
  1516. }
  1517. }
  1518. else
  1519. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1520. if (race_match == true) {
  1521. float distance = caster->GetDistance(target, true);
  1522. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1523. }
  1524. }
  1525. }
  1526. success = true;
  1527. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1528. }
  1529. else if (target) {
  1530. //check class and race/faction here
  1531. if (race_req.size() > 0) {
  1532. for (int8 i = 0; i < race_req.size(); i++) {
  1533. if (target->GetLuaRaceId() == race_req[i]) {
  1534. race_match = true;
  1535. }
  1536. }
  1537. }
  1538. else
  1539. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1540. if (race_match == true) {
  1541. float distance = caster->GetDistance(target, true);
  1542. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1543. success = true;
  1544. }
  1545. }
  1546. if (success) {
  1547. Spell* spell = luaspell->spell;
  1548. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1549. ((Player*)caster)->InCombat(true);
  1550. if (caster->GetZone())
  1551. caster->GetZone()->TriggerCharSheetTimer();
  1552. }
  1553. }
  1554. }
  1555. return 0;
  1556. }
  1557. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1558. if (!lua_interface)
  1559. return 0;
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1562. lua_interface->ResetFunctionStack(state);
  1563. if (spawn && value != 0) {
  1564. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1565. spawn->SetPower(spawn->GetTotalPower());
  1566. else
  1567. spawn->SetPower(spawn->GetPower() + value);
  1568. }
  1569. return 0;
  1570. }
  1571. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1572. if (!lua_interface)
  1573. return 0;
  1574. Spawn* spawn = lua_interface->GetSpawn(state);
  1575. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1576. lua_interface->ResetFunctionStack(state);
  1577. if (spawn && value != 0) {
  1578. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1579. spawn->SetHP(spawn->GetTotalHP());
  1580. else
  1581. spawn->SetHP(spawn->GetHP() + value);
  1582. }
  1583. return 0;
  1584. }
  1585. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1586. if (!lua_interface)
  1587. return 0;
  1588. Spawn* spawn = lua_interface->GetSpawn(state);
  1589. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1590. lua_interface->ResetFunctionStack(state);
  1591. if (spawn && value != 0) {
  1592. spawn->SetPower(spawn->GetPower() + value);
  1593. if (value > spawn->GetTotalHPBase())
  1594. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1595. }
  1596. return 0;
  1597. }
  1598. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1599. if (!lua_interface)
  1600. return 0;
  1601. Spawn* spawn = lua_interface->GetSpawn(state);
  1602. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1603. lua_interface->ResetFunctionStack(state);
  1604. if (spawn && value != 0) {
  1605. spawn->SetHP(spawn->GetHP() + value);
  1606. if (value > spawn->GetTotalHPBase())
  1607. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1608. }
  1609. return 0;
  1610. }
  1611. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1612. if (!lua_interface)
  1613. return 0;
  1614. Spawn* spawn = lua_interface->GetSpawn(state);
  1615. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1616. lua_interface->ResetFunctionStack(state);
  1617. if (spawn) {
  1618. spawn->SetHP(value);
  1619. if (value > spawn->GetTotalHPBase())
  1620. spawn->SetTotalHP(value);
  1621. }
  1622. return 0;
  1623. }
  1624. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1625. if (!lua_interface)
  1626. return 0;
  1627. Spawn* spawn = lua_interface->GetSpawn(state);
  1628. float value = lua_interface->GetFloatValue(state, 2);
  1629. lua_interface->ResetFunctionStack(state);
  1630. if (spawn && spawn->IsEntity() && value > 0)
  1631. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1632. if (spawn->IsPlayer())
  1633. ((Player*)spawn)->SetCharSheetChanged(true);
  1634. return 0;
  1635. }
  1636. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1637. if (!lua_interface)
  1638. return 0;
  1639. Spawn* spawn = lua_interface->GetSpawn(state);
  1640. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1641. lua_interface->ResetFunctionStack(state);
  1642. if (spawn && spawn->IsEntity() && value > 0)
  1643. ((Entity*)spawn)->SetTotalHPBase(value);
  1644. return 0;
  1645. }
  1646. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1647. if (!lua_interface)
  1648. return 0;
  1649. Spawn* spawn = lua_interface->GetSpawn(state);
  1650. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1651. lua_interface->ResetFunctionStack(state);
  1652. if (spawn && value > 0) {
  1653. spawn->SetPower(value);
  1654. if (value > spawn->GetTotalPowerBase())
  1655. spawn->SetTotalPower(value);
  1656. }
  1657. return 0;
  1658. }
  1659. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1660. if (!lua_interface)
  1661. return 0;
  1662. Spawn* spawn = lua_interface->GetSpawn(state);
  1663. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1664. lua_interface->ResetFunctionStack(state);
  1665. if (spawn && spawn->IsEntity() && value > 0)
  1666. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1667. return 0;
  1668. }
  1669. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1670. if (!lua_interface)
  1671. return 0;
  1672. Spawn* spawn = lua_interface->GetSpawn(state);
  1673. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1674. lua_interface->ResetFunctionStack(state);
  1675. if (spawn && spawn->IsEntity() && value > 0)
  1676. ((Entity*)spawn)->SetTotalPowerBase(value);
  1677. return 0;
  1678. }
  1679. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1680. if (!lua_interface)
  1681. return 0;
  1682. Spawn* spawn = lua_interface->GetSpawn(state);
  1683. float x = lua_interface->GetFloatValue(state, 2);
  1684. float y = lua_interface->GetFloatValue(state, 3);
  1685. float z = lua_interface->GetFloatValue(state, 4);
  1686. float heading = lua_interface->GetFloatValue(state, 5);
  1687. lua_interface->ResetFunctionStack(state);
  1688. if (spawn) {
  1689. spawn->SetX(x);
  1690. spawn->SetY(y);
  1691. spawn->SetZ(z);
  1692. if (heading != 0)
  1693. spawn->SetHeading(heading);
  1694. spawn->SetSpawnOrigX(spawn->GetX());
  1695. spawn->SetSpawnOrigY(spawn->GetY());
  1696. spawn->SetSpawnOrigZ(spawn->GetZ());
  1697. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1698. if (spawn->IsPlayer()) {
  1699. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1700. if (client) {
  1701. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1702. client->QueuePacket(packet);
  1703. }
  1704. }
  1705. }
  1706. return 0;
  1707. }
  1708. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1709. if (!lua_interface)
  1710. return 0;
  1711. Spawn* spawn = lua_interface->GetSpawn(state);
  1712. float value = lua_interface->GetFloatValue(state, 2);
  1713. lua_interface->ResetFunctionStack(state);
  1714. if (spawn) {
  1715. spawn->SetHeading(value);
  1716. if (spawn->IsPlayer()) {
  1717. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1718. if (client) {
  1719. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1720. client->QueuePacket(packet);
  1721. }
  1722. }
  1723. }
  1724. return 0;
  1725. }
  1726. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1727. if (!lua_interface)
  1728. return 0;
  1729. Spawn* spawn = lua_interface->GetSpawn(state);
  1730. int16 value = lua_interface->GetInt16Value(state, 2);
  1731. lua_interface->ResetFunctionStack(state);
  1732. if (spawn)
  1733. spawn->SetModelType(value);
  1734. return 0;
  1735. }
  1736. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1737. if (!lua_interface)
  1738. return 0;
  1739. Spawn* spawn = lua_interface->GetSpawn(state);
  1740. int8 value = lua_interface->GetInt8Value(state, 2);
  1741. lua_interface->ResetFunctionStack(state);
  1742. if (spawn) {
  1743. if (spawn->IsPlayer())
  1744. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1745. else
  1746. spawn->SetAdventureClass(value);
  1747. }
  1748. return 0;
  1749. }
  1750. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1751. if (!lua_interface)
  1752. return 0;
  1753. Spawn* spawn = lua_interface->GetSpawn(state);
  1754. int8 value = lua_interface->GetInt8Value(state, 2);
  1755. lua_interface->ResetFunctionStack(state);
  1756. if (spawn) {
  1757. spawn->SetTradeskillClass(value);
  1758. if (spawn->IsEntity()) {
  1759. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1760. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1761. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1762. }
  1763. if (spawn->IsPlayer())
  1764. ((Player*)spawn)->SetCharSheetChanged(true);
  1765. }
  1766. return 0;
  1767. }
  1768. int EQ2Emu_lua_SetMount(lua_State* state) {
  1769. if (!lua_interface)
  1770. return 0;
  1771. Spawn* spawn = lua_interface->GetSpawn(state);
  1772. int16 value = lua_interface->GetInt16Value(state, 2);
  1773. if (spawn && spawn->IsEntity()) {
  1774. ((Entity*)spawn)->SetMount(value);
  1775. EQ2_Color color;
  1776. color.red = 255;
  1777. color.green = 255;
  1778. color.blue = 255;
  1779. ((Entity*)spawn)->SetMountColor(&color);
  1780. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1781. }
  1782. return 0;
  1783. }
  1784. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1785. if (!lua_interface)
  1786. return 0;
  1787. Spawn* spawn = lua_interface->GetSpawn(state);
  1788. EQ2_Color mount_color;
  1789. EQ2_Color saddle_color;
  1790. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1791. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1792. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1793. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1794. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1795. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1796. if (spawn && spawn->IsEntity()) {
  1797. ((Entity*)spawn)->SetMountColor(&mount_color);
  1798. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1799. }
  1800. return 0;
  1801. }
  1802. int EQ2Emu_lua_GetMount(lua_State* state) {
  1803. if (!lua_interface)
  1804. return 0;
  1805. Spawn* spawn = lua_interface->GetSpawn(state);
  1806. if (spawn && spawn->IsEntity()) {
  1807. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1808. return 1;
  1809. }
  1810. return 0;
  1811. }
  1812. int EQ2Emu_lua_GetRace(lua_State* state) {
  1813. if (!lua_interface)
  1814. return 0;
  1815. Spawn* spawn = lua_interface->GetSpawn(state);
  1816. if (spawn)
  1817. {
  1818. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1819. lua_interface->SetInt32Value(state, spawn->GetRace());
  1820. return 1;
  1821. }
  1822. return 0;
  1823. }
  1824. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1825. if (!lua_interface)
  1826. return 0;
  1827. Spawn* spawn = lua_interface->GetSpawn(state);
  1828. if (spawn) {
  1829. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1830. return 1;
  1831. }
  1832. return 0;
  1833. }
  1834. int EQ2Emu_lua_GetClass(lua_State* state) {
  1835. Spawn* spawn = lua_interface->GetSpawn(state);
  1836. if (spawn) {
  1837. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1838. return 1;
  1839. }
  1840. return 0;
  1841. }
  1842. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1843. Spawn* spawn = lua_interface->GetSpawn(state);
  1844. if (spawn) {
  1845. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1846. return 1;
  1847. }
  1848. return 0;
  1849. }
  1850. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1851. if (!lua_interface)
  1852. return 0;
  1853. Spawn* spawn = lua_interface->GetSpawn(state);
  1854. float value = lua_interface->GetFloatValue(state, 2);
  1855. lua_interface->ResetFunctionStack(state);
  1856. if (spawn) {
  1857. spawn->SetSpeed(value);
  1858. ((Entity*)spawn)->SetSpeed(value);
  1859. if (spawn->IsPlayer()) {
  1860. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1861. if (client) {
  1862. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1863. if (packet) {
  1864. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1865. packet->setDataByName("speed", value);
  1866. packet->setDataByName("size", 0.51);
  1867. EQ2Packet* app = packet->serialize();
  1868. client->QueuePacket(app);
  1869. safe_delete(packet);
  1870. }
  1871. }
  1872. }
  1873. }
  1874. return 0;
  1875. }
  1876. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1877. if (!lua_interface)
  1878. return 0;
  1879. Spawn* spawn = lua_interface->GetSpawn(state);
  1880. const int16 type = lua_interface->GetInt16Value(state, 2);
  1881. const float value = lua_interface->GetFloatValue(state, 3);
  1882. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1883. int64 class_req = 0;
  1884. int32 class_id = 0;
  1885. vector<int16> faction_req;
  1886. vector<int16> race_req;
  1887. int32 i = 0;
  1888. int8 f = 0;
  1889. int8 r = 0;
  1890. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1891. if (class_id < 100) {
  1892. class_req += pow(2.0, double(class_id - 1));
  1893. }
  1894. else if (class_id > 100 && class_id < 1000) {
  1895. race_req.push_back(class_id);
  1896. r++;
  1897. }
  1898. else {
  1899. faction_req.push_back(class_id);
  1900. f++;
  1901. }
  1902. i++;
  1903. }
  1904. if (value != 0 && type >= 0) {
  1905. if (luaspell && luaspell->spell && luaspell->caster) {
  1906. ZoneServer* zone = luaspell->caster->GetZone();
  1907. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1908. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1909. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1910. if (target) {
  1911. if (target->IsPlayer()) {
  1912. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1913. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1914. if (((Player*)target)->GetGroupMemberInfo())
  1915. ((Player*)target)->UpdateGroupMemberInfo();
  1916. ((Player*)target)->SetCharSheetChanged(true);
  1917. }
  1918. else if (target->IsNPC())
  1919. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1920. else
  1921. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1922. }
  1923. }
  1924. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1925. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1926. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1927. }
  1928. else if (spawn && spawn->IsEntity()) {
  1929. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1930. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1931. if (spawn->IsPlayer())
  1932. ((Player*)spawn)->SetCharSheetChanged(true);
  1933. }
  1934. else
  1935. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1936. }
  1937. else
  1938. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1939. return 0;
  1940. }
  1941. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1942. if (!lua_interface)
  1943. return 0;
  1944. Spawn* spawn = lua_interface->GetSpawn(state);
  1945. int16 type = lua_interface->GetInt16Value(state, 2);
  1946. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1947. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1948. if (!spawn) {
  1949. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1950. return 0;
  1951. }
  1952. if (!spawn->IsEntity()) {
  1953. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1954. return 0;
  1955. }
  1956. if (value == 0) {
  1957. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1958. return 0;
  1959. }
  1960. if (!luaspell || !luaspell->spell) {
  1961. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1962. return 0;
  1963. }
  1964. int32 class_req = 0;
  1965. vector<int16> faction_req;
  1966. vector<int16> race_req;
  1967. int32 class_id = 0;
  1968. int32 i = 0;
  1969. int8 f = 0;
  1970. int8 r = 0;
  1971. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1972. if (class_id < 100) {
  1973. class_req += pow(2.0, double(class_id - 1));
  1974. }
  1975. else if (class_id > 100 && class_id < 1000) {
  1976. race_req.push_back(class_id);
  1977. r++;
  1978. }
  1979. else {
  1980. faction_req.push_back(class_id);
  1981. f++;
  1982. }
  1983. i++;
  1984. }
  1985. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1986. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1987. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1988. if (spawn->IsPlayer())
  1989. ((Player*)spawn)->SetCharSheetChanged(true);
  1990. return 0;
  1991. }
  1992. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  1993. if (!lua_interface)
  1994. return 0;
  1995. Spawn* spawn = lua_interface->GetSpawn(state);
  1996. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1997. if (!spawn) {
  1998. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1999. return 0;
  2000. }
  2001. if (!spawn->IsEntity()) {
  2002. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2003. return 0;
  2004. }
  2005. if (!luaspell || !luaspell->spell) {
  2006. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2007. return 0;
  2008. }
  2009. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2010. if (spawn->IsPlayer())
  2011. ((Player*)spawn)->SetCharSheetChanged(true);
  2012. return 0;
  2013. }
  2014. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2015. if (!lua_interface)
  2016. return 0;
  2017. Spawn* spawn = lua_interface->GetSpawn(state);
  2018. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2019. if (luaspell && luaspell->spell) {
  2020. ZoneServer* zone = luaspell->caster->GetZone();
  2021. Spawn* target = 0;
  2022. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2023. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2024. target = zone->GetSpawnByID(luaspell->targets[i]);
  2025. if (target && target->IsEntity()) {
  2026. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2027. if (target->IsPlayer())
  2028. ((Player*)target)->SetCharSheetChanged(true);
  2029. }
  2030. }
  2031. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2032. }
  2033. else if (spawn && spawn->IsEntity()) {
  2034. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2035. if (spawn->IsPlayer())
  2036. ((Player*)spawn)->SetCharSheetChanged(true);
  2037. }
  2038. return 0;
  2039. }
  2040. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2041. if (!lua_interface)
  2042. return 0;
  2043. Spawn* spawn = lua_interface->GetSpawn(state);
  2044. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2045. float value = lua_interface->GetFloatValue(state, 3);
  2046. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2047. if (value != 0) {
  2048. int32 spell_id = 0;
  2049. if (luaspell && luaspell->spell && luaspell->caster) {
  2050. spell_id = luaspell->spell->GetSpellID();
  2051. ZoneServer* zone = luaspell->caster->GetZone();
  2052. Spawn* target = 0;
  2053. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2054. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2055. target = zone->GetSpawnByID(luaspell->targets[i]);
  2056. if (target && target->Alive()) {
  2057. if (target->IsPlayer()) {
  2058. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2059. Client* client = target->GetZone()->GetClientBySpawn(target);
  2060. if (client) {
  2061. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2062. if (packet)
  2063. client->QueuePacket(packet);
  2064. }
  2065. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2066. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2067. }
  2068. else if (target->IsNPC()) {
  2069. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2070. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2071. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2072. }
  2073. else
  2074. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2075. }
  2076. }
  2077. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2078. }
  2079. else if (spawn) {
  2080. if (spawn->IsPlayer()) {
  2081. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2082. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2083. if (client) {
  2084. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2085. if (packet)
  2086. client->QueuePacket(packet);
  2087. }
  2088. }
  2089. else if (spawn->IsNPC())
  2090. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2091. else
  2092. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2093. }
  2094. }
  2095. else
  2096. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2097. return 0;
  2098. }
  2099. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2100. if (!lua_interface)
  2101. return 0;
  2102. Spawn* spawn = lua_interface->GetSpawn(state);
  2103. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2104. if (spawn && spawn->IsPlayer()) {
  2105. int32 spell_id = 0;
  2106. if (luaspell && luaspell->spell) {
  2107. spell_id = luaspell->spell->GetSpellID();
  2108. ZoneServer* zone = luaspell->caster->GetZone();
  2109. Spawn* target = 0;
  2110. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2111. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2112. target = zone->GetSpawnByID(luaspell->targets[i]);
  2113. if (target) {
  2114. if (target->IsPlayer()) {
  2115. ((Player*)target)->RemoveSkillBonus(spell_id);
  2116. Client* client = target->GetZone()->GetClientBySpawn(target);
  2117. if (client) {
  2118. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2119. if (packet)
  2120. client->QueuePacket(packet);
  2121. }
  2122. }
  2123. else if (target->IsNPC())
  2124. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2125. else
  2126. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2127. }
  2128. }
  2129. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2130. }
  2131. else if (spawn) {
  2132. if (spawn->IsPlayer()) {
  2133. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2134. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2135. if (client) {
  2136. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2137. if (packet)
  2138. client->QueuePacket(packet);
  2139. }
  2140. }
  2141. else if (spawn->IsNPC())
  2142. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2143. else
  2144. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2145. }
  2146. }
  2147. return 0;
  2148. }
  2149. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2150. if (!lua_interface)
  2151. return 0;
  2152. Spawn* spawn = lua_interface->GetSpawn(state);
  2153. int8 type = lua_interface->GetInt32Value(state, 2);
  2154. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2155. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2156. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2157. ZoneServer* zone = luaspell->caster->GetZone();
  2158. Spawn* target = 0;
  2159. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2160. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2161. target = zone->GetSpawnByID(luaspell->targets[i]);
  2162. if (target && target->IsEntity()) {
  2163. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2164. ((Entity*)target)->AddMezSpell(luaspell);
  2165. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2166. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2167. if (target->IsNPC())
  2168. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2169. }
  2170. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2171. ((Entity*)target)->AddStifleSpell(luaspell);
  2172. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2173. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2174. if (target->IsNPC())
  2175. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2176. }
  2177. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2178. ((Entity*)target)->AddDazeSpell(luaspell);
  2179. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2180. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2181. if (target->IsNPC())
  2182. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2183. }
  2184. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2185. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2186. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2187. ((Entity*)target)->AddStunSpell(luaspell);
  2188. if (target->IsNPC())
  2189. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2190. }
  2191. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2192. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2193. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2194. ((Entity*)target)->AddRootSpell(luaspell);
  2195. if (target->IsNPC())
  2196. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2197. }
  2198. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2199. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2200. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2201. ((Entity*)target)->AddFearSpell(luaspell);
  2202. if (target->IsNPC())
  2203. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2204. }
  2205. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2206. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2207. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2208. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2209. }
  2210. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2211. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2212. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2213. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2214. }
  2215. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2216. ((Entity*)target)->AddSnareSpell(luaspell);
  2217. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2218. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2219. if (target->IsNPC())
  2220. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2221. }
  2222. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2223. ((Entity*)target)->AddFlightSpell(luaspell);
  2224. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2225. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2226. }
  2227. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2228. ((Entity*)target)->AddGlideSpell(luaspell);
  2229. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2230. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2231. }
  2232. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2233. ((Entity*)target)->AddSafefallSpell(luaspell);
  2234. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2235. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2236. }
  2237. else
  2238. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2239. }
  2240. else
  2241. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2242. }
  2243. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2244. }
  2245. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2246. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2247. ((Entity*)spawn)->AddMezSpell(luaspell);
  2248. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2249. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2250. }
  2251. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2252. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2253. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2254. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2255. }
  2256. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2257. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2258. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2259. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2260. }
  2261. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2262. ((Entity*)spawn)->AddStunSpell(luaspell);
  2263. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2264. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2265. }
  2266. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2267. ((Entity*)spawn)->AddRootSpell(luaspell);
  2268. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2269. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2270. }
  2271. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2272. ((Entity*)spawn)->AddFearSpell(luaspell);
  2273. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2274. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2275. }
  2276. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2277. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2278. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2279. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2280. }
  2281. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2282. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2283. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2284. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2285. }
  2286. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2287. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2288. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2289. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2290. }
  2291. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2292. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2293. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2294. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2295. }
  2296. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2297. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2298. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2299. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2300. }
  2301. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2302. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2303. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2304. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2305. }
  2306. else
  2307. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2308. }
  2309. else
  2310. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2311. return 0;
  2312. }
  2313. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2314. if (!lua_interface)
  2315. return 0;
  2316. Spawn* spawn = lua_interface->GetSpawn(state);
  2317. int8 type = lua_interface->GetInt8Value(state, 2);
  2318. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2319. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2320. if (spawn && spawn->IsEntity()) {
  2321. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2322. ZoneServer* zone = luaspell->caster->GetZone();
  2323. Spawn* target = 0;
  2324. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2325. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2326. target = zone->GetSpawnByID(luaspell->targets[i]);
  2327. if (target) {
  2328. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2329. ((Entity*)target)->RemoveMezSpell(luaspell);
  2330. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2331. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2332. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2333. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2334. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2335. ((Entity*)target)->RemoveStunSpell(luaspell);
  2336. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2337. ((Entity*)target)->RemoveRootSpell(luaspell);
  2338. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2339. ((Entity*)target)->RemoveFearSpell(luaspell);
  2340. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2341. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2342. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2343. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2344. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2345. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2346. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2347. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2348. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2349. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2350. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2351. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2352. else
  2353. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2354. }
  2355. }
  2356. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2357. }
  2358. else if (only_remove_spawn) {
  2359. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2360. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2361. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2362. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2363. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2364. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2365. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2366. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2367. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2368. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2369. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2370. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2371. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2372. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2373. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2374. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2375. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2376. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2377. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2378. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2379. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2380. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2381. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2382. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2383. else
  2384. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2385. }
  2386. }
  2387. return 0;
  2388. }
  2389. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2390. if (!lua_interface)
  2391. return 0;
  2392. Spawn* spawn = lua_interface->GetSpawn(state);
  2393. int8 type = lua_interface->GetInt8Value(state, 2);
  2394. bool hasEffect = false;
  2395. if (!spawn)
  2396. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2397. else if (!spawn->IsEntity())
  2398. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2399. else if (type < CONTROL_MAX_EFFECTS)
  2400. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2401. else
  2402. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2403. lua_interface->SetBooleanValue(state, hasEffect);
  2404. return 1;
  2405. }
  2406. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2407. if (!lua_interface)
  2408. return 0;
  2409. Spawn* spawn = lua_interface->GetSpawn(state);
  2410. float distance = 0.0f;
  2411. if (!spawn)
  2412. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2413. else if (!spawn->IsNPC())
  2414. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2415. else
  2416. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2417. lua_interface->SetFloatValue(state, distance);
  2418. return 1;
  2419. }
  2420. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2421. if (!lua_interface)
  2422. return 0;
  2423. Spawn* spawn = lua_interface->GetSpawn(state);
  2424. float distance = 0.0f;
  2425. if (!spawn)
  2426. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2427. else if (!spawn->IsNPC())
  2428. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2429. else
  2430. distance = ((NPC*)spawn)->GetAggroRadius();
  2431. lua_interface->SetFloatValue(state, distance);
  2432. return 1;
  2433. }
  2434. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2435. if (!lua_interface)
  2436. return 0;
  2437. Spawn* spawn = lua_interface->GetSpawn(state);
  2438. float distance = lua_interface->GetFloatValue(state, 2);
  2439. bool override = lua_interface->GetBooleanValue(state, 3);
  2440. bool result = false;
  2441. lua_interface->ResetFunctionStack(state);
  2442. if (!spawn)
  2443. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2444. else if (!spawn->IsNPC())
  2445. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2446. else
  2447. {
  2448. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2449. result = true;
  2450. }
  2451. lua_interface->SetBooleanValue(state, result);
  2452. return 1;
  2453. }
  2454. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2455. if (!lua_interface)
  2456. return 0;
  2457. Spawn* spawn = lua_interface->GetSpawn(state);
  2458. int16 value = lua_interface->GetInt16Value(state, 2);
  2459. if (spawn && spawn->IsEntity()) {
  2460. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2461. if (spawn->IsPlayer())
  2462. ((Player*)spawn)->SetCharSheetChanged(true);
  2463. }
  2464. return 0;
  2465. }
  2466. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2467. if (!lua_interface)
  2468. return 0;
  2469. Spawn* spawn = lua_interface->GetSpawn(state);
  2470. int16 value = lua_interface->GetInt16Value(state, 2);
  2471. if (spawn && spawn->IsEntity()) {
  2472. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2473. if (spawn->IsPlayer())
  2474. ((Player*)spawn)->SetCharSheetChanged(true);
  2475. }
  2476. return 0;
  2477. }
  2478. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2479. if (!lua_interface)
  2480. return 0;
  2481. Spawn* spawn = lua_interface->GetSpawn(state);
  2482. int16 value = lua_interface->GetInt16Value(state, 2);
  2483. if (spawn && spawn->IsEntity()) {
  2484. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2485. if (spawn->IsPlayer())
  2486. ((Player*)spawn)->SetCharSheetChanged(true);
  2487. }
  2488. return 0;
  2489. }
  2490. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2491. if (!lua_interface)
  2492. return 0;
  2493. Spawn* spawn = lua_interface->GetSpawn(state);
  2494. int16 value = lua_interface->GetInt16Value(state, 2);
  2495. if (spawn && spawn->IsEntity()) {
  2496. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2497. if (spawn->IsPlayer())
  2498. ((Player*)spawn)->SetCharSheetChanged(true);
  2499. }
  2500. return 0;
  2501. }
  2502. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2503. if (!lua_interface)
  2504. return 0;
  2505. Spawn* spawn = lua_interface->GetSpawn(state);
  2506. int16 value = lua_interface->GetInt16Value(state, 2);
  2507. if (spawn && spawn->IsEntity()) {
  2508. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2509. if (spawn->IsPlayer())
  2510. ((Player*)spawn)->SetCharSheetChanged(true);
  2511. }
  2512. return 0;
  2513. }
  2514. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2515. if (!lua_interface)
  2516. return 0;
  2517. Spawn* spawn = lua_interface->GetSpawn(state);
  2518. int8 value = lua_interface->GetInt8Value(state, 2);
  2519. if (spawn && spawn->IsEntity()) {
  2520. ((Entity*)spawn)->SetDeity(value);
  2521. if (spawn->IsPlayer())
  2522. ((Player*)spawn)->SetCharSheetChanged(true);
  2523. }
  2524. lua_interface->ResetFunctionStack(state);
  2525. return 0;
  2526. }
  2527. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2528. if (!lua_interface)
  2529. return 0;
  2530. Spawn* spawn = lua_interface->GetSpawn(state);
  2531. if (spawn && spawn->IsEntity()) {
  2532. int8 deity = ((Entity*)spawn)->GetDeity();
  2533. lua_interface->SetInt32Value(state, deity);
  2534. return 1;
  2535. }
  2536. return 0;
  2537. }
  2538. int EQ2Emu_lua_SetInt(lua_State* state) {
  2539. if (!lua_interface)
  2540. return 0;
  2541. Spawn* spawn = lua_interface->GetSpawn(state);
  2542. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2543. if (spawn && spawn->IsEntity()) {
  2544. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2545. if (spawn->IsPlayer())
  2546. ((Player*)spawn)->SetCharSheetChanged(true);
  2547. }
  2548. return 0;
  2549. }
  2550. int EQ2Emu_lua_SetWis(lua_State* state) {
  2551. if (!lua_interface)
  2552. return 0;
  2553. Spawn* spawn = lua_interface->GetSpawn(state);
  2554. float value = lua_interface->GetFloatValue(state, 2);
  2555. if (spawn && spawn->IsEntity()) {
  2556. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2557. if (spawn->IsPlayer())
  2558. ((Player*)spawn)->SetCharSheetChanged(true);
  2559. }
  2560. return 0;
  2561. }
  2562. int EQ2Emu_lua_SetSta(lua_State* state) {
  2563. if (!lua_interface)
  2564. return 0;
  2565. Spawn* spawn = lua_interface->GetSpawn(state);
  2566. float value = lua_interface->GetFloatValue(state, 2);
  2567. if (spawn && spawn->IsEntity()) {
  2568. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2569. if (spawn->IsPlayer())
  2570. ((Player*)spawn)->SetCharSheetChanged(true);
  2571. }
  2572. return 0;
  2573. }
  2574. int EQ2Emu_lua_SetStr(lua_State* state) {
  2575. if (!lua_interface)
  2576. return 0;
  2577. Spawn* spawn = lua_interface->GetSpawn(state);
  2578. float value = lua_interface->GetFloatValue(state, 2);
  2579. if (spawn && spawn->IsEntity()) {
  2580. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2581. if (spawn->IsPlayer())
  2582. ((Player*)spawn)->SetCharSheetChanged(true);
  2583. }
  2584. return 0;
  2585. }
  2586. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2587. if (!lua_interface)
  2588. return 0;
  2589. Spawn* spawn = lua_interface->GetSpawn(state);
  2590. float value = lua_interface->GetFloatValue(state, 2);
  2591. if (spawn && spawn->IsEntity()) {
  2592. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2593. if (spawn->IsPlayer())
  2594. ((Player*)spawn)->SetCharSheetChanged(true);
  2595. }
  2596. return 0;
  2597. }
  2598. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2599. if (!lua_interface)
  2600. return 0;
  2601. Spawn* spawn = lua_interface->GetSpawn(state);
  2602. if (spawn) {
  2603. lua_interface->SetInt32Value(state, spawn->GetHP());
  2604. return 1;
  2605. }
  2606. return 0;
  2607. }
  2608. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2609. if (!lua_interface)
  2610. return 0;
  2611. Spawn* spawn = lua_interface->GetSpawn(state);
  2612. if (spawn) {
  2613. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2614. return 1;
  2615. }
  2616. return 0;
  2617. }
  2618. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2619. if (!lua_interface)
  2620. return 0;
  2621. Spawn* spawn = lua_interface->GetSpawn(state);
  2622. if (spawn) {
  2623. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2624. return 1;
  2625. }
  2626. return 0;
  2627. }
  2628. int EQ2Emu_lua_GetName(lua_State* state) {
  2629. if (!lua_interface)
  2630. return 0;
  2631. Spawn* spawn = lua_interface->GetSpawn(state);
  2632. if (spawn) {
  2633. lua_interface->SetStringValue(state, spawn->GetName());
  2634. return 1;
  2635. }
  2636. return 0;
  2637. }
  2638. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2639. Spawn* spawn = lua_interface->GetSpawn(state);
  2640. if (spawn) {
  2641. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2642. return 1;
  2643. }
  2644. return 0;
  2645. }
  2646. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2647. if (!lua_interface)
  2648. return 0;
  2649. Spawn* spawn = lua_interface->GetSpawn(state);
  2650. if (spawn) {
  2651. lua_interface->SetInt32Value(state, spawn->GetPower());
  2652. return 1;
  2653. }
  2654. return 0;
  2655. }
  2656. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2657. if (!lua_interface)
  2658. return 0;
  2659. Spawn* spawn = lua_interface->GetSpawn(state);
  2660. if (spawn) {
  2661. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2662. return 1;
  2663. }
  2664. return 0;
  2665. }
  2666. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2667. if (!lua_interface)
  2668. return 0;
  2669. Spawn* spawn = lua_interface->GetSpawn(state);
  2670. if (spawn) {
  2671. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2672. return 1;
  2673. }
  2674. return 0;
  2675. }
  2676. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2677. if (!lua_interface)
  2678. return 0;
  2679. Spawn* spawn = lua_interface->GetSpawn(state);
  2680. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2681. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2682. if (spawn && spawn2) {
  2683. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2684. lua_interface->SetFloatValue(state, distance);
  2685. return 1;
  2686. }
  2687. return 0;
  2688. }
  2689. int EQ2Emu_lua_GetX(lua_State* state) {
  2690. if (!lua_interface)
  2691. return 0;
  2692. Spawn* spawn = lua_interface->GetSpawn(state);
  2693. if (spawn) {
  2694. lua_interface->SetFloatValue(state, spawn->GetX());
  2695. return 1;
  2696. }
  2697. return 0;
  2698. }
  2699. int EQ2Emu_lua_GetY(lua_State* state) {
  2700. if (!lua_interface)
  2701. return 0;
  2702. Spawn* spawn = lua_interface->GetSpawn(state);
  2703. if (spawn) {
  2704. lua_interface->SetFloatValue(state, spawn->GetY());
  2705. return 1;
  2706. }
  2707. return 0;
  2708. }
  2709. int EQ2Emu_lua_GetZ(lua_State* state) {
  2710. if (!lua_interface)
  2711. return 0;
  2712. Spawn* spawn = lua_interface->GetSpawn(state);
  2713. if (spawn) {
  2714. lua_interface->SetFloatValue(state, spawn->GetZ());
  2715. return 1;
  2716. }
  2717. return 0;
  2718. }
  2719. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2720. if (!lua_interface)
  2721. return 0;
  2722. Spawn* spawn = lua_interface->GetSpawn(state);
  2723. if (spawn) {
  2724. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2725. return 1;
  2726. }
  2727. return 0;
  2728. }
  2729. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2730. if (!lua_interface)
  2731. return 0;
  2732. Spawn* spawn = lua_interface->GetSpawn(state);
  2733. if (spawn) {
  2734. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2735. return 1;
  2736. }
  2737. return 0;
  2738. }
  2739. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2740. if (!lua_interface)
  2741. return 0;
  2742. Spawn* spawn = lua_interface->GetSpawn(state);
  2743. if (spawn) {
  2744. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2745. return 1;
  2746. }
  2747. return 0;
  2748. }
  2749. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2750. if (!lua_interface)
  2751. return 0;
  2752. Spawn* spawn = lua_interface->GetSpawn(state);
  2753. if (spawn && spawn->IsEntity()) {
  2754. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2755. return 1;
  2756. }
  2757. return 0;
  2758. }
  2759. int EQ2Emu_lua_GetInt(lua_State* state) {
  2760. if (!lua_interface)
  2761. return 0;
  2762. Spawn* spawn = lua_interface->GetSpawn(state);
  2763. if (spawn && spawn->IsEntity()) {
  2764. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2765. return 1;
  2766. }
  2767. return 0;
  2768. }
  2769. int EQ2Emu_lua_GetWis(lua_State* state) {
  2770. if (!lua_interface)
  2771. return 0;
  2772. Spawn* spawn = lua_interface->GetSpawn(state);
  2773. if (spawn && spawn->IsEntity()) {
  2774. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2775. return 1;
  2776. }
  2777. return 0;
  2778. }
  2779. int EQ2Emu_lua_GetSta(lua_State* state) {
  2780. if (!lua_interface)
  2781. return 0;
  2782. Spawn* spawn = lua_interface->GetSpawn(state);
  2783. if (spawn && spawn->IsEntity()) {
  2784. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2785. return 1;
  2786. }
  2787. return 0;
  2788. }
  2789. int EQ2Emu_lua_GetStr(lua_State* state) {
  2790. if (!lua_interface)
  2791. return 0;
  2792. Spawn* spawn = lua_interface->GetSpawn(state);
  2793. if (spawn && spawn->IsEntity()) {
  2794. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2795. return 1;
  2796. }
  2797. return 0;
  2798. }
  2799. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. Spawn* spawn = lua_interface->GetSpawn(state);
  2803. if (spawn && spawn->IsEntity()) {
  2804. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2805. return 1;
  2806. }
  2807. return 0;
  2808. }
  2809. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2810. if (!lua_interface)
  2811. return 0;
  2812. Spawn* spawn = lua_interface->GetSpawn(state);
  2813. if (spawn && spawn->IsEntity()) {
  2814. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2815. return 1;
  2816. }
  2817. return 0;
  2818. }
  2819. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2820. if (!lua_interface)
  2821. return 0;
  2822. Spawn* spawn = lua_interface->GetSpawn(state);
  2823. if (spawn && spawn->IsEntity()) {
  2824. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2825. return 1;
  2826. }
  2827. return 0;
  2828. }
  2829. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2830. if (!lua_interface)
  2831. return 0;
  2832. Spawn* spawn = lua_interface->GetSpawn(state);
  2833. if (spawn && spawn->IsEntity()) {
  2834. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2835. return 1;
  2836. }
  2837. return 0;
  2838. }
  2839. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2840. if (!lua_interface)
  2841. return 0;
  2842. Spawn* spawn = lua_interface->GetSpawn(state);
  2843. if (spawn && spawn->IsEntity()) {
  2844. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2845. return 1;
  2846. }
  2847. return 0;
  2848. }
  2849. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2850. if (!lua_interface)
  2851. return 0;
  2852. Spawn* spawn = lua_interface->GetSpawn(state);
  2853. if (spawn && spawn->IsEntity()) {
  2854. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2855. return 1;
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* player = lua_interface->GetSpawn(state);
  2863. if (!player || !player->IsPlayer()) {
  2864. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2865. return 0;
  2866. }
  2867. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2868. if (quest_id <= 0) {
  2869. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2870. return 0;
  2871. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2872. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2873. return 0;
  2874. }
  2875. int32 step = lua_interface->GetInt32Value(state, 3);
  2876. if (step > 0) {
  2877. Client* client = player->GetZone()->GetClientBySpawn(player);
  2878. if (client)
  2879. client->AddPendingQuestUpdate(quest_id, step);
  2880. } else {
  2881. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2882. }
  2883. return 0;
  2884. }
  2885. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2886. Spawn* player = lua_interface->GetSpawn(state);
  2887. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2888. int32 step = lua_interface->GetInt32Value(state, 3);
  2889. int32 progress = lua_interface->GetInt32Value(state, 4);
  2890. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2891. Client* client = player->GetZone()->GetClientBySpawn(player);
  2892. if (client)
  2893. client->AddPendingQuestUpdate(quest_id, step, progress);
  2894. }
  2895. return 0;
  2896. }
  2897. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2898. if (!lua_interface)
  2899. return 0;
  2900. Spawn* player = lua_interface->GetSpawn(state);
  2901. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2902. if (player && player->IsPlayer() && quest_id > 0) {
  2903. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2904. return 1;
  2905. }
  2906. return 0;
  2907. }
  2908. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2909. if (!lua_interface)
  2910. return 0;
  2911. Spawn* player = lua_interface->GetSpawn(state);
  2912. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2913. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2914. if (player && player->IsPlayer() && quest_id > 0) {
  2915. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2916. return 1;
  2917. }
  2918. return 0;
  2919. }
  2920. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2921. if (!lua_interface)
  2922. return 0;
  2923. Spawn* player = lua_interface->GetSpawn(state);
  2924. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2925. if (player && player->IsPlayer() && quest_id > 0) {
  2926. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2927. return 1;
  2928. }
  2929. return 0;
  2930. }
  2931. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2932. if (!lua_interface)
  2933. return 0;
  2934. Quest* quest = lua_interface->GetQuest(state);
  2935. string name = lua_interface->GetStringValue(state, 2);
  2936. string type = lua_interface->GetStringValue(state, 3);
  2937. string zone = lua_interface->GetStringValue(state, 4);
  2938. int16 level = lua_interface->GetInt16Value(state, 5);
  2939. string description = lua_interface->GetStringValue(state, 6);
  2940. bool load = true;
  2941. if (!quest) {
  2942. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2943. load = false;
  2944. }
  2945. if (load && name.length() == 0) {
  2946. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2947. load = false;
  2948. }
  2949. if (load && type.length() == 0) {
  2950. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2951. load = false;
  2952. }
  2953. if (load && zone.length() == 0) {
  2954. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2955. load = false;
  2956. }
  2957. if (load && description.length() == 0) {
  2958. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2959. load = false;
  2960. }
  2961. if (load && level == 0) {
  2962. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2963. load = false;
  2964. }
  2965. if (load)
  2966. quest->RegisterQuest(name, type, zone, level, description);
  2967. return 0;
  2968. }
  2969. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2970. if (!lua_interface)
  2971. return 0;
  2972. Quest* quest = lua_interface->GetQuest(state);
  2973. if (quest) {
  2974. int8 level = lua_interface->GetInt16Value(state, 2);
  2975. quest->SetPrereqLevel(level);
  2976. }
  2977. return 0;
  2978. }
  2979. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2980. if (!lua_interface)
  2981. return 0;
  2982. Quest* quest = lua_interface->GetQuest(state);
  2983. if (quest) {
  2984. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2985. quest->AddPrereqQuest(quest_id);
  2986. }
  2987. return 0;
  2988. }
  2989. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2990. if (!lua_interface)
  2991. return 0;
  2992. Quest* quest = lua_interface->GetQuest(state);
  2993. if (quest) {
  2994. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2995. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2996. if (quantity == 0)
  2997. quantity = 1;
  2998. Item* master_item = master_item_list.GetItem(item_id);
  2999. if (master_item) {
  3000. Item* item = new Item(master_item);
  3001. item->details.count = quantity;
  3002. quest->AddPrereqItem(item);
  3003. }
  3004. }
  3005. return 0;
  3006. }
  3007. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3008. if (!lua_interface)
  3009. return 0;
  3010. Spawn* player = lua_interface->GetSpawn(state);
  3011. if(!player || !player->IsPlayer()) {
  3012. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3013. return 0;
  3014. }
  3015. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3016. if (quest_id > 0) {
  3017. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3018. return 1;
  3019. } else {
  3020. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3021. }
  3022. return 0;
  3023. }
  3024. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3025. if (!lua_interface)
  3026. return 0;
  3027. Quest* quest = lua_interface->GetQuest(state);
  3028. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3029. if (quest && spawn_id > 0)
  3030. quest->SetQuestReturnNPC(spawn_id);
  3031. return 0;
  3032. }
  3033. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3034. if (!lua_interface)
  3035. return 0;
  3036. Spawn* spawn = lua_interface->GetSpawn(state);
  3037. if (!spawn) {
  3038. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3039. return 0;
  3040. }
  3041. int32 time = lua_interface->GetInt32Value(state, 2);
  3042. if (time <= 0) {
  3043. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3044. return 0;
  3045. }
  3046. string function = lua_interface->GetStringValue(state, 3);
  3047. if (function.length() == 0) {
  3048. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3049. return 0;
  3050. }
  3051. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3052. Spawn* player = lua_interface->GetSpawn(state, 5);
  3053. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3054. timer->timer = Timer::GetCurrentTime2() + time;
  3055. timer->function = function;
  3056. timer->spawn = spawn->GetID();
  3057. timer->player = player ? player->GetID() : 0;
  3058. if (max_count == 0)
  3059. max_count = 1;
  3060. timer->max_count = max_count;
  3061. timer->current_count = 0;
  3062. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3063. return 0;
  3064. }
  3065. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3066. if (!lua_interface)
  3067. return 0;
  3068. Spawn* player = lua_interface->GetSpawn(state);
  3069. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3070. if (player && player->IsPlayer() && quest_id > 0) {
  3071. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3072. return 1;
  3073. }
  3074. return 0;
  3075. }
  3076. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3077. if (!lua_interface)
  3078. return 0;
  3079. Spawn* player = lua_interface->GetSpawn(state);
  3080. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3081. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3082. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3083. if (quest)
  3084. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3085. return 1;
  3086. }
  3087. return 0;
  3088. }
  3089. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3090. if (!lua_interface)
  3091. return 0;
  3092. Spawn* player = lua_interface->GetSpawn(state);
  3093. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3094. if (player && player->IsPlayer() && quest_id > 0) {
  3095. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3096. return 1;
  3097. }
  3098. return 0;
  3099. }
  3100. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3101. if (!lua_interface)
  3102. return 0;
  3103. Spawn* npc = lua_interface->GetSpawn(state);
  3104. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3105. if (npc && !npc->IsPlayer() && quest_id > 0)
  3106. npc->AddProvidedQuest(quest_id);
  3107. return 0;
  3108. }
  3109. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3110. if (!lua_interface)
  3111. return 0;
  3112. Spawn* npc = lua_interface->GetSpawn(state);
  3113. Spawn* player = lua_interface->GetSpawn(state, 2);
  3114. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3115. bool forced = lua_interface->GetBooleanValue(state, 4);
  3116. /* NPC is allowed to be null */
  3117. if (player && player->IsPlayer() && quest_id > 0) {
  3118. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3119. if (master_quest) {
  3120. Client* client = player->GetZone()->GetClientBySpawn(player);
  3121. if (!client) {
  3122. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3123. }
  3124. Quest* quest = new Quest(master_quest);
  3125. if (!quest) {
  3126. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3127. }
  3128. if (client && quest) {
  3129. if (npc)
  3130. quest->SetQuestGiver(npc->GetDatabaseID());
  3131. else
  3132. quest->SetQuestGiver(0);
  3133. client->AddPendingQuest(quest, forced);
  3134. }
  3135. }
  3136. else {
  3137. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3138. }
  3139. }
  3140. else {
  3141. 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);
  3142. }
  3143. return 0;
  3144. }
  3145. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3146. if (!lua_interface)
  3147. return 0;
  3148. Quest* quest = lua_interface->GetQuest(state);
  3149. if (quest) {
  3150. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3151. quest->AddPrereqClass(class_id);
  3152. }
  3153. return 0;
  3154. }
  3155. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3156. if (!lua_interface)
  3157. return 0;
  3158. Quest* quest = lua_interface->GetQuest(state);
  3159. if (quest) {
  3160. int8 race = lua_interface->GetInt8Value(state, 2);
  3161. quest->AddPrereqRace(race);
  3162. }
  3163. return 0;
  3164. }
  3165. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3166. if (!lua_interface)
  3167. return 0;
  3168. Quest* quest = lua_interface->GetQuest(state);
  3169. if (quest) {
  3170. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3171. quest->AddPrereqModelType(model_type);
  3172. }
  3173. return 0;
  3174. }
  3175. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3176. if (!lua_interface)
  3177. return 0;
  3178. Quest* quest = lua_interface->GetQuest(state);
  3179. if (!quest) {
  3180. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3181. return 0;
  3182. }
  3183. int8 level = lua_interface->GetInt8Value(state, 2);
  3184. quest->SetPrereqTSLevel(level);
  3185. return 0;
  3186. }
  3187. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3188. if (!lua_interface)
  3189. return 0;
  3190. Quest* quest = lua_interface->GetQuest(state);
  3191. if (!quest) {
  3192. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3193. return 0;
  3194. }
  3195. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3196. quest->AddPrereqTradeskillClass(class_id);
  3197. return 0;
  3198. }
  3199. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3200. if (!lua_interface)
  3201. return 0;
  3202. Quest* quest = lua_interface->GetQuest(state);
  3203. if (quest) {
  3204. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3205. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3206. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3207. quest->AddPrereqFaction(faction_id, min, max);
  3208. }
  3209. return 0;
  3210. }
  3211. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3212. if (!lua_interface)
  3213. return 0;
  3214. Quest* quest = lua_interface->GetQuest(state);
  3215. if (quest) {
  3216. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3217. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3218. if (quantity == 0)
  3219. quantity = 1;
  3220. Item* master_item = master_item_list.GetItem(item_id);
  3221. if (master_item) {
  3222. Item* item = new Item(master_item);
  3223. item->details.count = quantity;
  3224. quest->AddSelectableRewardItem(item);
  3225. }
  3226. }
  3227. return 0;
  3228. }
  3229. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3230. if (!lua_interface)
  3231. return 0;
  3232. Quest* quest = lua_interface->GetQuest(state);
  3233. if (quest) {
  3234. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3235. vector<Item*>* items = quest->GetRewardItems();
  3236. if (items) {
  3237. vector<Item*>::iterator itr;
  3238. for (itr = items->begin(); itr != items->end(); itr++) {
  3239. if (*itr && (*itr)->details.item_id == item_id) {
  3240. lua_interface->SetBooleanValue(state, true);
  3241. return 1;
  3242. }
  3243. }
  3244. }
  3245. }
  3246. lua_interface->SetBooleanValue(state, false);
  3247. return 1;
  3248. }
  3249. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3250. if (!lua_interface)
  3251. return 0;
  3252. Quest* quest = lua_interface->GetQuest(state);
  3253. if (quest) {
  3254. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3255. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3256. if (quantity == 0)
  3257. quantity = 1;
  3258. Item* master_item = master_item_list.GetItem(item_id);
  3259. if (master_item) {
  3260. Item* item = new Item(master_item);
  3261. item->details.count = quantity;
  3262. quest->AddRewardItem(item);
  3263. }
  3264. }
  3265. return 0;
  3266. }
  3267. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3268. if (!lua_interface)
  3269. return 0;
  3270. Quest* quest = lua_interface->GetQuest(state);
  3271. if (quest) {
  3272. int32 copper = lua_interface->GetInt32Value(state, 2);
  3273. int32 silver = lua_interface->GetInt32Value(state, 3);
  3274. int32 gold = lua_interface->GetInt32Value(state, 4);
  3275. int32 plat = lua_interface->GetInt32Value(state, 5);
  3276. quest->AddRewardCoins(copper, silver, gold, plat);
  3277. }
  3278. return 0;
  3279. }
  3280. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3281. if (!lua_interface)
  3282. return 0;
  3283. Quest* quest = lua_interface->GetQuest(state);
  3284. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3285. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3286. if (quest && faction_id > 0 && amount != 0)
  3287. quest->AddRewardFaction(faction_id, amount);
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Quest* quest = lua_interface->GetQuest(state);
  3294. if (quest) {
  3295. int32 status = lua_interface->GetInt32Value(state, 2);
  3296. quest->SetRewardStatus(status);
  3297. }
  3298. return 0;
  3299. }
  3300. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3301. if (!lua_interface)
  3302. return 0;
  3303. Quest* quest = lua_interface->GetQuest(state);
  3304. if (quest) {
  3305. string comment = lua_interface->GetStringValue(state, 2);
  3306. quest->SetRewardComment(comment);
  3307. }
  3308. return 0;
  3309. }
  3310. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3311. if (!lua_interface)
  3312. return 0;
  3313. Quest* quest = lua_interface->GetQuest(state);
  3314. if (quest) {
  3315. int32 exp = lua_interface->GetInt32Value(state, 2);
  3316. quest->SetRewardXP(exp);
  3317. }
  3318. return 0;
  3319. }
  3320. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3321. Quest* quest = lua_interface->GetQuest(state);
  3322. if (quest) {
  3323. int32 step = lua_interface->GetInt32Value(state, 2);
  3324. string description = lua_interface->GetStringValue(state, 3);
  3325. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3326. float percentage = lua_interface->GetFloatValue(state, 5);
  3327. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3328. int16 icon = lua_interface->GetInt16Value(state, 7);
  3329. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3330. const char* taskgroup = 0;
  3331. if (str_taskgroup.length() > 0)
  3332. taskgroup = str_taskgroup.c_str();
  3333. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3334. if (quest_step && icon && quantity > 0)
  3335. quest_step->SetIcon(icon);
  3336. }
  3337. return 0;
  3338. }
  3339. int EQ2Emu_lua_AddQuestStepKill(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. float percentage = lua_interface->GetFloatValue(state, 5);
  3348. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3349. int16 icon = lua_interface->GetInt16Value(state, 7);
  3350. const char* taskgroup = 0;
  3351. if (str_taskgroup.length() > 0)
  3352. taskgroup = str_taskgroup.c_str();
  3353. int32 npc_id = 0;
  3354. vector<int32>* ids = 0;
  3355. int i = 0;
  3356. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3357. if (ids == 0)
  3358. ids = new vector<int32>;
  3359. ids->push_back(npc_id);
  3360. i++;
  3361. }
  3362. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3363. if (quest_step && icon > 0 && quantity > 0)
  3364. quest_step->SetIcon(icon);
  3365. if (quest->GetPlayer()) {
  3366. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3367. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3368. }
  3369. }
  3370. return 0;
  3371. }
  3372. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3373. if (!lua_interface)
  3374. return 0;
  3375. Quest* quest = lua_interface->GetQuest(state);
  3376. if (quest) {
  3377. int32 step = lua_interface->GetInt32Value(state, 2);
  3378. string description = lua_interface->GetStringValue(state, 3);
  3379. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3380. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3381. int16 icon = lua_interface->GetInt16Value(state, 6);
  3382. const char* taskgroup = 0;
  3383. if (str_taskgroup.length() > 0)
  3384. taskgroup = str_taskgroup.c_str();
  3385. int32 npc_id = 0;
  3386. vector<int32>* ids = 0;
  3387. int i = 0;
  3388. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3389. if (ids == 0)
  3390. ids = new vector<int32>;
  3391. ids->push_back(npc_id);
  3392. i++;
  3393. }
  3394. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3395. if (quest_step && icon > 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_AddQuestStepObtainItem(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. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3412. float percentage = lua_interface->GetFloatValue(state, 5);
  3413. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3414. int16 icon = lua_interface->GetInt16Value(state, 7);
  3415. const char* taskgroup = 0;
  3416. if (str_taskgroup.length() > 0)
  3417. taskgroup = str_taskgroup.c_str();
  3418. int32 item_id = 0;
  3419. vector<int32>* ids = 0;
  3420. int i = 0;
  3421. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3422. if (ids == 0)
  3423. ids = new vector<int32>;
  3424. ids->push_back(item_id);
  3425. i++;
  3426. }
  3427. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3428. if (quest_step && icon > 0 && quantity > 0)
  3429. quest_step->SetIcon(icon);
  3430. if (quest->GetPlayer()) {
  3431. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3432. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3433. }
  3434. }
  3435. return 0;
  3436. }
  3437. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3438. if (!lua_interface)
  3439. return 0;
  3440. Quest* quest = lua_interface->GetQuest(state);
  3441. if (quest) {
  3442. int32 step = lua_interface->GetInt32Value(state, 2);
  3443. string description = lua_interface->GetStringValue(state, 3);
  3444. float max_variation = lua_interface->GetFloatValue(state, 4);
  3445. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3446. int16 icon = lua_interface->GetInt16Value(state, 6);
  3447. const char* taskgroup = 0;
  3448. if (str_taskgroup.length() > 0)
  3449. taskgroup = str_taskgroup.c_str();
  3450. vector<Location>* locations = 0;
  3451. int i = 7;
  3452. while (true) {
  3453. Location loc;
  3454. loc.x = lua_interface->GetFloatValue(state, i);
  3455. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3456. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3457. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3458. break;
  3459. if (locations == 0)
  3460. locations = new vector<Location>;
  3461. locations->push_back(loc);
  3462. i += 3;
  3463. }
  3464. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3465. if (quest_step && icon > 0)
  3466. quest_step->SetIcon(icon);
  3467. if (quest->GetPlayer()) {
  3468. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3469. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3470. }
  3471. }
  3472. return 0;
  3473. }
  3474. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3475. if (!lua_interface)
  3476. return 0;
  3477. Quest* quest = lua_interface->GetQuest(state);
  3478. if (quest) {
  3479. int32 step = lua_interface->GetInt32Value(state, 2);
  3480. string description = lua_interface->GetStringValue(state, 3);
  3481. float max_variation = lua_interface->GetFloatValue(state, 4);
  3482. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3483. int16 icon = lua_interface->GetInt16Value(state, 6);
  3484. const char* taskgroup = 0;
  3485. if (str_taskgroup.length() > 0)
  3486. taskgroup = str_taskgroup.c_str();
  3487. vector<Location>* locations = 0;
  3488. int i = 7;
  3489. while (true) {
  3490. Location loc;
  3491. loc.x = lua_interface->GetFloatValue(state, i);
  3492. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3493. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3494. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3495. break;
  3496. if (locations == 0)
  3497. locations = new vector<Location>;
  3498. locations->push_back(loc);
  3499. i += 3;
  3500. }
  3501. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3502. if (quest_step && icon > 0)
  3503. quest_step->SetIcon(icon);
  3504. if (quest->GetPlayer()) {
  3505. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3506. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3507. }
  3508. }
  3509. return 0;
  3510. }
  3511. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  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 spell_id = 0;
  3524. vector<int32>* ids = 0;
  3525. int i = 0;
  3526. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3527. if (ids == 0)
  3528. ids = new vector<int32>;
  3529. ids->push_back(spell_id);
  3530. i++;
  3531. }
  3532. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, 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_AddQuestStepCraft(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_CRAFT, 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_AddQuestStepHarvest(lua_State* state) {
  3576. if (!lua_interface)
  3577. return 0;
  3578. Quest* quest = lua_interface->GetQuest(state);
  3579. if (quest) {
  3580. int32 step = lua_interface->GetInt32Value(state, 2);
  3581. string description = lua_interface->GetStringValue(state, 3);
  3582. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3583. float percentage = lua_interface->GetFloatValue(state, 5);
  3584. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3585. int16 icon = lua_interface->GetInt16Value(state, 7);
  3586. const char* taskgroup = 0;
  3587. if (str_taskgroup.length() > 0)
  3588. taskgroup = str_taskgroup.c_str();
  3589. int32 item_id = 0;
  3590. vector<int32>* ids = 0;
  3591. int i = 0;
  3592. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3593. if (ids == 0)
  3594. ids = new vector<int32>;
  3595. ids->push_back(item_id);
  3596. i++;
  3597. }
  3598. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3599. if (quest_step && icon > 0 && quantity > 0)
  3600. quest_step->SetIcon(icon);
  3601. if (quest->GetPlayer()) {
  3602. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3603. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3604. }
  3605. }
  3606. return 0;
  3607. }
  3608. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3609. if (!lua_interface)
  3610. return 0;
  3611. Quest* quest = lua_interface->GetQuest(state);
  3612. if (quest) {
  3613. string action = lua_interface->GetStringValue(state, 2);
  3614. if (action.length() > 0)
  3615. quest->SetCompleteAction(action);
  3616. }
  3617. return 0;
  3618. }
  3619. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3620. if (!lua_interface)
  3621. return 0;
  3622. Quest* quest = lua_interface->GetQuest(state);
  3623. if (quest) {
  3624. int32 step = lua_interface->GetInt32Value(state, 2);
  3625. string action = lua_interface->GetStringValue(state, 3);
  3626. if (step > 0 && action.length() > 0)
  3627. quest->AddCompleteAction(step, action);
  3628. }
  3629. return 0;
  3630. }
  3631. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3632. if (!lua_interface)
  3633. return 0;
  3634. Quest* quest = lua_interface->GetQuest(state);
  3635. if (quest) {
  3636. int32 step = lua_interface->GetInt32Value(state, 2);
  3637. string action = lua_interface->GetStringValue(state, 3);
  3638. if (step > 0 && action.length() > 0)
  3639. quest->AddProgressAction(step, action);
  3640. }
  3641. return 0;
  3642. }
  3643. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3644. if (!lua_interface)
  3645. return 0;
  3646. Quest* quest = lua_interface->GetQuest(state);
  3647. string description = lua_interface->GetStringValue(state, 2);
  3648. if (quest && description.length() > 0)
  3649. quest->SetDescription(description);
  3650. return 0;
  3651. }
  3652. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3653. if (!lua_interface)
  3654. return 0;
  3655. Quest* quest = lua_interface->GetQuest(state);
  3656. string description = lua_interface->GetStringValue(state, 2);
  3657. if (quest && description.length() > 0)
  3658. quest->SetCompletedDescription(description);
  3659. return 0;
  3660. }
  3661. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3662. if (!lua_interface)
  3663. return 0;
  3664. Quest* quest = lua_interface->GetQuest(state);
  3665. int32 step = lua_interface->GetInt32Value(state, 2);
  3666. string description = lua_interface->GetStringValue(state, 3);
  3667. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3668. if (quest && step > 0 && description.length() > 0) {
  3669. quest->SetTaskGroupDescription(step, description, display_bullets);
  3670. if (quest->GetPlayer()) {
  3671. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3672. if (client)
  3673. client->SendQuestUpdateStep(quest, step, false);
  3674. }
  3675. }
  3676. return 0;
  3677. }
  3678. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3679. if (!lua_interface)
  3680. return 0;
  3681. Quest* quest = lua_interface->GetQuest(state);
  3682. int32 step = lua_interface->GetInt32Value(state, 2);
  3683. string description = lua_interface->GetStringValue(state, 3);
  3684. if (quest && step > 0 && description.length() > 0) {
  3685. quest->SetStepDescription(step, description);
  3686. if (quest->GetPlayer()) {
  3687. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3688. if (client)
  3689. client->SendQuestUpdateStepImmediately(quest, step);
  3690. }
  3691. }
  3692. return 0;
  3693. }
  3694. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3695. Quest* quest = lua_interface->GetQuest(state);
  3696. string zone = lua_interface->GetStringValue(state, 2);
  3697. if (quest && zone.length() > 0)
  3698. quest->SetZone(zone);
  3699. return 0;
  3700. }
  3701. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3702. if (!lua_interface)
  3703. return 0;
  3704. Quest* quest = lua_interface->GetQuest(state);
  3705. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3706. int32 coin = lua_interface->GetInt32Value(state, 3);
  3707. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3708. string rewards_str = lua_interface->GetStringValue(state, 5);
  3709. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3710. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3711. string text = lua_interface->GetStringValue(state, 8);
  3712. if (playerSpawn && playerSpawn->IsPlayer()) {
  3713. Player* player = (Player*)playerSpawn;
  3714. Client* client = player->GetZone()->GetClientBySpawn(player);
  3715. if (client) {
  3716. vector<Item*> reward_items;
  3717. vector<Item*> selectable_reward_items;
  3718. if (rewards_str.length() > 0) {
  3719. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3720. map<unsigned int, unsigned short>::iterator itr;
  3721. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3722. if (itr->first > 0) {
  3723. Item* item = new Item(master_item_list.GetItem(itr->first));
  3724. if (item) {
  3725. if (itr->second > 0)
  3726. item->details.count = itr->second;
  3727. reward_items.push_back(item);
  3728. }
  3729. }
  3730. }
  3731. }
  3732. if (select_rewards_str.length() > 0) {
  3733. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3734. map<unsigned int, unsigned short>::iterator itr;
  3735. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3736. if (itr->first > 0) {
  3737. Item* item = new Item(master_item_list.GetItem(itr->first));
  3738. if (item) {
  3739. if (itr->second > 0)
  3740. item->stack_count = itr->second;
  3741. selectable_reward_items.push_back(item);
  3742. }
  3743. }
  3744. }
  3745. }
  3746. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3747. const char* reward_type = "Quest Reward!";
  3748. if (!quest)
  3749. reward_type = "Reward!";
  3750. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3751. }
  3752. }
  3753. return 0;
  3754. }
  3755. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3756. if (!lua_interface)
  3757. return 0;
  3758. Quest* quest = lua_interface->GetQuest(state);
  3759. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3760. if (quest && spawn) {
  3761. if (spawn->IsPlayer()) {
  3762. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3763. if (client)
  3764. client->AddPendingQuestReward(quest);
  3765. }
  3766. }
  3767. return 0;
  3768. }
  3769. int EQ2Emu_lua_Harvest(lua_State* state) {
  3770. if (!lua_interface)
  3771. return 0;
  3772. Spawn* player = lua_interface->GetSpawn(state);
  3773. Spawn* node = lua_interface->GetSpawn(state, 2);
  3774. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3775. Client* client = player->GetZone()->GetClientBySpawn(player);
  3776. if (client) {
  3777. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3778. ((GroundSpawn*)node)->ProcessHarvest(client);
  3779. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3780. player->GetZone()->RemoveSpawn(node, true);
  3781. }
  3782. }
  3783. else if (player && player->IsPlayer()) {
  3784. Client* client = player->GetZone()->GetClientBySpawn(player);
  3785. if (client)
  3786. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3787. }
  3788. return 0;
  3789. }
  3790. int EQ2Emu_lua_Bind(lua_State* state) {
  3791. if (!lua_interface)
  3792. return 0;
  3793. Spawn* spawn = lua_interface->GetSpawn(state);
  3794. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3795. float x = lua_interface->GetFloatValue(state, 3);
  3796. float y = lua_interface->GetFloatValue(state, 4);
  3797. float z = lua_interface->GetFloatValue(state, 5);
  3798. float h = lua_interface->GetFloatValue(state, 6);
  3799. if (!spawn) {
  3800. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3801. return 0;
  3802. }
  3803. if (!spawn->IsPlayer()) {
  3804. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3805. return 0;
  3806. }
  3807. if (zone_id == 0) {
  3808. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3809. if (!client) {
  3810. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3811. return 0;
  3812. }
  3813. if (!client->Bind())
  3814. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3815. }
  3816. else {
  3817. Player* player = (Player*)spawn;
  3818. player->GetPlayerInfo()->SetBindZone(zone_id);
  3819. player->GetPlayerInfo()->SetBindX(x);
  3820. player->GetPlayerInfo()->SetBindY(y);
  3821. player->GetPlayerInfo()->SetBindZ(z);
  3822. player->GetPlayerInfo()->SetBindHeading(h);
  3823. }
  3824. return 0;
  3825. }
  3826. int EQ2Emu_lua_Gate(lua_State* state) {
  3827. if (!lua_interface)
  3828. return 0;
  3829. Spawn* spawn = lua_interface->GetSpawn(state);
  3830. if (spawn) {
  3831. if (spawn->IsPlayer()) {
  3832. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3833. if (client) {
  3834. if (!client->Gate())
  3835. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3836. }
  3837. }
  3838. }
  3839. return 0;
  3840. }
  3841. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3842. if (!lua_interface)
  3843. return 0;
  3844. bool ret = false;
  3845. Spawn* spawn = lua_interface->GetSpawn(state);
  3846. if (spawn) {
  3847. if (spawn->IsPlayer()) {
  3848. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3849. if (client)
  3850. ret = client->BindAllowed();
  3851. }
  3852. }
  3853. lua_interface->SetBooleanValue(state, ret);
  3854. return 1;
  3855. }
  3856. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3857. if (!lua_interface)
  3858. return 0;
  3859. bool ret = false;
  3860. Spawn* spawn = lua_interface->GetSpawn(state);
  3861. if (spawn) {
  3862. if (spawn->IsPlayer()) {
  3863. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3864. if (client)
  3865. ret = client->GateAllowed();
  3866. }
  3867. }
  3868. lua_interface->SetBooleanValue(state, ret);
  3869. return 1;
  3870. }
  3871. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3872. Spawn* spawn = lua_interface->GetSpawn(state);
  3873. if (spawn) {
  3874. lua_interface->SetBooleanValue(state, spawn->Alive());
  3875. return 1;
  3876. }
  3877. return 0;
  3878. }
  3879. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3880. if (!lua_interface)
  3881. return 0;
  3882. Spawn* spawn = lua_interface->GetSpawn(state);
  3883. if (spawn && spawn->IsEntity()) {
  3884. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3885. return 1;
  3886. }
  3887. return 0;
  3888. }
  3889. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3890. Spawn* spawn = lua_interface->GetSpawn(state);
  3891. string message = lua_interface->GetStringValue(state, 2);
  3892. string color_str = lua_interface->GetStringValue(state, 3);
  3893. int8 color = CHANNEL_NARRATIVE;
  3894. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3895. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3896. if (client) {
  3897. if (color_str.length() > 0) {
  3898. // leave for backwards compat, but all future should just use the number
  3899. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3900. color = CHANNEL_COLOR_RED;
  3901. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3902. color = CHANNEL_COLOR_YELLOW;
  3903. else
  3904. {
  3905. // use a number to specify the channel as per Commands/Commands.h defines
  3906. color = (int8)atoul(color_str.c_str());
  3907. }
  3908. }
  3909. client->SimpleMessage(color, message.c_str());
  3910. }
  3911. }
  3912. return 0;
  3913. }
  3914. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3915. Spawn* spawn = lua_interface->GetSpawn(state);
  3916. string message = lua_interface->GetStringValue(state, 2);
  3917. int8 red = lua_interface->GetInt8Value(state, 3);
  3918. int8 green = lua_interface->GetInt8Value(state, 4);
  3919. int8 blue = lua_interface->GetInt8Value(state, 5);
  3920. if (!spawn) {
  3921. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3922. return 0;
  3923. }
  3924. int32 words = ::CountWordsInString(message.c_str());
  3925. if (words < 5)
  3926. words = 5;
  3927. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3928. if (client)
  3929. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3930. return 0;
  3931. }
  3932. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3933. Spawn* spawn = lua_interface->GetSpawn(state);
  3934. int8 param = lua_interface->GetInt8Value(state, 2);
  3935. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3936. int8 value = lua_interface->GetInt8Value(state, 4);
  3937. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3938. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3939. if (client) {
  3940. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3941. switch (param) {
  3942. case 1: {
  3943. packet->setDataByName("parameter1", param_value);
  3944. break;
  3945. }
  3946. case 2: {
  3947. packet->setDataByName("parameter2", param_value);
  3948. break;
  3949. }
  3950. case 3: {
  3951. packet->setDataByName("parameter3", param_value);
  3952. break;
  3953. }
  3954. case 4: {
  3955. packet->setDataByName("parameter4", param_value);
  3956. break;
  3957. }
  3958. case 5: {
  3959. packet->setDataByName("parameter5", param_value);
  3960. break;
  3961. }
  3962. }
  3963. packet->setDataByName("value", value);
  3964. client->QueuePacket(packet->serialize());
  3965. safe_delete(packet);
  3966. }
  3967. }
  3968. return 0;
  3969. }
  3970. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3971. Spawn* spawn = lua_interface->GetSpawn(state);
  3972. if (spawn && spawn->IsPlayer()) {
  3973. if (((Player*)spawn)->GetIsTracking())
  3974. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3975. else
  3976. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3977. }
  3978. return 0;
  3979. }
  3980. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3981. Spawn* player = lua_interface->GetSpawn(state);
  3982. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3983. string name = lua_interface->GetStringValue(state, 3);
  3984. float distance = lua_interface->GetFloatValue(state, 4);
  3985. string command = lua_interface->GetStringValue(state, 5);
  3986. string error_text = lua_interface->GetStringValue(state, 6);
  3987. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3988. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3989. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3990. if (spawn) {
  3991. if (distance == 0)
  3992. distance = 10.0f;
  3993. if (command.length() == 0)
  3994. command = name;
  3995. if (command.length() < 1 && name.length() < 1)
  3996. {
  3997. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3998. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3999. spawn->RemovePrimaryCommands();
  4000. }
  4001. else
  4002. {
  4003. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4004. }
  4005. }
  4006. return 0;
  4007. }
  4008. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4009. if (!lua_interface)
  4010. return 0;
  4011. Spawn* player = lua_interface->GetSpawn(state);
  4012. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4013. int16 tier = lua_interface->GetInt16Value(state, 3);
  4014. if (player && player->IsPlayer()) {
  4015. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4016. return 1;
  4017. }
  4018. return 0;
  4019. }
  4020. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4021. if (!lua_interface)
  4022. return 0;
  4023. Spawn* player = lua_interface->GetSpawn(state);
  4024. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4025. int16 tier = lua_interface->GetInt16Value(state, 3);
  4026. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4027. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4028. bool add_to_hotbar = true;
  4029. if (num_args > 4) {
  4030. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4031. }
  4032. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4033. if (player && spell && player->IsPlayer()) {
  4034. Client* client = player->GetClient();
  4035. if (client) {
  4036. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4037. {
  4038. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4039. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4040. client->GetPlayer()->UnlockSpell(spell);
  4041. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4042. }
  4043. else
  4044. {
  4045. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4046. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4047. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4048. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4049. client->GetPlayer()->UnlockSpell(spell);
  4050. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4051. }
  4052. //if (client ) {
  4053. // ((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);
  4054. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4055. if (outapp)
  4056. client->QueuePacket(outapp);
  4057. }
  4058. }
  4059. return 0;
  4060. }
  4061. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4062. if (!lua_interface)
  4063. return 0;
  4064. Spawn* player = lua_interface->GetSpawn(state);
  4065. if (player && player->IsPlayer()) {
  4066. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4067. return 1;
  4068. }
  4069. return 0;
  4070. }
  4071. int EQ2Emu_lua_Attack(lua_State* state) {
  4072. if (lua_interface) {
  4073. Spawn* npc = lua_interface->GetSpawn(state);
  4074. Spawn* player = lua_interface->GetSpawn(state, 2);
  4075. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4076. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4077. }
  4078. return 0;
  4079. }
  4080. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4081. if (lua_interface) {
  4082. Spawn* target = lua_interface->GetSpawn(state);
  4083. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4084. if (target && target->GetZone())
  4085. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4086. }
  4087. return 0;
  4088. }
  4089. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4090. Spawn* player;
  4091. if (lua_interface) {
  4092. player = lua_interface->GetSpawn(state);
  4093. if (player && player->IsPlayer()) {
  4094. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4095. return 1;
  4096. }
  4097. }
  4098. return 0;
  4099. }
  4100. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4101. Spawn* player;
  4102. Client* client;
  4103. if (lua_interface) {
  4104. player = lua_interface->GetSpawn(state);
  4105. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4106. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4107. client->HandInCollections();
  4108. }
  4109. return 0;
  4110. }
  4111. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4112. Spawn* widget;
  4113. if (lua_interface) {
  4114. widget = lua_interface->GetSpawn(state);
  4115. if (widget && widget->IsWidget())
  4116. ((Widget*)widget)->HandleUse(nullptr, "");
  4117. }
  4118. return 0;
  4119. }
  4120. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4121. Spawn* spawn = 0;
  4122. int32 primary_list = 0;
  4123. int32 secondary_list = 0;
  4124. if (lua_interface) {
  4125. spawn = lua_interface->GetSpawn(state);
  4126. primary_list = lua_interface->GetInt32Value(state, 2);
  4127. secondary_list = lua_interface->GetInt32Value(state, 3);
  4128. if (!spawn->IsNPC()) {
  4129. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4130. return 0;
  4131. }
  4132. NPC* npc = (NPC*)spawn;
  4133. npc->SetPrimarySpellList(primary_list);
  4134. npc->SetSecondarySpellList(secondary_list);
  4135. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4136. }
  4137. return 0;
  4138. }
  4139. int EQ2Emu_lua_GetPet(lua_State* state) {
  4140. if (!lua_interface)
  4141. return 0;
  4142. Spawn* spawn = lua_interface->GetSpawn(state);
  4143. if (spawn) {
  4144. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4145. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4146. return 1;
  4147. }
  4148. }
  4149. return 0;
  4150. }
  4151. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4152. if (!lua_interface)
  4153. return 0;
  4154. Spawn* spawn = lua_interface->GetSpawn(state);
  4155. if (spawn) {
  4156. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4157. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4158. return 1;
  4159. }
  4160. }
  4161. return 0;
  4162. }
  4163. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4164. if (!lua_interface)
  4165. return 0;
  4166. Spawn* spawn = lua_interface->GetSpawn(state);
  4167. if (spawn) {
  4168. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4169. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4170. return 1;
  4171. }
  4172. }
  4173. return 0;
  4174. }
  4175. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4176. if (!lua_interface)
  4177. return 0;
  4178. Spawn* spawn = lua_interface->GetSpawn(state);
  4179. if (spawn) {
  4180. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4181. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4182. return 1;
  4183. }
  4184. }
  4185. return 0;
  4186. }
  4187. int EQ2Emu_lua_Charm(lua_State* state) {
  4188. if (!lua_interface)
  4189. return 0;
  4190. Spawn* owner = lua_interface->GetSpawn(state);
  4191. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4192. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4193. if (!luaspell) {
  4194. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4195. return 0;
  4196. }
  4197. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4198. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4199. pet->SetPet(true);
  4200. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4201. ((NPC*)pet)->SetOwner((Entity*)owner);
  4202. // If owner is player and player does not have a summoned pet set the players charsheet
  4203. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4204. Player* player = (Player*)owner;
  4205. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4206. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4207. player->GetInfoStruct()->set_pet_movement(2);
  4208. player->GetInfoStruct()->set_pet_behavior(3);
  4209. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4210. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4211. // Make sure the values get sent to the client
  4212. player->SetCharSheetChanged(true);
  4213. }
  4214. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4215. pet->SetSpawnScript("");
  4216. // Set faction to the same as the owner
  4217. pet->SetFactionID(owner->GetFactionID());
  4218. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4219. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4220. // Clear hate list
  4221. ((NPC*)pet)->Brain()->ClearHate();
  4222. // Set the brain to a pet brain
  4223. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4224. }
  4225. return 0;
  4226. }
  4227. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4228. if (!lua_interface)
  4229. return 0;
  4230. Spawn* spawn = lua_interface->GetSpawn(state);
  4231. if (!spawn) {
  4232. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4233. return 0;
  4234. }
  4235. vector<Spawn*> groupMembers;
  4236. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4237. groupMembers = *spawn->GetSpawnGroup();
  4238. }
  4239. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4240. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4241. deque<GroupMemberInfo*>::iterator itr;
  4242. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4243. if (group)
  4244. {
  4245. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4246. deque<GroupMemberInfo*>* members = group->GetMembers();
  4247. GroupMemberInfo* info = 0;
  4248. for (itr = members->begin(); itr != members->end(); itr++) {
  4249. info = *itr;
  4250. if (info->client)
  4251. groupMembers.push_back(info->client->GetPlayer());
  4252. }
  4253. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4254. }
  4255. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4256. }
  4257. else
  4258. return 0;
  4259. lua_createtable(state, groupMembers.size(), 0);
  4260. int newTable = lua_gettop(state);
  4261. for (int32 i = 0; i < groupMembers.size(); i++) {
  4262. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4263. lua_rawseti(state, newTable, i + 1);
  4264. }
  4265. return 1;
  4266. }
  4267. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4268. if (!lua_interface)
  4269. return 0;
  4270. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4271. lua_interface->SetOptionWindowValue(state, option_window);
  4272. return 1;
  4273. }
  4274. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4275. if (!lua_interface)
  4276. return 0;
  4277. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4278. if (option_window) {
  4279. OptionWindowOption option_window_option;
  4280. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4281. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4282. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4283. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4284. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4285. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4286. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4287. option_window->push_back(option_window_option);
  4288. }
  4289. return 0;
  4290. }
  4291. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4292. if (!lua_interface)
  4293. return 0;
  4294. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4295. Spawn* player = lua_interface->GetSpawn(state, 2);
  4296. string window_title = lua_interface->GetStringValue(state, 3);
  4297. string cancel_command = lua_interface->GetStringValue(state, 4);
  4298. Client* client = player->GetZone()->GetClientBySpawn(player);
  4299. if (option_window && window_title.length() > 0 && client) {
  4300. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4301. if (!packet)
  4302. return 0;
  4303. packet->setDataByName("title_text", window_title.c_str());
  4304. if (cancel_command.length() > 0)
  4305. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4306. packet->setArrayLengthByName("num_selections", option_window->size());
  4307. vector<OptionWindowOption>::iterator itr;
  4308. int8 i = 0;
  4309. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4310. OptionWindowOption opt = *itr;
  4311. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4312. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4313. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4314. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4315. if (opt.optionCommand.length() > 0)
  4316. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4317. if (opt.optionConfirmTitle.length() > 0)
  4318. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4319. i++;
  4320. }
  4321. client->QueuePacket(packet->serialize());
  4322. safe_delete(option_window);
  4323. safe_delete(packet);
  4324. }
  4325. return 0;
  4326. }
  4327. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4328. if (!lua_interface)
  4329. return 0;
  4330. Spawn* spawn = lua_interface->GetSpawn(state);
  4331. if (spawn) {
  4332. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4333. return 1;
  4334. }
  4335. else
  4336. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4337. return 0;
  4338. }
  4339. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4340. if (!lua_interface)
  4341. return 0;
  4342. Spawn* spawn = lua_interface->GetSpawn(state);
  4343. if (spawn) {
  4344. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4345. return 1;
  4346. }
  4347. else
  4348. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4349. return 0;
  4350. }
  4351. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4352. if (!lua_interface)
  4353. return 0;
  4354. Spawn* spawn = lua_interface->GetSpawn(state);
  4355. if (spawn) {
  4356. int8 class_id = spawn->GetTradeskillClass();
  4357. // Need to add 42 for the offset in the array
  4358. class_id += 44;
  4359. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4360. return 1;
  4361. }
  4362. else
  4363. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4364. return 0;
  4365. }
  4366. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4367. if (!lua_interface)
  4368. return 0;
  4369. Spawn* spawn = lua_interface->GetSpawn(state);
  4370. int16 level = lua_interface->GetInt8Value(state, 2);
  4371. if (spawn) {
  4372. if (spawn->IsPlayer())
  4373. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4374. else
  4375. spawn->SetTSLevel(level);
  4376. }
  4377. else
  4378. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4379. return 0;
  4380. }
  4381. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4382. if (!lua_interface)
  4383. return 0;
  4384. Spawn* spawn = lua_interface->GetSpawn(state);
  4385. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4386. if (spawn) {
  4387. spawn->SetAttackable(attackable);
  4388. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4389. }
  4390. return 0;
  4391. }
  4392. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4393. // Check to see if we have a valid lua_interface
  4394. if (!lua_interface)
  4395. return 0;
  4396. // Get the spawn that is getting the pet
  4397. Spawn* spawn = lua_interface->GetSpawn(state);
  4398. // Get the DB ID of the pet
  4399. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4400. // The max level the pet can gain
  4401. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4402. // Get the spell that this command was called from
  4403. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4404. // Check to make sure the spawn pointer is valid
  4405. if (!spawn) {
  4406. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4407. return 0;
  4408. }
  4409. // Check to make sure the spawn is an entity
  4410. if (!spawn->IsEntity()) {
  4411. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4412. return 0;
  4413. }
  4414. // Check to make sure the spawn doesn't already have a pet of this type
  4415. if (((Entity*)spawn)->GetPet()) {
  4416. if (spawn->IsPlayer()) {
  4417. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4418. if (client)
  4419. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4420. }
  4421. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4422. return 0;
  4423. }
  4424. // Check to see if the DB ID for the pet is set
  4425. if (pet_id == 0) {
  4426. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4427. return 0;
  4428. }
  4429. // Check to see if the pointer to the spell is valid
  4430. if (!luaspell) {
  4431. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4432. return 0;
  4433. }
  4434. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4435. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4436. if (!pet) {
  4437. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4438. return 0;
  4439. }
  4440. // Check to make sure the pet is an npc
  4441. if (!pet->IsNPC()) {
  4442. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4443. return 0;
  4444. }
  4445. // Spawn the pet at the same location as the owner
  4446. pet->SetX(spawn->GetX());
  4447. pet->SetY(spawn->GetY());
  4448. pet->SetZ(spawn->GetZ());
  4449. pet->SetLocation(spawn->GetLocation());
  4450. pet->SetHeading(spawn->GetHeading());
  4451. spawn->GetZone()->AddSpawn(pet);
  4452. /*
  4453. const char* spawn_script = world.GetSpawnScript(pet_id);
  4454. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4455. spawn->SetSpawnScript(string(spawn_script));
  4456. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4457. }*/
  4458. // Get a random pet name
  4459. string random_pet_name;
  4460. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4461. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4462. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4463. // If player set various values for the char sheet (pet window)
  4464. if (spawn->IsPlayer()) {
  4465. Player* player = (Player*)spawn;
  4466. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4467. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4468. player->GetInfoStruct()->set_pet_movement(2);
  4469. player->GetInfoStruct()->set_pet_behavior(3);
  4470. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4471. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4472. // Make sure the values get sent to the client
  4473. player->SetCharSheetChanged(true);
  4474. }
  4475. // Set the pets name
  4476. pet->SetName(random_pet_name.c_str());
  4477. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4478. if (max_level > 0)
  4479. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4480. else
  4481. pet->SetLevel(spawn->GetLevel());
  4482. // Set the max level this pet can reach
  4483. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4484. // Set the faction of the pet to the same faction as the owner
  4485. pet->SetFactionID(spawn->GetFactionID());
  4486. // Set the spawn as a pet
  4487. pet->SetPet(true);
  4488. // Give a pointer of the owner to the pet
  4489. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4490. // Give a pointer of the pet to the owner
  4491. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4492. // Set the pet type
  4493. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4494. // Set the spell id used to create this pet
  4495. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4496. // Set the spell tier used to create this pet
  4497. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4498. // Set the pets spawn type to 6
  4499. pet->SetSpawnType(6);
  4500. // Set the pets brain
  4501. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4502. // Check to see if the pet has a subtitle
  4503. if (strlen(pet->GetSubTitle()) > 0) {
  4504. // Add the players name to the front of the sub title
  4505. string pet_subtitle;
  4506. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4507. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4508. // Set the pets subtitle to the new one
  4509. pet->SetSubTitle(pet_subtitle.c_str());
  4510. }
  4511. // Add the "Pet Options" entity command to the pet
  4512. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4513. // Set the pet as the return value for this function
  4514. lua_interface->SetSpawnValue(state, pet);
  4515. return 1;
  4516. }
  4517. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4518. if (!lua_interface)
  4519. return 0;
  4520. Spawn* spawn = lua_interface->GetSpawn(state);
  4521. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4522. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4523. if (!spawn) {
  4524. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4525. return 0;
  4526. }
  4527. if (!spawn->IsEntity()) {
  4528. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4529. return 0;
  4530. }
  4531. if (((Entity*)spawn)->GetDeityPet()) {
  4532. if (spawn->IsPlayer()) {
  4533. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4534. if (client)
  4535. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4536. }
  4537. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4538. return 0;
  4539. }
  4540. if (pet_id == 0) {
  4541. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4542. return 0;
  4543. }
  4544. if (!luaspell) {
  4545. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4546. return 0;
  4547. }
  4548. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4549. if (!pet) {
  4550. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4551. return 0;
  4552. }
  4553. if (!pet->IsNPC()) {
  4554. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4555. return 0;
  4556. }
  4557. pet->SetX(spawn->GetX());
  4558. pet->SetY(spawn->GetY());
  4559. pet->SetZ(spawn->GetZ());
  4560. pet->SetLocation(spawn->GetLocation());
  4561. pet->SetHeading(spawn->GetHeading());
  4562. spawn->GetZone()->AddSpawn(pet);
  4563. string random_pet_name;
  4564. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4565. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4566. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4567. pet->SetName(random_pet_name.c_str());
  4568. pet->SetLevel(spawn->GetLevel());
  4569. pet->SetFactionID(spawn->GetFactionID());
  4570. pet->SetPet(true);
  4571. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4572. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4573. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4574. pet->SetSpawnType(6);
  4575. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4576. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4577. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4578. if (strlen(pet->GetSubTitle()) > 0) {
  4579. string pet_subtitle;
  4580. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4581. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4582. pet->SetSubTitle(pet_subtitle.c_str());
  4583. }
  4584. // deity and cosmetic pets are not attackable
  4585. pet->SetAttackable(false);
  4586. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4587. lua_interface->SetSpawnValue(state, pet);
  4588. return 1;
  4589. }
  4590. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4591. if (!lua_interface)
  4592. return 0;
  4593. Spawn* spawn = lua_interface->GetSpawn(state);
  4594. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4595. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4596. if (!spawn) {
  4597. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4598. return 0;
  4599. }
  4600. if (!spawn->IsEntity()) {
  4601. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4602. return 0;
  4603. }
  4604. if (((Entity*)spawn)->GetCosmeticPet()) {
  4605. if (spawn->IsPlayer()) {
  4606. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4607. if (client)
  4608. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4609. }
  4610. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4611. return 0;
  4612. }
  4613. if (pet_id == 0) {
  4614. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4615. return 0;
  4616. }
  4617. if (!luaspell) {
  4618. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4619. return 0;
  4620. }
  4621. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4622. if (!pet) {
  4623. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4624. return 0;
  4625. }
  4626. if (!pet->IsNPC()) {
  4627. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4628. return 0;
  4629. }
  4630. pet->SetX(spawn->GetX());
  4631. pet->SetY(spawn->GetY());
  4632. pet->SetZ(spawn->GetZ());
  4633. pet->SetLocation(spawn->GetLocation());
  4634. pet->SetHeading(spawn->GetHeading());
  4635. spawn->GetZone()->AddSpawn(pet);
  4636. string random_pet_name;
  4637. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4638. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4639. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4640. pet->SetName(random_pet_name.c_str());
  4641. pet->SetLevel(spawn->GetLevel());
  4642. pet->SetFactionID(spawn->GetFactionID());
  4643. pet->SetPet(true);
  4644. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4645. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4646. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4647. pet->SetSpawnType(6);
  4648. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4649. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4650. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4651. if (strlen(pet->GetSubTitle()) > 0) {
  4652. string pet_subtitle;
  4653. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4654. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4655. pet->SetSubTitle(pet_subtitle.c_str());
  4656. }
  4657. pet->SetAttackable(false);
  4658. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4659. lua_interface->SetSpawnValue(state, pet);
  4660. return 1;
  4661. }
  4662. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4663. if (!lua_interface)
  4664. return 0;
  4665. Spawn* spawn = lua_interface->GetSpawn(state);
  4666. if (!spawn) {
  4667. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4668. return 0;
  4669. }
  4670. if (!spawn->IsPet()) {
  4671. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4672. return 0;
  4673. }
  4674. if (!((NPC*)spawn)->IsDismissing())
  4675. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4676. return 0;
  4677. }
  4678. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4679. if (!lua_interface)
  4680. return 0;
  4681. Quest* quest = lua_interface->GetQuest(state);
  4682. if (!quest) {
  4683. 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));
  4684. return 0;
  4685. }
  4686. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4687. if (feather_color > 0)
  4688. quest->SetFeatherColor(feather_color);
  4689. return 0;
  4690. }
  4691. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4692. if (!lua_interface)
  4693. return 0;
  4694. Spawn* spawn = lua_interface->GetSpawn(state);
  4695. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4696. if (!spawn) {
  4697. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4698. return 0;
  4699. }
  4700. if (!spawn2) {
  4701. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4702. return 0;
  4703. }
  4704. spawn->RemoveSpawnAccess(spawn2);
  4705. return 0;
  4706. }
  4707. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4708. if (!lua_interface)
  4709. return 0;
  4710. ZoneServer* zone = lua_interface->GetZone(state);
  4711. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4712. if (!zone) {
  4713. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4714. return 0;
  4715. }
  4716. if (location_id == 0) {
  4717. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4718. return 0;
  4719. }
  4720. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4721. if (!location) {
  4722. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4723. return 0;
  4724. }
  4725. Spawn* spawn = 0;
  4726. if (location->entities[0]) {
  4727. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4728. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4729. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4730. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4731. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4732. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4733. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4734. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4735. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4736. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4737. if (spawn) {
  4738. const char* script = 0;
  4739. for (int x = 0; x < 3; x++) {
  4740. switch (x) {
  4741. case 0:
  4742. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4743. break;
  4744. case 1:
  4745. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4746. break;
  4747. case 2:
  4748. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4749. break;
  4750. }
  4751. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4752. spawn->SetSpawnScript(string(script));
  4753. break;
  4754. }
  4755. }
  4756. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4757. lua_interface->SetSpawnValue(state, spawn);
  4758. return 1;
  4759. }
  4760. else {
  4761. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4762. safe_delete(spawn);
  4763. }
  4764. }
  4765. return 0;
  4766. }
  4767. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4768. if (!lua_interface)
  4769. return 0;
  4770. Spawn* caster = lua_interface->GetSpawn(state);
  4771. Spawn* target = lua_interface->GetSpawn(state, 2);
  4772. int32 id = lua_interface->GetInt32Value(state, 3);
  4773. string command = lua_interface->GetStringValue(state, 4);
  4774. if (!caster) {
  4775. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4776. return 0;
  4777. }
  4778. if (!target) {
  4779. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4780. return 0;
  4781. }
  4782. if (!caster->IsPlayer()) {
  4783. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4784. return 0;
  4785. }
  4786. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4787. if (!entity_command) {
  4788. 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());
  4789. return 0;
  4790. }
  4791. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4792. if (!client) {
  4793. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4794. return 0;
  4795. }
  4796. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4797. return 0;
  4798. }
  4799. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4800. if (!lua_interface)
  4801. return 0;
  4802. Spawn* spawn = lua_interface->GetSpawn(state);
  4803. if (!spawn) {
  4804. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4805. return 0;
  4806. }
  4807. if (!spawn->IsNPC()) {
  4808. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4809. return 0;
  4810. }
  4811. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4812. return 0;
  4813. }
  4814. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4815. if (!lua_interface)
  4816. return 0;
  4817. Spawn* spawn = lua_interface->GetSpawn(state);
  4818. int16 tick = lua_interface->GetInt16Value(state, 2);
  4819. if (!spawn) {
  4820. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4821. return 0;
  4822. }
  4823. if (!spawn->IsNPC()) {
  4824. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4825. return 0;
  4826. }
  4827. if (tick < 20) {
  4828. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4829. return 0;
  4830. }
  4831. ((NPC*)spawn)->Brain()->SetTick(tick);
  4832. return 0;
  4833. }
  4834. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4835. if (!lua_interface)
  4836. return 0;
  4837. Spawn* spawn = lua_interface->GetSpawn(state);
  4838. Spawn* target = lua_interface->GetSpawn(state, 2);
  4839. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4840. if (!spawn) {
  4841. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4842. return 0;
  4843. }
  4844. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4845. spawn->SetFollowTarget(target, follow_distance);
  4846. return 0;
  4847. }
  4848. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4849. if (!lua_interface)
  4850. return 0;
  4851. Spawn* spawn = lua_interface->GetSpawn(state);
  4852. if (!spawn) {
  4853. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4854. return 0;
  4855. }
  4856. Spawn* target = spawn->GetFollowTarget();
  4857. if (target) {
  4858. lua_interface->SetSpawnValue(state, target);
  4859. return 1;
  4860. }
  4861. return 0;
  4862. }
  4863. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4864. if (!lua_interface)
  4865. return 0;
  4866. Spawn* spawn = lua_interface->GetSpawn(state);
  4867. if (!spawn) {
  4868. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4869. return 0;
  4870. }
  4871. if (spawn->following)
  4872. spawn->following = false;
  4873. else
  4874. spawn->following = true;
  4875. return 0;
  4876. }
  4877. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4878. if (!lua_interface)
  4879. return 0;
  4880. Spawn* spawn = lua_interface->GetSpawn(state);
  4881. if (!spawn) {
  4882. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4883. return 0;
  4884. }
  4885. lua_interface->SetBooleanValue(state, spawn->following);
  4886. return 1;
  4887. }
  4888. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4889. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4890. // I will attempt to explain how this function works for future refrence
  4891. // Fist lets make sure lua_interface is valid, if not return out
  4892. if (!lua_interface)
  4893. return 0;
  4894. // Next we grab the first 2 params same as we usually would
  4895. Spawn* spawn = lua_interface->GetSpawn(state);
  4896. string var = lua_interface->GetStringValue(state, 2);
  4897. // 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
  4898. // 1 = Spawn
  4899. // 2 = Zone
  4900. // 3 = Item
  4901. // 4 = Quest
  4902. // 5 = String
  4903. // 6 = nil (null)
  4904. int8 dataType = 0;
  4905. // Define pointers for each potential type
  4906. Spawn* spawnVal = 0;
  4907. ZoneServer* zone = 0;
  4908. Item* item = 0;
  4909. Quest* quest = 0;
  4910. string val;
  4911. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4912. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4913. // options window are also light user data be we do not handle those.
  4914. // We check with lua_islightuserdata(lua_State*, index)
  4915. if (lua_islightuserdata(state, 3)) {
  4916. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4917. // and convert it to LUAUserData*
  4918. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4919. // Check to make sure the data we got is valid, if not give an error
  4920. if (!data || !data->IsCorrectlyInitialized()) {
  4921. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4922. }
  4923. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4924. else if (data->IsSpawn()) {
  4925. spawnVal = data->spawn;
  4926. dataType = 1;
  4927. }
  4928. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4929. else if (data->IsZone()) {
  4930. zone = data->zone;
  4931. dataType = 2;
  4932. }
  4933. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4934. else if (data->IsItem()) {
  4935. item = data->item;
  4936. dataType = 3;
  4937. }
  4938. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4939. else if (data->IsQuest()) {
  4940. quest = data->quest;
  4941. dataType = 4;
  4942. }
  4943. }
  4944. // Wasn't light user data, check if it is nil(null)
  4945. else if (lua_isnil(state, 3)) {
  4946. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4947. dataType = 6;
  4948. }
  4949. // Wasn't light user data or nil (null), must be a string
  4950. else {
  4951. // Set the string and dataType variable
  4952. val = lua_interface->GetStringValue(state, 3);
  4953. dataType = 5;
  4954. }
  4955. // We now have all the params, lets check to make sure they are valid
  4956. if (!spawn) {
  4957. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4958. return 0;
  4959. }
  4960. if (var.length() == 0) {
  4961. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4962. return 0;
  4963. }
  4964. if (dataType == 0) {
  4965. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4966. return 0;
  4967. }
  4968. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4969. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4970. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4971. switch (dataType) {
  4972. case 1:
  4973. // 1 = Spawn
  4974. spawn->AddTempVariable(var, spawnVal);
  4975. break;
  4976. case 2:
  4977. // 2 = Zone
  4978. spawn->AddTempVariable(var, zone);
  4979. break;
  4980. case 3:
  4981. // 3 = Item
  4982. spawn->AddTempVariable(var, item);
  4983. break;
  4984. case 4:
  4985. // 4 = Quest
  4986. spawn->AddTempVariable(var, quest);
  4987. break;
  4988. case 5:
  4989. // 5 = String
  4990. spawn->AddTempVariable(var, val);
  4991. break;
  4992. case 6:
  4993. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4994. spawn->DeleteTempVariable(var);
  4995. break;
  4996. }
  4997. // And we are done so return out
  4998. return 0;
  4999. }
  5000. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5001. if (!lua_interface)
  5002. return 0;
  5003. Spawn* spawn = lua_interface->GetSpawn(state);
  5004. string var = lua_interface->GetStringValue(state, 2);
  5005. if (!spawn) {
  5006. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5007. return 0;
  5008. }
  5009. if (var.length() == 0) {
  5010. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5011. return 0;
  5012. }
  5013. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5014. int8 type = spawn->GetTempVariableType(var);
  5015. Spawn* spawn2 = 0;
  5016. ZoneServer* zone = 0;
  5017. Item* item = 0;
  5018. Quest* quest = 0;
  5019. // Set the lua function return value based on the type of data the variable contains
  5020. switch (type) {
  5021. case 1:
  5022. spawn2 = spawn->GetTempVariableSpawn(var);
  5023. if (!spawn2)
  5024. return 0;
  5025. lua_interface->SetSpawnValue(state, spawn2);
  5026. break;
  5027. case 2:
  5028. zone = spawn->GetTempVariableZone(var);
  5029. if (!zone)
  5030. return 0;
  5031. lua_interface->SetZoneValue(state, zone);
  5032. break;
  5033. case 3:
  5034. item = spawn->GetTempVariableItem(var);
  5035. if (!item)
  5036. return 0;
  5037. lua_interface->SetItemValue(state, item);
  5038. break;
  5039. case 4:
  5040. quest = spawn->GetTempVariableQuest(var);
  5041. if (!quest)
  5042. return 0;
  5043. lua_interface->SetQuestValue(state, quest);
  5044. break;
  5045. case 5:
  5046. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5047. break;
  5048. default:
  5049. // Not a valid type then the variable was not set so return out
  5050. return 0;
  5051. }
  5052. // Return value was set so return out
  5053. return 1;
  5054. }
  5055. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5056. {
  5057. if (!lua_interface)
  5058. return 0;
  5059. Quest* quest = lua_interface->GetQuest(state);
  5060. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5061. string description = lua_interface->GetStringValue(state, 3);
  5062. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5063. if (!quest) {
  5064. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5065. lua_interface->SetBooleanValue(state, false);
  5066. return 1;
  5067. }
  5068. if (!spawn) {
  5069. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5070. lua_interface->SetBooleanValue(state, false);
  5071. return 1;
  5072. }
  5073. if (!spawn->IsPlayer()) {
  5074. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5075. lua_interface->SetBooleanValue(state, false);
  5076. return 1;
  5077. }
  5078. if (item_id == 0) {
  5079. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5080. lua_interface->SetBooleanValue(state, false);
  5081. return 1;
  5082. }
  5083. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5084. if (!client) {
  5085. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5086. lua_interface->SetBooleanValue(state, false);
  5087. return 1;
  5088. }
  5089. Item* item = master_item_list.GetItem(item_id);
  5090. if (!item) {
  5091. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5092. lua_interface->SetBooleanValue(state, false);
  5093. return 1;
  5094. }
  5095. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  5096. if (packet) {
  5097. packet->setDataByName("title", "Quest Reward!");
  5098. packet->setDataByName("name", quest->GetName());
  5099. packet->setDataByName("description", description.c_str());
  5100. packet->setDataByName("level", quest->GetLevel());
  5101. packet->setArrayLengthByName("num_rewards", 1);
  5102. packet->setArrayDataByName("reward_id", item->details.item_id);
  5103. if (client->GetVersion() < 860)
  5104. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  5105. else if (client->GetVersion() < 1193)
  5106. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  5107. else
  5108. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  5109. client->QueuePacket(packet->serialize());
  5110. safe_delete(packet);
  5111. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  5112. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  5113. return 1;
  5114. }
  5115. lua_interface->SetBooleanValue(state, false);
  5116. return 1;
  5117. }
  5118. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5119. if (!lua_interface)
  5120. return 0;
  5121. Quest* quest = lua_interface->GetQuest(state);
  5122. if (!quest) {
  5123. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5124. return 0;
  5125. }
  5126. quest->SetRepeatable(true);
  5127. return 0;
  5128. }
  5129. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5130. if (!lua_interface)
  5131. return 0;
  5132. Spawn* spawn = lua_interface->GetSpawn(state);
  5133. if (!spawn) {
  5134. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5135. return 0;
  5136. }
  5137. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5138. string ret = classes.GetClassNameCase(base_class);
  5139. if (ret.length() > 0) {
  5140. lua_interface->SetStringValue(state, ret.c_str());
  5141. return 1;
  5142. }
  5143. return 0;
  5144. }
  5145. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5146. if (!lua_interface)
  5147. return 0;
  5148. Spawn* player = lua_interface->GetSpawn(state);
  5149. if (player && player->IsPlayer()) {
  5150. Client* client = player->GetClient();
  5151. if (client)
  5152. client->SendWaypoints();
  5153. }
  5154. return 0;
  5155. }
  5156. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5157. if (!lua_interface)
  5158. return 0;
  5159. Spawn* player = lua_interface->GetSpawn(state);
  5160. string name = lua_interface->GetStringValue(state, 2);
  5161. int32 type = lua_interface->GetInt32Value(state, 3);
  5162. if (type == 0)
  5163. type = 2;
  5164. if (name.length() > 0) {
  5165. if (player && player->IsPlayer()) {
  5166. Client* client = player->GetClient();
  5167. if (client)
  5168. client->AddWaypoint(name, type);
  5169. }
  5170. }
  5171. return 0;
  5172. }
  5173. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5174. if (!lua_interface)
  5175. return 0;
  5176. Spawn* player = lua_interface->GetSpawn(state);
  5177. string name = lua_interface->GetStringValue(state, 2);
  5178. if (name.length() > 0) {
  5179. if (player && player->IsPlayer()) {
  5180. Client* client = player->GetClient();
  5181. if (client)
  5182. client->RemoveWaypoint(name);
  5183. }
  5184. }
  5185. return 0;
  5186. }
  5187. int EQ2Emu_lua_AddWard(lua_State* state) {
  5188. if (!lua_interface)
  5189. return 0;
  5190. int32 damage = lua_interface->GetInt32Value(state);
  5191. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5192. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5193. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5194. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5195. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5196. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5197. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5198. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5199. bool ward_was_added = false;
  5200. ZoneServer* zone = spell->caster->GetZone();
  5201. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5202. for (int32 i = 0; i < spell->targets.size(); i++) {
  5203. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5204. if (!target)
  5205. continue;
  5206. if (target->IsEntity()) {
  5207. // If the ward is already active remove it
  5208. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5209. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5210. // Create new ward info
  5211. WardInfo* ward = new WardInfo;
  5212. ward->Spell = spell;
  5213. ward->BaseDamage = damage;
  5214. ward->DamageLeft = damage;
  5215. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5216. ward->keepWard = keepWard;
  5217. ward->WardType = wardType;
  5218. if (damageAbsorptionPercent > 100)
  5219. damageAbsorptionPercent = 100;
  5220. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5221. if (damageAbsorptionMaxHealthPercent > 100)
  5222. damageAbsorptionMaxHealthPercent = 100;
  5223. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5224. ward->RedirectDamagePercent = redirectDamagePercent;
  5225. ward->LastRedirectDamage = 0;
  5226. ward->LastAbsorbedDamage = 0;
  5227. ward->HitCount = 0;
  5228. spell->num_triggers = maxHitCount;
  5229. spell->had_triggers = true;
  5230. spell->cancel_after_all_triggers = false;
  5231. ward->MaxHitCount = maxHitCount;
  5232. if (wardType == WARD_TYPE_MAGICAL)
  5233. ward->DamageType = damageTypes;
  5234. // Add the ward to the entity
  5235. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5236. ward_was_added = true;
  5237. }
  5238. }
  5239. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5240. if (ward_was_added && spell->caster->IsPlayer()) {
  5241. spell->had_dmg_remaining = true;
  5242. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5243. }
  5244. return 0;
  5245. }
  5246. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5247. if (!lua_interface)
  5248. return 0;
  5249. int32 amount = lua_interface->GetInt32Value(state);
  5250. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5251. WardInfo* ward = 0;
  5252. ZoneServer* zone = spell->caster->GetZone();
  5253. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5254. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5255. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5256. ward = target->GetWard(spell->spell->GetSpellID());
  5257. if (ward) {
  5258. ward->DamageLeft += amount;
  5259. if (ward->DamageLeft > ward->BaseDamage)
  5260. ward->DamageLeft = ward->BaseDamage;
  5261. for (int32 i = 0; i < spell->targets.size(); i++) {
  5262. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5263. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5264. }
  5265. }
  5266. }
  5267. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5268. if (ward && spell->caster->IsPlayer())
  5269. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5270. return 0;
  5271. }
  5272. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5273. if (!lua_interface)
  5274. return 0;
  5275. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5276. if (!spell) {
  5277. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5278. return 0;
  5279. }
  5280. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5281. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5282. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5283. if (ward) {
  5284. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5285. return 1;
  5286. }
  5287. }
  5288. return 0;
  5289. }
  5290. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5291. if (!lua_interface)
  5292. return 0;
  5293. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5294. if (!spell) {
  5295. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5296. return 0;
  5297. }
  5298. string type = lua_interface->GetStringValue(state, 2);
  5299. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5300. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5301. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5302. if (ward) {
  5303. if (boost::iequals(type, "damageleft"))
  5304. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5305. else if (boost::iequals(type, "basedamage"))
  5306. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5307. else if (boost::iequals(type, "keepward"))
  5308. lua_interface->SetBooleanValue(state, ward->keepWard);
  5309. else if (boost::iequals(type, "wardtype"))
  5310. lua_interface->SetInt32Value(state, ward->WardType);
  5311. else if (boost::iequals(type, "dmgabsorptionpct"))
  5312. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5313. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5314. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5315. else if (boost::iequals(type, "redirectdamagepercent"))
  5316. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5317. else if (boost::iequals(type, "lastredirectdamage"))
  5318. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5319. else if (boost::iequals(type, "lastabsorbeddamage"))
  5320. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5321. else if (boost::iequals(type, "hitcount"))
  5322. lua_interface->SetInt32Value(state, ward->HitCount);
  5323. else if (boost::iequals(type, "maxhitcount"))
  5324. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5325. else
  5326. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5327. return 1;
  5328. }
  5329. }
  5330. return 0;
  5331. }
  5332. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5333. if (!lua_interface)
  5334. return 0;
  5335. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5336. ZoneServer* zone = spell->caster->GetZone();
  5337. Spawn* target = 0;
  5338. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5339. for (int32 i = 0; i < spell->targets.size(); i++) {
  5340. target = zone->GetSpawnByID(spell->targets.at(i));
  5341. if (target && target->IsEntity()) {
  5342. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5343. }
  5344. }
  5345. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5346. return 0;
  5347. }
  5348. int EQ2Emu_lua_Interrupt(lua_State* state)
  5349. {
  5350. if (!lua_interface)
  5351. return 0;
  5352. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5353. Spawn* target = lua_interface->GetSpawn(state, 2);
  5354. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5355. if (!caster)
  5356. {
  5357. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5358. return 0;
  5359. }
  5360. if (!target)
  5361. {
  5362. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5363. return 0;
  5364. }
  5365. if (!spell) {
  5366. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5367. return 0;
  5368. }
  5369. if (!target->IsEntity() && !spell)
  5370. {
  5371. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5372. return 0;
  5373. }
  5374. if (!target && spell) {
  5375. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5376. for (int8 i = 0; i < spell->targets.size(); i++) {
  5377. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5378. if (!target || !target->IsEntity())
  5379. continue;
  5380. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5381. }
  5382. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5383. }
  5384. else
  5385. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5386. return 0;
  5387. }
  5388. int EQ2Emu_lua_Stealth(lua_State* state) {
  5389. if (!lua_interface)
  5390. return 0;
  5391. int8 type = lua_interface->GetInt8Value(state);
  5392. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5393. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5394. if (!spell) {
  5395. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5396. return 0;
  5397. }
  5398. ZoneServer* zone = spell->caster->GetZone();
  5399. if (spawn) {
  5400. if (spawn->IsEntity()) {
  5401. if (type == 1) {
  5402. ((Entity*)spawn)->AddStealthSpell(spell);
  5403. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5404. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5405. }
  5406. else if (type == 2) {
  5407. ((Entity*)spawn)->AddInvisSpell(spell);
  5408. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5409. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5410. }
  5411. return 0;
  5412. }
  5413. else {
  5414. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5415. return 0;
  5416. }
  5417. }
  5418. else {
  5419. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5420. for (int32 i = 0; i < spell->targets.size(); i++) {
  5421. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5422. if (!spawn || !spawn->IsEntity())
  5423. continue;
  5424. if (type == 1) {
  5425. ((Entity*)spawn)->AddStealthSpell(spell);
  5426. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5427. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5428. }
  5429. else if (type == 2) {
  5430. ((Entity*)spawn)->AddInvisSpell(spell);
  5431. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5432. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5433. }
  5434. else {
  5435. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5436. break;
  5437. }
  5438. }
  5439. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5440. }
  5441. return 0;
  5442. }
  5443. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5444. if (!lua_interface)
  5445. return 0;
  5446. Spawn* spawn = lua_interface->GetSpawn(state);
  5447. if (!spawn) {
  5448. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5449. return 0;
  5450. }
  5451. if (spawn->IsEntity()) {
  5452. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5453. return 1;
  5454. }
  5455. else
  5456. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5457. return 0;
  5458. }
  5459. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5460. if (!lua_interface)
  5461. return 0;
  5462. Spawn* spawn = lua_interface->GetSpawn(state);
  5463. if (!spawn) {
  5464. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5465. return 0;
  5466. }
  5467. if (spawn->IsEntity()) {
  5468. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5469. return 1;
  5470. }
  5471. else
  5472. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5473. return 0;
  5474. }
  5475. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5476. if (!lua_interface)
  5477. return 0;
  5478. Spawn* player = lua_interface->GetSpawn(state);
  5479. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5480. lua_interface->ResetFunctionStack(state);
  5481. if (!player->IsPlayer()) {
  5482. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5483. return 0;
  5484. }
  5485. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5486. return 1;
  5487. }
  5488. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5489. if (!lua_interface)
  5490. return 0;
  5491. Spawn* player = lua_interface->GetSpawn(state);
  5492. int8 slot = lua_interface->GetInt8Value(state, 2);
  5493. lua_interface->ResetFunctionStack(state);
  5494. if (!player) {
  5495. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5496. return 0;
  5497. }
  5498. if (!player->IsPlayer()) {
  5499. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5500. return 0;
  5501. }
  5502. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5503. if (!item) {
  5504. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5505. return 0;
  5506. }
  5507. lua_interface->SetItemValue(state, item);
  5508. return 1;
  5509. }
  5510. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5511. if (!lua_interface)
  5512. return 0;
  5513. Spawn* player = lua_interface->GetSpawn(state);
  5514. int32 id = lua_interface->GetInt32Value(state, 2);
  5515. lua_interface->ResetFunctionStack(state);
  5516. if (!player) {
  5517. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5518. return 0;
  5519. }
  5520. if (!player->IsPlayer()) {
  5521. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5522. return 0;
  5523. }
  5524. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5525. if (!item) {
  5526. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5527. return 0;
  5528. }
  5529. lua_interface->SetItemValue(state, item);
  5530. return 1;
  5531. }
  5532. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5533. if (!lua_interface)
  5534. return 0;
  5535. Spawn* spawn = lua_interface->GetSpawn(state);
  5536. int8 slot = lua_interface->GetInt8Value(state, 2);
  5537. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5538. lua_interface->ResetFunctionStack(state);
  5539. if (!spawn) {
  5540. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5541. return 0;
  5542. }
  5543. if (!spawn->IsEntity()) {
  5544. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5545. return 0;
  5546. }
  5547. Item* item = master_item_list.GetItem(item_id);
  5548. if (!item) {
  5549. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5550. return 0;
  5551. }
  5552. Item* copy = new Item(item);
  5553. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5554. if(result)
  5555. {
  5556. ((Entity*)spawn)->SetEquipment(copy, slot);
  5557. spawn->vis_changed = true;
  5558. if(spawn->IsPlayer())
  5559. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5560. }
  5561. else
  5562. {
  5563. safe_delete(copy);
  5564. }
  5565. lua_interface->SetBooleanValue(state, result);
  5566. return 1;
  5567. }
  5568. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5569. if (!lua_interface)
  5570. return 0;
  5571. Spawn* spawn = lua_interface->GetSpawn(state);
  5572. int8 slot = lua_interface->GetInt8Value(state, 2);
  5573. Item* item = lua_interface->GetItem(state, 3);
  5574. lua_interface->ResetFunctionStack(state);
  5575. if (!spawn) {
  5576. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5577. return 0;
  5578. }
  5579. if (!spawn->IsEntity()) {
  5580. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5581. return 0;
  5582. }
  5583. if (!item) {
  5584. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5585. return 0;
  5586. }
  5587. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5588. if(result)
  5589. {
  5590. ((Entity*)spawn)->SetEquipment(item, slot);
  5591. spawn->vis_changed = true;
  5592. if(spawn->IsPlayer())
  5593. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5594. }
  5595. lua_interface->SetBooleanValue(state, result);
  5596. return 1;
  5597. }
  5598. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5599. if (!lua_interface)
  5600. return 0;
  5601. Spawn* spawn = lua_interface->GetSpawn(state);
  5602. int8 slot = lua_interface->GetInt8Value(state, 2);
  5603. 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
  5604. lua_interface->ResetFunctionStack(state);
  5605. if (!spawn) {
  5606. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5607. return 0;
  5608. }
  5609. if (!spawn->IsEntity()) {
  5610. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5611. return 0;
  5612. }
  5613. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5614. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5615. spawn->vis_changed = true;
  5616. if(spawn->IsPlayer())
  5617. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5618. lua_interface->SetBooleanValue(state, true);
  5619. return 1;
  5620. }
  5621. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5622. if (!lua_interface)
  5623. return 0;
  5624. Spawn* spawn = lua_interface->GetSpawn(state);
  5625. int8 slot = lua_interface->GetInt8Value(state, 2);
  5626. int16 type = lua_interface->GetInt16Value(state, 3);
  5627. int8 r = lua_interface->GetInt8Value(state, 4);
  5628. int8 g = lua_interface->GetInt8Value(state, 5);
  5629. int8 b = lua_interface->GetInt8Value(state, 6);
  5630. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5631. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5632. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5633. lua_interface->ResetFunctionStack(state);
  5634. if (!spawn) {
  5635. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5636. return 0;
  5637. }
  5638. if (!spawn->IsEntity()) {
  5639. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5640. return 0;
  5641. }
  5642. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5643. spawn->vis_changed = true;
  5644. lua_interface->SetBooleanValue(state, true);
  5645. return 1;
  5646. }
  5647. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5648. if (!lua_interface)
  5649. return 0;
  5650. Spawn* player = lua_interface->GetSpawn(state);
  5651. int32 id = lua_interface->GetInt32Value(state, 2);
  5652. int8 count = lua_interface->GetInt8Value(state, 3);
  5653. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5654. lua_interface->ResetFunctionStack(state);
  5655. if (!player) {
  5656. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5657. return 0;
  5658. }
  5659. if (!player->IsPlayer()) {
  5660. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5661. return 0;
  5662. }
  5663. if (!count)
  5664. count = 1;
  5665. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5666. if (!item) {
  5667. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5668. return 0;
  5669. }
  5670. lua_interface->SetItemValue(state, item);
  5671. return 1;
  5672. }
  5673. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5674. if (!lua_interface)
  5675. return 0;
  5676. Spawn* spawn = lua_interface->GetSpawn(state);
  5677. int32 anim = lua_interface->GetInt32Value(state, 2);
  5678. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5679. int8 type = lua_interface->GetInt8Value(state, 4);
  5680. if (!spawn) {
  5681. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5682. return 0;
  5683. }
  5684. if (spawn2) {
  5685. if (spawn2->IsPlayer()) {
  5686. if (type != 1 && type != 2)
  5687. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5688. else
  5689. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5690. return 0;
  5691. }
  5692. else {
  5693. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5694. return 0;
  5695. }
  5696. }
  5697. else
  5698. spawn->GetZone()->PlayAnimation(spawn, anim);
  5699. return 0;
  5700. }
  5701. int EQ2Emu_lua_IsPet(lua_State* state) {
  5702. if (!lua_interface)
  5703. return 0;
  5704. Spawn* spawn = lua_interface->GetSpawn(state);
  5705. if (!spawn) {
  5706. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5707. return 0;
  5708. }
  5709. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5710. return 1;
  5711. }
  5712. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5713. if (!lua_interface)
  5714. return 0;
  5715. Spawn* spawn = lua_interface->GetSpawn(state);
  5716. if (!spawn) {
  5717. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5718. return 0;
  5719. }
  5720. if (!spawn->IsNPC()) {
  5721. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5722. return 0;
  5723. }
  5724. if (((NPC*)spawn)->GetOwner()) {
  5725. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5726. return 1;
  5727. }
  5728. return 0;
  5729. }
  5730. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5731. if (!lua_interface)
  5732. return 0;
  5733. Spawn* spawn = lua_interface->GetSpawn(state);
  5734. Spawn* target = lua_interface->GetSpawn(state, 2);
  5735. if (!spawn) {
  5736. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5737. return 0;
  5738. }
  5739. if (!spawn) {
  5740. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5741. return 0;
  5742. }
  5743. spawn->SetTarget(target);
  5744. return 0;
  5745. }
  5746. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5747. if (!lua_interface)
  5748. return 0;
  5749. Spawn* spawn = lua_interface->GetSpawn(state);
  5750. bool val = lua_interface->GetBooleanValue(state, 2);
  5751. if (!spawn) {
  5752. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5753. return 0;
  5754. }
  5755. if (!spawn->IsEntity()) {
  5756. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5757. return 0;
  5758. }
  5759. ((Entity*)spawn)->InCombat(val);
  5760. if (val) {
  5761. spawn->ClearRunningLocations();
  5762. spawn->CalculateRunningLocation(true);
  5763. }
  5764. return 0;
  5765. }
  5766. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5767. if (!lua_interface)
  5768. return 0;
  5769. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5770. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5771. if (!spawn1) {
  5772. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5773. return 0;
  5774. }
  5775. if (!spawn2) {
  5776. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5777. return 0;
  5778. }
  5779. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5780. return 1;
  5781. }
  5782. int EQ2Emu_lua_Runback(lua_State* state) {
  5783. if (!lua_interface)
  5784. return 0;
  5785. Spawn* spawn = lua_interface->GetSpawn(state);
  5786. if (!spawn) {
  5787. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5788. return 0;
  5789. }
  5790. if (!spawn->IsNPC()) {
  5791. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5792. return 0;
  5793. }
  5794. ((NPC*)spawn)->Runback();
  5795. return 0;
  5796. }
  5797. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5798. if (!lua_interface)
  5799. return 0;
  5800. Spawn* spawn = lua_interface->GetSpawn(state);
  5801. if (!spawn) {
  5802. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5803. return 0;
  5804. }
  5805. if (!spawn->IsNPC()) {
  5806. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5807. return 0;
  5808. }
  5809. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5810. return 1;
  5811. }
  5812. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5813. if (!lua_interface)
  5814. return 0;
  5815. Spawn* spawn = lua_interface->GetSpawn(state);
  5816. if (!spawn) {
  5817. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. if (!spawn->IsEntity()) {
  5821. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5822. return 0;
  5823. }
  5824. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5825. return 1;
  5826. }
  5827. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5828. if (!lua_interface)
  5829. return 0;
  5830. Spawn* spawn = lua_interface->GetSpawn(state);
  5831. if (!spawn) {
  5832. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5833. return 0;
  5834. }
  5835. if (!spawn->IsEntity()) {
  5836. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5837. return 0;
  5838. }
  5839. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5840. return 1;
  5841. }
  5842. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5843. if (!lua_interface)
  5844. return 0;
  5845. Spawn* spawn = lua_interface->GetSpawn(state);
  5846. if (!spawn) {
  5847. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5848. return 0;
  5849. }
  5850. if (!spawn->IsEntity()) {
  5851. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5852. return 0;
  5853. }
  5854. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5855. return 1;
  5856. }
  5857. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5858. if (!lua_interface)
  5859. return 0;
  5860. Spawn* spawn = lua_interface->GetSpawn(state);
  5861. if (!spawn) {
  5862. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. if (!spawn->IsEntity()) {
  5866. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5867. return 0;
  5868. }
  5869. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5870. return 1;
  5871. }
  5872. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5873. if (!lua_interface)
  5874. return 0;
  5875. Spawn* spawn = lua_interface->GetSpawn(state);
  5876. Spawn* target = lua_interface->GetSpawn(state, 2);
  5877. float distance = lua_interface->GetFloatValue(state, 3);
  5878. if (!spawn) {
  5879. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5880. return 0;
  5881. }
  5882. if (!target) {
  5883. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. if (!spawn->IsNPC()) {
  5887. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5888. return 0;
  5889. }
  5890. if (!target->IsEntity()) {
  5891. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5892. return 0;
  5893. }
  5894. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5895. return 1;
  5896. }
  5897. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5898. if (!lua_interface)
  5899. return 0;
  5900. Spawn* spawn = lua_interface->GetSpawn(state);
  5901. Spawn* target = lua_interface->GetSpawn(state, 2);
  5902. float distance = lua_interface->GetFloatValue(state, 3);
  5903. if (!spawn) {
  5904. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5905. return 0;
  5906. }
  5907. if (!target) {
  5908. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5909. return 0;
  5910. }
  5911. if (!spawn->IsNPC()) {
  5912. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5913. return 0;
  5914. }
  5915. if (!target->IsEntity()) {
  5916. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5917. return 0;
  5918. }
  5919. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5920. return 0;
  5921. }
  5922. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5923. if (!lua_interface)
  5924. return 0;
  5925. Spawn* spawn = lua_interface->GetSpawn(state);
  5926. if (!spawn) {
  5927. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5928. return 0;
  5929. }
  5930. if (!spawn->IsNPC()) {
  5931. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5932. return 0;
  5933. }
  5934. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5935. return 1;
  5936. }
  5937. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5938. if (!lua_interface)
  5939. return 0;
  5940. Spawn* spawn = lua_interface->GetSpawn(state);
  5941. if (!spawn) {
  5942. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5943. return 0;
  5944. }
  5945. if (!spawn->IsNPC()) {
  5946. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5947. return 0;
  5948. }
  5949. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5950. return 1;
  5951. }
  5952. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5953. if (!lua_interface)
  5954. return 0;
  5955. Spawn* spawn = lua_interface->GetSpawn(state);
  5956. if (!spawn) {
  5957. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5958. return 0;
  5959. }
  5960. if (!spawn->IsNPC()) {
  5961. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5962. return 0;
  5963. }
  5964. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5965. if (hated) {
  5966. lua_interface->SetSpawnValue(state, hated);
  5967. return 1;
  5968. }
  5969. return 0;
  5970. }
  5971. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5972. if (!lua_interface)
  5973. return 0;
  5974. Spawn* spawn = lua_interface->GetSpawn(state);
  5975. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5976. if (!spawn) {
  5977. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5978. return 0;
  5979. }
  5980. if (!spawn->IsNPC()) {
  5981. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5982. return 0;
  5983. }
  5984. if (!hated) {
  5985. ((NPC*)spawn)->Brain()->ClearHate();
  5986. return 0;
  5987. }
  5988. else
  5989. {
  5990. if (!hated->IsEntity()) {
  5991. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5992. return 0;
  5993. }
  5994. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5995. return 0;
  5996. }
  5997. return 0;
  5998. }
  5999. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6000. if (!lua_interface)
  6001. return 0;
  6002. Spawn* spawn = lua_interface->GetSpawn(state);
  6003. if (!spawn) {
  6004. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6005. return 0;
  6006. }
  6007. if (!spawn->IsNPC()) {
  6008. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6009. return 0;
  6010. }
  6011. ((NPC*)spawn)->Brain()->ClearEncounter();
  6012. return 0;
  6013. }
  6014. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6015. if (!lua_interface)
  6016. return 0;
  6017. Spawn* spawn = lua_interface->GetSpawn(state);
  6018. if (!spawn) {
  6019. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6020. return 0;
  6021. }
  6022. if (!spawn->IsNPC()) {
  6023. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6024. return 0;
  6025. }
  6026. // Temp list to store hate list
  6027. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6028. if (encounterList->size() == 0) {
  6029. safe_delete(encounterList);
  6030. return 0;
  6031. }
  6032. lua_createtable(state, encounterList->size(), 0);
  6033. int newTable = lua_gettop(state);
  6034. for (int32 i = 0; i < encounterList->size(); i++) {
  6035. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6036. if (temp)
  6037. lua_interface->SetSpawnValue(state, temp);
  6038. lua_rawseti(state, newTable, i + 1);
  6039. }
  6040. safe_delete(encounterList);
  6041. return 1;
  6042. }
  6043. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6044. if (!lua_interface)
  6045. return 0;
  6046. Spawn* spawn = lua_interface->GetSpawn(state);
  6047. if (!spawn) {
  6048. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6049. return 0;
  6050. }
  6051. if (!spawn->IsNPC()) {
  6052. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6053. return 0;
  6054. }
  6055. // Temp list to store hate list
  6056. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6057. if (hateList->size() == 0) {
  6058. safe_delete(hateList);
  6059. return 0;
  6060. }
  6061. lua_createtable(state, hateList->size(), 0);
  6062. int newTable = lua_gettop(state);
  6063. for (int32 i = 0; i < hateList->size(); i++) {
  6064. lua_interface->SetSpawnValue(state, hateList->at(i));
  6065. lua_rawseti(state, newTable, i + 1);
  6066. }
  6067. safe_delete(hateList);
  6068. return 1;
  6069. }
  6070. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6071. if (!lua_interface)
  6072. return 0;
  6073. Spawn* spawn = lua_interface->GetSpawn(state);
  6074. if (!spawn) {
  6075. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6076. return 0;
  6077. }
  6078. if (spawn->IsPlayer()) {
  6079. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6080. lua_interface->SetBooleanValue(state, true);
  6081. else
  6082. lua_interface->SetBooleanValue(state, false);
  6083. return 1;
  6084. }
  6085. else {
  6086. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6087. return 1;
  6088. }
  6089. }
  6090. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6091. if (!lua_interface)
  6092. return 0;
  6093. Quest* quest = lua_interface->GetQuest(state);
  6094. if (!quest) {
  6095. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6096. return 0;
  6097. }
  6098. quest->SetCompletedFlag(true);
  6099. return 0;
  6100. }
  6101. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6102. if (!lua_interface)
  6103. return 0;
  6104. Spawn* spawn = lua_interface->GetSpawn(state);
  6105. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6106. int8 tier = lua_interface->GetInt8Value(state, 3);
  6107. if (!spawn) {
  6108. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6109. return 0;
  6110. }
  6111. if (!spawn->IsEntity()) {
  6112. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6113. return 0;
  6114. }
  6115. if (spellID == 0) {
  6116. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6117. return 0;
  6118. }
  6119. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6120. if (effect) {
  6121. if (tier > 0) {
  6122. // If a tier was passed chec to see if it is the same as the effect
  6123. if (tier == effect->tier)
  6124. lua_interface->SetBooleanValue(state, true);
  6125. else
  6126. lua_interface->SetBooleanValue(state, false);
  6127. return 1;
  6128. }
  6129. else {
  6130. // Have an effect but no tier was passed so return true
  6131. lua_interface->SetBooleanValue(state, true);
  6132. }
  6133. return 1;
  6134. }
  6135. // no effect so return false
  6136. lua_interface->SetBooleanValue(state, false);
  6137. return 1;
  6138. }
  6139. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6140. if (!lua_interface)
  6141. return 0;
  6142. Spawn* spawn = lua_interface->GetSpawn(state);
  6143. int32 id = lua_interface->GetInt32Value(state, 2);
  6144. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6145. Spawn* spawn2 = 0;
  6146. vector<Spawn*> list;
  6147. if (!spawn) {
  6148. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6149. return 0;
  6150. }
  6151. //If zone not provided, use spawn's zone
  6152. if (!zone)
  6153. zone = spawn->GetZone();
  6154. list = zone->GetSpawnsByID(id);
  6155. if (list.size() == 0) {
  6156. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6157. return 0;
  6158. }
  6159. vector<Spawn*>::iterator itr = list.begin();
  6160. for (int8 i = 0; i < list.size(); i++) {
  6161. spawn2 = itr[i];
  6162. if (spawn2)
  6163. spawn2->AddAllowAccessSpawn(spawn);
  6164. }
  6165. return 0;
  6166. }
  6167. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6168. if (!lua_interface)
  6169. return 0;
  6170. Spawn* spawn = lua_interface->GetSpawn(state);
  6171. int32 id = lua_interface->GetInt32Value(state, 2);
  6172. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6173. Spawn* spawn2 = 0;
  6174. if (!spawn) {
  6175. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6176. return 0;
  6177. }
  6178. //If zone not provided, use spawn's zone
  6179. if (!zone)
  6180. zone = spawn->GetZone();
  6181. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6182. vector<Spawn*>::iterator itr = list.begin();
  6183. if (list.size() == 0) {
  6184. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6185. return 0;
  6186. }
  6187. for (int8 i = 0; i < list.size(); i++) {
  6188. spawn2 = itr[i];
  6189. if (spawn2)
  6190. spawn2->RemoveSpawnAccess(spawn);
  6191. }
  6192. return 0;
  6193. }
  6194. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6195. if (!lua_interface)
  6196. return 0;
  6197. Quest* quest = lua_interface->GetQuest(state);
  6198. if (!quest) {
  6199. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6200. return 0;
  6201. }
  6202. quest->SetYellowName(true);
  6203. return 0;
  6204. }
  6205. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6206. if (!lua_interface)
  6207. return 0;
  6208. Spawn* spawn = lua_interface->GetSpawn(state);
  6209. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6210. if (!spawn) {
  6211. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6212. return 0;
  6213. }
  6214. if (!spawn->IsPlayer()) {
  6215. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6216. return 0;
  6217. }
  6218. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6219. return 1;
  6220. }
  6221. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6222. if (!lua_interface)
  6223. return 0;
  6224. Spawn* spawn = lua_interface->GetSpawn(state);
  6225. if (!spawn) {
  6226. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6227. return 0;
  6228. }
  6229. if (!spawn->IsPlayer()) {
  6230. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6231. return 0;
  6232. }
  6233. ZoneServer* zone = spawn->GetZone();
  6234. if (!zone) {
  6235. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. Instance_Type iType = zone->GetInstanceType();
  6239. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6240. iType == GROUP_LOCKOUT_INSTANCE ||
  6241. iType == RAID_LOCKOUT_INSTANCE ||
  6242. iType == SOLO_PERSIST_INSTANCE ||
  6243. iType == GROUP_PERSIST_INSTANCE ||
  6244. iType == RAID_PERSIST_INSTANCE) {
  6245. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6246. if (data) {
  6247. // Check to see if the timer has already been set, if it has return out.
  6248. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6249. return 0;
  6250. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6251. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6252. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6253. if (client) {
  6254. string time_msg = "";
  6255. int32 time = data->success_lockout_time;
  6256. int16 hour;
  6257. int8 min;
  6258. int8 sec;
  6259. hour = time / 3600;
  6260. time = time % 3600;
  6261. min = time / 60;
  6262. time = time % 60;
  6263. sec = time;
  6264. if (hour > 0) {
  6265. char temp[10];
  6266. sprintf(temp, " %i", hour);
  6267. time_msg.append(temp);
  6268. time_msg.append(" hour");
  6269. time_msg.append((hour > 1) ? "s" : "");
  6270. }
  6271. if (min > 0) {
  6272. char temp[5];
  6273. sprintf(temp, " %i", min);
  6274. time_msg.append(temp);
  6275. time_msg.append(" minute");
  6276. time_msg.append((min > 1) ? "s" : "");
  6277. }
  6278. // Only add seconds if minutes and hours are 0
  6279. if (hour == 0 && min == 0 && sec > 0) {
  6280. char temp[5];
  6281. sprintf(temp, " %i", sec);
  6282. time_msg.append(temp);
  6283. time_msg.append(" second");
  6284. time_msg.append((sec > 1) ? "s" : "");
  6285. }
  6286. 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());
  6287. }
  6288. }
  6289. else
  6290. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6291. }
  6292. else
  6293. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6294. return 0;
  6295. }
  6296. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6297. if (!lua_interface)
  6298. return 0;
  6299. Spawn* spawn = lua_interface->GetSpawn(state);
  6300. if (!spawn) {
  6301. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6302. return 0;
  6303. }
  6304. if (!spawn->IsPlayer()) {
  6305. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6306. return 0;
  6307. }
  6308. ZoneServer* zone = spawn->GetZone();
  6309. if (!zone) {
  6310. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6311. return 0;
  6312. }
  6313. Instance_Type iType = zone->GetInstanceType();
  6314. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6315. iType == GROUP_LOCKOUT_INSTANCE ||
  6316. iType == RAID_LOCKOUT_INSTANCE ||
  6317. iType == SOLO_PERSIST_INSTANCE ||
  6318. iType == GROUP_PERSIST_INSTANCE ||
  6319. iType == RAID_PERSIST_INSTANCE) {
  6320. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6321. if (data) {
  6322. // Check to see if the timer has already been set, if it has return out.
  6323. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6324. return 0;
  6325. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6326. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6327. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6328. if (client) {
  6329. string time_msg = "";
  6330. int32 time = data->failure_lockout_time;
  6331. int16 hour;
  6332. int8 min;
  6333. int8 sec;
  6334. hour = time / 3600;
  6335. time = time % 3600;
  6336. min = time / 60;
  6337. time = time % 60;
  6338. sec = time;
  6339. if (hour > 0) {
  6340. char temp[10];
  6341. sprintf(temp, " %i", hour);
  6342. time_msg.append(temp);
  6343. time_msg.append(" hour");
  6344. time_msg.append((hour > 1) ? "s" : "");
  6345. }
  6346. if (min > 0) {
  6347. char temp[5];
  6348. sprintf(temp, " %i", min);
  6349. time_msg.append(temp);
  6350. time_msg.append(" minute");
  6351. time_msg.append((min > 1) ? "s" : "");
  6352. }
  6353. // Only add seconds if minutes and hours are 0
  6354. if (hour == 0 && min == 0 && sec > 0) {
  6355. char temp[5];
  6356. sprintf(temp, " %i", sec);
  6357. time_msg.append(temp);
  6358. time_msg.append(" second");
  6359. time_msg.append((sec > 1) ? "s" : "");
  6360. }
  6361. 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());
  6362. }
  6363. }
  6364. else
  6365. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6366. }
  6367. else
  6368. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6369. return 0;
  6370. }
  6371. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6372. if (!lua_interface)
  6373. return 0;
  6374. Spawn* spawn = lua_interface->GetSpawn(state);
  6375. if (!spawn) {
  6376. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6377. return 0;
  6378. }
  6379. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6380. return 1;
  6381. }
  6382. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6383. if (!lua_interface)
  6384. return 0;
  6385. Spawn* player = lua_interface->GetSpawn(state);
  6386. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6387. if (!player) {
  6388. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. if (!player->IsPlayer()) {
  6392. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6393. return 0;
  6394. }
  6395. if (!ground) {
  6396. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6397. return 0;
  6398. }
  6399. if (!ground->IsGroundSpawn()) {
  6400. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6401. return 0;
  6402. }
  6403. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6404. if (!groundspawn_entries) {
  6405. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6406. return 0;
  6407. }
  6408. Skill* skill = 0;
  6409. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6410. if (collection_skill == "Collecting")
  6411. skill = ((Player*)player)->GetSkillByName("Gathering");
  6412. else
  6413. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6414. if (!skill) {
  6415. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6416. return 0;
  6417. }
  6418. vector<GroundSpawnEntry*>::iterator itr;
  6419. GroundSpawnEntry* entry = 0;
  6420. bool can_harvest = false;
  6421. sint32 min_skill = -1;
  6422. int16 totalSkill = skill->current_val;
  6423. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6424. if(skillID != 0xFFFFFFFF)
  6425. {
  6426. ((Entity*)player)->MStats.lock();
  6427. totalSkill += ((Entity*)player)->stats[skillID];
  6428. ((Entity*)player)->MStats.unlock();
  6429. }
  6430. // first, iterate through groundspawn_entries, discard tables player cannot use
  6431. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6432. {
  6433. entry = *itr;
  6434. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6435. min_skill = entry->min_skill_level;
  6436. // if player lacks skill, skip table
  6437. if (entry->min_skill_level > totalSkill)
  6438. continue;
  6439. // if bonus, but player lacks level, skip table
  6440. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6441. continue;
  6442. can_harvest = true;
  6443. break;
  6444. }
  6445. lua_interface->SetBooleanValue(state, can_harvest);
  6446. // If false, send the message to the client
  6447. if (!can_harvest) {
  6448. Client* client = player->GetZone()->GetClientBySpawn(player);
  6449. if (client) {
  6450. string msg = "You do not have enough skill to ";
  6451. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6452. msg.append("gather");
  6453. else if (collection_skill == "Mining")
  6454. msg.append("mine");
  6455. else if (collection_skill == "Trapping")
  6456. msg.append("trap");
  6457. else if (collection_skill == "Foresting")
  6458. msg.append("forest");
  6459. else if (collection_skill == "Fishing")
  6460. msg.append("catch");
  6461. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6462. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6463. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6464. }
  6465. }
  6466. return 1;
  6467. }
  6468. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6469. if (!lua_interface)
  6470. return 0;
  6471. Spawn* player = lua_interface->GetSpawn(state);
  6472. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6473. if (!player) {
  6474. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6475. return 0;
  6476. }
  6477. if (!player->IsPlayer()) {
  6478. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6479. return 0;
  6480. }
  6481. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6482. lua_interface->SetBooleanValue(state, ret);
  6483. return 1;
  6484. }
  6485. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6486. // Check to see if we have a valid lua_interface
  6487. if (!lua_interface)
  6488. return 0;
  6489. // Get the spawn that is getting the pet
  6490. Spawn* spawn = lua_interface->GetSpawn(state);
  6491. Spawn* target = lua_interface->GetSpawn(state, 2);
  6492. // Get the DB ID of the pet
  6493. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6494. float x = lua_interface->GetFloatValue(state, 4);
  6495. float y = lua_interface->GetFloatValue(state, 5);
  6496. float z = lua_interface->GetFloatValue(state, 6);
  6497. // Get the spell that this command was called from
  6498. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6499. // Check to make sure the spawn pointer is valid
  6500. if (!spawn) {
  6501. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6502. return 0;
  6503. }
  6504. // Check to make sure the spawn is an entity
  6505. if (!spawn->IsEntity()) {
  6506. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6507. return 0;
  6508. }
  6509. if (!target) {
  6510. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6511. return 0;
  6512. }
  6513. if (!target->IsEntity()) {
  6514. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6515. return 0;
  6516. }
  6517. // Check to see if the DB ID for the pet is set
  6518. if (pet_id == 0) {
  6519. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6520. return 0;
  6521. }
  6522. // Check to see if the pointer to the spell is valid
  6523. if (!luaspell) {
  6524. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6525. return 0;
  6526. }
  6527. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6528. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6529. if (!pet) {
  6530. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6531. return 0;
  6532. }
  6533. // Check to make sure the pet is an npc
  6534. if (!pet->IsNPC()) {
  6535. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6536. return 0;
  6537. }
  6538. if (x == 0)
  6539. x = spawn->GetX();
  6540. if (y == 0)
  6541. y = spawn->GetY();
  6542. if (z == 0)
  6543. z = spawn->GetZ();
  6544. // Spawn the pet at the same location as the owner
  6545. pet->SetX(x);
  6546. pet->SetY(y);
  6547. pet->SetZ(z);
  6548. pet->SetLocation(spawn->GetLocation());
  6549. pet->SetHeading(spawn->GetHeading());
  6550. spawn->GetZone()->AddSpawn(pet);
  6551. /*
  6552. const char* spawn_script = world.GetSpawnScript(pet_id);
  6553. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6554. spawn->SetSpawnScript(string(spawn_script));
  6555. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6556. }*/
  6557. // Get a random pet name
  6558. string random_pet_name;
  6559. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6560. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6561. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6562. // Set the pets name
  6563. pet->SetName(random_pet_name.c_str());
  6564. // Set the level of the pet to the owners level
  6565. pet->SetLevel(spawn->GetLevel());
  6566. // Set the faction of the pet to the same faction as the owner
  6567. pet->SetFactionID(spawn->GetFactionID());
  6568. // Set the spawn as a pet
  6569. pet->SetPet(true);
  6570. // Give a pointer of the owner to the pet
  6571. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6572. // Set the pet type
  6573. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6574. // Set the spell id used to create this pet
  6575. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6576. // Set the spell tier used to create this pet
  6577. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6578. // Set the pets spawn type to 6
  6579. pet->SetSpawnType(6);
  6580. // Set the pets brain
  6581. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6582. // Check to see if the pet has a subtitle
  6583. if (strlen(pet->GetSubTitle()) > 0) {
  6584. // Add the players name to the front of the sub title
  6585. string pet_subtitle;
  6586. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6587. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6588. // Set the pets subtitle to the new one
  6589. pet->SetSubTitle(pet_subtitle.c_str());
  6590. }
  6591. // Set the pet as the return value for this function
  6592. lua_interface->SetSpawnValue(state, pet);
  6593. return 1;
  6594. }
  6595. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6596. if (!lua_interface)
  6597. return 0;
  6598. Spawn* spawn = lua_interface->GetSpawn(state);
  6599. Spawn* player = lua_interface->GetSpawn(state, 2);
  6600. float max_distance = lua_interface->GetFloatValue(state, 3);
  6601. string type = lua_interface->GetStringValue(state, 4);
  6602. if (!spawn || (spawn && spawn->IsPlayer())) {
  6603. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6604. return 0;
  6605. }
  6606. if (!player || (player && !player->IsPlayer())) {
  6607. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6608. return 0;
  6609. }
  6610. Client* client = 0;
  6611. if (player->GetZone())
  6612. client = player->GetZone()->GetClientBySpawn(player);
  6613. if (!client) {
  6614. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6615. return 0;
  6616. }
  6617. //Set max_distance to default if not set or not proper value
  6618. if (max_distance <= 0)
  6619. max_distance = 500;
  6620. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6621. if (packet) {
  6622. float unknown2_3 = 0;
  6623. int8 placement_mode = 0;
  6624. if (type == "wall") {
  6625. placement_mode = 2;
  6626. unknown2_3 = 150;
  6627. }
  6628. else if (type == "ceiling")
  6629. placement_mode = 1;
  6630. packet->setDataByName("placement_mode", placement_mode);
  6631. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6632. packet->setDataByName("model_type", spawn->GetModelType());
  6633. packet->setDataByName("unknown", 1); //size
  6634. packet->setDataByName("unknown2", 1); //size 2
  6635. packet->setDataByName("unknown2", .5, 1); //size 3
  6636. packet->setDataByName("unknown2", 3, 2);
  6637. packet->setDataByName("unknown2", unknown2_3, 3);
  6638. packet->setDataByName("max_distance", max_distance);
  6639. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6640. client->QueuePacket(packet->serialize());
  6641. safe_delete(packet);
  6642. }
  6643. return 0;
  6644. }
  6645. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6646. if (!lua_interface)
  6647. return 0;
  6648. Item* item = lua_interface->GetItem(state);
  6649. if (!item) {
  6650. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6651. return 0;
  6652. }
  6653. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6654. return 1;
  6655. }
  6656. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6657. if (!lua_interface)
  6658. return 0;
  6659. Spawn* spawn = lua_interface->GetSpawn(state);
  6660. if (!spawn) {
  6661. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6662. return 0;
  6663. }
  6664. if (spawn->GetZone())
  6665. spawn->GetZone()->AddTransportSpawn(spawn);
  6666. return 0;
  6667. }
  6668. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6669. if (!lua_interface)
  6670. return 0;
  6671. Skill* skill = lua_interface->GetSkill(state);
  6672. if (!skill) {
  6673. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6674. return 0;
  6675. }
  6676. lua_interface->SetInt32Value(state, skill->current_val);
  6677. return 1;
  6678. }
  6679. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6680. if (!lua_interface)
  6681. return 0;
  6682. Skill* skill = lua_interface->GetSkill(state);
  6683. if (!skill) {
  6684. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6685. return 0;
  6686. }
  6687. lua_interface->SetInt32Value(state, skill->max_val);
  6688. return 1;
  6689. }
  6690. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6691. if (!lua_interface)
  6692. return 0;
  6693. Skill* skill = lua_interface->GetSkill(state);
  6694. if (!skill) {
  6695. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6696. return 0;
  6697. }
  6698. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6699. return 1;
  6700. }
  6701. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6702. if (!lua_interface)
  6703. return 0;
  6704. Skill* skill = lua_interface->GetSkill(state);
  6705. int16 value = lua_interface->GetInt16Value(state, 2);
  6706. if (!skill) {
  6707. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6708. return 0;
  6709. }
  6710. skill->max_val = value;
  6711. if (skill->max_val < skill->current_val)
  6712. skill->current_val = skill->max_val;
  6713. return 0;
  6714. }
  6715. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6716. if (!lua_interface)
  6717. return 0;
  6718. Skill* skill = lua_interface->GetSkill(state);
  6719. int16 value = lua_interface->GetInt16Value(state, 2);
  6720. if (!skill) {
  6721. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6722. return 0;
  6723. }
  6724. if (value > skill->max_val)
  6725. skill->current_val = skill->max_val;
  6726. else
  6727. skill->current_val = value;
  6728. return 0;
  6729. }
  6730. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6731. if (!lua_interface)
  6732. return 0;
  6733. Spawn* player = lua_interface->GetSpawn(state);
  6734. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6735. if (skill_id > 0 && player && player->IsPlayer()) {
  6736. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6737. return 1;
  6738. }
  6739. return 0;
  6740. }
  6741. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6742. if (!lua_interface)
  6743. return 0;
  6744. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6745. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6746. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6747. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6748. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6749. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6750. if (player_spawn && player_spawn->IsPlayer()) {
  6751. Player* player = (Player*)player_spawn;
  6752. bool added = false;
  6753. if (!player->skill_list.HasSkill(skill_id)) {
  6754. player->AddSkill(skill_id, current_val, max_val, true);
  6755. added = true;
  6756. }
  6757. 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
  6758. Client* client = player->GetClient();
  6759. if (client) {
  6760. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6761. if (packet)
  6762. client->QueuePacket(packet);
  6763. }
  6764. }
  6765. if (added) {
  6766. lua_interface->SetBooleanValue(state, true);
  6767. return 1;
  6768. }
  6769. }
  6770. else {
  6771. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6772. }
  6773. }
  6774. else {
  6775. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6776. }
  6777. lua_interface->SetBooleanValue(state, false);
  6778. return 1;
  6779. }
  6780. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6781. if (!lua_interface)
  6782. return 0;
  6783. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6784. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6785. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6786. if (skill_id > 0) {
  6787. if (player_spawn && player_spawn->IsPlayer()) {
  6788. Player* player = (Player*)player_spawn;
  6789. if (player->skill_list.HasSkill(skill_id)) {
  6790. player->RemovePlayerSkill(skill_id);
  6791. if (!more_to_remove) {
  6792. Client* client = player->GetClient();
  6793. if (client) {
  6794. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6795. if (packet)
  6796. client->QueuePacket(packet);
  6797. }
  6798. }
  6799. }
  6800. }
  6801. else {
  6802. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6803. }
  6804. }
  6805. else {
  6806. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6807. }
  6808. return 0;
  6809. }
  6810. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6811. if (!lua_interface)
  6812. return 0;
  6813. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6814. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6815. int16 amount = lua_interface->GetInt8Value(state, 3);
  6816. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6817. if (amount > 0 && skill_type < 100) {
  6818. if (player_spawn && player_spawn->IsPlayer()) {
  6819. Player* player = (Player*)player_spawn;
  6820. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6821. if (!more_to_increase) {
  6822. Client* client = player->GetClient();
  6823. if (client) {
  6824. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6825. if (packet)
  6826. client->QueuePacket(packet);
  6827. }
  6828. }
  6829. }
  6830. else {
  6831. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6832. }
  6833. }
  6834. else {
  6835. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6836. }
  6837. return 0;
  6838. }
  6839. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6840. if (!lua_interface)
  6841. return 0;
  6842. Spawn* spawn = lua_interface->GetSpawn(state);
  6843. string name = lua_interface->GetStringValue(state, 2);
  6844. if (!spawn) {
  6845. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6846. return 0;
  6847. }
  6848. if (!spawn->IsEntity()) {
  6849. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6850. return 0;
  6851. }
  6852. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6853. if (skill) {
  6854. lua_interface->SetSkillValue(state, skill);
  6855. return 1;
  6856. }
  6857. return 0;
  6858. }
  6859. int EQ2Emu_lua_AddProc(lua_State* state) {
  6860. if (!lua_interface)
  6861. return 0;
  6862. Spawn* spawn = lua_interface->GetSpawn(state);
  6863. int8 type = lua_interface->GetInt8Value(state, 2);
  6864. float chance = lua_interface->GetFloatValue(state, 3);
  6865. Item* item = lua_interface->GetItem(state, 4);
  6866. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6867. LuaSpell* spell = 0;
  6868. if (!spawn && (!spell || !use_all_spelltargets)) {
  6869. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6870. return 0;
  6871. }
  6872. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6873. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6874. return 0;
  6875. }
  6876. if (!item)
  6877. spell = lua_interface->GetCurrentSpell(state);
  6878. if (!item && !spell) {
  6879. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6880. return 0;
  6881. }
  6882. if (spell && use_all_spelltargets) {
  6883. Spawn* target;
  6884. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6885. for (int8 i = 0; i < spell->targets.size(); i++) {
  6886. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6887. if (!target || !target->IsEntity())
  6888. continue;
  6889. ((Entity*)target)->AddProc(type, chance, item, spell);
  6890. }
  6891. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6892. }
  6893. else
  6894. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6895. return 0;
  6896. }
  6897. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6898. if (!lua_interface)
  6899. return 0;
  6900. Spawn* spawn = lua_interface->GetSpawn(state);
  6901. Item* item = lua_interface->GetItem(state, 2);
  6902. LuaSpell* spell = 0;
  6903. if (!spawn) {
  6904. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6905. return 0;
  6906. }
  6907. if (!spawn->IsEntity()) {
  6908. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6909. return 0;
  6910. }
  6911. if (!item)
  6912. spell = lua_interface->GetCurrentSpell(state);
  6913. if (!item && !spell) {
  6914. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6915. return 0;
  6916. }
  6917. if (spell) {
  6918. Spawn* target;
  6919. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6920. for (int8 i = 0; i < spell->targets.size(); i++) {
  6921. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6922. if (!target || !target->IsEntity())
  6923. continue;
  6924. ((Entity*)target)->RemoveProc(item, spell);
  6925. }
  6926. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6927. spell->caster->RemoveProc(item, spell);
  6928. }
  6929. else
  6930. ((Entity*)spawn)->RemoveProc(item, spell);
  6931. return 0;
  6932. }
  6933. int EQ2Emu_lua_Knockback(lua_State* state) {
  6934. if (!lua_interface)
  6935. return 0;
  6936. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6937. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6938. int32 duration = lua_interface->GetInt32Value(state, 3);
  6939. float vertical = lua_interface->GetFloatValue(state, 4);
  6940. float horizontal = lua_interface->GetFloatValue(state, 5);
  6941. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6942. if (!target_spawn) {
  6943. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6944. return 0;
  6945. }
  6946. if (!spawn) {
  6947. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6948. return 0;
  6949. }
  6950. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6951. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6952. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6953. if (packet) {
  6954. packet->setDataByName("target_x", target_spawn->GetX());
  6955. packet->setDataByName("target_y", target_spawn->GetY());
  6956. packet->setDataByName("target_z", target_spawn->GetZ());
  6957. packet->setDataByName("vertical_movement", vertical);
  6958. packet->setDataByName("horizontal_movement", horizontal);
  6959. if (use_heading)
  6960. packet->setDataByName("use_player_heading", 1);
  6961. client->QueuePacket(packet->serialize());
  6962. }
  6963. safe_delete(packet);
  6964. }
  6965. return 0;
  6966. }
  6967. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6968. if (!lua_interface)
  6969. return 0;
  6970. Spawn* spawn = lua_interface->GetSpawn(state);
  6971. if (!spawn) {
  6972. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6973. return 0;
  6974. }
  6975. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6976. return 1;
  6977. }
  6978. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6979. if (!lua_interface)
  6980. return 0;
  6981. Spawn* caster = lua_interface->GetSpawn(state);
  6982. Spawn* target = lua_interface->GetSpawn(state, 2);
  6983. string name = lua_interface->GetStringValue(state, 3);
  6984. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6985. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6986. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6987. string success_msg = lua_interface->GetStringValue(state, 7);
  6988. string effect_msg = lua_interface->GetStringValue(state, 8);
  6989. if (!caster) {
  6990. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6991. return 0;
  6992. }
  6993. if (!caster->IsEntity()) {
  6994. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6995. return 0;
  6996. }
  6997. if (!target) {
  6998. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6999. return 0;
  7000. }
  7001. if (!target->IsEntity()) {
  7002. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7003. return 0;
  7004. }
  7005. if (name.length() == 0) {
  7006. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7007. return 0;
  7008. }
  7009. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7010. return 0;
  7011. }
  7012. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7013. if (!lua_interface)
  7014. return 0;
  7015. string name = lua_interface->GetStringValue(state);
  7016. if (name.length() == 0) {
  7017. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7018. return 0;
  7019. }
  7020. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7021. if (!skill) {
  7022. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7023. return 0;
  7024. }
  7025. lua_interface->SetInt32Value(state, skill->skill_id);
  7026. return 1;
  7027. }
  7028. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7029. if (!lua_interface)
  7030. return 0;
  7031. Spawn* spawn = lua_interface->GetSpawn(state);
  7032. if (!spawn) {
  7033. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7034. return 0;
  7035. }
  7036. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7037. return 1;
  7038. }
  7039. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7040. if (!lua_interface)
  7041. return 0;
  7042. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7043. if (!luaspell) {
  7044. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7045. return 0;
  7046. }
  7047. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7048. return 1;
  7049. }
  7050. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7051. if (!lua_interface)
  7052. return 0;
  7053. Spawn* spawn = lua_interface->GetSpawn(state);
  7054. Spawn* target = lua_interface->GetSpawn(state, 2);
  7055. if (!spawn) {
  7056. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7057. return 0;
  7058. }
  7059. if (!spawn->IsEntity()) {
  7060. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7061. return 0;
  7062. }
  7063. if (!target) {
  7064. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7065. return 0;
  7066. }
  7067. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7068. return 1;
  7069. }
  7070. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7071. if (!lua_interface)
  7072. return 0;
  7073. Spawn* spawn = lua_interface->GetSpawn(state);
  7074. Spawn* target = lua_interface->GetSpawn(state, 2);
  7075. if (!spawn) {
  7076. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7077. return 0;
  7078. }
  7079. if (!spawn->IsEntity()) {
  7080. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7081. return 0;
  7082. }
  7083. if (!target) {
  7084. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7085. return 0;
  7086. }
  7087. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7088. return 1;
  7089. }
  7090. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7091. if (!lua_interface)
  7092. return 0;
  7093. Item* item = lua_interface->GetItem(state);
  7094. if (!item) {
  7095. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7096. return 0;
  7097. }
  7098. lua_interface->SetInt32Value(state, item->details.count);
  7099. return 1;
  7100. }
  7101. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7102. if (!lua_interface)
  7103. return 0;
  7104. Item* item = lua_interface->GetItem(state);
  7105. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7106. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7107. if (!item) {
  7108. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7109. return 0;
  7110. }
  7111. if (!owner) {
  7112. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7113. return 0;
  7114. }
  7115. if (!owner->IsPlayer()) {
  7116. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7117. return 0;
  7118. }
  7119. if (item->stack_count < new_count) {
  7120. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7121. return 0;
  7122. }
  7123. if (new_count > 0) {
  7124. item->details.count = new_count;
  7125. item->save_needed = true;
  7126. }
  7127. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7128. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7129. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7130. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7131. else
  7132. {
  7133. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7134. return 0;
  7135. }
  7136. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7137. if (!client)
  7138. return 0;
  7139. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7140. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  7141. if (app)
  7142. client->QueuePacket(app);
  7143. return 0;
  7144. }
  7145. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7146. if (!lua_interface)
  7147. return 0;
  7148. int32 time = lua_interface->GetInt32Value(state);
  7149. string function = lua_interface->GetStringValue(state, 2);
  7150. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7151. Spawn* target = lua_interface->GetSpawn(state, 4);
  7152. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7153. if (time == 0) {
  7154. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7155. return 0;
  7156. }
  7157. if (function.length() == 0) {
  7158. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7159. return 0;
  7160. }
  7161. if (!spell) {
  7162. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7163. return 0;
  7164. }
  7165. SpellScriptTimer* timer = new SpellScriptTimer;
  7166. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7167. #ifdef WIN32
  7168. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7169. #else
  7170. bzero(timer, sizeof(SpellScriptTimer));
  7171. #endif*/
  7172. timer->caster = 0;
  7173. timer->deleteWhenDone = false;
  7174. timer->target = 0;
  7175. timer->time = Timer::GetCurrentTime2() + time;
  7176. timer->customFunction = function;
  7177. timer->spell = spell;
  7178. if (caster)
  7179. timer->caster = caster->GetID();
  7180. if (target)
  7181. timer->target = target->GetID();
  7182. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7183. return 0;
  7184. }
  7185. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7186. if (!lua_interface)
  7187. return 0;
  7188. float hp_perc = lua_interface->GetFloatValue(state);
  7189. float power_perc = lua_interface->GetFloatValue(state, 2);
  7190. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7191. Spawn* target = lua_interface->GetSpawn(state, 4);
  7192. string heal_name = lua_interface->GetStringValue(state, 5);
  7193. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7194. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7195. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7196. if (!spell) {
  7197. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7198. return 0;
  7199. }
  7200. Entity* caster = spell->caster;
  7201. if (!caster) {
  7202. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. Client* client = 0;
  7206. PendingResurrection* rez = 0;
  7207. ZoneServer* zone = spell->caster->GetZone();
  7208. if (!target) {
  7209. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7210. if (spell->targets.size() > 0) {
  7211. vector<int32> spell_targets = spell->targets;
  7212. for (int8 i = 0; i < spell_targets.size(); i++) {
  7213. target = zone->GetSpawnByID(spell_targets.at(i));
  7214. if (!target)
  7215. continue;
  7216. if (!target->IsPlayer())
  7217. continue;
  7218. client = target->GetZone()->GetClientBySpawn(target);
  7219. if (!client)
  7220. continue;
  7221. rez = client->GetCurrentRez();
  7222. if (rez->active)
  7223. continue;
  7224. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7225. rez->active = true;
  7226. rez->caster = caster;
  7227. rez->expire_timer = new Timer;
  7228. int32 duration = spell->spell->GetSpellDuration();
  7229. rez->expire_timer->Start(duration * 100);
  7230. rez->hp_perc = hp_perc;
  7231. rez->mp_perc = power_perc;
  7232. rez->range = spell->spell->GetSpellData()->range;
  7233. rez->spell_name = spell->spell->GetName();
  7234. if (heal_name.length() > 0)
  7235. rez->heal_name = heal_name;
  7236. else
  7237. rez->heal_name = rez->spell_name;
  7238. rez->no_calcs = no_calcs;
  7239. rez->crit_mod = crit_mod;
  7240. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7241. if (send_window)
  7242. client->SendResurrectionWindow();
  7243. else {
  7244. target->GetZone()->ResurrectSpawn(target, client);
  7245. rez->should_delete = true;
  7246. }
  7247. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7248. }
  7249. }
  7250. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7251. }
  7252. else {
  7253. client = target->GetZone()->GetClientBySpawn(target);
  7254. if (!client)
  7255. return 0;
  7256. rez = client->GetCurrentRez();
  7257. if (rez->active)
  7258. return 0;
  7259. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7260. rez->active = true;
  7261. rez->caster = caster;
  7262. rez->expire_timer = new Timer;
  7263. int32 duration = spell->spell->GetSpellDuration();
  7264. rez->expire_timer->Start(duration * 100);
  7265. rez->hp_perc = hp_perc;
  7266. rez->mp_perc = power_perc;
  7267. rez->range = spell->spell->GetSpellData()->range;
  7268. rez->spell_name = spell->spell->GetName();
  7269. if (heal_name.length() > 0)
  7270. rez->heal_name = heal_name;
  7271. else
  7272. rez->heal_name = rez->spell_name;
  7273. rez->no_calcs = no_calcs;
  7274. rez->crit_mod = crit_mod;
  7275. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7276. if (send_window)
  7277. client->SendResurrectionWindow();
  7278. else {
  7279. target->GetZone()->ResurrectSpawn(target, client);
  7280. rez->should_delete = true;
  7281. }
  7282. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7283. }
  7284. return 0;
  7285. }
  7286. int EQ2Emu_lua_SetVision(lua_State* state) {
  7287. if (!lua_interface)
  7288. return 0;
  7289. Spawn* spawn = lua_interface->GetSpawn(state);
  7290. int8 vision = lua_interface->GetInt8Value(state, 2);
  7291. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7292. if (!spawn) {
  7293. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7294. return 0;
  7295. }
  7296. if (!spawn->IsEntity()) {
  7297. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7298. return 0;
  7299. }
  7300. if (spell && spell->targets.size() > 0) {
  7301. ZoneServer* zone = spell->caster->GetZone();
  7302. for (int8 i = 0; i < spell->targets.size(); i++) {
  7303. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7304. if (target->IsEntity()) {
  7305. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7306. if (target->IsPlayer())
  7307. ((Player*)target)->SetCharSheetChanged(true);
  7308. }
  7309. }
  7310. }
  7311. else {
  7312. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7313. if (spawn->IsPlayer())
  7314. ((Player*)spawn)->SetCharSheetChanged(true);
  7315. }
  7316. return 0;
  7317. }
  7318. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7319. if (!lua_interface)
  7320. return 0;
  7321. Spawn* spawn = lua_interface->GetSpawn(state);
  7322. float intensity = lua_interface->GetFloatValue(state, 2);
  7323. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7324. if (!spawn) {
  7325. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7326. return 0;
  7327. }
  7328. if (!spawn->IsEntity()) {
  7329. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7330. return 0;
  7331. }
  7332. if (spell && spell->targets.size() > 0) {
  7333. ZoneServer* zone = spell->caster->GetZone();
  7334. for (int8 i = 0; i < spell->targets.size(); i++) {
  7335. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7336. if (target && target->IsEntity()) {
  7337. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7338. if (target->IsPlayer())
  7339. ((Player*)target)->SetCharSheetChanged(true);
  7340. }
  7341. }
  7342. }
  7343. else {
  7344. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7345. if (spawn->IsPlayer())
  7346. ((Player*)spawn)->SetCharSheetChanged(true);
  7347. }
  7348. return 0;
  7349. }
  7350. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7351. if (!lua_interface)
  7352. return 0;
  7353. Spawn* spawn = lua_interface->GetSpawn(state);
  7354. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7355. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7356. if (!spawn) {
  7357. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7358. return 0;
  7359. }
  7360. if (!spawn->IsEntity()) {
  7361. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7362. return 0;
  7363. }
  7364. if (spell && spell->targets.size() > 0) {
  7365. ZoneServer* zone = spell->caster->GetZone();
  7366. for (int8 i = 0; i < spell->targets.size(); i++) {
  7367. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7368. if (target->IsEntity()) {
  7369. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7370. if (target->IsPlayer())
  7371. ((Player*)target)->SetCharSheetChanged(true);
  7372. }
  7373. }
  7374. }
  7375. else {
  7376. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7377. if (spawn->IsPlayer())
  7378. ((Player*)spawn)->SetCharSheetChanged(true);
  7379. }
  7380. return 0;
  7381. }
  7382. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7383. if (!lua_interface)
  7384. return 0;
  7385. Item* item = lua_interface->GetItem(state);
  7386. int8 type = lua_interface->GetInt32Value(state, 2);
  7387. if (!item) {
  7388. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7389. return 0;
  7390. }
  7391. if (type == 1)
  7392. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7393. else if (type == 2)
  7394. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7395. return 1;
  7396. }
  7397. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7398. if (!lua_interface)
  7399. return 0;
  7400. Spawn* target = lua_interface->GetSpawn(state);
  7401. float val = lua_interface->GetFloatValue(state, 2);
  7402. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7403. // Added from Gangrenous post
  7404. if (spell && spell->resisted)
  7405. return 0;
  7406. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7407. if (val > 1.0f)
  7408. val = 1.0f - (val / 100.0f);
  7409. if (spell && spell->spell && spell->targets.size() > 0) {
  7410. ZoneServer* zone = spell->caster->GetZone();
  7411. for (int32 i = 0; i != spell->targets.size(); i++) {
  7412. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7413. if (spawn && spawn->IsEntity()) {
  7414. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7415. if (spawn->IsPlayer())
  7416. ((Player*)spawn)->SetCharSheetChanged(true);
  7417. }
  7418. }
  7419. }
  7420. else {
  7421. if (target && target->IsEntity()) {
  7422. ((Entity*)target)->SetSpeedMultiplier(val);
  7423. if (target->IsPlayer())
  7424. ((Player*)target)->SetCharSheetChanged(true);
  7425. }
  7426. }
  7427. return 0;
  7428. }
  7429. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7430. if (!lua_interface)
  7431. return 0;
  7432. Spawn* spawn = lua_interface->GetSpawn(state);
  7433. int16 model = lua_interface->GetInt16Value(state, 2);
  7434. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7435. if (spell && spell->spell && spell->targets.size() > 0) {
  7436. ZoneServer* zone = spell->caster->GetZone();
  7437. for (int32 i = 0; i < spell->targets.size(); i++) {
  7438. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7439. if (target)
  7440. target->SetIllusionModel(model);
  7441. }
  7442. }
  7443. else {
  7444. if (!spawn) {
  7445. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7446. return 0;
  7447. }
  7448. spawn->SetIllusionModel(model);
  7449. }
  7450. return 0;
  7451. }
  7452. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7453. if (!lua_interface)
  7454. return 0;
  7455. Spawn* spawn = lua_interface->GetSpawn(state);
  7456. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7457. if (spell && spell->spell && spell->targets.size() > 0) {
  7458. ZoneServer* zone = spell->caster->GetZone();
  7459. for (int32 i = 0; i < spell->targets.size(); i++) {
  7460. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7461. if (target)
  7462. target->SetIllusionModel(0);
  7463. }
  7464. }
  7465. else {
  7466. if (!spawn) {
  7467. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7468. return 0;
  7469. }
  7470. spawn->SetIllusionModel(0);
  7471. }
  7472. return 0;
  7473. }
  7474. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7475. if (!lua_interface)
  7476. return 0;
  7477. Spawn* caster = lua_interface->GetSpawn(state);
  7478. Spawn* target = lua_interface->GetSpawn(state, 2);
  7479. float chance = lua_interface->GetFloatValue(state, 3);
  7480. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7481. if (!caster) {
  7482. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7483. return 0;
  7484. }
  7485. if (!caster->IsEntity()) {
  7486. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. if (!target) {
  7490. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7491. return 0;
  7492. }
  7493. if (!target->IsEntity()) {
  7494. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7495. return 0;
  7496. }
  7497. if (chance <= 0) {
  7498. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7499. return 0;
  7500. }
  7501. if (!spell) {
  7502. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7503. return 0;
  7504. }
  7505. if (((Entity*)caster)->GetThreatTransfer()) {
  7506. return 0;
  7507. }
  7508. ThreatTransfer* transfer = new ThreatTransfer;
  7509. transfer->Target = target->GetID();
  7510. transfer->Amount = chance;
  7511. transfer->Spell = spell;
  7512. ((Entity*)caster)->SetThreatTransfer(transfer);
  7513. return 0;
  7514. }
  7515. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7516. if (!lua_interface)
  7517. return 0;
  7518. Spawn* spawn = lua_interface->GetSpawn(state);
  7519. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7520. if (!spawn) {
  7521. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7522. return 0;
  7523. }
  7524. if (!spell) {
  7525. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7526. return 0;
  7527. }
  7528. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7529. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7530. ((Entity*)spawn)->SetThreatTransfer(0);
  7531. safe_delete(transfer);
  7532. }
  7533. return 0;
  7534. }
  7535. int EQ2Emu_lua_CureByType(lua_State* state) {
  7536. if (!lua_interface)
  7537. return 0;
  7538. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7539. if (!spell) {
  7540. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7541. return 0;
  7542. }
  7543. int8 cure_count = lua_interface->GetInt8Value(state);
  7544. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7545. string cure_name = lua_interface->GetStringValue(state, 3);
  7546. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7547. Spawn* target = lua_interface->GetSpawn(state, 5);
  7548. if (target) {
  7549. if (!target->IsEntity()) {
  7550. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7551. return 0;
  7552. }
  7553. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7554. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7555. }
  7556. else {
  7557. ZoneServer* zone = spell->caster->GetZone();
  7558. vector<int32> targets = spell->targets;
  7559. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7560. for (int8 i = 0; i < targets.size(); i++) {
  7561. target = zone->GetSpawnByID(targets.at(i));
  7562. if (!target || !target->IsEntity())
  7563. continue;
  7564. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7565. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7566. }
  7567. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7568. }
  7569. return 0;
  7570. }
  7571. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7572. if (!lua_interface)
  7573. return 0;
  7574. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7575. if (!spell) {
  7576. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7577. return 0;
  7578. }
  7579. int8 cure_count = lua_interface->GetInt8Value(state);
  7580. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7581. string cure_name = lua_interface->GetStringValue(state, 3);
  7582. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7583. Spawn* target = lua_interface->GetSpawn(state, 5);
  7584. if (target) {
  7585. if (!target->IsEntity()) {
  7586. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7587. return 0;
  7588. }
  7589. if (((Entity*)target)->GetDetCount() > 0)
  7590. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7591. }
  7592. else {
  7593. ZoneServer* zone = spell->caster->GetZone();
  7594. vector<int32> targets = spell->targets;
  7595. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7596. for (int8 i = 0; i < targets.size(); i++) {
  7597. target = zone->GetSpawnByID(targets.at(i));
  7598. if (!target || !target->IsEntity())
  7599. continue;
  7600. if (((Entity*)target)->GetDetCount() > 0)
  7601. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7602. }
  7603. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7604. }
  7605. return 0;
  7606. }
  7607. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7608. if (!lua_interface)
  7609. return 0;
  7610. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7611. if (!spell) {
  7612. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7613. return 0;
  7614. }
  7615. if (!spell->caster) {
  7616. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7617. return 0;
  7618. }
  7619. if (!spell->caster->GetZone()) {
  7620. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7621. return 0;
  7622. }
  7623. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7624. return 0;
  7625. }
  7626. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7627. if (!lua_interface)
  7628. return 0;
  7629. Spawn* spawn = lua_interface->GetSpawn(state);
  7630. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7631. if (!spell) {
  7632. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7633. return 0;
  7634. }
  7635. if (spawn && spawn->IsEntity())
  7636. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7637. else {
  7638. ZoneServer* zone = spell->caster->GetZone();
  7639. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7640. for (int32 i = 0; i < spell->targets.size(); i++) {
  7641. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7642. if (!spawn || !spawn->IsEntity())
  7643. continue;
  7644. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7645. }
  7646. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7647. }
  7648. return 0;
  7649. }
  7650. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7651. if (!lua_interface)
  7652. return 0;
  7653. Spawn* spawn = lua_interface->GetSpawn(state);
  7654. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7655. if (!spell) {
  7656. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7657. return 0;
  7658. }
  7659. if (spawn && spawn->IsEntity())
  7660. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7661. else {
  7662. ZoneServer* zone = spell->caster->GetZone();
  7663. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7664. for (int32 i = 0; i < spell->targets.size(); i++) {
  7665. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7666. if (!spawn || !spawn->IsEntity())
  7667. continue;
  7668. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7669. }
  7670. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7671. }
  7672. return 0;
  7673. }
  7674. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7675. if (!lua_interface)
  7676. return 0;
  7677. Spawn* caster = lua_interface->GetSpawn(state);
  7678. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7679. if (!caster) {
  7680. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7681. return 0;
  7682. }
  7683. if (!caster->IsPlayer()) {
  7684. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7685. return 0;
  7686. }
  7687. Spawn* target = caster->GetTarget();
  7688. if (!target) {
  7689. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7690. return 0;
  7691. }
  7692. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7693. if (!client) {
  7694. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7695. return 0;
  7696. }
  7697. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7698. if (ho) {
  7699. ho->SetTarget(target->GetID());
  7700. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7701. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7702. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7703. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7704. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7705. deque<GroupMemberInfo*>::iterator itr;
  7706. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7707. if (group)
  7708. {
  7709. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7710. deque<GroupMemberInfo*>* members = group->GetMembers();
  7711. for (itr = members->begin(); itr != members->end(); itr++) {
  7712. if ((*itr)->client)
  7713. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7714. }
  7715. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7716. }
  7717. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7718. }
  7719. else
  7720. safe_delete(ho);
  7721. }
  7722. else {
  7723. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7724. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7725. }
  7726. else
  7727. safe_delete(ho);
  7728. }
  7729. }
  7730. return 0;
  7731. }
  7732. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7733. if (!lua_interface)
  7734. return 0;
  7735. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7736. if (!spell) {
  7737. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7738. return 0;
  7739. }
  7740. int16 triggerCount = lua_interface->GetInt16Value(state);
  7741. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7742. if (!triggerCount) {
  7743. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7744. return 0;
  7745. }
  7746. spell->num_triggers = triggerCount;
  7747. spell->had_triggers = true;
  7748. spell->cancel_after_all_triggers = cancel_after_triggers;
  7749. return 0;
  7750. }
  7751. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7752. if (!lua_interface)
  7753. return 0;
  7754. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7755. if (!spell) {
  7756. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7757. return 0;
  7758. }
  7759. lua_interface->SetInt32Value(state, spell->num_triggers);
  7760. return 1;
  7761. }
  7762. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7763. if (!lua_interface)
  7764. return 0;
  7765. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7766. if (!spell) {
  7767. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7768. return 0;
  7769. }
  7770. int16 remove_count = lua_interface->GetInt16Value(state);
  7771. if (!remove_count)
  7772. remove_count = 1;
  7773. if (remove_count >= spell->num_triggers) {
  7774. spell->num_triggers = 0;
  7775. if (spell->cancel_after_all_triggers)
  7776. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7777. }
  7778. else {
  7779. spell->num_triggers -= remove_count;
  7780. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7781. }
  7782. return 0;
  7783. }
  7784. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7785. if (!lua_interface)
  7786. return 0;
  7787. Spawn* spawn = lua_interface->GetSpawn(state);
  7788. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7789. if (!spawn) {
  7790. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7791. return 0;
  7792. }
  7793. if (!copy_spawn) {
  7794. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7795. return 0;
  7796. }
  7797. spawn->CopySpawnAppearance(copy_spawn);
  7798. return 0;
  7799. }
  7800. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7801. Spawn* spawn = lua_interface->GetSpawn(state);
  7802. int8 type = lua_interface->GetInt8Value(state, 2);
  7803. if (!spawn) {
  7804. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7805. return 0;
  7806. }
  7807. else if (!spawn->IsEntity()) {
  7808. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7809. return 0;
  7810. }
  7811. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7812. return 1;
  7813. }
  7814. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7815. if (!lua_interface)
  7816. return 0;
  7817. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7818. int8 type = lua_interface->GetInt8Value(state);
  7819. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7820. if (!spell) {
  7821. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7822. return 0;
  7823. }
  7824. if (spawn) {
  7825. if (!spawn->IsEntity()) {
  7826. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7827. return 0;
  7828. }
  7829. Entity* entity = ((Entity*)spawn);
  7830. entity->AddImmunity(spell, type);
  7831. }
  7832. else {
  7833. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7834. for (int8 i = 0; i < spell->targets.size(); i++) {
  7835. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7836. if (!spawn || !spawn->IsEntity())
  7837. continue;
  7838. Entity* entity = ((Entity*)spawn);
  7839. entity->AddImmunity(spell, type);
  7840. }
  7841. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7842. }
  7843. return 0;
  7844. }
  7845. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7846. if (!lua_interface)
  7847. return 0;
  7848. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7849. int8 type = lua_interface->GetInt8Value(state);
  7850. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7851. if (!spell) {
  7852. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7853. return 0;
  7854. }
  7855. if (spawn) {
  7856. if (!spawn->IsEntity()) {
  7857. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7858. return 0;
  7859. }
  7860. Entity* entity = ((Entity*)spawn);
  7861. entity->RemoveImmunity(spell, type);
  7862. }
  7863. else {
  7864. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7865. for (int8 i = 0; i < spell->targets.size(); i++) {
  7866. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7867. if (!spawn || !spawn->IsEntity())
  7868. continue;
  7869. Entity* entity = ((Entity*)spawn);
  7870. entity->RemoveImmunity(spell, type);
  7871. }
  7872. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7873. }
  7874. return 0;
  7875. }
  7876. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7877. if (!lua_interface)
  7878. return 0;
  7879. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7880. if (!spell) {
  7881. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7882. return 0;
  7883. }
  7884. float snare = lua_interface->GetFloatValue(state);
  7885. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7886. // convert the val to the speed multipler value (100 - val)
  7887. float val = 100.0 - snare;
  7888. val /= 100.0;
  7889. if (spawn) {
  7890. if (!spawn->IsEntity()) {
  7891. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7892. return 0;
  7893. }
  7894. ((Entity*)spawn)->SetSnareValue(spell, val);
  7895. }
  7896. else {
  7897. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7898. for (int8 i = 0; i < spell->targets.size(); i++) {
  7899. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7900. if (!spawn || !spawn->IsEntity())
  7901. continue;
  7902. ((Entity*)spawn)->SetSnareValue(spell, val);
  7903. }
  7904. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7905. }
  7906. return 0;
  7907. }
  7908. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7909. if (!lua_interface)
  7910. return 0;
  7911. Spawn* spawn = lua_interface->GetSpawn(state);
  7912. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7913. if (!spawn) {
  7914. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7915. return 0;
  7916. }
  7917. if (race_id == 0) {
  7918. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7919. return 0;
  7920. }
  7921. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7922. return 1;
  7923. }
  7924. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7925. if (!lua_interface)
  7926. return 0;
  7927. Spawn* spawn = lua_interface->GetSpawn(state);
  7928. if (!spawn) {
  7929. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7930. return 0;
  7931. }
  7932. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7933. return 1;
  7934. }
  7935. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7936. if (!lua_interface)
  7937. return 0;
  7938. Spawn* spawn = lua_interface->GetSpawn(state);
  7939. if (!spawn) {
  7940. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7941. return 0;
  7942. }
  7943. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7944. return 1;
  7945. }
  7946. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7947. if (!lua_interface)
  7948. return 0;
  7949. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7950. if (!spell) {
  7951. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7952. return 0;
  7953. }
  7954. lua_interface->SetStringValue(state, spell->spell->GetName());
  7955. return 1;
  7956. }
  7957. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7958. if (!lua_interface)
  7959. return 0;
  7960. Quest* quest = lua_interface->GetQuest(state);
  7961. if (!quest) {
  7962. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7963. return 0;
  7964. }
  7965. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7966. return 1;
  7967. }
  7968. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7969. if (!lua_interface)
  7970. return 0;
  7971. Quest* quest = lua_interface->GetQuest(state);
  7972. int32 flags = lua_interface->GetInt32Value(state, 2);
  7973. if (!quest) {
  7974. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7975. return 0;
  7976. }
  7977. quest->SetQuestFlags(flags);
  7978. return 0;
  7979. }
  7980. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7981. if (!lua_interface)
  7982. return 0;
  7983. Quest* quest = lua_interface->GetQuest(state);
  7984. Spawn* player = lua_interface->GetSpawn(state, 2);
  7985. int32 step = lua_interface->GetInt32Value(state, 3);
  7986. int32 duration = lua_interface->GetInt32Value(state, 4);
  7987. string action = lua_interface->GetStringValue(state, 5);
  7988. if (!quest) {
  7989. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7990. return 0;
  7991. }
  7992. if (!player) {
  7993. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7994. return 0;
  7995. }
  7996. if (!player->IsPlayer()) {
  7997. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7998. return 0;
  7999. }
  8000. if (step == 0) {
  8001. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8002. return 0;
  8003. }
  8004. if (duration == 0) {
  8005. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8006. return 0;
  8007. }
  8008. if (action.length() == 0) {
  8009. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8010. return 0;
  8011. }
  8012. Client* client = player->GetZone()->GetClientBySpawn(player);
  8013. if (!client) {
  8014. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8015. return 0;
  8016. }
  8017. quest->SetTimerStep(step);
  8018. quest->AddFailedAction(step, action);
  8019. quest->SetStepTimer(duration);
  8020. client->AddQuestTimer(quest->GetQuestID());
  8021. return 0;
  8022. }
  8023. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8024. if (!lua_interface)
  8025. return 0;
  8026. Quest* quest = lua_interface->GetQuest(state);
  8027. Spawn* player = lua_interface->GetSpawn(state, 2);
  8028. if (!quest) {
  8029. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8030. return 0;
  8031. }
  8032. if (!player) {
  8033. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8034. return 0;
  8035. }
  8036. if (!player->IsPlayer()) {
  8037. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8038. return 0;
  8039. }
  8040. Client* client = player->GetZone()->GetClientBySpawn(player);
  8041. if (!client) {
  8042. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8043. return 0;
  8044. }
  8045. quest->SetTimerStep(0);
  8046. quest->SetStepTimer(0);
  8047. client->RemoveQuestTimer(quest->GetQuestID());
  8048. return 0;
  8049. }
  8050. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8051. if (!lua_interface)
  8052. return 0;
  8053. Spawn* player = lua_interface->GetSpawn(state);
  8054. Quest* quest = lua_interface->GetQuest(state, 2);
  8055. int32 step = lua_interface->GetInt32Value(state, 3);
  8056. if (!player) {
  8057. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8058. return 0;
  8059. }
  8060. if (!player->IsPlayer()) {
  8061. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8062. return 0;
  8063. }
  8064. if (!quest) {
  8065. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8066. return 0;
  8067. }
  8068. if (step == 0) {
  8069. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8070. return 0;
  8071. }
  8072. Client* client = player->GetZone()->GetClientBySpawn(player);
  8073. if (!client) {
  8074. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8075. return 0;
  8076. }
  8077. if (quest->RemoveQuestStep(step, client)) {
  8078. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8079. client->GetCurrentZone()->SendQuestUpdates(client);
  8080. }
  8081. else
  8082. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8083. return 0;
  8084. }
  8085. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8086. if (!lua_interface)
  8087. return 0;
  8088. Quest* quest = lua_interface->GetQuest(state, 1);
  8089. int32 step = lua_interface->GetInt32Value(state, 2);
  8090. string desc = lua_interface->GetStringValue(state, 3);
  8091. string task_group = lua_interface->GetStringValue(state, 4);
  8092. if (!quest) {
  8093. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8094. return 0;
  8095. }
  8096. if (step == 0) {
  8097. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8098. return 0;
  8099. }
  8100. QuestStep* quest_step = quest->GetQuestStep(step);
  8101. if (!quest_step) {
  8102. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8103. return 0;
  8104. }
  8105. quest_step->SetStepProgress(0);
  8106. quest_step->SetTaskGroup(task_group);
  8107. quest_step->SetDescription(desc);
  8108. return 0;
  8109. }
  8110. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8111. if (!lua_interface)
  8112. return 0;
  8113. Quest* quest = lua_interface->GetQuest(state);
  8114. int32 step = lua_interface->GetInt32Value(state, 2);
  8115. string action = lua_interface->GetStringValue(state, 3);
  8116. if (!quest) {
  8117. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8118. return 0;
  8119. }
  8120. if (step == 0) {
  8121. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8122. return 0;
  8123. }
  8124. if (action.length() == 0) {
  8125. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8126. return 0;
  8127. }
  8128. quest->AddFailedAction(step, action);
  8129. return 0;
  8130. }
  8131. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8132. if (!lua_interface)
  8133. return 0;
  8134. Spawn* player = lua_interface->GetSpawn(state);
  8135. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8136. int32 step = lua_interface->GetInt32Value(state, 3);
  8137. if (!player) {
  8138. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8139. return 0;
  8140. }
  8141. if (!player->IsPlayer()) {
  8142. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8143. return 0;
  8144. }
  8145. if (quest_id == 0) {
  8146. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8147. return 0;
  8148. }
  8149. if (step == 0) {
  8150. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8151. return 0;
  8152. }
  8153. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8154. if (!quest) {
  8155. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8156. return 0;
  8157. }
  8158. quest->StepFailed(step);
  8159. return 0;
  8160. }
  8161. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8162. if (!lua_interface)
  8163. return 0;
  8164. Spawn* player = lua_interface->GetSpawn(state);
  8165. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8166. if (!player) {
  8167. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8168. return 0;
  8169. }
  8170. if (!player->IsPlayer()) {
  8171. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8172. return 0;
  8173. }
  8174. if (quest_id == 0) {
  8175. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8176. return 0;
  8177. }
  8178. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8179. if (!quest) {
  8180. lua_interface->SetInt32Value(state, 0);
  8181. return 1;
  8182. }
  8183. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8184. return 1;
  8185. }
  8186. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8187. if (!lua_interface)
  8188. return 0;
  8189. string name = lua_interface->GetStringValue(state);
  8190. string value = lua_interface->GetStringValue(state, 2);
  8191. string comment = lua_interface->GetStringValue(state, 3);
  8192. if (name.length() == 0) {
  8193. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8194. return 0;
  8195. }
  8196. if (value.length() == 0) {
  8197. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8198. return 0;
  8199. }
  8200. string varname = string("lua_").append(name);
  8201. Variable* var = variables.FindVariable(varname);
  8202. if (var)
  8203. var->SetValue(value.c_str());
  8204. else {
  8205. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8206. variables.AddVariable(var);
  8207. }
  8208. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8209. return 0;
  8210. }
  8211. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8212. if (!lua_interface)
  8213. return 0;
  8214. string name = lua_interface->GetStringValue(state);
  8215. if (name.length() == 0) {
  8216. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8217. return 0;
  8218. }
  8219. string varname = string("lua_").append(name);
  8220. Variable* var = variables.FindVariable(varname);
  8221. if (var)
  8222. lua_interface->SetStringValue(state, var->GetValue());
  8223. else
  8224. lua_interface->SetStringValue(state, "NULL");
  8225. return 1;
  8226. }
  8227. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8228. if (!lua_interface)
  8229. return 0;
  8230. Spawn* player = lua_interface->GetSpawn(state);
  8231. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8232. if (!player) {
  8233. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8234. return 0;
  8235. }
  8236. if (!player->IsPlayer()) {
  8237. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8238. return 0;
  8239. }
  8240. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8241. return 1;
  8242. }
  8243. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8244. if (!lua_interface)
  8245. return 0;
  8246. Spawn* player = lua_interface->GetSpawn(state);
  8247. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8248. if (!player) {
  8249. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8250. return 0;
  8251. }
  8252. if (!player->IsPlayer()) {
  8253. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8254. return 0;
  8255. }
  8256. Language* language = master_languages_list.GetLanguage(language_id);
  8257. if (language)
  8258. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8259. return 0;
  8260. }
  8261. int EQ2Emu_lua_IsNight(lua_State* state) {
  8262. if (!lua_interface)
  8263. return 0;
  8264. ZoneServer* zone = lua_interface->GetZone(state);
  8265. if (!zone) {
  8266. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8267. return 0;
  8268. }
  8269. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8270. return 1;
  8271. }
  8272. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8273. if (!lua_interface)
  8274. return 0;
  8275. Spawn* spawn = lua_interface->GetSpawn(state);
  8276. if (!spawn) {
  8277. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8278. return 0;
  8279. }
  8280. if (!spawn->IsWidget()) {
  8281. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8282. return 0;
  8283. }
  8284. ((Widget*)spawn)->SetMultiFloorLift(true);
  8285. if (spawn->GetZone())
  8286. spawn->GetZone()->AddTransportSpawn(spawn);
  8287. return 0;
  8288. }
  8289. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8290. if (!lua_interface)
  8291. return 0;
  8292. Spawn* player = lua_interface->GetSpawn(state);
  8293. int32 path = lua_interface->GetInt32Value(state, 2);
  8294. if (!player) {
  8295. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8296. return 0;
  8297. }
  8298. if (!player->IsPlayer()) {
  8299. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8300. return 0;
  8301. }
  8302. if (path == 0) {
  8303. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8304. return 0;
  8305. }
  8306. Client* client = player->GetZone()->GetClientBySpawn(player);
  8307. if (!client) {
  8308. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8309. return 0;
  8310. }
  8311. client->SendFlightAutoMount(path);
  8312. return 0;
  8313. }
  8314. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8315. if (!lua_interface)
  8316. return 0;
  8317. Spawn* player = lua_interface->GetSpawn(state);
  8318. if (!player) {
  8319. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8320. return 0;
  8321. }
  8322. if (!player->IsPlayer()) {
  8323. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8324. return 0;
  8325. }
  8326. Client* client = player->GetZone()->GetClientBySpawn(player);
  8327. if (!client) {
  8328. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8329. return 0;
  8330. }
  8331. client->EndAutoMount();
  8332. return 0;
  8333. }
  8334. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8335. if (!lua_interface)
  8336. return 0;
  8337. Spawn* player = lua_interface->GetSpawn(state);
  8338. if (!player) {
  8339. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8340. return 0;
  8341. }
  8342. if (!player->IsPlayer()) {
  8343. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8344. return 0;
  8345. }
  8346. Client* client = player->GetZone()->GetClientBySpawn(player);
  8347. if (!client) {
  8348. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8349. return 0;
  8350. }
  8351. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8352. return 1;
  8353. }
  8354. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8355. if (!lua_interface)
  8356. return 0;
  8357. Spawn* player = lua_interface->GetSpawn(state);
  8358. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8359. int32 value = lua_interface->GetInt32Value(state, 3);
  8360. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8361. if (!player) {
  8362. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8363. return 0;
  8364. }
  8365. if (!player->IsPlayer()) {
  8366. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8367. return 0;
  8368. }
  8369. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8370. return 0;
  8371. }
  8372. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8373. if (!lua_interface)
  8374. return 0;
  8375. Spawn* player = lua_interface->GetSpawn(state);
  8376. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8377. if (!player) {
  8378. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8379. return 0;
  8380. }
  8381. if (!player->IsPlayer()) {
  8382. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8383. return 0;
  8384. }
  8385. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8386. if (!hd)
  8387. return 0;
  8388. lua_interface->SetInt32Value(state, hd->Value);
  8389. lua_interface->SetInt32Value(state, hd->Value2);
  8390. return 2;
  8391. }
  8392. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8393. if (!lua_interface)
  8394. return 0;
  8395. Spawn* spawn = lua_interface->GetSpawn(state);
  8396. int32 grid = lua_interface->GetInt32Value(state, 2);
  8397. if (!spawn) {
  8398. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8399. return 0;
  8400. }
  8401. if (grid == 0) {
  8402. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8403. return 0;
  8404. }
  8405. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8406. return 0;
  8407. }
  8408. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8409. if (!lua_interface)
  8410. return 0;
  8411. Spawn* spawn = lua_interface->GetSpawn(state);
  8412. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8413. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8414. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8415. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8416. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8417. if (!spawn) {
  8418. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8419. return 0;
  8420. }
  8421. //Add this quest to the list of required quests for this spawn
  8422. spawn->SetRequiredHistory(event_id, value1, value2);
  8423. //If private spawn value set
  8424. if (private_spawn) {
  8425. //Set the spawn to be private when not granted access via history
  8426. spawn->AddAllowAccessSpawn(spawn);
  8427. spawn->SetPrivateQuestSpawn(true);
  8428. }
  8429. //This value will override vis_flags in the vis packet
  8430. if (flag_override > 0)
  8431. spawn->SetQuestsRequiredOverride(flag_override);
  8432. return 0;
  8433. }
  8434. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8435. if (!lua_interface)
  8436. return 0;
  8437. Spawn* player = lua_interface->GetSpawn(state);
  8438. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8439. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8440. if (!player) {
  8441. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8442. return 0;
  8443. }
  8444. if (!player->IsPlayer()) {
  8445. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8446. return 0;
  8447. }
  8448. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8449. return 1;
  8450. }
  8451. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8452. if (!lua_interface)
  8453. return 0;
  8454. Spawn* player = lua_interface->GetSpawn(state);
  8455. int8 level = lua_interface->GetInt8Value(state, 2);
  8456. if (!player) {
  8457. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8458. return 0;
  8459. }
  8460. if (!player->IsPlayer()) {
  8461. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8462. return 0;
  8463. }
  8464. if (level == 0) {
  8465. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8466. return 0;
  8467. }
  8468. Client* client = player->GetZone()->GetClientBySpawn(player);
  8469. if (!client) {
  8470. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8471. return 0;
  8472. }
  8473. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8474. return 0;
  8475. }
  8476. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8477. if (!lua_interface)
  8478. return 0;
  8479. Spawn* player = lua_interface->GetSpawn(state);
  8480. int32 amount = lua_interface->GetInt32Value(state, 2);
  8481. if (!player) {
  8482. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8483. return 0;
  8484. }
  8485. if (!player->IsPlayer()) {
  8486. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8487. return 0;
  8488. }
  8489. if (amount == 0) {
  8490. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8491. return 0;
  8492. }
  8493. ((Player*)player)->AddCoins(amount);
  8494. return 0;
  8495. }
  8496. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8497. if (!lua_interface)
  8498. return 0;
  8499. Spawn* player = lua_interface->GetSpawn(state);
  8500. int32 amount = lua_interface->GetInt32Value(state, 2);
  8501. if (!player) {
  8502. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8503. return 0;
  8504. }
  8505. if (!player->IsPlayer()) {
  8506. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8507. return 0;
  8508. }
  8509. if (amount == 0) {
  8510. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8511. return 0;
  8512. }
  8513. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8514. return 1;
  8515. }
  8516. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8517. if (!lua_interface)
  8518. return 0;
  8519. ZoneServer* zone = lua_interface->GetZone(state);
  8520. if (!zone) {
  8521. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8522. return 0;
  8523. }
  8524. vector<Entity*> players = zone->GetPlayers();
  8525. if (players.size() == 0)
  8526. return 0;
  8527. lua_createtable(state, players.size(), 0);
  8528. int newTable = lua_gettop(state);
  8529. for (int32 i = 0; i < players.size(); i++) {
  8530. lua_interface->SetSpawnValue(state, players.at(i));
  8531. lua_rawseti(state, newTable, i + 1);
  8532. }
  8533. return 1;
  8534. }
  8535. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8536. if (!lua_interface)
  8537. return 0;
  8538. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8539. if (!zone) {
  8540. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8541. return 0;
  8542. }
  8543. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8544. //Map of <placement_id, location_id>
  8545. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8546. map<int32, int32>::iterator itr;
  8547. vector<Spawn*> group;
  8548. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8549. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8550. if (!location) {
  8551. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8552. return 0;
  8553. }
  8554. Spawn* spawn = 0;
  8555. if (location->entities[0]) {
  8556. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8557. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8558. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8559. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8560. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8561. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8562. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8563. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8564. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8565. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8566. if (spawn) {
  8567. const char* script = 0;
  8568. for (int x = 0; x < 3; x++) {
  8569. switch (x) {
  8570. case 0:
  8571. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8572. break;
  8573. case 1:
  8574. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8575. break;
  8576. case 2:
  8577. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8578. break;
  8579. }
  8580. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8581. spawn->SetSpawnScript(string(script));
  8582. break;
  8583. }
  8584. }
  8585. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8586. lua_interface->SetSpawnValue(state, spawn);
  8587. group.push_back(spawn);
  8588. }
  8589. else {
  8590. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8591. safe_delete(spawn);
  8592. }
  8593. }
  8594. }
  8595. if (!group.empty()) {
  8596. lua_createtable(state, group.size(), 0);
  8597. int newTable = lua_gettop(state);
  8598. for (int32 i = 0; i < group.size(); i++) {
  8599. lua_interface->SetSpawnValue(state, group[i]);
  8600. lua_rawseti(state, newTable, i + 1);
  8601. }
  8602. }
  8603. else
  8604. lua_pushnil(state);
  8605. return 1;
  8606. }
  8607. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8608. if (!lua_interface)
  8609. return 0;
  8610. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8611. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8612. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8613. if (!spawn) {
  8614. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8615. return 0;
  8616. }
  8617. if (anim_id == 0) {
  8618. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8619. return 0;
  8620. }
  8621. if (leeway == 0)
  8622. leeway = 5000;
  8623. spawn->SetSpawnAnim(anim_id);
  8624. spawn->SetSpawnAnimLeeway(leeway);
  8625. return 0;
  8626. }
  8627. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8628. if (!lua_interface)
  8629. return 0;
  8630. Spawn* player = lua_interface->GetSpawn(state);
  8631. if (!player) {
  8632. return 0;
  8633. }
  8634. Client* client = player->GetZone()->GetClientBySpawn(player);
  8635. if (!client) {
  8636. return 0;
  8637. }
  8638. lua_interface->SetInt32Value(state, client->GetVersion());
  8639. return 1;
  8640. }
  8641. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8642. if (!lua_interface)
  8643. return 0;
  8644. Item* item = lua_interface->GetItem(state);
  8645. if (!item) {
  8646. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8647. return 0;
  8648. }
  8649. lua_interface->SetInt32Value(state, item->details.item_id);
  8650. return 1;
  8651. }
  8652. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8653. if (!lua_interface)
  8654. return 0;
  8655. Spawn* spawn = lua_interface->GetSpawn(state);
  8656. if (!spawn) {
  8657. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8658. return 0;
  8659. }
  8660. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8661. return 1;
  8662. }
  8663. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8664. if (!lua_interface)
  8665. return 0;
  8666. Spawn* spawn = lua_interface->GetSpawn(state);
  8667. if (!spawn) {
  8668. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8669. return 0;
  8670. }
  8671. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8672. return 1;
  8673. }
  8674. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8675. if (!lua_interface)
  8676. return 0;
  8677. Spawn* spawn = lua_interface->GetSpawn(state);
  8678. if (!spawn) {
  8679. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8680. return 0;
  8681. }
  8682. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8683. return 1;
  8684. }
  8685. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8686. if (!lua_interface)
  8687. return 0;
  8688. Spawn* spawn = lua_interface->GetSpawn(state);
  8689. if (!spawn) {
  8690. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8691. return 0;
  8692. }
  8693. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8694. return 1;
  8695. }
  8696. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8697. if (!lua_interface)
  8698. return 0;
  8699. Spawn* spawn = lua_interface->GetSpawn(state);
  8700. float pct = lua_interface->GetFloatValue(state, 2);
  8701. if (!spawn) {
  8702. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8703. return 0;
  8704. }
  8705. if (pct == 0) {
  8706. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8707. return 0;
  8708. }
  8709. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8710. lua_interface->SetInt32Value(state, amount);
  8711. return 1;
  8712. }
  8713. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8714. if (!lua_interface)
  8715. return 0;
  8716. Spawn* spawn = lua_interface->GetSpawn(state);
  8717. float pct = lua_interface->GetFloatValue(state, 2);
  8718. if (!spawn) {
  8719. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8720. return 0;
  8721. }
  8722. if (pct == 0) {
  8723. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8724. return 0;
  8725. }
  8726. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8727. lua_interface->SetInt32Value(state, amount);
  8728. return 1;
  8729. }
  8730. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8731. if (!lua_interface)
  8732. return 0;
  8733. Spawn* spawn = lua_interface->GetSpawn(state);
  8734. if (!spawn) {
  8735. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8736. return 0;
  8737. }
  8738. if (!spawn->IsPlayer()) {
  8739. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8740. return 0;
  8741. }
  8742. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8743. return 1;
  8744. }
  8745. int EQ2Emu_lua_Evac(lua_State* state) {
  8746. if (!lua_interface)
  8747. return 0;
  8748. Spawn* target = lua_interface->GetSpawn(state);
  8749. if (target) {
  8750. float x = target->GetZone()->GetSafeX();
  8751. float y = target->GetZone()->GetSafeY();
  8752. float z = target->GetZone()->GetSafeZ();
  8753. float h = target->GetZone()->GetSafeHeading();
  8754. target->SetX(x);
  8755. target->SetY(y);
  8756. target->SetZ(z);
  8757. target->SetHeading(h);
  8758. target->SetSpawnOrigX(target->GetX());
  8759. target->SetSpawnOrigY(target->GetY());
  8760. target->SetSpawnOrigZ(target->GetZ());
  8761. target->SetSpawnOrigHeading(target->GetHeading());
  8762. if (target->IsPlayer()) {
  8763. Client* client = target->GetZone()->GetClientBySpawn(target);
  8764. if (client) {
  8765. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8766. if (packet)
  8767. {
  8768. packet->setDataByName("x", x);
  8769. packet->setDataByName("y", y);
  8770. packet->setDataByName("z", z);
  8771. client->QueuePacket(packet->serialize());
  8772. safe_delete(packet);
  8773. }
  8774. }
  8775. }
  8776. }
  8777. else {
  8778. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8779. ZoneServer* zone = spell->caster->GetZone();
  8780. float x = spell->caster->GetZone()->GetSafeX();
  8781. float y = spell->caster->GetZone()->GetSafeY();
  8782. float z = spell->caster->GetZone()->GetSafeZ();
  8783. float h = spell->caster->GetZone()->GetSafeHeading();
  8784. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8785. for (int32 i = 0; i < spell->targets.size(); i++) {
  8786. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8787. if (!target2)
  8788. continue;
  8789. target2->SetX(x);
  8790. target2->SetY(y);
  8791. target2->SetZ(z);
  8792. target2->SetHeading(h);
  8793. target2->SetSpawnOrigX(target2->GetX());
  8794. target2->SetSpawnOrigY(target2->GetY());
  8795. target2->SetSpawnOrigZ(target2->GetZ());
  8796. target2->SetSpawnOrigHeading(target2->GetHeading());
  8797. if (target2->IsPlayer()) {
  8798. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8799. if (client) {
  8800. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8801. if (packet)
  8802. {
  8803. client->SetReloadingZone(true);
  8804. packet->setDataByName("x", x);
  8805. packet->setDataByName("y", y);
  8806. packet->setDataByName("z", z);
  8807. client->QueuePacket(packet->serialize());
  8808. safe_delete(packet);
  8809. }
  8810. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8811. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8812. }
  8813. }
  8814. }
  8815. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8816. }
  8817. return 0;
  8818. }
  8819. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8820. if (!lua_interface)
  8821. return 0;
  8822. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8823. if (!luaspell) {
  8824. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8825. return 0;
  8826. }
  8827. int8 tier = luaspell->spell->GetSpellTier();
  8828. lua_interface->SetInt32Value(state, tier);
  8829. return 1;
  8830. }
  8831. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8832. if (!lua_interface)
  8833. return 0;
  8834. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8835. if (!luaspell) {
  8836. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8837. return 0;
  8838. }
  8839. int32 spell_id = luaspell->spell->GetSpellID();
  8840. lua_interface->SetInt32Value(state, spell_id);
  8841. return 1;
  8842. }
  8843. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8844. if (!lua_interface)
  8845. return 0;
  8846. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8847. if (!spawn) {
  8848. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8849. return 0;
  8850. }
  8851. if (!spawn->IsPlayer()) {
  8852. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8853. return 0;
  8854. }
  8855. ZoneServer* zone = spawn->GetZone();
  8856. if (!zone) {
  8857. return 0;
  8858. }
  8859. Client* client = zone->GetClientBySpawn(spawn);
  8860. if (!client) {
  8861. return 0;
  8862. }
  8863. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8864. return 0;
  8865. }
  8866. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8867. if (!lua_interface)
  8868. return 0;
  8869. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8870. if (!spawn) {
  8871. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8872. return 0;
  8873. }
  8874. if (!spawn->IsPlayer()) {
  8875. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8876. return 0;
  8877. }
  8878. ZoneServer* zone = spawn->GetZone();
  8879. if (!zone) {
  8880. return 0;
  8881. }
  8882. Client* client = zone->GetClientBySpawn(spawn);
  8883. if (!client) {
  8884. return 0;
  8885. }
  8886. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8887. return 0;
  8888. }
  8889. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8890. if (!lua_interface)
  8891. return 0;
  8892. Spawn* caster = lua_interface->GetSpawn(state);
  8893. Spawn* target = lua_interface->GetSpawn(state, 2);
  8894. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8895. string spell_name = lua_interface->GetStringValue(state, 4);
  8896. if (!caster) {
  8897. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8898. return 0;
  8899. }
  8900. if (!caster->IsEntity()) {
  8901. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8902. return 0;
  8903. }
  8904. if (!target) {
  8905. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8906. return 0;
  8907. }
  8908. if (!target->IsEntity()) {
  8909. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8910. return 0;
  8911. }
  8912. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8913. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8914. return 0;
  8915. }
  8916. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8917. if (!lua_interface)
  8918. return 0;
  8919. Spawn* player = lua_interface->GetSpawn(state);
  8920. int32 amount = lua_interface->GetInt32Value(state, 2);
  8921. if (player && player->IsPlayer() && amount > 0) {
  8922. ((Player*)player)->AddXP(amount);
  8923. ((Player*)player)->SetCharSheetChanged(true);
  8924. Client* client = player->GetZone()->GetClientBySpawn(player);
  8925. if (client) {
  8926. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8927. }
  8928. }
  8929. return 0;
  8930. }
  8931. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8932. if (!lua_interface)
  8933. return 0;
  8934. Spawn* player = lua_interface->GetSpawn(state);
  8935. int8 type = lua_interface->GetInt8Value(state, 2);
  8936. string text = lua_interface->GetStringValue(state, 3);
  8937. Client* client = 0;
  8938. if (player && player->IsPlayer())
  8939. client = player->GetZone()->GetClientBySpawn(player);
  8940. if (!client || text.length() == 0) {
  8941. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8942. return 0;
  8943. }
  8944. client->SimpleMessage(type, text.c_str());
  8945. return 0;
  8946. }
  8947. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8948. if (!lua_interface)
  8949. return 0;
  8950. Spawn* player = lua_interface->GetSpawn(state);
  8951. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8952. Client* client = 0;
  8953. if (player && player->IsPlayer())
  8954. client = player->GetZone()->GetClientBySpawn(player);
  8955. if (!client || !spawn) {
  8956. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8957. return 0;
  8958. }
  8959. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8960. if (!items) {
  8961. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8962. return 0;
  8963. }
  8964. client->Loot(spawn->GetLootCoins(), items, spawn);
  8965. return 0;
  8966. }
  8967. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8968. if (!lua_interface)
  8969. return 0;
  8970. Spawn* spawnref = lua_interface->GetSpawn(state);
  8971. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8972. if (spawn_id > 0 && spawnref) {
  8973. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8974. if (spawns.size() == 0) {
  8975. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8976. return 0;
  8977. }
  8978. Spawn* spawn = 0;
  8979. int16 index = MakeRandomInt(0, spawns.size());
  8980. if (index >= spawns.size() || index < 0)
  8981. index = 0;
  8982. spawn = spawns[index];
  8983. lua_interface->SetSpawnValue(state, spawn);
  8984. return 1;
  8985. }
  8986. else {
  8987. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8988. }
  8989. return 0;
  8990. }
  8991. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8992. Spawn* player = lua_interface->GetSpawn(state);
  8993. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8994. string name = lua_interface->GetStringValue(state, 3);
  8995. float distance = lua_interface->GetFloatValue(state, 4);
  8996. string command = lua_interface->GetStringValue(state, 5);
  8997. string error_text = lua_interface->GetStringValue(state, 6);
  8998. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8999. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9000. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9001. if (distance == 0)
  9002. distance = 10.0f;
  9003. if (command.length() == 0)
  9004. command = name;
  9005. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9006. if (spawns.size() == 0) {
  9007. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9008. return 0;
  9009. }
  9010. Spawn* spawn = 0;
  9011. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9012. spawn = *itr;
  9013. if (spawn) {
  9014. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9015. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9016. }
  9017. }
  9018. }
  9019. return 0;
  9020. }
  9021. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9022. if (!lua_interface)
  9023. return 0;
  9024. Client* client = 0;
  9025. Spawn* player = lua_interface->GetSpawn(state);
  9026. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9027. if (player && player->IsPlayer() && player->GetZone())
  9028. client = player->GetZone()->GetClientBySpawn(player);
  9029. else{
  9030. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9031. return 0;
  9032. }
  9033. if (client) {
  9034. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9035. if (packet) {
  9036. packet->setDataByName("goal_num", goal_num);
  9037. client->QueuePacket(packet->serialize());
  9038. safe_delete(packet);
  9039. }
  9040. }
  9041. return 0;
  9042. }
  9043. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9044. if (!lua_interface)
  9045. return 0;
  9046. Client* client = 0;
  9047. Spawn* player = lua_interface->GetSpawn(state);
  9048. if (player && player->IsPlayer() && player->GetZone())
  9049. client = player->GetZone()->GetClientBySpawn(player);
  9050. else {
  9051. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9052. return 0;
  9053. }
  9054. if (client) {
  9055. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9056. }
  9057. return 0;
  9058. }
  9059. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9060. if (!lua_interface)
  9061. return 0;
  9062. Client* client = 0;
  9063. Spawn* player = lua_interface->GetSpawn(state);
  9064. float duration = lua_interface->GetFloatValue(state, 2);
  9065. string text = lua_interface->GetStringValue(state, 3);
  9066. string voice = lua_interface->GetStringValue(state, 4);
  9067. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9068. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9069. string signal = lua_interface->GetStringValue(state, 7);
  9070. string goal1 = lua_interface->GetStringValue(state, 8);
  9071. string task1 = lua_interface->GetStringValue(state, 9);
  9072. string goal2 = lua_interface->GetStringValue(state, 10);
  9073. string task2 = lua_interface->GetStringValue(state, 11);
  9074. string goal3 = lua_interface->GetStringValue(state, 12);
  9075. string task3 = lua_interface->GetStringValue(state, 13);
  9076. string goal4 = lua_interface->GetStringValue(state, 14);
  9077. string task4 = lua_interface->GetStringValue(state, 15);
  9078. if (!player) {
  9079. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9080. return 0;
  9081. }
  9082. if (!player->IsPlayer()) {
  9083. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9084. return 0;
  9085. }
  9086. else
  9087. client = ((Player*)player)->GetClient();
  9088. if (!client) {
  9089. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9090. return 0;
  9091. }
  9092. if (text.length() == 0) {
  9093. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9094. return 0;
  9095. }
  9096. if (duration >= 0 && duration < 2)
  9097. duration = 2;
  9098. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9099. if (packet) {
  9100. packet->setDataByName("open_seconds_max", duration);
  9101. packet->setDataByName("text", text.c_str());
  9102. packet->setDataByName("voice", voice.c_str());
  9103. int8 num_goals = 1;
  9104. if (task2.length() > 0)
  9105. num_goals++;
  9106. if (task3.length() > 0)
  9107. num_goals++;
  9108. if (task4.length() > 0)
  9109. num_goals++;
  9110. packet->setArrayLengthByName("num_goals", num_goals);
  9111. for (int8 i = 0; i < num_goals; i++) {
  9112. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9113. }
  9114. if (goal1.length() > 0)
  9115. packet->setArrayDataByName("goal_text", goal1.c_str());
  9116. if (goal2.length() > 0)
  9117. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9118. if (goal3.length() > 0)
  9119. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9120. if (goal4.length() > 0)
  9121. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9122. packet->setSubArrayDataByName("task_text", task1.c_str());
  9123. if (task2.length() > 0)
  9124. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9125. if (task3.length() > 0)
  9126. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9127. if (task4.length() > 0)
  9128. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9129. packet->setDataByName("complete_sound", "click");
  9130. packet->setDataByName("signal", signal.c_str());
  9131. packet->setDataByName("voice_key1", voice_key1);
  9132. packet->setDataByName("voice_key2", voice_key2);
  9133. client->QueuePacket(packet->serialize());
  9134. safe_delete(packet);
  9135. }
  9136. return 0;
  9137. }
  9138. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9139. if (!lua_interface)
  9140. return 0;
  9141. Client* client = 0;
  9142. Spawn* player = lua_interface->GetSpawn(state);
  9143. string window = lua_interface->GetStringValue(state, 2);
  9144. int8 show = lua_interface->GetInt8Value(state, 3);
  9145. if (!player) {
  9146. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9147. return 0;
  9148. }
  9149. if (!player->IsPlayer()) {
  9150. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9151. return 0;
  9152. }
  9153. else
  9154. client = ((Player*)player)->GetClient();
  9155. if (!client) {
  9156. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9157. return 0;
  9158. }
  9159. if (window.length() == 0) {
  9160. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9161. return 0;
  9162. }
  9163. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9164. if (packet) {
  9165. packet->setDataByName("window", window.c_str());
  9166. packet->setDataByName("show", show);
  9167. client->QueuePacket(packet->serialize());
  9168. safe_delete(packet);
  9169. }
  9170. return 0;
  9171. }
  9172. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9173. //See GameEvents.txt for options that can be used for this function
  9174. if (!lua_interface)
  9175. return 0;
  9176. Client* client = 0;
  9177. Spawn* player = lua_interface->GetSpawn(state);
  9178. string event_name = lua_interface->GetStringValue(state, 2);
  9179. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9180. if (!player || !player->IsPlayer()) {
  9181. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9182. return 0;
  9183. }
  9184. if (player->GetZone())
  9185. client = player->GetZone()->GetClientBySpawn(player);
  9186. if (!client) {
  9187. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9188. return 0;
  9189. }
  9190. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9191. if (packet) {
  9192. packet->setDataByName("event_name", event_name.c_str());
  9193. packet->setDataByName("enabled", enabled);
  9194. client->QueuePacket(packet->serialize());
  9195. safe_delete(packet);
  9196. }
  9197. return 0;
  9198. }
  9199. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9200. if (!lua_interface)
  9201. return 0;
  9202. Spawn* player = lua_interface->GetSpawn(state);
  9203. if (player && player->IsPlayer()) {
  9204. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9205. return 1;
  9206. }
  9207. return 0;
  9208. }
  9209. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9210. if (!lua_interface)
  9211. return 0;
  9212. Spawn* player = lua_interface->GetSpawn(state);
  9213. int8 step = lua_interface->GetInt8Value(state, 2);
  9214. if (player && player->IsPlayer() && step > 0) {
  9215. ((Player*)player)->SetTutorialStep(step);
  9216. }
  9217. return 0;
  9218. }
  9219. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9220. if (!lua_interface)
  9221. return 0;
  9222. Client* client = 0;
  9223. Spawn* player = lua_interface->GetSpawn(state);
  9224. string window = lua_interface->GetStringValue(state, 2);
  9225. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9226. if (!player) {
  9227. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9228. return 0;
  9229. }
  9230. if (!player->IsPlayer()) {
  9231. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9232. return 0;
  9233. }
  9234. else
  9235. client = ((Player*)player)->GetClient();
  9236. if (!client) {
  9237. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9238. return 0;
  9239. }
  9240. if (window.length() == 0) {
  9241. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9242. return 0;
  9243. }
  9244. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9245. if (packet) {
  9246. packet->setDataByName("window", window.c_str());
  9247. packet->setDataByName("flash_seconds", flash_seconds);
  9248. client->QueuePacket(packet->serialize());
  9249. safe_delete(packet);
  9250. }
  9251. return 0;
  9252. }
  9253. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9254. if (!lua_interface)
  9255. return 0;
  9256. Spawn* spawn = lua_interface->GetSpawn(state);
  9257. Spawn* target = lua_interface->GetSpawn(state, 2);
  9258. if (spawn && target)
  9259. return spawn->CheckLoS(target);
  9260. return 0;
  9261. }
  9262. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9263. if (!lua_interface)
  9264. return 0;
  9265. Spawn* spawn = lua_interface->GetSpawn(state);
  9266. float x = lua_interface->GetFloatValue(state, 2);
  9267. float y = lua_interface->GetFloatValue(state, 3);
  9268. float z = lua_interface->GetFloatValue(state, 4);
  9269. if (spawn)
  9270. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9271. return 0;
  9272. }
  9273. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9274. if (!lua_interface)
  9275. return 0;
  9276. ZoneServer* zone = lua_interface->GetZone(state);
  9277. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9278. if (zone)
  9279. zone->SetExpansionFlag(xpackFlag);
  9280. return 0;
  9281. }
  9282. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9283. if (!lua_interface)
  9284. return 0;
  9285. ZoneServer* zone = lua_interface->GetZone(state);
  9286. if (zone) {
  9287. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9288. return 1;
  9289. }
  9290. return 0;
  9291. }
  9292. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9293. if (!lua_interface)
  9294. return 0;
  9295. ZoneServer* zone = lua_interface->GetZone(state);
  9296. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9297. if (zone)
  9298. zone->SetHolidayFlag(holidayFlag);
  9299. return 0;
  9300. }
  9301. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9302. if (!lua_interface)
  9303. return 0;
  9304. ZoneServer* zone = lua_interface->GetZone(state);
  9305. if (zone) {
  9306. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9307. return 1;
  9308. }
  9309. return 0;
  9310. }
  9311. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9312. if (!lua_interface)
  9313. return 0;
  9314. Spawn* spawn = lua_interface->GetSpawn(state);
  9315. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9316. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9317. float distance = lua_interface->GetFloatValue(state, 4);
  9318. string in_range_function = lua_interface->GetStringValue(state, 5);
  9319. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9320. if (spawn && distance > 0 && in_range_function.length() > 0)
  9321. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9322. return 0;
  9323. }
  9324. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9325. if (!lua_interface)
  9326. return 0;
  9327. Spawn* spawn = lua_interface->GetSpawn(state);
  9328. Spawn* target = lua_interface->GetSpawn(state, 2);
  9329. if (spawn && target)
  9330. {
  9331. if (spawn->IsPlayer() && target->IsEntity())
  9332. {
  9333. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9334. return 1;
  9335. }
  9336. else if (spawn->IsEntity() && target->IsEntity())
  9337. {
  9338. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9339. return 1;
  9340. }
  9341. }
  9342. return 0;
  9343. }
  9344. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9345. if (!lua_interface)
  9346. return 0;
  9347. Spawn* spawn = lua_interface->GetSpawn(state);
  9348. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9349. if (spawn && spawn->IsEntity())
  9350. {
  9351. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9352. if (spawn->IsPlayer())
  9353. {
  9354. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9355. if (client)
  9356. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9357. }
  9358. }
  9359. return 0;
  9360. }
  9361. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9362. if (!lua_interface)
  9363. return 0;
  9364. Spawn* spawn = lua_interface->GetSpawn(state);
  9365. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9366. if (spawn && spawn->IsEntity())
  9367. {
  9368. ((Entity*)spawn)->SetSeeHideSpell(val);
  9369. if (spawn->IsPlayer())
  9370. {
  9371. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9372. if (client)
  9373. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9374. }
  9375. }
  9376. return 0;
  9377. }
  9378. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9379. {
  9380. if (!lua_interface)
  9381. return 0;
  9382. Spawn* player = lua_interface->GetSpawn(state);
  9383. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9384. string command = lua_interface->GetStringValue(state, 3);
  9385. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9386. lua_interface->ResetFunctionStack(state);
  9387. if (spawn && player && player->IsPlayer())
  9388. {
  9389. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9390. bool res = false;
  9391. if (cmd)
  9392. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9393. lua_interface->SetBooleanValue(state, res);
  9394. return 1;
  9395. }
  9396. return 0;
  9397. }
  9398. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9399. {
  9400. if (!lua_interface)
  9401. return 0;
  9402. Spawn* spawn = lua_interface->GetSpawn(state);
  9403. int32 charID = lua_interface->GetInt32Value(state, 2);
  9404. string command = lua_interface->GetStringValue(state, 3);
  9405. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9406. lua_interface->ResetFunctionStack(state);
  9407. if (spawn && charID)
  9408. {
  9409. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9410. bool res = false;
  9411. if (cmd)
  9412. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9413. lua_interface->SetBooleanValue(state, res);
  9414. return 1;
  9415. }
  9416. return 0;
  9417. }
  9418. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9419. {
  9420. if (!lua_interface)
  9421. return 0;
  9422. Spawn* spawn = lua_interface->GetSpawn(state);
  9423. string command = lua_interface->GetStringValue(state, 2);
  9424. lua_interface->ResetFunctionStack(state);
  9425. if (spawn && command.length() > 0)
  9426. spawn->RemovePrimaryEntityCommand(command.c_str());
  9427. return 0;
  9428. }
  9429. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9430. if (!lua_interface)
  9431. return 0;
  9432. Spawn* spawn = lua_interface->GetSpawn(state);
  9433. float distance = lua_interface->GetFloatValue(state, 2);
  9434. string command = lua_interface->GetStringValue(state, 3);
  9435. Spawn* player = lua_interface->GetSpawn(state, 4);
  9436. lua_interface->ResetFunctionStack(state);
  9437. if (spawn) {
  9438. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9439. }
  9440. return 0;
  9441. }
  9442. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9443. if (!lua_interface)
  9444. return 0;
  9445. Spawn* spawn = lua_interface->GetSpawn(state);
  9446. Spawn* player = lua_interface->GetSpawn(state, 2);
  9447. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9448. lua_interface->ResetFunctionStack(state);
  9449. if (spawn && player && transport_id && player->IsPlayer()) {
  9450. Client* client = 0;
  9451. if (player && player->IsPlayer())
  9452. client = player->GetZone()->GetClientBySpawn(player);
  9453. if (!client)
  9454. return 0;
  9455. vector<TransportDestination*> destinations;
  9456. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9457. if (destinations.size())
  9458. {
  9459. client->SetTemporaryTransportID(transport_id);
  9460. client->ProcessTeleport(spawn, &destinations, transport_id);
  9461. }
  9462. else
  9463. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9464. }
  9465. return 0;
  9466. }
  9467. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9468. if (!lua_interface)
  9469. return 0;
  9470. Spawn* player = lua_interface->GetSpawn(state);
  9471. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9472. lua_interface->ResetFunctionStack(state);
  9473. if (player && player->IsPlayer()) {
  9474. Client* client = 0;
  9475. if (player && player->IsPlayer())
  9476. client = player->GetZone()->GetClientBySpawn(player);
  9477. if (!client)
  9478. return 0;
  9479. client->SetTemporaryTransportID(transport_id);
  9480. }
  9481. return 0;
  9482. }
  9483. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9484. if (!lua_interface)
  9485. return 0;
  9486. Spawn* player = lua_interface->GetSpawn(state);
  9487. lua_interface->ResetFunctionStack(state);
  9488. if (player && player->IsPlayer()) {
  9489. Client* client = 0;
  9490. if (player && player->IsPlayer())
  9491. client = player->GetZone()->GetClientBySpawn(player);
  9492. if (!client)
  9493. return 0;
  9494. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9495. return 1;
  9496. }
  9497. return 0;
  9498. }
  9499. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9500. if (!lua_interface)
  9501. return 0;
  9502. Spawn* spawn = lua_interface->GetSpawn(state);
  9503. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9504. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9505. if (!spawn) {
  9506. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9507. return 0;
  9508. }
  9509. if (!spawn->IsEntity()) {
  9510. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9511. return 0;
  9512. }
  9513. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9514. {
  9515. 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);
  9516. return 0;
  9517. }
  9518. lua_interface->ResetFunctionStack(state);
  9519. if (spell && spell->targets.size() > 0) {
  9520. ZoneServer* zone = spell->caster->GetZone();
  9521. for (int8 i = 0; i < spell->targets.size(); i++) {
  9522. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9523. if (target->IsEntity()) {
  9524. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9525. if (target->IsPlayer())
  9526. ((Player*)target)->SetCharSheetChanged(true);
  9527. }
  9528. }
  9529. }
  9530. else {
  9531. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9532. if (spawn->IsPlayer())
  9533. ((Player*)spawn)->SetCharSheetChanged(true);
  9534. }
  9535. return 0;
  9536. }
  9537. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9538. if (!lua_interface)
  9539. return 0;
  9540. Spawn* spawn = lua_interface->GetSpawn(state);
  9541. lua_interface->ResetFunctionStack(state);
  9542. if (!spawn) {
  9543. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9544. return 0;
  9545. }
  9546. if (!spawn->IsEntity()) {
  9547. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9548. return 0;
  9549. }
  9550. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9551. return 1;
  9552. }
  9553. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9554. if (!lua_interface)
  9555. return 0;
  9556. int32 spell_id = lua_interface->GetInt32Value(state);
  9557. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9558. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9559. if (spell_id > 0) {
  9560. if (spell_tier == 0)
  9561. spell_tier = 1;
  9562. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9563. LuaSpell* lua_spell = 0;
  9564. if(custom_lua_script.size() > 0)
  9565. {
  9566. // attempt to load the custom script since it isn't already loaded
  9567. // we will re-obtain the lua_spell further below
  9568. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9569. {
  9570. LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
  9571. lua_interface->LoadLuaSpell(custom_lua_script);
  9572. }
  9573. }
  9574. else
  9575. custom_lua_script = spell->GetSpellData()->lua_script;
  9576. if (!lua_spell && lua_interface)
  9577. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9578. if (!lua_spell)
  9579. {
  9580. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9581. return 0;
  9582. }
  9583. lua_spell->spell = new Spell(spell);
  9584. lua_interface->AddCustomSpell(lua_spell);
  9585. lua_interface->SetSpellValue(state, lua_spell);
  9586. return 1;
  9587. }
  9588. return 0;
  9589. }
  9590. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9591. if (!lua_interface)
  9592. return 0;
  9593. LuaSpell* spell = lua_interface->GetSpell(state);
  9594. string field = lua_interface->GetStringValue(state, 2);
  9595. if (!spell) {
  9596. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9597. return 0;
  9598. }
  9599. if (!spell->spell || !spell->spell->GetSpellData()) {
  9600. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9601. return 0;
  9602. }
  9603. boost::to_lower(field);
  9604. return spell->spell->GetSpellData(state, field);
  9605. }
  9606. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9607. if (!lua_interface)
  9608. return 0;
  9609. LuaSpell* spell = lua_interface->GetSpell(state);
  9610. string field = lua_interface->GetStringValue(state, 2);
  9611. int8 fieldArg = 3; // field value after the initial set
  9612. if (!spell) {
  9613. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9614. return 0;
  9615. }
  9616. if (!spell->spell || !spell->spell->GetSpellData()) {
  9617. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9618. return 0;
  9619. }
  9620. boost::to_lower(field);
  9621. bool valSet = false;
  9622. spell->spell->SetSpellData(state, field, fieldArg);
  9623. return valSet;
  9624. }
  9625. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9626. if (!lua_interface)
  9627. return 0;
  9628. LuaSpell* spell = lua_interface->GetSpell(state);
  9629. int8 idx = lua_interface->GetInt32Value(state, 2);
  9630. if (!spell) {
  9631. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9632. return 0;
  9633. }
  9634. if (!spell->spell || !spell->spell->GetSpellData()) {
  9635. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9636. return 0;
  9637. }
  9638. if (spell->spell->lua_data.size() <= idx)
  9639. {
  9640. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9641. return 0;
  9642. }
  9643. bool setVal = true;
  9644. LUAData* data = spell->spell->lua_data[idx];
  9645. switch (data->type)
  9646. {
  9647. case 0:
  9648. {
  9649. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9650. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9651. data->int_value = value;
  9652. data->int_value2 = value2;
  9653. break;
  9654. }
  9655. case 1:
  9656. {
  9657. float value = lua_interface->GetFloatValue(state, 3);
  9658. float value2 = lua_interface->GetFloatValue(state, 4);
  9659. data->float_value = value;
  9660. data->float_value2 = value2;
  9661. break;
  9662. }
  9663. case 2:
  9664. {
  9665. bool value = lua_interface->GetBooleanValue(state, 3);
  9666. data->bool_value = value;
  9667. break;
  9668. }
  9669. case 3:
  9670. {
  9671. string value = lua_interface->GetStringValue(state, 3);
  9672. string value2 = lua_interface->GetStringValue(state, 4);
  9673. data->string_value = value;
  9674. data->string_value2 = value2;
  9675. break;
  9676. }
  9677. default:
  9678. setVal = false;
  9679. }
  9680. return setVal;
  9681. }
  9682. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9683. if (!lua_interface)
  9684. return 0;
  9685. LuaSpell* spell = lua_interface->GetSpell(state);
  9686. int8 idx = lua_interface->GetInt32Value(state, 2);
  9687. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9688. if (!spell) {
  9689. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9690. return 0;
  9691. }
  9692. if (!spell->spell || !spell->spell->GetSpellData()) {
  9693. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9694. return 0;
  9695. }
  9696. if (spell->spell->lua_data.size() <= idx)
  9697. {
  9698. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9699. return 0;
  9700. }
  9701. bool setVal = true;
  9702. LUAData* data = spell->spell->lua_data[idx];
  9703. switch (data->type)
  9704. {
  9705. case 0:
  9706. {
  9707. if(!secondfield)
  9708. lua_interface->SetSInt32Value(state, data->int_value);
  9709. else
  9710. lua_interface->SetSInt32Value(state, data->int_value2);
  9711. break;
  9712. }
  9713. case 1:
  9714. {
  9715. if (!secondfield)
  9716. lua_interface->SetFloatValue(state, data->float_value);
  9717. else
  9718. lua_interface->SetFloatValue(state, data->float_value2);
  9719. break;
  9720. }
  9721. case 2:
  9722. {
  9723. lua_interface->SetBooleanValue(state, data->bool_value);
  9724. break;
  9725. }
  9726. case 3:
  9727. {
  9728. if (!secondfield)
  9729. lua_interface->SetStringValue(state, data->string_value.c_str());
  9730. else
  9731. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9732. break;
  9733. }
  9734. default:
  9735. setVal = false;
  9736. }
  9737. return setVal;
  9738. }
  9739. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9740. if (!lua_interface)
  9741. return 0;
  9742. LuaSpell* spell = lua_interface->GetSpell(state);
  9743. int8 idx = lua_interface->GetInt32Value(state, 2);
  9744. string field = lua_interface->GetStringValue(state, 3);
  9745. boost::to_lower(field);
  9746. if (!spell) {
  9747. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9748. return 0;
  9749. }
  9750. if (!spell->spell || !spell->spell->GetSpellData()) {
  9751. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9752. return 0;
  9753. }
  9754. if (spell->spell->effects.size() <= idx)
  9755. {
  9756. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9757. return 0;
  9758. }
  9759. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9760. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9761. if (field == "description")
  9762. effect->description = string(lua_interface->GetStringValue(state, 4));
  9763. else if (field == "bullet")
  9764. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9765. else if (field == "percentage")
  9766. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9767. else // no match
  9768. return 0;
  9769. return 1;
  9770. }
  9771. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9772. if (!lua_interface)
  9773. return 0;
  9774. LuaSpell* spell = lua_interface->GetSpell(state);
  9775. int8 idx = lua_interface->GetInt32Value(state, 2);
  9776. string field = lua_interface->GetStringValue(state, 3);
  9777. boost::to_lower(field);
  9778. if (!spell) {
  9779. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9780. return 0;
  9781. }
  9782. if (!spell->spell || !spell->spell->GetSpellData()) {
  9783. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9784. return 0;
  9785. }
  9786. if (spell->spell->effects.size() <= idx)
  9787. {
  9788. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9789. return 0;
  9790. }
  9791. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9792. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9793. if (field == "description")
  9794. lua_interface->SetStringValue(state, effect->description.c_str());
  9795. else if (field == "bullet")
  9796. lua_interface->SetInt32Value(state, effect->subbullet);
  9797. else if (field == "percentage")
  9798. lua_interface->SetInt32Value(state, effect->percentage);
  9799. else // no match
  9800. return 0;
  9801. return 1;
  9802. }
  9803. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9804. if (!lua_interface)
  9805. return 0;
  9806. LuaSpell* spell = lua_interface->GetSpell(state);
  9807. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9808. Spawn* target = lua_interface->GetSpawn(state, 3);
  9809. if (!target) {
  9810. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9811. return 0;
  9812. }
  9813. if (!target->IsEntity()) {
  9814. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9815. return 0;
  9816. }
  9817. if (!spell) {
  9818. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9819. return 0;
  9820. }
  9821. if (caster && !caster->IsEntity()) {
  9822. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9823. return 0;
  9824. }
  9825. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9826. return 0;
  9827. }
  9828. int EQ2Emu_lua_InWater(lua_State* state) {
  9829. if (!lua_interface)
  9830. return 0;
  9831. Spawn* spawn = lua_interface->GetSpawn(state);
  9832. lua_interface->ResetFunctionStack(state);
  9833. if (spawn) {
  9834. lua_interface->SetBooleanValue(state, spawn->InWater());
  9835. return 1;
  9836. }
  9837. return 0;
  9838. }
  9839. int EQ2Emu_lua_InLava(lua_State* state) {
  9840. if (!lua_interface)
  9841. return 0;
  9842. Spawn* spawn = lua_interface->GetSpawn(state);
  9843. lua_interface->ResetFunctionStack(state);
  9844. if (spawn) {
  9845. lua_interface->SetBooleanValue(state, spawn->InLava());
  9846. return 1;
  9847. }
  9848. return 0;
  9849. }
  9850. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9851. if (!lua_interface)
  9852. return 0;
  9853. Spawn* attacker = lua_interface->GetSpawn(state);
  9854. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9855. int8 type = lua_interface->GetInt8Value(state, 3);
  9856. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9857. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9858. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9859. string spell_name = lua_interface->GetStringValue(state, 7);
  9860. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9861. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9862. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9863. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9864. lua_interface->ResetFunctionStack(state);
  9865. if (!attacker) {
  9866. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9867. return 0;
  9868. }
  9869. if (!attacker->IsEntity()) {
  9870. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9871. return 0;
  9872. }
  9873. if (!victim) {
  9874. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9875. return 0;
  9876. }
  9877. if (!victim->IsEntity()) {
  9878. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9879. return 0;
  9880. }
  9881. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9882. return 0;
  9883. }
  9884. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9885. if (!lua_interface)
  9886. return 0;
  9887. Spawn* spawn = lua_interface->GetSpawn(state);
  9888. lua_interface->ResetFunctionStack(state);
  9889. if (spawn) {
  9890. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9891. return 1;
  9892. }
  9893. return 0;
  9894. }
  9895. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9896. if (!lua_interface)
  9897. return 0;
  9898. Spawn* spawn = lua_interface->GetSpawn(state);
  9899. bool invul = lua_interface->GetBooleanValue(state, 2);
  9900. lua_interface->ResetFunctionStack(state);
  9901. if (spawn) {
  9902. spawn->SetInvulnerable(invul);
  9903. }
  9904. return 0;
  9905. }
  9906. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  9907. if (!lua_interface)
  9908. return 0;
  9909. string category = lua_interface->GetStringValue(state);
  9910. string name = lua_interface->GetStringValue(state, 2);
  9911. lua_interface->ResetFunctionStack(state);
  9912. Rule *ret = 0;
  9913. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9914. lua_interface->SetBooleanValue(state, ret->GetBool());
  9915. return 1;
  9916. }
  9917. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9918. return 0;
  9919. }
  9920. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9921. if (!lua_interface)
  9922. return 0;
  9923. string category = lua_interface->GetStringValue(state);
  9924. string name = lua_interface->GetStringValue(state, 2);
  9925. lua_interface->ResetFunctionStack(state);
  9926. Rule *ret = 0;
  9927. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9928. lua_interface->SetInt32Value(state, ret->GetInt32());
  9929. return 1;
  9930. }
  9931. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9932. return 0;
  9933. }
  9934. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  9935. if (!lua_interface)
  9936. return 0;
  9937. string category = lua_interface->GetStringValue(state);
  9938. string name = lua_interface->GetStringValue(state, 2);
  9939. lua_interface->ResetFunctionStack(state);
  9940. Rule *ret = 0;
  9941. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9942. lua_interface->SetFloatValue(state, ret->GetFloat());
  9943. return 1;
  9944. }
  9945. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9946. return 0;
  9947. }
  9948. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  9949. if (!lua_interface)
  9950. return 0;
  9951. Spawn* spawn = lua_interface->GetSpawn(state);
  9952. string type = lua_interface->GetStringValue(state, 2);
  9953. lua_interface->ResetFunctionStack(state);
  9954. if (spawn) {
  9955. int res = 1;
  9956. boost::to_lower(type);
  9957. if(type == "assigned_aa")
  9958. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  9959. else if ( type == "unassigned_aa")
  9960. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  9961. else if ( type == "assigned_tradeskill_aa")
  9962. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  9963. else if ( type == "unassigned_tradeskill_aa")
  9964. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  9965. else if ( type == "assigned_prestige_aa")
  9966. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  9967. else if ( type == "unassigned_prestige_aa")
  9968. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  9969. else if ( type == "assigned_tradeskill_prestige_aa")
  9970. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  9971. else if ( type == "unassigned_tradeskill_prestige_aa")
  9972. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  9973. else
  9974. res = 0;
  9975. return res;
  9976. }
  9977. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  9978. return 0;
  9979. }
  9980. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  9981. if (!lua_interface)
  9982. return 0;
  9983. Spawn* spawn = lua_interface->GetSpawn(state);
  9984. string type = lua_interface->GetStringValue(state, 2);
  9985. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9986. lua_interface->ResetFunctionStack(state);
  9987. if (spawn) {
  9988. boost::to_lower(type);
  9989. if(type == "assigned_aa")
  9990. spawn->SetAssignedAA((sint16)value);
  9991. else if ( type == "unassigned_aa")
  9992. spawn->SetUnassignedAA((sint16)value);
  9993. else if ( type == "assigned_tradeskill_aa")
  9994. spawn->SetTradeskillAA((sint16)value);
  9995. else if ( type == "unassigned_tradeskill_aa")
  9996. spawn->SetUnassignedTradeskillAA((sint16)value);
  9997. else if ( type == "assigned_prestige_aa")
  9998. spawn->SetPrestigeAA((sint16)value);
  9999. else if ( type == "unassigned_prestige_aa")
  10000. spawn->SetUnassignedPrestigeAA((sint16)value);
  10001. else if ( type == "assigned_tradeskill_prestige_aa")
  10002. spawn->SetTradeskillPrestigeAA((sint16)value);
  10003. else if ( type == "unassigned_tradeskill_prestige_aa")
  10004. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10005. if(spawn->IsPlayer())
  10006. ((Player*)spawn)->SetCharSheetChanged(true);
  10007. }
  10008. return 0;
  10009. }
  10010. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10011. if (!lua_interface)
  10012. return 0;
  10013. string titleName = lua_interface->GetStringValue(state);
  10014. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10015. lua_interface->ResetFunctionStack(state);
  10016. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10017. lua_interface->SetSInt32Value(state, index);
  10018. return 1;
  10019. }
  10020. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10021. if (!lua_interface)
  10022. return 0;
  10023. Spawn* spawn = lua_interface->GetSpawn(state);
  10024. string titleName = lua_interface->GetStringValue(state, 2);
  10025. lua_interface->ResetFunctionStack(state);
  10026. if(!spawn->IsPlayer())
  10027. {
  10028. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10029. lua_interface->SetSInt32Value(state, -1);
  10030. return 1;
  10031. }
  10032. Player* player = (Player*)spawn;
  10033. // check if player already has the title, don't need to add twice
  10034. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10035. if ( playerHasTitle)
  10036. {
  10037. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10038. return 1;
  10039. }
  10040. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10041. if(!title)
  10042. {
  10043. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10044. lua_interface->SetSInt32Value(state, -1);
  10045. return 1;
  10046. }
  10047. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10048. if(returnIdx < 0)
  10049. {
  10050. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10051. }
  10052. lua_interface->SetSInt32Value(state, returnIdx);
  10053. player->GetClient()->SendTitleUpdate();
  10054. return 1;
  10055. }
  10056. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10057. if (!lua_interface)
  10058. return 0;
  10059. Spawn* spawn = lua_interface->GetSpawn(state);
  10060. string titleName = lua_interface->GetStringValue(state, 2);
  10061. lua_interface->ResetFunctionStack(state);
  10062. if(!spawn->IsPlayer())
  10063. {
  10064. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10065. return 0;
  10066. }
  10067. Player* player = (Player*)spawn;
  10068. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10069. if(!title)
  10070. {
  10071. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10072. return 0;
  10073. }
  10074. if(title->GetPrefix())
  10075. {
  10076. 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());
  10077. return 0;
  10078. }
  10079. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10080. player->GetClient()->SendTitleUpdate();
  10081. return 1;
  10082. }
  10083. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10084. if (!lua_interface)
  10085. return 0;
  10086. Spawn* spawn = lua_interface->GetSpawn(state);
  10087. string titleName = lua_interface->GetStringValue(state, 2);
  10088. lua_interface->ResetFunctionStack(state);
  10089. if(!spawn->IsPlayer())
  10090. {
  10091. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10092. return 0;
  10093. }
  10094. Player* player = (Player*)spawn;
  10095. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10096. if(!title)
  10097. {
  10098. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10099. return 0;
  10100. }
  10101. if(!title->GetPrefix())
  10102. {
  10103. 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());
  10104. return 0;
  10105. }
  10106. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10107. player->GetClient()->SendTitleUpdate();
  10108. return 1;
  10109. }
  10110. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10111. if (!lua_interface)
  10112. return 0;
  10113. Spawn* spawn = lua_interface->GetSpawn(state);
  10114. lua_interface->ResetFunctionStack(state);
  10115. if(!spawn->IsPlayer())
  10116. {
  10117. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10118. return 0;
  10119. }
  10120. Player* player = (Player*)spawn;
  10121. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10122. player->GetClient()->SendTitleUpdate();
  10123. return 1;
  10124. }
  10125. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10126. if (!lua_interface)
  10127. return 0;
  10128. Spawn* spawn = lua_interface->GetSpawn(state);
  10129. lua_interface->ResetFunctionStack(state);
  10130. if(!spawn->IsPlayer())
  10131. {
  10132. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10133. return 0;
  10134. }
  10135. Player* player = (Player*)spawn;
  10136. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10137. player->GetClient()->SendTitleUpdate();
  10138. return 1;
  10139. }
  10140. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10141. if (!lua_interface)
  10142. return 0;
  10143. Spawn* spawn = lua_interface->GetSpawn(state);
  10144. string field = lua_interface->GetStringValue(state, 2);
  10145. lua_interface->ResetFunctionStack(state);
  10146. if(!spawn || !spawn->IsEntity())
  10147. {
  10148. 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));
  10149. return 0;
  10150. }
  10151. Entity* ent = (Entity*)spawn;
  10152. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10153. return 1;
  10154. }
  10155. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10156. if (!lua_interface)
  10157. return 0;
  10158. Spawn* spawn = lua_interface->GetSpawn(state);
  10159. string field = lua_interface->GetStringValue(state, 2);
  10160. lua_interface->ResetFunctionStack(state);
  10161. if(!spawn || !spawn->IsEntity())
  10162. {
  10163. 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));
  10164. return 0;
  10165. }
  10166. Entity* ent = (Entity*)spawn;
  10167. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10168. return 1;
  10169. }
  10170. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10171. if (!lua_interface)
  10172. return 0;
  10173. Spawn* spawn = lua_interface->GetSpawn(state);
  10174. string field = lua_interface->GetStringValue(state, 2);
  10175. lua_interface->ResetFunctionStack(state);
  10176. if(!spawn || !spawn->IsEntity())
  10177. {
  10178. 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));
  10179. return 0;
  10180. }
  10181. Entity* ent = (Entity*)spawn;
  10182. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10183. return 1;
  10184. }
  10185. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10186. if (!lua_interface)
  10187. return 0;
  10188. Spawn* spawn = lua_interface->GetSpawn(state);
  10189. string field = lua_interface->GetStringValue(state, 2);
  10190. lua_interface->ResetFunctionStack(state);
  10191. if(!spawn || !spawn->IsEntity())
  10192. {
  10193. 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));
  10194. return 0;
  10195. }
  10196. Entity* ent = (Entity*)spawn;
  10197. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10198. return 1;
  10199. }
  10200. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10201. if (!lua_interface)
  10202. return 0;
  10203. Spawn* spawn = lua_interface->GetSpawn(state);
  10204. string field = lua_interface->GetStringValue(state, 2);
  10205. string value = lua_interface->GetStringValue(state, 3);
  10206. lua_interface->ResetFunctionStack(state);
  10207. if(!spawn || !spawn->IsEntity())
  10208. {
  10209. 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));
  10210. return 0;
  10211. }
  10212. Entity* ent = (Entity*)spawn;
  10213. bool set_ = ent->SetInfoStructString(field, value);
  10214. lua_interface->SetBooleanValue(state, set_);
  10215. return 1;
  10216. }
  10217. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10218. if (!lua_interface)
  10219. return 0;
  10220. Spawn* spawn = lua_interface->GetSpawn(state);
  10221. string field = lua_interface->GetStringValue(state, 2);
  10222. int64 value = lua_interface->GetInt64Value(state, 3);
  10223. lua_interface->ResetFunctionStack(state);
  10224. if(!spawn || !spawn->IsEntity())
  10225. {
  10226. 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));
  10227. return 0;
  10228. }
  10229. Entity* ent = (Entity*)spawn;
  10230. bool set_ = ent->SetInfoStructUInt(field, value);
  10231. lua_interface->SetBooleanValue(state, set_);
  10232. return 1;
  10233. }
  10234. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10235. if (!lua_interface)
  10236. return 0;
  10237. Spawn* spawn = lua_interface->GetSpawn(state);
  10238. string field = lua_interface->GetStringValue(state, 2);
  10239. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10240. lua_interface->ResetFunctionStack(state);
  10241. if(!spawn || !spawn->IsEntity())
  10242. {
  10243. 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));
  10244. return 0;
  10245. }
  10246. Entity* ent = (Entity*)spawn;
  10247. bool set_ = ent->SetInfoStructSInt(field, value);
  10248. lua_interface->SetBooleanValue(state, set_);
  10249. return 1;
  10250. }
  10251. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10252. if (!lua_interface)
  10253. return 0;
  10254. Spawn* spawn = lua_interface->GetSpawn(state);
  10255. string field = lua_interface->GetStringValue(state, 2);
  10256. float value = lua_interface->GetFloatValue(state, 3);
  10257. lua_interface->ResetFunctionStack(state);
  10258. if(!spawn || !spawn->IsEntity())
  10259. {
  10260. 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));
  10261. return 0;
  10262. }
  10263. Entity* ent = (Entity*)spawn;
  10264. bool set_ = ent->SetInfoStructFloat(field, value);
  10265. lua_interface->SetBooleanValue(state, set_);
  10266. return 1;
  10267. }
  10268. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10269. if (!lua_interface)
  10270. return 0;
  10271. Spawn* spawn = lua_interface->GetSpawn(state);
  10272. bool value = lua_interface->GetBooleanValue(state, 2);
  10273. lua_interface->ResetFunctionStack(state);
  10274. if(!spawn || !spawn->IsPlayer())
  10275. {
  10276. 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));
  10277. return 0;
  10278. }
  10279. ((Player*)spawn)->SetCharSheetChanged(value);
  10280. return 0;
  10281. }
  10282. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10283. if (!lua_interface)
  10284. return 0;
  10285. Spawn* spawn = lua_interface->GetSpawn(state);
  10286. std::string fromName = lua_interface->GetStringValue(state, 2);
  10287. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10288. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10289. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10290. int32 copper = lua_interface->GetInt32Value(state, 6);
  10291. int32 silver = lua_interface->GetInt32Value(state, 7);
  10292. int32 gold = lua_interface->GetInt32Value(state, 8);
  10293. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10294. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10295. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10296. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10297. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10298. lua_interface->ResetFunctionStack(state);
  10299. if(!spawn || !spawn->IsPlayer())
  10300. {
  10301. 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));
  10302. lua_interface->SetBooleanValue(state, false);
  10303. return 1;
  10304. }
  10305. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10306. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10307. lua_interface->SetBooleanValue(state, true);
  10308. return 1;
  10309. }
  10310. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10311. if (!lua_interface)
  10312. return 0;
  10313. int32 char_id = lua_interface->GetInt32Value(state);
  10314. std::string fromName = lua_interface->GetStringValue(state, 2);
  10315. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10316. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10317. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10318. int32 copper = lua_interface->GetInt32Value(state, 6);
  10319. int32 silver = lua_interface->GetInt32Value(state, 7);
  10320. int32 gold = lua_interface->GetInt32Value(state, 8);
  10321. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10322. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10323. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10324. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10325. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10326. lua_interface->ResetFunctionStack(state);
  10327. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10328. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10329. lua_interface->SetBooleanValue(state, true);
  10330. return 1;
  10331. }
  10332. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10333. Spawn* widget;
  10334. if (lua_interface) {
  10335. widget = lua_interface->GetSpawn(state);
  10336. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10337. lua_interface->ResetFunctionStack(state);
  10338. if (widget && widget->IsWidget())
  10339. {
  10340. ((Widget*)widget)->OpenDoor();
  10341. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10342. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10343. }
  10344. else
  10345. 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));
  10346. }
  10347. return 0;
  10348. }
  10349. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10350. Spawn* widget;
  10351. if (lua_interface) {
  10352. widget = lua_interface->GetSpawn(state);
  10353. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10354. lua_interface->ResetFunctionStack(state);
  10355. if (widget && widget->IsWidget())
  10356. {
  10357. ((Widget*)widget)->CloseDoor();
  10358. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10359. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10360. }
  10361. else
  10362. 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));
  10363. }
  10364. return 0;
  10365. }
  10366. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10367. if (!lua_interface)
  10368. return 0;
  10369. Spawn* widget = lua_interface->GetSpawn(state);
  10370. lua_interface->ResetFunctionStack(state);
  10371. if (widget && widget->IsWidget())
  10372. {
  10373. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10374. return 1;
  10375. }
  10376. return 0;
  10377. }
  10378. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10379. if (!lua_interface)
  10380. return 0;
  10381. sint32 min = lua_interface->GetSInt32Value(state);
  10382. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10383. lua_interface->ResetFunctionStack(state);
  10384. sint32 result = MakeRandomInt(min, max);
  10385. lua_interface->SetSInt32Value(state, result);
  10386. return 1;
  10387. }
  10388. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10389. if (!lua_interface)
  10390. return 0;
  10391. float min = lua_interface->GetFloatValue(state);
  10392. float max = lua_interface->GetFloatValue(state, 2);
  10393. lua_interface->ResetFunctionStack(state);
  10394. float result = MakeRandomFloat(min, max);
  10395. lua_interface->SetFloatValue(state, result);
  10396. return 1;
  10397. }
  10398. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10399. if (!lua_interface)
  10400. return 0;
  10401. Spawn* spawn = lua_interface->GetSpawn(state);
  10402. int32 value = lua_interface->GetInt32Value(state, 2);
  10403. lua_interface->ResetFunctionStack(state);
  10404. if(!spawn)
  10405. {
  10406. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10407. lua_interface->SetBooleanValue(state, false);
  10408. return 1;
  10409. }
  10410. spawn->AddIconValue(value);
  10411. lua_interface->SetBooleanValue(state, true);
  10412. return 1;
  10413. }
  10414. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10415. if (!lua_interface)
  10416. return 0;
  10417. Spawn* spawn = lua_interface->GetSpawn(state);
  10418. int32 value = lua_interface->GetInt32Value(state, 2);
  10419. lua_interface->ResetFunctionStack(state);
  10420. if(!spawn)
  10421. {
  10422. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10423. lua_interface->SetBooleanValue(state, false);
  10424. return 1;
  10425. }
  10426. spawn->RemoveIconValue(value);
  10427. lua_interface->SetBooleanValue(state, true);
  10428. return 1;
  10429. }
  10430. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10431. Spawn* npc = lua_interface->GetSpawn(state);
  10432. lua_interface->ResetFunctionStack(state);
  10433. if (npc && npc->IsNPC()) {
  10434. NPC* shard = (NPC*)npc;
  10435. int32 shardid = shard->GetShardID();
  10436. lua_interface->SetInt32Value(state, shardid);
  10437. return 1;
  10438. }
  10439. lua_interface->SetInt32Value(state, 0);
  10440. return 1;
  10441. }
  10442. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10443. Spawn* npc = lua_interface->GetSpawn(state);
  10444. lua_interface->ResetFunctionStack(state);
  10445. if (npc && npc->IsNPC()) {
  10446. NPC* shard = (NPC*)npc;
  10447. int32 charid = shard->GetShardCharID();
  10448. lua_interface->SetInt32Value(state, charid);
  10449. return 1;
  10450. }
  10451. lua_interface->SetInt32Value(state, 0);
  10452. return 1;
  10453. }
  10454. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10455. Spawn* npc = lua_interface->GetSpawn(state);
  10456. lua_interface->ResetFunctionStack(state);
  10457. if (npc && npc->IsNPC()) {
  10458. NPC* shard = (NPC*)npc;
  10459. int64 timestamp = shard->GetShardCreatedTimestamp();
  10460. lua_interface->SetSInt64Value(state, timestamp);
  10461. return 1;
  10462. }
  10463. lua_interface->SetSInt64Value(state, 0);
  10464. return 1;
  10465. }
  10466. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10467. if (!lua_interface)
  10468. return 0;
  10469. int32 shardid = lua_interface->GetInt32Value(state);
  10470. lua_interface->ResetFunctionStack(state);
  10471. if(shardid < 1)
  10472. lua_interface->SetBooleanValue(state, false);
  10473. else
  10474. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10475. return 1;
  10476. }