LuaFunctions.cpp 393 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870
  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. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = spawn->GetZone()->GetClientBySpawn(player);
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlaySound(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. string sound_string = lua_interface->GetStringValue(state, 2);
  183. float x = lua_interface->GetFloatValue(state, 3);
  184. float y = lua_interface->GetFloatValue(state, 4);
  185. float z = lua_interface->GetFloatValue(state, 5);
  186. Spawn* player = lua_interface->GetSpawn(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn && sound_string.length() > 0) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = spawn->GetZone()->GetClientBySpawn(player);
  192. if (client)
  193. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  194. else
  195. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  196. }
  197. return 0;
  198. }
  199. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  200. if (!lua_interface)
  201. return 0;
  202. Spawn* spawn = lua_interface->GetSpawn(state);
  203. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  204. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  205. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  206. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  207. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  208. lua_interface->ResetFunctionStack(state);
  209. if (!spawn) {
  210. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  211. return 0;
  212. }
  213. if (quest_id > 0) {
  214. //Add this quest to the list of required quests for this spawn
  215. spawn->SetQuestsRequired(quest_id, quest_step);
  216. //If private spawn value set
  217. if (private_spawn) {
  218. //Set the spawn to be private when not granted access through this quest
  219. spawn->AddAllowAccessSpawn(spawn);
  220. spawn->SetPrivateQuestSpawn(true);
  221. }
  222. //This value allows access after a quest step, or the whole quest has been completed
  223. if (continued_access)
  224. spawn->SetQuestsRequiredContinuedAccess(true);
  225. //This value will override vis_flags in the vis packet
  226. if (flag_override > 0)
  227. spawn->SetQuestsRequiredOverride(flag_override);
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. Spawn* spawn = lua_interface->GetSpawn(state);
  235. float max_distance = lua_interface->GetFloatValue(state, 2);
  236. string variable = lua_interface->GetStringValue(state, 3);
  237. string value = lua_interface->GetStringValue(state, 4);
  238. lua_interface->ResetFunctionStack(state);
  239. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  240. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  241. return 0;
  242. }
  243. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  244. if (!lua_interface)
  245. return 0;
  246. Client* client = 0;
  247. Spawn* player = lua_interface->GetSpawn(state);
  248. if (!player) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  250. return 0;
  251. }
  252. if (!player->IsPlayer()) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  254. return 0;
  255. }
  256. if (player->GetZone())
  257. client = player->GetZone()->GetClientBySpawn(player);
  258. if (!client) {
  259. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  260. return 0;
  261. }
  262. float intensity = lua_interface->GetFloatValue(state, 2);
  263. int8 direction = lua_interface->GetInt8Value(state, 3);
  264. lua_interface->ResetFunctionStack(state);
  265. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  266. if (packet) {
  267. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  268. v1 = *(float *)(a1 + 4);
  269. if ( v1 > 0.0 )
  270. v2 = fminf(v1, 1.0);
  271. else
  272. v2 = 0.1;
  273. */
  274. packet->setDataByName("intensity", intensity);
  275. if ( client->GetVersion() > 546 )
  276. packet->setDataByName("direction", direction);
  277. client->QueuePacket(packet->serialize());
  278. safe_delete(packet);
  279. }
  280. return 0;
  281. }
  282. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  283. if (!lua_interface)
  284. return 0;
  285. Spawn* dead = lua_interface->GetSpawn(state);
  286. Spawn* killer = lua_interface->GetSpawn(state, 2);
  287. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  288. lua_interface->ResetFunctionStack(state);
  289. if (dead && dead->Alive() && dead->GetZone())
  290. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  291. return 0;
  292. }
  293. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  294. if (!lua_interface)
  295. return 0;
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. float max_distance = lua_interface->GetFloatValue(state, 2);
  298. bool include_players = lua_interface->GetInt8Value(state, 3);
  299. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  300. lua_interface->ResetFunctionStack(state);
  301. if (max_distance > 0 && spawn && spawn->GetZone())
  302. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_Despawn(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int32 delay = lua_interface->GetInt32Value(state, 2);
  310. lua_interface->ResetFunctionStack(state);
  311. if (spawn && spawn->GetZone())
  312. spawn->GetZone()->Despawn(spawn, delay);
  313. return 0;
  314. }
  315. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  316. if (!lua_interface)
  317. return 0;
  318. Spawn* spawn = lua_interface->GetSpawn(state);
  319. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  320. lua_interface->ResetFunctionStack(state);
  321. if (spawn) {
  322. spawn->info_changed = true;
  323. spawn->SetShowHandIcon(displayHandIcon);
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //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
  329. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. lua_interface->ResetFunctionStack(state);
  334. if (spawn) {
  335. spawn->vis_changed = true;
  336. spawn->GetZone()->AddChangedSpawn(spawn);
  337. }
  338. return 0;
  339. }
  340. //this function is used to force an update packet to be sent.
  341. //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
  342. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. lua_interface->ResetFunctionStack(state);
  347. if (spawn) {
  348. spawn->info_changed = true;
  349. spawn->GetZone()->AddChangedSpawn(spawn);
  350. }
  351. return 0;
  352. }
  353. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  354. if (!lua_interface)
  355. return 0;
  356. Spawn* spawn = lua_interface->GetSpawn(state);
  357. int32 new_state = lua_interface->GetInt32Value(state, 2);
  358. Spawn* player = lua_interface->GetSpawn(state, 3);
  359. lua_interface->ResetFunctionStack(state);
  360. if (spawn) {
  361. if(player)
  362. {
  363. if(player->IsPlayer())
  364. {
  365. Client* client = ((Player*)player)->GetClient();
  366. if(client)
  367. {
  368. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  369. lua_interface->SetBooleanValue(state, true);
  370. return 1;
  371. }
  372. else
  373. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  374. }
  375. else
  376. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  377. }
  378. else
  379. {
  380. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  381. lua_interface->SetBooleanValue(state, true);
  382. return 1;
  383. }
  384. }
  385. lua_interface->SetBooleanValue(state, false);
  386. return 1;
  387. }
  388. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  389. if (!lua_interface)
  390. return 0;
  391. Spawn* spawn = lua_interface->GetSpawn(state);
  392. string variable = lua_interface->GetStringValue(state, 2);
  393. string value = lua_interface->GetStringValue(state, 3);
  394. 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.
  395. bool temporary_flag = true;
  396. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  397. int8 index = 0;
  398. if(num_args >= 5)
  399. {
  400. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  401. index = lua_interface->GetInt8Value(state, 6);
  402. }
  403. lua_interface->ResetFunctionStack(state);
  404. int32 type = commands.GetSpawnSetType(variable);
  405. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  406. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  407. return 0;
  408. }
  409. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  410. if (!lua_interface)
  411. return 0;
  412. Spawn* spawn = lua_interface->GetSpawn(state);
  413. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  414. lua_interface->ResetFunctionStack(state);
  415. if (spawn && spawn_id > 0) {
  416. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  417. if (closest_spawn) {
  418. lua_interface->SetSpawnValue(state, closest_spawn);
  419. return 1;
  420. }
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. int32 position = lua_interface->GetInt32Value(state, 2);
  429. lua_interface->ResetFunctionStack(state);
  430. if (spawnList) {
  431. if (spawnList->size() > position) {
  432. lua_interface->SetSpawnValue(state, spawnList->at(position));
  433. return 1;
  434. }
  435. else {
  436. return 0;
  437. }
  438. return spawnList->size();
  439. }
  440. return 0;
  441. }
  442. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  443. if (!lua_interface)
  444. return 0;
  445. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  446. lua_interface->ResetFunctionStack(state);
  447. if (spawnList) {
  448. return spawnList->size();
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = new vector<Spawn*>();
  456. lua_interface->SetSpawnListValue(state, spawnList);
  457. return 1;
  458. }
  459. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  460. if (!lua_interface)
  461. return 0;
  462. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  463. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  464. lua_interface->ResetFunctionStack(state);
  465. if (spawnList) {
  466. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  467. if (it == spawnList->end())
  468. spawnList->push_back(spawn);
  469. }
  470. return 0;
  471. }
  472. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  473. if (!lua_interface)
  474. return 0;
  475. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  476. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  477. lua_interface->ResetFunctionStack(state);
  478. if (spawnList) {
  479. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  480. if(it != spawnList->end())
  481. spawnList->erase(it);
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* spawn = lua_interface->GetSpawn(state);
  489. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  490. lua_interface->ResetFunctionStack(state);
  491. if (spawn) {
  492. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  493. if (spawns.size() > 0) {
  494. vector<Spawn*>* spawnList = new vector<Spawn*>();
  495. vector<Spawn*>::iterator itr;
  496. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  497. spawnList->push_back(*itr);
  498. }
  499. lua_interface->SetSpawnListValue(state, spawnList);
  500. return 1;
  501. }
  502. }
  503. return 0;
  504. }
  505. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. Spawn* spawn = lua_interface->GetSpawn(state);
  509. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  510. lua_interface->ResetFunctionStack(state);
  511. if (spawn) {
  512. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  513. if (spawns.size() > 0) {
  514. vector<Spawn*>* spawnList = new vector<Spawn*>();
  515. vector<Spawn*>::iterator itr;
  516. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  517. spawnList->push_back(*itr);
  518. }
  519. lua_interface->SetSpawnListValue(state, spawnList);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  526. if (!lua_interface)
  527. return 0;
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. lua_interface->ResetFunctionStack(state);
  530. if (spawn) {
  531. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  532. if (spawns.size() > 0) {
  533. lua_createtable(state, spawns.size(), 0);
  534. int newTable = lua_gettop(state);
  535. for (int32 i = 0; i < spawns.size(); i++) {
  536. lua_interface->SetSpawnValue(state, spawns.at(i));
  537. lua_rawseti(state, newTable, i + 1);
  538. }
  539. return 1;
  540. }
  541. }
  542. return 0;
  543. }
  544. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  545. if (!lua_interface)
  546. return 0;
  547. string variable_name = lua_interface->GetStringValue(state);
  548. lua_interface->ResetFunctionStack(state);
  549. Variable* var = variables.FindVariable(variable_name);
  550. if (var) {
  551. lua_interface->SetStringValue(state, var->GetValue());
  552. return 1;
  553. }
  554. return 0;
  555. }
  556. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  557. if (!lua_interface)
  558. return 0;
  559. int32 total_coins = lua_interface->GetInt32Value(state);
  560. lua_interface->ResetFunctionStack(state);
  561. if (total_coins == 0) {
  562. lua_interface->SetStringValue(state, "0 copper");
  563. return 1;
  564. }
  565. char tmp[64] = { 0 };
  566. string message = "";
  567. int32 val = 0;
  568. if (total_coins >= 1000000) {
  569. val = total_coins / 1000000;
  570. total_coins -= 1000000 * val;
  571. sprintf(tmp, " %u Platinum", val);
  572. message.append(tmp);
  573. memset(tmp, 0, 64);
  574. }
  575. if (total_coins >= 10000) {
  576. val = total_coins / 10000;
  577. total_coins -= 10000 * val;
  578. sprintf(tmp, " %u Gold", val);
  579. message.append(tmp);
  580. memset(tmp, 0, 64);
  581. }
  582. if (total_coins >= 100) {
  583. val = total_coins / 100;
  584. total_coins -= 100 * val;
  585. sprintf(tmp, " %u Silver", val);
  586. message.append(tmp);
  587. memset(tmp, 0, 64);
  588. }
  589. if (total_coins > 0) {
  590. sprintf(tmp, " %u Copper", (int32)total_coins);
  591. message.append(tmp);
  592. }
  593. lua_interface->SetStringValue(state, message.c_str());
  594. return 1;
  595. }
  596. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  597. ZoneServer* zone = lua_interface->GetZone(state);
  598. int32 group_id = lua_interface->GetInt32Value(state, 2);
  599. lua_interface->ResetFunctionStack(state);
  600. if (zone) {
  601. Spawn* spawn = zone->GetSpawnGroup(group_id);
  602. if (spawn) {
  603. lua_interface->SetSpawnValue(state, spawn);
  604. return 1;
  605. }
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  610. ZoneServer* zone = lua_interface->GetZone(state);
  611. int32 location_id = lua_interface->GetInt32Value(state, 2);
  612. lua_interface->ResetFunctionStack(state);
  613. if (zone) {
  614. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  615. if (spawn) {
  616. lua_interface->SetSpawnValue(state, spawn);
  617. return 1;
  618. }
  619. }
  620. return 0;
  621. }
  622. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. lua_interface->ResetFunctionStack(state);
  625. if (spawn) {
  626. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  632. Spawn* spawn = lua_interface->GetSpawn(state);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  636. return 1;
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  645. lua_interface->ResetFunctionStack(state);
  646. if (spawn) {
  647. spawn->SetSpawnGroupID(new_group_id);
  648. lua_interface->SetBooleanValue(state, true);
  649. return 1;
  650. }
  651. lua_interface->SetBooleanValue(state, false);
  652. return 1;
  653. }
  654. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  659. lua_interface->ResetFunctionStack(state);
  660. if (spawn) {
  661. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  662. lua_interface->SetBooleanValue(state, true);
  663. return 1;
  664. }
  665. lua_interface->SetBooleanValue(state, false);
  666. return 1;
  667. }
  668. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  669. Spawn* spawn = lua_interface->GetSpawn(state);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  673. return 1;
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. lua_interface->ResetFunctionStack(state);
  680. if (spawn) {
  681. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  682. return 1;
  683. }
  684. return 0;
  685. }
  686. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  687. Player* player = (Player*)lua_interface->GetSpawn(state);
  688. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  689. lua_interface->ResetFunctionStack(state);
  690. if (player && player->IsPlayer() && faction_id > 0) {
  691. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  692. return 1;
  693. }
  694. return 0;
  695. }
  696. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  697. if (!lua_interface)
  698. return 0;
  699. Spawn* spawn = lua_interface->GetSpawn(state);
  700. int32 value = lua_interface->GetInt32Value(state, 2);
  701. lua_interface->ResetFunctionStack(state);
  702. if (spawn) {
  703. spawn->SetFactionID(value);
  704. }
  705. return 0;
  706. }
  707. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  708. Spawn* spawn = lua_interface->GetSpawn(state);
  709. lua_interface->ResetFunctionStack(state);
  710. if (spawn) {
  711. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_GetGender(lua_State* state) {
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. lua_interface->ResetFunctionStack(state);
  719. if (spawn) {
  720. lua_interface->SetInt32Value(state, spawn->GetGender());
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_GetTarget(lua_State* state) {
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. lua_interface->ResetFunctionStack(state);
  728. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  730. return 1;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. string mp3_string = lua_interface->GetStringValue(state, 2);
  739. int32 key1 = lua_interface->GetInt32Value(state, 3);
  740. int32 key2 = lua_interface->GetInt32Value(state, 4);
  741. Spawn* player = lua_interface->GetSpawn(state, 5);
  742. lua_interface->ResetFunctionStack(state);
  743. if (spawn && mp3_string.length() > 0) {
  744. Client* client = 0;
  745. if (player && player->IsPlayer())
  746. client = spawn->GetZone()->GetClientBySpawn(player);
  747. if (client) {
  748. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  749. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  750. }
  751. else
  752. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  753. }
  754. return 0;
  755. }
  756. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  757. if (!lua_interface)
  758. return 0;
  759. Spawn* spawn = lua_interface->GetSpawn(state);
  760. lua_interface->ResetFunctionStack(state);
  761. if (spawn) {
  762. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  763. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  764. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  765. return 3;
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 item_id = lua_interface->GetInt32Value(state, 2);
  775. lua_interface->ResetFunctionStack(state);
  776. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  777. return 1;
  778. }
  779. lua_interface->ResetFunctionStack(state);
  780. return 0;
  781. }
  782. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  783. if (!lua_interface)
  784. return 0;
  785. Spawn* spawn = lua_interface->GetSpawn(state);
  786. if (spawn && spawn->IsEntity()) {
  787. int32 item_id = lua_interface->GetInt32Value(state, 2);
  788. int16 charges = lua_interface->GetInt16Value(state, 3);
  789. if (charges == 0)
  790. charges = 1;
  791. ((Entity*)spawn)->AddLootItem(item_id, charges);
  792. }
  793. lua_interface->ResetFunctionStack(state);
  794. return 0;
  795. }
  796. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn && spawn->IsEntity()) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. Item* item = spawn->LootItem(item_id);
  803. safe_delete(item);
  804. }
  805. lua_interface->ResetFunctionStack(state);
  806. return 0;
  807. }
  808. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  809. if (!lua_interface)
  810. return 0;
  811. Spawn* spawn = lua_interface->GetSpawn(state);
  812. if (spawn) {
  813. int32 val = lua_interface->GetInt32Value(state, 2);
  814. spawn->AddLootCoins(val);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* entity = lua_interface->GetSpawn(state);
  823. Spawn* player = lua_interface->GetSpawn(state, 2);
  824. if (entity && player && player->IsPlayer()) {
  825. int32 coins = lua_interface->GetInt32Value(state, 3);
  826. vector<Item*>* items = 0;
  827. int i = 0;
  828. int32 item_id = 0;
  829. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  830. if (items == 0)
  831. items = new vector<Item*>;
  832. if (master_item_list.GetItem(item_id))
  833. items->push_back(master_item_list.GetItem(item_id));
  834. i++;
  835. }
  836. Client* client = 0;
  837. client = player->GetZone()->GetClientBySpawn(player);
  838. if (client)
  839. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  840. if(coins > 0)
  841. entity->AddLootCoins(coins);
  842. safe_delete(items);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. int32 item_id = lua_interface->GetInt32Value(state, 3);
  853. lua_interface->ResetFunctionStack(state);
  854. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  855. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  856. return 1;
  857. }
  858. return 0;
  859. }
  860. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* entity = lua_interface->GetSpawn(state);
  864. Spawn* player = lua_interface->GetSpawn(state, 2);
  865. lua_interface->ResetFunctionStack(state);
  866. if (entity && player && player->IsPlayer()) {
  867. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  868. return 1;
  869. }
  870. return 0;
  871. }
  872. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  876. safe_delete(conversation);
  877. lua_interface->ResetFunctionStack(state);
  878. conversation = new vector<ConversationOption>();
  879. lua_interface->SetConversationValue(state, conversation);
  880. return 1;
  881. }
  882. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  883. if (!lua_interface)
  884. return 0;
  885. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  886. if (conversation) {
  887. ConversationOption conv_option;
  888. conv_option.option = lua_interface->GetStringValue(state, 2);
  889. conv_option.function = lua_interface->GetStringValue(state, 3);
  890. if (conv_option.option.length() > 0)
  891. conversation->push_back(conv_option);
  892. }
  893. lua_interface->ResetFunctionStack(state);
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. Spawn* npc = lua_interface->GetSpawn(state);
  900. Spawn* player = lua_interface->GetSpawn(state, 2);
  901. lua_interface->ResetFunctionStack(state);
  902. if (npc && player && player->IsPlayer() && player->GetZone()) {
  903. Client* client = player->GetZone()->GetClientBySpawn(player);
  904. if (client) {
  905. int32 conversation_id = client->GetConversationID(npc, 0);
  906. client->CloseDialog(conversation_id);
  907. }
  908. }
  909. return 0;
  910. }
  911. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. Item* item = lua_interface->GetItem(state);
  915. Spawn* player = lua_interface->GetSpawn(state, 2);
  916. lua_interface->ResetFunctionStack(state);
  917. if (item && player && player->IsPlayer() && player->GetZone()) {
  918. Client* client = player->GetZone()->GetClientBySpawn(player);
  919. if (client) {
  920. int32 conversation_id = client->GetConversationID(0, item);
  921. client->CloseDialog(conversation_id);
  922. }
  923. }
  924. return 0;
  925. }
  926. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  927. if (!lua_interface)
  928. return 0;
  929. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  930. Spawn* spawn = 0;
  931. Item* item = 0;
  932. int8 type = lua_interface->GetInt8Value(state, 2);
  933. if (type == 1 || type == 3)
  934. spawn = lua_interface->GetSpawn(state, 3);
  935. else if (type == 2 || type == 4)
  936. item = lua_interface->GetItem(state, 3);
  937. Spawn* player = lua_interface->GetSpawn(state, 4);
  938. string text = lua_interface->GetStringValue(state, 5);
  939. string mp3 = lua_interface->GetStringValue(state, 6);
  940. int32 key1 = lua_interface->GetInt32Value(state, 7);
  941. int32 key2 = lua_interface->GetInt32Value(state, 8);
  942. lua_interface->ResetFunctionStack(state);
  943. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  944. Client* client = player->GetZone()->GetClientBySpawn(player);
  945. if (client) {
  946. if (spawn) {
  947. // Need to do this so the function works the same as it did before
  948. if (type == 1)
  949. type++;
  950. if (mp3.length() > 0)
  951. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  952. else
  953. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  954. }
  955. else {
  956. if (mp3.length() > 0)
  957. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  958. else
  959. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  960. }
  961. }
  962. }
  963. safe_delete(conversation);
  964. lua_interface->SetConversationValue(state, NULL);
  965. return 0;
  966. }
  967. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  968. if(!lua_interface)
  969. return 0;
  970. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  971. Item* item = lua_interface->GetItem(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. string text = lua_interface->GetStringValue(state, 4);
  974. string mp3 = lua_interface->GetStringValue(state, 5);
  975. int32 key1 = lua_interface->GetInt32Value(state, 6);
  976. int32 key2 = lua_interface->GetInt32Value(state, 7);
  977. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  978. Client* client = player->GetZone()->GetClientBySpawn(player);
  979. if(client){
  980. if(mp3.length() > 0)
  981. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  982. else
  983. client->DisplayConversation(item, conversation, (char*)text.c_str());
  984. }
  985. safe_delete(conversation);
  986. }
  987. return 0;
  988. }*/
  989. int EQ2Emu_lua_StartConversation(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  993. Spawn* source = lua_interface->GetSpawn(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. string text = lua_interface->GetStringValue(state, 4);
  996. string mp3 = lua_interface->GetStringValue(state, 5);
  997. int32 key1 = lua_interface->GetInt32Value(state, 6);
  998. int32 key2 = lua_interface->GetInt32Value(state, 7);
  999. lua_interface->ResetFunctionStack(state);
  1000. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1001. Client* client = source->GetZone()->GetClientBySpawn(player);
  1002. if (mp3.length() > 0)
  1003. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  1004. else
  1005. client->DisplayConversation(source, 1, conversation, text.c_str());
  1006. safe_delete(conversation);
  1007. lua_interface->SetConversationValue(state, NULL);
  1008. }
  1009. else
  1010. 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);
  1011. return 0;
  1012. }
  1013. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1014. if (!lua_interface)
  1015. return 0;
  1016. Spawn* spawn = lua_interface->GetSpawn(state);
  1017. float distance = lua_interface->GetFloatValue(state, 2);
  1018. string in_range_function = lua_interface->GetStringValue(state, 3);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1020. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1021. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1022. return 0;
  1023. }
  1024. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1025. ZoneServer* zone = lua_interface->GetZone(state);
  1026. float x = lua_interface->GetFloatValue(state, 2);
  1027. float y = lua_interface->GetFloatValue(state, 3);
  1028. float z = lua_interface->GetFloatValue(state, 4);
  1029. float max_variation = lua_interface->GetFloatValue(state, 5);
  1030. string in_range_function = lua_interface->GetStringValue(state, 6);
  1031. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1032. lua_interface->ResetFunctionStack(state);
  1033. if (zone && in_range_function.length() > 0)
  1034. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1038. if (!lua_interface)
  1039. return 0;
  1040. Spawn* spawn = lua_interface->GetSpawn(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. int32 val = lua_interface->GetInt32Value(state, 2);
  1043. ((Entity*)spawn)->SetLootCoins(val);
  1044. }
  1045. lua_interface->ResetFunctionStack(state);
  1046. return 0;
  1047. }
  1048. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1049. if (!lua_interface)
  1050. return 0;
  1051. Spawn* spawn = lua_interface->GetSpawn(state);
  1052. lua_interface->ResetFunctionStack(state);
  1053. if (spawn && spawn->IsEntity()) {
  1054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1060. if (!lua_interface)
  1061. return 0;
  1062. Spawn* spawn = lua_interface->GetSpawn(state);
  1063. float x = lua_interface->GetFloatValue(state, 2);
  1064. float y = lua_interface->GetFloatValue(state, 3);
  1065. float z = lua_interface->GetFloatValue(state, 4);
  1066. float speed = lua_interface->GetFloatValue(state, 5);
  1067. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1068. string function = lua_interface->GetStringValue(state, 7);
  1069. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1070. float heading = lua_interface->GetFloatValue(state, 8);
  1071. if (spawn) {
  1072. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1073. spawn->GetZone()->AddMovementNPC(spawn);
  1074. }
  1075. lua_interface->ResetFunctionStack(state);
  1076. return 0;
  1077. }
  1078. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1079. if (!lua_interface)
  1080. return 0;
  1081. Spawn* spawn = lua_interface->GetSpawn(state);
  1082. lua_interface->ResetFunctionStack(state);
  1083. if (spawn) {
  1084. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1085. return 1;
  1086. }
  1087. return 0;
  1088. }
  1089. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. lua_interface->ResetFunctionStack(state);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1096. return 1;
  1097. }
  1098. lua_interface->SetInt32Value(state, 0);
  1099. return 1;
  1100. }
  1101. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1102. if (!lua_interface)
  1103. return 0;
  1104. Spawn* spawn = lua_interface->GetSpawn(state);
  1105. Spawn* target = lua_interface->GetSpawn(state, 2);
  1106. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1107. bool reset_action_state = true;
  1108. if(num_args > 2)
  1109. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1110. if (spawn && target) {
  1111. if (spawn->IsEntity())
  1112. // ((Entity*)spawn)->FaceTarget(target);
  1113. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1114. }
  1115. lua_interface->ResetFunctionStack(state);
  1116. return 0;
  1117. }
  1118. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. float x = lua_interface->GetFloatValue(state, 2);
  1123. float y = lua_interface->GetFloatValue(state, 3);
  1124. float z = lua_interface->GetFloatValue(state, 4);
  1125. float speed = lua_interface->GetFloatValue(state, 5);
  1126. string lua_function = lua_interface->GetStringValue(state, 6);
  1127. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1128. if (spawn) {
  1129. if (speed == 0)
  1130. speed = spawn->GetSpeed();
  1131. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1132. }
  1133. lua_interface->ResetFunctionStack(state);
  1134. return 0;
  1135. }
  1136. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1137. if (!lua_interface)
  1138. return 0;
  1139. Spawn* spawn = lua_interface->GetSpawn(state);
  1140. lua_interface->ResetFunctionStack(state);
  1141. if (spawn) {
  1142. spawn->ClearRunningLocations();
  1143. }
  1144. return 0;
  1145. }
  1146. int EQ2Emu_lua_Say(lua_State* state) {
  1147. if (!lua_interface)
  1148. return 0;
  1149. Spawn* spawn = lua_interface->GetSpawn(state);
  1150. string message = lua_interface->GetStringValue(state, 2);
  1151. Spawn* player = lua_interface->GetSpawn(state, 3);
  1152. int32 language = lua_interface->GetInt32Value(state, 4);
  1153. if (spawn && message.length() > 0) {
  1154. Client* client = 0;
  1155. if (player && player->IsPlayer())
  1156. client = spawn->GetZone()->GetClientBySpawn(player);
  1157. if (client)
  1158. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1159. else
  1160. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1161. }
  1162. lua_interface->ResetFunctionStack(state);
  1163. return 0;
  1164. }
  1165. int EQ2Emu_lua_Shout(lua_State* state) {
  1166. if (!lua_interface)
  1167. return 0;
  1168. Spawn* spawn = lua_interface->GetSpawn(state);
  1169. string message = lua_interface->GetStringValue(state, 2);
  1170. Spawn* player = lua_interface->GetSpawn(state, 3);
  1171. float dist = lua_interface->GetFloatValue(state, 4);
  1172. if (spawn && message.length() > 0) {
  1173. Client* client = 0;
  1174. if (player && player->IsPlayer())
  1175. client = spawn->GetZone()->GetClientBySpawn(player);
  1176. if (client)
  1177. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1178. else
  1179. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1180. }
  1181. lua_interface->ResetFunctionStack(state);
  1182. return 0;
  1183. }
  1184. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1185. if (!lua_interface)
  1186. return 0;
  1187. Spawn* spawn = lua_interface->GetSpawn(state);
  1188. string message = lua_interface->GetStringValue(state, 2);
  1189. Spawn* player = lua_interface->GetSpawn(state, 3);
  1190. if (spawn && message.length() > 0) {
  1191. Client* client = 0;
  1192. if (player && player->IsPlayer())
  1193. client = spawn->GetZone()->GetClientBySpawn(player);
  1194. if (client)
  1195. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1196. else
  1197. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1198. }
  1199. lua_interface->ResetFunctionStack(state);
  1200. return 0;
  1201. }
  1202. int EQ2Emu_lua_Emote(lua_State* state) {
  1203. if (!lua_interface)
  1204. return 0;
  1205. Spawn* spawn = lua_interface->GetSpawn(state);
  1206. string message = lua_interface->GetStringValue(state, 2);
  1207. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1208. Spawn* player = lua_interface->GetSpawn(state, 4);
  1209. char* to = 0;
  1210. if (spawn2)
  1211. to = spawn2->GetName();
  1212. if (spawn && message.length() > 0) {
  1213. Client* client = 0;
  1214. if (player && player->IsPlayer())
  1215. client = spawn->GetZone()->GetClientBySpawn(player);
  1216. if (client)
  1217. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1218. else
  1219. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1220. }
  1221. lua_interface->ResetFunctionStack(state);
  1222. return 0;
  1223. }
  1224. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1225. if (!lua_interface)
  1226. return 0;
  1227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1228. if (!luaspell)
  1229. return 0;
  1230. Spawn* caster = luaspell->caster;
  1231. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1232. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1233. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1234. Spawn* target = lua_interface->GetSpawn(state, 4);
  1235. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1236. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1237. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1238. lua_interface->ResetFunctionStack(state);
  1239. boost::to_lower(heal_type);
  1240. if (caster && caster->IsEntity()) {
  1241. bool success = false;
  1242. luaspell->resisted = false;
  1243. if (target) {
  1244. float distance = caster->GetDistance(target, true);
  1245. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1246. success = true;
  1247. }
  1248. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1249. Spawn* target = 0;
  1250. ZoneServer* zone = luaspell->caster->GetZone();
  1251. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1252. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1253. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1254. float distance = caster->GetDistance(target, true);
  1255. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1256. }
  1257. }
  1258. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1259. success = true;
  1260. }
  1261. if (success) {
  1262. if (caster->GetZone())
  1263. caster->GetZone()->TriggerCharSheetTimer();
  1264. }
  1265. }
  1266. return 0;
  1267. }
  1268. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1269. if (!lua_interface)
  1270. return 0;
  1271. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1272. if (!luaspell)
  1273. return 0;
  1274. Spawn* caster = luaspell->caster;
  1275. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1276. float percentage = lua_interface->GetFloatValue(state, 2);
  1277. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1278. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1279. Spawn* target = lua_interface->GetSpawn(state, 5);
  1280. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1281. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1282. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1283. lua_interface->ResetFunctionStack(state);
  1284. boost::to_lower(heal_type);
  1285. int32 min_heal = 0, max_heal = 0;
  1286. if (caster && caster->IsEntity() && target) {
  1287. if(percentage <= 0.0f)
  1288. {
  1289. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1290. return 0;
  1291. }
  1292. if(heal_type == "power")
  1293. {
  1294. if(current_value)
  1295. {
  1296. if(caster_value)
  1297. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1298. else
  1299. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1300. }
  1301. else
  1302. {
  1303. if(caster_value)
  1304. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1305. else
  1306. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1307. }
  1308. }
  1309. else
  1310. {
  1311. if(current_value)
  1312. {
  1313. if(caster_value)
  1314. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1315. else
  1316. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1317. }
  1318. else
  1319. {
  1320. if(caster_value)
  1321. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1322. else
  1323. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1324. }
  1325. }
  1326. bool success = false;
  1327. luaspell->resisted = false;
  1328. if (target) {
  1329. float distance = caster->GetDistance(target, true);
  1330. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1331. success = true;
  1332. }
  1333. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1334. Spawn* target = 0;
  1335. ZoneServer* zone = luaspell->caster->GetZone();
  1336. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1337. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1338. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1339. float distance = caster->GetDistance(target, true);
  1340. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1341. }
  1342. }
  1343. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1344. success = true;
  1345. }
  1346. if (success) {
  1347. if (caster->GetZone())
  1348. caster->GetZone()->TriggerCharSheetTimer();
  1349. }
  1350. }
  1351. return 0;
  1352. }
  1353. int EQ2Emu_lua_AddItem(lua_State* state) {
  1354. if (!lua_interface)
  1355. return 0;
  1356. Spawn* spawn = lua_interface->GetSpawn(state);
  1357. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1358. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1359. lua_interface->ResetFunctionStack(state);
  1360. // default of 1 quantity to add
  1361. if (quantity == 0)
  1362. quantity = 1;
  1363. if (spawn && spawn->IsPlayer()) {
  1364. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1365. if (client && item_id > 0) {
  1366. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1367. return 1;
  1368. }
  1369. }
  1370. lua_interface->SetBooleanValue(state, false);
  1371. return 1;
  1372. }
  1373. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1374. if (!lua_interface)
  1375. return 0;
  1376. Spawn* spawn = lua_interface->GetSpawn(state);
  1377. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1378. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1379. string location = lua_interface->GetStringValue(state, 4);
  1380. int16 item_count = lua_interface->GetInt16Value(state,5);
  1381. //devn00b: if we dont have a count, assume 1 item.
  1382. if(!item_count) {
  1383. item_count = 1;
  1384. }
  1385. lua_interface->ResetFunctionStack(state);
  1386. if (spawn && spawn->IsPlayer()) {
  1387. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1388. if (client && item_id > 0) {
  1389. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1390. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1391. else
  1392. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1393. if (send_messages) {
  1394. Item* item = master_item_list.GetItem(item_id);
  1395. if (item) {
  1396. if(item_count > 1) {
  1397. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1398. string popup_text1 = "You receive "+ item_count;
  1399. string popup_text2 = " " + item->name;
  1400. string popup_text = popup_text1 + popup_text2;
  1401. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1402. // return 1;
  1403. } else {
  1404. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1405. string popup_text = "You receive " + item->name;
  1406. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1407. }
  1408. }
  1409. }
  1410. return 1;
  1411. }
  1412. }
  1413. lua_interface->SetBooleanValue(state, false);
  1414. return 1;
  1415. }
  1416. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1417. Spawn* spawn = lua_interface->GetSpawn(state);
  1418. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1419. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1420. lua_interface->ResetFunctionStack(state);
  1421. // default of 1 to remove
  1422. if (quantity == 0)
  1423. quantity = 1;
  1424. Client* client;
  1425. Item* item;
  1426. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1427. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1428. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1429. if (client->RemoveItem(item, quantity)) {
  1430. lua_interface->SetBooleanValue(state, true);
  1431. return 1;
  1432. }
  1433. }
  1434. }
  1435. }
  1436. lua_interface->SetBooleanValue(state, false);
  1437. return 1;
  1438. }
  1439. int EQ2Emu_lua_HasItem(lua_State* state) {
  1440. Spawn* player = lua_interface->GetSpawn(state);
  1441. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1442. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1443. lua_interface->ResetFunctionStack(state);
  1444. if (player && player->IsPlayer()) {
  1445. bool hasItem = false;
  1446. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1447. if (!hasItem)
  1448. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1449. lua_interface->SetBooleanValue(state, hasItem);
  1450. return 1;
  1451. }
  1452. lua_interface->SetBooleanValue(state, false);
  1453. return 1;
  1454. }
  1455. int EQ2Emu_lua_Spawn(lua_State* state) {
  1456. if (!lua_interface)
  1457. return 0;
  1458. ZoneServer* zone = lua_interface->GetZone(state);
  1459. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1460. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1461. float x = lua_interface->GetFloatValue(state, 4);
  1462. float y = lua_interface->GetFloatValue(state, 5);
  1463. float z = lua_interface->GetFloatValue(state, 6);
  1464. float heading = lua_interface->GetFloatValue(state, 7);
  1465. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1466. Spawn* spawn = zone->GetSpawn(spawn_id);
  1467. if (!spawn)
  1468. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1469. else {
  1470. spawn->SetX(x);
  1471. spawn->SetZ(z);
  1472. spawn->SetY(y,true,true);
  1473. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1474. spawn->SetHeading(heading);
  1475. if (restricted_npc)
  1476. spawn->AddAllowAccessSpawn(spawn);
  1477. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1478. bool scriptActive = false;
  1479. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1480. scriptActive = true;
  1481. spawn->SetSpawnScript(string(spawn_script));
  1482. }
  1483. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1484. zone->AddSpawn(spawn);
  1485. if (scriptActive) {
  1486. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1487. }
  1488. lua_interface->ResetFunctionStack(state);
  1489. lua_interface->SetSpawnValue(state, spawn);
  1490. return 1;
  1491. }
  1492. }
  1493. else {
  1494. string output = "Invalid paramaters to LUA Spawn command: \n";
  1495. if (!zone)
  1496. output = output.append("\t").append("Missing zone reference. \n");
  1497. if (spawn_id == 0)
  1498. output = output.append("\t").append("Missing spawn_id.");
  1499. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1500. }
  1501. lua_interface->ResetFunctionStack(state);
  1502. return 0;
  1503. }
  1504. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1505. if (!lua_interface)
  1506. return 0;
  1507. ZoneServer* zone = lua_interface->GetZone(state);
  1508. lua_interface->ResetFunctionStack(state);
  1509. if (zone) {
  1510. lua_interface->SetStringValue(state, zone->GetZoneName());
  1511. return 1;
  1512. }
  1513. return 0;
  1514. }
  1515. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1516. if (!lua_interface)
  1517. return 0;
  1518. ZoneServer* zone = lua_interface->GetZone(state);
  1519. lua_interface->ResetFunctionStack(state);
  1520. if (zone) {
  1521. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1522. return 1;
  1523. }
  1524. return 0;
  1525. }
  1526. int EQ2Emu_lua_GetZone(lua_State* state) {
  1527. if (!lua_interface)
  1528. return 0;
  1529. int32 zone_id = lua_interface->GetInt32Value(state);
  1530. ZoneServer* zone = 0;
  1531. if (zone_id > 0)
  1532. zone = zone_list.Get(zone_id);
  1533. else {
  1534. string zone_name = lua_interface->GetStringValue(state);
  1535. if (zone_name.length() > 0) {
  1536. zone = zone_list.Get(zone_name.c_str());
  1537. }
  1538. else {
  1539. Spawn* spawn = lua_interface->GetSpawn(state);
  1540. if (spawn)
  1541. zone = spawn->GetZone();
  1542. }
  1543. }
  1544. lua_interface->ResetFunctionStack(state);
  1545. if (zone) {
  1546. lua_interface->SetZoneValue(state, zone);
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. int EQ2Emu_lua_AddHate(lua_State* state) {
  1552. Spawn* entity = lua_interface->GetSpawn(state);
  1553. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1554. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1555. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1556. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1557. if (entity && entity->IsEntity() && amount != 0) {
  1558. if (luaspell) {
  1559. ZoneServer* zone = luaspell->caster->GetZone();
  1560. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1561. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1562. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1563. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1564. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1565. if (send_packet)
  1566. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1567. }
  1568. }
  1569. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1570. }
  1571. else if (npc && npc->IsNPC() && npc->GetZone())
  1572. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1573. }
  1574. lua_interface->ResetFunctionStack(state);
  1575. return 0;
  1576. }
  1577. int EQ2Emu_lua_Zone(lua_State* state) {
  1578. if (!lua_interface)
  1579. return 0;
  1580. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1581. ZoneServer* zone = lua_interface->GetZone(state);
  1582. Spawn* player = lua_interface->GetSpawn(state, 2);
  1583. Client* client = 0;
  1584. if (player && player->IsPlayer())
  1585. client = player->GetZone()->GetClientBySpawn(player);
  1586. float x = lua_interface->GetFloatValue(state, 3);
  1587. float y = lua_interface->GetFloatValue(state, 4);
  1588. float z = lua_interface->GetFloatValue(state, 5);
  1589. float heading = lua_interface->GetFloatValue(state, 6);
  1590. if (zone && client) {
  1591. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1592. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1593. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1594. {
  1595. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1596. return 0;
  1597. }
  1598. if (x != 0 || y != 0 || z != 0) {
  1599. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1600. player->SetX(x);
  1601. player->SetY(y);
  1602. player->SetZ(z);
  1603. player->SetHeading(heading);
  1604. client->Zone(zone->GetZoneName(), false);
  1605. }
  1606. else
  1607. client->Zone(zone->GetZoneName());
  1608. }
  1609. else
  1610. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1611. lua_interface->ResetFunctionStack(state);
  1612. return 0;
  1613. }
  1614. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1615. if (!lua_interface)
  1616. return 0;
  1617. Spawn* spawn = lua_interface->GetSpawn(state);
  1618. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1619. if (spawn && spawn2)
  1620. spawn->AddAllowAccessSpawn(spawn2);
  1621. lua_interface->ResetFunctionStack(state);
  1622. return 0;
  1623. }
  1624. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1625. if (!lua_interface)
  1626. return 0;
  1627. Spawn* target = lua_interface->GetSpawn(state);
  1628. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1629. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1630. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1631. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1632. lua_interface->ResetFunctionStack(state);
  1633. if (!target) {
  1634. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1635. return 0;
  1636. }
  1637. if (!target->IsEntity()) {
  1638. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1639. return 0;
  1640. }
  1641. if (spell_id <= 0) {
  1642. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1643. return 0;
  1644. }
  1645. if (caster && !caster->IsEntity()) {
  1646. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1647. return 0;
  1648. }
  1649. if (spell_tier == 0)
  1650. spell_tier = 1;
  1651. if (!caster)
  1652. caster = target;
  1653. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1654. return 0;
  1655. }
  1656. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1657. if (!lua_interface)
  1658. return 0;
  1659. Spawn* target = lua_interface->GetSpawn(state);
  1660. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1661. if (!luaspell)
  1662. return 0;
  1663. Spawn* caster = luaspell->caster;
  1664. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1665. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1666. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1667. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1668. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1669. //lua_interface->ResetFunctionStack(state);
  1670. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1671. vector<int16> faction_req;
  1672. vector<int16> race_req;
  1673. int32 class_req = 0;
  1674. int32 i = 0;
  1675. int8 f = 0;
  1676. int8 r = 0;
  1677. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1678. if (class_id < 100) {
  1679. class_req += pow(2.0, double(class_id - 1));
  1680. }
  1681. else if (class_id > 100 && class_id < 1000) {
  1682. race_req.push_back(class_id);
  1683. r++;
  1684. }
  1685. else {
  1686. faction_req.push_back(class_id);
  1687. f++;
  1688. }
  1689. i++;
  1690. }
  1691. lua_interface->ResetFunctionStack(state);
  1692. if (caster && caster->IsEntity()) {
  1693. bool race_match = false;
  1694. bool success = false;
  1695. luaspell->resisted = false;
  1696. if (luaspell->targets.size() > 0) {
  1697. ZoneServer* zone = luaspell->caster->GetZone();
  1698. Spawn* target = 0;
  1699. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1700. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1701. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1702. if (race_req.size() > 0) {
  1703. for (int8 i = 0; i < race_req.size(); i++) {
  1704. if (target->GetLuaRaceId() == race_req[i]) {
  1705. race_match = true;
  1706. }
  1707. }
  1708. }
  1709. else
  1710. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1711. if (race_match == true) {
  1712. float distance = caster->GetDistance(target, true);
  1713. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1714. }
  1715. }
  1716. }
  1717. success = true;
  1718. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1719. }
  1720. else if (target) {
  1721. //check class and race/faction here
  1722. if (race_req.size() > 0) {
  1723. for (int8 i = 0; i < race_req.size(); i++) {
  1724. if (target->GetLuaRaceId() == race_req[i]) {
  1725. race_match = true;
  1726. }
  1727. }
  1728. }
  1729. else
  1730. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1731. if (race_match == true) {
  1732. float distance = caster->GetDistance(target, true);
  1733. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1734. success = true;
  1735. }
  1736. }
  1737. if (success) {
  1738. Spell* spell = luaspell->spell;
  1739. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1740. ((Player*)caster)->InCombat(true);
  1741. if (caster->GetZone())
  1742. caster->GetZone()->TriggerCharSheetTimer();
  1743. }
  1744. }
  1745. }
  1746. return 0;
  1747. }
  1748. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1749. if (!lua_interface)
  1750. return 0;
  1751. Spawn* spawn = lua_interface->GetSpawn(state);
  1752. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1753. lua_interface->ResetFunctionStack(state);
  1754. if (spawn && value != 0) {
  1755. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1756. spawn->SetPower(spawn->GetTotalPower());
  1757. else
  1758. spawn->SetPower(spawn->GetPower() + value);
  1759. }
  1760. return 0;
  1761. }
  1762. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1763. if (!lua_interface)
  1764. return 0;
  1765. Spawn* spawn = lua_interface->GetSpawn(state);
  1766. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1767. lua_interface->ResetFunctionStack(state);
  1768. if (spawn && value != 0) {
  1769. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1770. spawn->SetHP(spawn->GetTotalHP());
  1771. else
  1772. spawn->SetHP(spawn->GetHP() + value);
  1773. }
  1774. return 0;
  1775. }
  1776. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1777. if (!lua_interface)
  1778. return 0;
  1779. Spawn* spawn = lua_interface->GetSpawn(state);
  1780. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1781. lua_interface->ResetFunctionStack(state);
  1782. if (spawn && value != 0) {
  1783. spawn->SetPower(spawn->GetPower() + value);
  1784. if (value > spawn->GetTotalHPBase())
  1785. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1786. }
  1787. return 0;
  1788. }
  1789. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1790. if (!lua_interface)
  1791. return 0;
  1792. Spawn* spawn = lua_interface->GetSpawn(state);
  1793. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1794. lua_interface->ResetFunctionStack(state);
  1795. if (spawn && value != 0) {
  1796. spawn->SetHP(spawn->GetHP() + value);
  1797. if (value > spawn->GetTotalHPBase())
  1798. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1799. }
  1800. return 0;
  1801. }
  1802. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1803. if (!lua_interface)
  1804. return 0;
  1805. Spawn* spawn = lua_interface->GetSpawn(state);
  1806. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1807. lua_interface->ResetFunctionStack(state);
  1808. if (spawn) {
  1809. spawn->SetHP(value);
  1810. if (value > spawn->GetTotalHPBase())
  1811. spawn->SetTotalHP(value);
  1812. }
  1813. return 0;
  1814. }
  1815. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1816. if (!lua_interface)
  1817. return 0;
  1818. Spawn* spawn = lua_interface->GetSpawn(state);
  1819. float value = lua_interface->GetFloatValue(state, 2);
  1820. lua_interface->ResetFunctionStack(state);
  1821. if (spawn && spawn->IsEntity() && value > 0)
  1822. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1823. if (spawn->IsPlayer())
  1824. ((Player*)spawn)->SetCharSheetChanged(true);
  1825. return 0;
  1826. }
  1827. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1828. if (!lua_interface)
  1829. return 0;
  1830. Spawn* spawn = lua_interface->GetSpawn(state);
  1831. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1832. lua_interface->ResetFunctionStack(state);
  1833. if (spawn && spawn->IsEntity() && value > 0)
  1834. ((Entity*)spawn)->SetTotalHPBase(value);
  1835. return 0;
  1836. }
  1837. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1838. if (!lua_interface)
  1839. return 0;
  1840. Spawn* spawn = lua_interface->GetSpawn(state);
  1841. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1842. lua_interface->ResetFunctionStack(state);
  1843. if (spawn && value > 0) {
  1844. spawn->SetPower(value);
  1845. if (value > spawn->GetTotalPowerBase())
  1846. spawn->SetTotalPower(value);
  1847. }
  1848. return 0;
  1849. }
  1850. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1851. if (!lua_interface)
  1852. return 0;
  1853. Spawn* spawn = lua_interface->GetSpawn(state);
  1854. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1855. lua_interface->ResetFunctionStack(state);
  1856. if (spawn && spawn->IsEntity() && value > 0)
  1857. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1858. return 0;
  1859. }
  1860. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1861. if (!lua_interface)
  1862. return 0;
  1863. Spawn* spawn = lua_interface->GetSpawn(state);
  1864. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1865. lua_interface->ResetFunctionStack(state);
  1866. if (spawn && spawn->IsEntity() && value > 0)
  1867. ((Entity*)spawn)->SetTotalPowerBase(value);
  1868. return 0;
  1869. }
  1870. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1871. if (!lua_interface)
  1872. return 0;
  1873. Spawn* spawn = lua_interface->GetSpawn(state);
  1874. float x = lua_interface->GetFloatValue(state, 2);
  1875. float y = lua_interface->GetFloatValue(state, 3);
  1876. float z = lua_interface->GetFloatValue(state, 4);
  1877. float heading = lua_interface->GetFloatValue(state, 5);
  1878. lua_interface->ResetFunctionStack(state);
  1879. if (spawn) {
  1880. spawn->SetX(x);
  1881. spawn->SetY(y);
  1882. spawn->SetZ(z);
  1883. if (heading != 0)
  1884. spawn->SetHeading(heading);
  1885. spawn->SetSpawnOrigX(spawn->GetX());
  1886. spawn->SetSpawnOrigY(spawn->GetY());
  1887. spawn->SetSpawnOrigZ(spawn->GetZ());
  1888. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1889. if (spawn->IsPlayer()) {
  1890. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1891. if (client) {
  1892. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1893. client->QueuePacket(packet);
  1894. }
  1895. }
  1896. }
  1897. return 0;
  1898. }
  1899. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1900. if (!lua_interface)
  1901. return 0;
  1902. Spawn* spawn = lua_interface->GetSpawn(state);
  1903. float value = lua_interface->GetFloatValue(state, 2);
  1904. lua_interface->ResetFunctionStack(state);
  1905. if (spawn) {
  1906. spawn->SetHeading(value);
  1907. if (spawn->IsPlayer()) {
  1908. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1909. if (client) {
  1910. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1911. client->QueuePacket(packet);
  1912. }
  1913. }
  1914. }
  1915. return 0;
  1916. }
  1917. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1918. if (!lua_interface)
  1919. return 0;
  1920. Spawn* spawn = lua_interface->GetSpawn(state);
  1921. int16 value = lua_interface->GetInt16Value(state, 2);
  1922. lua_interface->ResetFunctionStack(state);
  1923. if (spawn)
  1924. spawn->SetModelType(value);
  1925. return 0;
  1926. }
  1927. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1928. if (!lua_interface)
  1929. return 0;
  1930. Spawn* spawn = lua_interface->GetSpawn(state);
  1931. int8 value = lua_interface->GetInt8Value(state, 2);
  1932. lua_interface->ResetFunctionStack(state);
  1933. if (spawn) {
  1934. if (spawn->IsPlayer())
  1935. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1936. else
  1937. spawn->SetAdventureClass(value);
  1938. }
  1939. return 0;
  1940. }
  1941. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1942. if (!lua_interface)
  1943. return 0;
  1944. Spawn* spawn = lua_interface->GetSpawn(state);
  1945. int8 value = lua_interface->GetInt8Value(state, 2);
  1946. lua_interface->ResetFunctionStack(state);
  1947. if (spawn) {
  1948. spawn->SetTradeskillClass(value);
  1949. if (spawn->IsEntity()) {
  1950. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1951. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1952. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1953. }
  1954. if (spawn->IsPlayer())
  1955. ((Player*)spawn)->SetCharSheetChanged(true);
  1956. }
  1957. return 0;
  1958. }
  1959. int EQ2Emu_lua_SetMount(lua_State* state) {
  1960. if (!lua_interface)
  1961. return 0;
  1962. Spawn* spawn = lua_interface->GetSpawn(state);
  1963. int16 value = lua_interface->GetInt16Value(state, 2);
  1964. if (spawn && spawn->IsEntity()) {
  1965. ((Entity*)spawn)->SetMount(value);
  1966. EQ2_Color color;
  1967. color.red = 255;
  1968. color.green = 255;
  1969. color.blue = 255;
  1970. ((Entity*)spawn)->SetMountColor(&color);
  1971. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1972. }
  1973. return 0;
  1974. }
  1975. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1976. if (!lua_interface)
  1977. return 0;
  1978. Spawn* spawn = lua_interface->GetSpawn(state);
  1979. EQ2_Color mount_color;
  1980. EQ2_Color saddle_color;
  1981. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1982. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1983. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1984. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1985. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1986. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1987. if (spawn && spawn->IsEntity()) {
  1988. ((Entity*)spawn)->SetMountColor(&mount_color);
  1989. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1990. }
  1991. return 0;
  1992. }
  1993. int EQ2Emu_lua_GetMount(lua_State* state) {
  1994. if (!lua_interface)
  1995. return 0;
  1996. Spawn* spawn = lua_interface->GetSpawn(state);
  1997. if (spawn && spawn->IsEntity()) {
  1998. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1999. return 1;
  2000. }
  2001. return 0;
  2002. }
  2003. int EQ2Emu_lua_GetRace(lua_State* state) {
  2004. if (!lua_interface)
  2005. return 0;
  2006. Spawn* spawn = lua_interface->GetSpawn(state);
  2007. if (spawn)
  2008. {
  2009. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2010. lua_interface->SetInt32Value(state, spawn->GetRace());
  2011. return 1;
  2012. }
  2013. return 0;
  2014. }
  2015. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2016. if (!lua_interface)
  2017. return 0;
  2018. Spawn* spawn = lua_interface->GetSpawn(state);
  2019. if (spawn) {
  2020. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2021. return 1;
  2022. }
  2023. return 0;
  2024. }
  2025. int EQ2Emu_lua_GetClass(lua_State* state) {
  2026. Spawn* spawn = lua_interface->GetSpawn(state);
  2027. if (spawn) {
  2028. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2029. return 1;
  2030. }
  2031. return 0;
  2032. }
  2033. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2034. Spawn* spawn = lua_interface->GetSpawn(state);
  2035. if (spawn) {
  2036. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2037. return 1;
  2038. }
  2039. return 0;
  2040. }
  2041. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2042. if (!lua_interface)
  2043. return 0;
  2044. Spawn* spawn = lua_interface->GetSpawn(state);
  2045. float value = lua_interface->GetFloatValue(state, 2);
  2046. lua_interface->ResetFunctionStack(state);
  2047. if (spawn) {
  2048. spawn->SetSpeed(value);
  2049. if(spawn->IsEntity())
  2050. ((Entity*)spawn)->SetSpeed(value);
  2051. if (spawn->IsPlayer()) {
  2052. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2053. if (client) {
  2054. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2055. if (packet) {
  2056. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2057. packet->setDataByName("speed", value);
  2058. packet->setDataByName("size", 0.51);
  2059. EQ2Packet* app = packet->serialize();
  2060. client->QueuePacket(app);
  2061. safe_delete(packet);
  2062. }
  2063. }
  2064. }
  2065. }
  2066. return 0;
  2067. }
  2068. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2069. if (!lua_interface)
  2070. return 0;
  2071. Spawn* spawn = lua_interface->GetSpawn(state);
  2072. const int16 type = lua_interface->GetInt16Value(state, 2);
  2073. const float value = lua_interface->GetFloatValue(state, 3);
  2074. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2075. int64 class_req = 0;
  2076. int32 class_id = 0;
  2077. vector<int16> faction_req;
  2078. vector<int16> race_req;
  2079. int32 i = 0;
  2080. int8 f = 0;
  2081. int8 r = 0;
  2082. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2083. if (class_id < 100) {
  2084. class_req += pow(2.0, double(class_id - 1));
  2085. }
  2086. else if (class_id > 100 && class_id < 1000) {
  2087. race_req.push_back(class_id);
  2088. r++;
  2089. }
  2090. else {
  2091. faction_req.push_back(class_id);
  2092. f++;
  2093. }
  2094. i++;
  2095. }
  2096. if (value != 0 && type >= 0) {
  2097. if (luaspell && luaspell->spell && luaspell->caster) {
  2098. ZoneServer* zone = luaspell->caster->GetZone();
  2099. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2100. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2101. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2102. if (target) {
  2103. if (target->IsPlayer()) {
  2104. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2105. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2106. if (((Player*)target)->GetGroupMemberInfo())
  2107. ((Player*)target)->UpdateGroupMemberInfo();
  2108. ((Player*)target)->SetCharSheetChanged(true);
  2109. }
  2110. else if (target->IsNPC())
  2111. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2112. else
  2113. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2114. }
  2115. }
  2116. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2117. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2118. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2119. }
  2120. else if (spawn && spawn->IsEntity()) {
  2121. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2122. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2123. if (spawn->IsPlayer())
  2124. ((Player*)spawn)->SetCharSheetChanged(true);
  2125. }
  2126. else
  2127. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2128. }
  2129. else
  2130. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2131. return 0;
  2132. }
  2133. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2134. if (!lua_interface)
  2135. return 0;
  2136. Spawn* spawn = lua_interface->GetSpawn(state);
  2137. int16 type = lua_interface->GetInt16Value(state, 2);
  2138. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2139. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2140. if (!spawn) {
  2141. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2142. return 0;
  2143. }
  2144. if (!spawn->IsEntity()) {
  2145. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2146. return 0;
  2147. }
  2148. if (value == 0) {
  2149. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2150. return 0;
  2151. }
  2152. if (!luaspell || !luaspell->spell) {
  2153. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2154. return 0;
  2155. }
  2156. int32 class_req = 0;
  2157. vector<int16> faction_req;
  2158. vector<int16> race_req;
  2159. int32 class_id = 0;
  2160. int32 i = 0;
  2161. int8 f = 0;
  2162. int8 r = 0;
  2163. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2164. if (class_id < 100) {
  2165. class_req += pow(2.0, double(class_id - 1));
  2166. }
  2167. else if (class_id > 100 && class_id < 1000) {
  2168. race_req.push_back(class_id);
  2169. r++;
  2170. }
  2171. else {
  2172. faction_req.push_back(class_id);
  2173. f++;
  2174. }
  2175. i++;
  2176. }
  2177. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2178. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2179. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2180. if (spawn->IsPlayer())
  2181. ((Player*)spawn)->SetCharSheetChanged(true);
  2182. return 0;
  2183. }
  2184. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2185. if (!lua_interface)
  2186. return 0;
  2187. Spawn* spawn = lua_interface->GetSpawn(state);
  2188. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2189. if (!spawn) {
  2190. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2191. return 0;
  2192. }
  2193. if (!spawn->IsEntity()) {
  2194. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2195. return 0;
  2196. }
  2197. if (!luaspell || !luaspell->spell) {
  2198. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2199. return 0;
  2200. }
  2201. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2202. if (spawn->IsPlayer())
  2203. ((Player*)spawn)->SetCharSheetChanged(true);
  2204. return 0;
  2205. }
  2206. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2207. if (!lua_interface)
  2208. return 0;
  2209. Spawn* spawn = lua_interface->GetSpawn(state);
  2210. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2211. if (luaspell && luaspell->spell) {
  2212. ZoneServer* zone = luaspell->caster->GetZone();
  2213. Spawn* target = 0;
  2214. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2215. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2216. target = zone->GetSpawnByID(luaspell->targets[i]);
  2217. if (target && target->IsEntity()) {
  2218. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2219. if (target->IsPlayer())
  2220. ((Player*)target)->SetCharSheetChanged(true);
  2221. }
  2222. }
  2223. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2224. }
  2225. else if (spawn && spawn->IsEntity()) {
  2226. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2227. if (spawn->IsPlayer())
  2228. ((Player*)spawn)->SetCharSheetChanged(true);
  2229. }
  2230. return 0;
  2231. }
  2232. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2233. if (!lua_interface)
  2234. return 0;
  2235. Spawn* spawn = lua_interface->GetSpawn(state);
  2236. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2237. float value = lua_interface->GetFloatValue(state, 3);
  2238. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2239. if (value != 0) {
  2240. int32 spell_id = 0;
  2241. if (luaspell && luaspell->spell && luaspell->caster) {
  2242. spell_id = luaspell->spell->GetSpellID();
  2243. ZoneServer* zone = luaspell->caster->GetZone();
  2244. Spawn* target = 0;
  2245. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2246. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2247. target = zone->GetSpawnByID(luaspell->targets[i]);
  2248. if (target && target->Alive()) {
  2249. if (target->IsPlayer()) {
  2250. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2251. Client* client = target->GetZone()->GetClientBySpawn(target);
  2252. if (client) {
  2253. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2254. if (packet)
  2255. client->QueuePacket(packet);
  2256. }
  2257. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2258. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2259. }
  2260. else if (target->IsNPC()) {
  2261. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2262. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2263. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2264. }
  2265. else
  2266. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2267. }
  2268. }
  2269. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2270. }
  2271. else if (spawn) {
  2272. if (spawn->IsPlayer()) {
  2273. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2274. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2275. if (client) {
  2276. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2277. if (packet)
  2278. client->QueuePacket(packet);
  2279. }
  2280. }
  2281. else if (spawn->IsNPC())
  2282. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2283. else
  2284. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2285. }
  2286. }
  2287. else
  2288. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2289. return 0;
  2290. }
  2291. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2292. if (!lua_interface)
  2293. return 0;
  2294. Spawn* spawn = lua_interface->GetSpawn(state);
  2295. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2296. if (spawn && spawn->IsPlayer()) {
  2297. int32 spell_id = 0;
  2298. if (luaspell && luaspell->spell) {
  2299. spell_id = luaspell->spell->GetSpellID();
  2300. ZoneServer* zone = luaspell->caster->GetZone();
  2301. Spawn* target = 0;
  2302. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2303. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2304. target = zone->GetSpawnByID(luaspell->targets[i]);
  2305. if (target) {
  2306. if (target->IsPlayer()) {
  2307. ((Player*)target)->RemoveSkillBonus(spell_id);
  2308. Client* client = target->GetZone()->GetClientBySpawn(target);
  2309. if (client) {
  2310. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2311. if (packet)
  2312. client->QueuePacket(packet);
  2313. }
  2314. }
  2315. else if (target->IsNPC())
  2316. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2317. else
  2318. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2319. }
  2320. }
  2321. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2322. }
  2323. else if (spawn) {
  2324. if (spawn->IsPlayer()) {
  2325. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2326. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2327. if (client) {
  2328. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2329. if (packet)
  2330. client->QueuePacket(packet);
  2331. }
  2332. }
  2333. else if (spawn->IsNPC())
  2334. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2335. else
  2336. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2337. }
  2338. }
  2339. return 0;
  2340. }
  2341. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2342. if (!lua_interface)
  2343. return 0;
  2344. Spawn* spawn = lua_interface->GetSpawn(state);
  2345. int8 type = lua_interface->GetInt32Value(state, 2);
  2346. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2347. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2348. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2349. ZoneServer* zone = luaspell->caster->GetZone();
  2350. Spawn* target = 0;
  2351. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2352. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2353. target = zone->GetSpawnByID(luaspell->targets[i]);
  2354. if (target && target->IsEntity()) {
  2355. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2356. ((Entity*)target)->AddMezSpell(luaspell);
  2357. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2358. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2359. if (target->IsNPC())
  2360. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2361. }
  2362. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2363. ((Entity*)target)->AddStifleSpell(luaspell);
  2364. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2365. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2366. if (target->IsNPC())
  2367. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2368. }
  2369. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2370. ((Entity*)target)->AddDazeSpell(luaspell);
  2371. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2372. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2373. if (target->IsNPC())
  2374. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2375. }
  2376. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2377. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2378. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2379. ((Entity*)target)->AddStunSpell(luaspell);
  2380. if (target->IsNPC())
  2381. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2382. }
  2383. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2384. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2385. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2386. ((Entity*)target)->AddRootSpell(luaspell);
  2387. if (target->IsNPC())
  2388. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2389. }
  2390. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2391. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2392. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2393. ((Entity*)target)->AddFearSpell(luaspell);
  2394. if (target->IsNPC())
  2395. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2396. }
  2397. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2398. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2399. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2400. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2401. }
  2402. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2403. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2404. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2405. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2406. }
  2407. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2408. ((Entity*)target)->AddSnareSpell(luaspell);
  2409. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2410. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2411. if (target->IsNPC())
  2412. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2413. }
  2414. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2415. ((Entity*)target)->AddFlightSpell(luaspell);
  2416. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2417. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2418. }
  2419. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2420. ((Entity*)target)->AddGlideSpell(luaspell);
  2421. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2422. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2423. }
  2424. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2425. ((Entity*)target)->AddSafefallSpell(luaspell);
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2428. }
  2429. else
  2430. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2431. }
  2432. else
  2433. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2434. }
  2435. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2436. }
  2437. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2438. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2439. ((Entity*)spawn)->AddMezSpell(luaspell);
  2440. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2441. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2442. }
  2443. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2444. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2445. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2446. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2447. }
  2448. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2449. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2450. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2451. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2452. }
  2453. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2454. ((Entity*)spawn)->AddStunSpell(luaspell);
  2455. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2456. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2457. }
  2458. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2459. ((Entity*)spawn)->AddRootSpell(luaspell);
  2460. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2461. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2462. }
  2463. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2464. ((Entity*)spawn)->AddFearSpell(luaspell);
  2465. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2466. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2467. }
  2468. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2469. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2470. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2471. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2472. }
  2473. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2474. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2475. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2476. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2477. }
  2478. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2479. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2480. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2481. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2482. }
  2483. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2484. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2485. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2486. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2487. }
  2488. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2489. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2490. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2491. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2492. }
  2493. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2494. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2495. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2496. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2497. }
  2498. else
  2499. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2500. }
  2501. else
  2502. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2503. return 0;
  2504. }
  2505. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2506. if (!lua_interface)
  2507. return 0;
  2508. Spawn* spawn = lua_interface->GetSpawn(state);
  2509. int8 type = lua_interface->GetInt8Value(state, 2);
  2510. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2511. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2512. if (spawn && spawn->IsEntity()) {
  2513. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2514. ZoneServer* zone = luaspell->caster->GetZone();
  2515. Spawn* target = 0;
  2516. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2517. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2518. target = zone->GetSpawnByID(luaspell->targets[i]);
  2519. if (target) {
  2520. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2521. ((Entity*)target)->RemoveMezSpell(luaspell);
  2522. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2523. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2524. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2525. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2526. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2527. ((Entity*)target)->RemoveStunSpell(luaspell);
  2528. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2529. ((Entity*)target)->RemoveRootSpell(luaspell);
  2530. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2531. ((Entity*)target)->RemoveFearSpell(luaspell);
  2532. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2533. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2534. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2535. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2536. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2537. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2538. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2539. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2540. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2541. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2542. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2543. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2544. else
  2545. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2546. }
  2547. }
  2548. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2549. }
  2550. else if (only_remove_spawn) {
  2551. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2552. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2553. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2554. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2555. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2556. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2557. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2558. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2559. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2560. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2561. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2562. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2563. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2564. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2565. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2566. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2567. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2568. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2569. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2570. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2571. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2572. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2573. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2574. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2575. else
  2576. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2577. }
  2578. }
  2579. return 0;
  2580. }
  2581. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2582. if (!lua_interface)
  2583. return 0;
  2584. Spawn* spawn = lua_interface->GetSpawn(state);
  2585. int8 type = lua_interface->GetInt8Value(state, 2);
  2586. bool hasEffect = false;
  2587. if (!spawn)
  2588. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2589. else if (!spawn->IsEntity())
  2590. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2591. else if (type < CONTROL_MAX_EFFECTS)
  2592. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2593. else
  2594. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2595. lua_interface->SetBooleanValue(state, hasEffect);
  2596. return 1;
  2597. }
  2598. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2599. if (!lua_interface)
  2600. return 0;
  2601. Spawn* spawn = lua_interface->GetSpawn(state);
  2602. float distance = 0.0f;
  2603. if (!spawn)
  2604. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2605. else if (!spawn->IsNPC())
  2606. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2607. else
  2608. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2609. lua_interface->SetFloatValue(state, distance);
  2610. return 1;
  2611. }
  2612. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2613. if (!lua_interface)
  2614. return 0;
  2615. Spawn* spawn = lua_interface->GetSpawn(state);
  2616. float distance = 0.0f;
  2617. if (!spawn)
  2618. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2619. else if (!spawn->IsNPC())
  2620. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2621. else
  2622. distance = ((NPC*)spawn)->GetAggroRadius();
  2623. lua_interface->SetFloatValue(state, distance);
  2624. return 1;
  2625. }
  2626. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2627. if (!lua_interface)
  2628. return 0;
  2629. Spawn* spawn = lua_interface->GetSpawn(state);
  2630. float distance = lua_interface->GetFloatValue(state, 2);
  2631. bool override = lua_interface->GetBooleanValue(state, 3);
  2632. bool result = false;
  2633. lua_interface->ResetFunctionStack(state);
  2634. if (!spawn)
  2635. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2636. else if (!spawn->IsNPC())
  2637. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2638. else
  2639. {
  2640. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2641. result = true;
  2642. }
  2643. lua_interface->SetBooleanValue(state, result);
  2644. return 1;
  2645. }
  2646. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2647. if (!lua_interface)
  2648. return 0;
  2649. Spawn* spawn = lua_interface->GetSpawn(state);
  2650. int16 value = lua_interface->GetInt16Value(state, 2);
  2651. if (spawn && spawn->IsEntity()) {
  2652. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2653. if (spawn->IsPlayer())
  2654. ((Player*)spawn)->SetCharSheetChanged(true);
  2655. }
  2656. return 0;
  2657. }
  2658. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2659. if (!lua_interface)
  2660. return 0;
  2661. Spawn* spawn = lua_interface->GetSpawn(state);
  2662. int16 value = lua_interface->GetInt16Value(state, 2);
  2663. if (spawn && spawn->IsEntity()) {
  2664. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2665. if (spawn->IsPlayer())
  2666. ((Player*)spawn)->SetCharSheetChanged(true);
  2667. }
  2668. return 0;
  2669. }
  2670. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2671. if (!lua_interface)
  2672. return 0;
  2673. Spawn* spawn = lua_interface->GetSpawn(state);
  2674. int16 value = lua_interface->GetInt16Value(state, 2);
  2675. if (spawn && spawn->IsEntity()) {
  2676. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2677. if (spawn->IsPlayer())
  2678. ((Player*)spawn)->SetCharSheetChanged(true);
  2679. }
  2680. return 0;
  2681. }
  2682. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2683. if (!lua_interface)
  2684. return 0;
  2685. Spawn* spawn = lua_interface->GetSpawn(state);
  2686. int16 value = lua_interface->GetInt16Value(state, 2);
  2687. if (spawn && spawn->IsEntity()) {
  2688. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2689. if (spawn->IsPlayer())
  2690. ((Player*)spawn)->SetCharSheetChanged(true);
  2691. }
  2692. return 0;
  2693. }
  2694. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2695. if (!lua_interface)
  2696. return 0;
  2697. Spawn* spawn = lua_interface->GetSpawn(state);
  2698. int16 value = lua_interface->GetInt16Value(state, 2);
  2699. if (spawn && spawn->IsEntity()) {
  2700. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2701. if (spawn->IsPlayer())
  2702. ((Player*)spawn)->SetCharSheetChanged(true);
  2703. }
  2704. return 0;
  2705. }
  2706. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2707. if (!lua_interface)
  2708. return 0;
  2709. Spawn* spawn = lua_interface->GetSpawn(state);
  2710. int8 value = lua_interface->GetInt8Value(state, 2);
  2711. if (spawn && spawn->IsEntity()) {
  2712. ((Entity*)spawn)->SetDeity(value);
  2713. if (spawn->IsPlayer())
  2714. ((Player*)spawn)->SetCharSheetChanged(true);
  2715. }
  2716. lua_interface->ResetFunctionStack(state);
  2717. return 0;
  2718. }
  2719. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2720. if (!lua_interface)
  2721. return 0;
  2722. Spawn* spawn = lua_interface->GetSpawn(state);
  2723. if (spawn && spawn->IsEntity()) {
  2724. int8 deity = ((Entity*)spawn)->GetDeity();
  2725. lua_interface->SetInt32Value(state, deity);
  2726. return 1;
  2727. }
  2728. return 0;
  2729. }
  2730. int EQ2Emu_lua_SetInt(lua_State* state) {
  2731. if (!lua_interface)
  2732. return 0;
  2733. Spawn* spawn = lua_interface->GetSpawn(state);
  2734. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2735. if (spawn && spawn->IsEntity()) {
  2736. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2737. if (spawn->IsPlayer())
  2738. ((Player*)spawn)->SetCharSheetChanged(true);
  2739. }
  2740. return 0;
  2741. }
  2742. int EQ2Emu_lua_SetWis(lua_State* state) {
  2743. if (!lua_interface)
  2744. return 0;
  2745. Spawn* spawn = lua_interface->GetSpawn(state);
  2746. float value = lua_interface->GetFloatValue(state, 2);
  2747. if (spawn && spawn->IsEntity()) {
  2748. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2749. if (spawn->IsPlayer())
  2750. ((Player*)spawn)->SetCharSheetChanged(true);
  2751. }
  2752. return 0;
  2753. }
  2754. int EQ2Emu_lua_SetSta(lua_State* state) {
  2755. if (!lua_interface)
  2756. return 0;
  2757. Spawn* spawn = lua_interface->GetSpawn(state);
  2758. float value = lua_interface->GetFloatValue(state, 2);
  2759. if (spawn && spawn->IsEntity()) {
  2760. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2761. if (spawn->IsPlayer())
  2762. ((Player*)spawn)->SetCharSheetChanged(true);
  2763. }
  2764. return 0;
  2765. }
  2766. int EQ2Emu_lua_SetStr(lua_State* state) {
  2767. if (!lua_interface)
  2768. return 0;
  2769. Spawn* spawn = lua_interface->GetSpawn(state);
  2770. float value = lua_interface->GetFloatValue(state, 2);
  2771. if (spawn && spawn->IsEntity()) {
  2772. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2773. if (spawn->IsPlayer())
  2774. ((Player*)spawn)->SetCharSheetChanged(true);
  2775. }
  2776. return 0;
  2777. }
  2778. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2779. if (!lua_interface)
  2780. return 0;
  2781. Spawn* spawn = lua_interface->GetSpawn(state);
  2782. float value = lua_interface->GetFloatValue(state, 2);
  2783. if (spawn && spawn->IsEntity()) {
  2784. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2785. if (spawn->IsPlayer())
  2786. ((Player*)spawn)->SetCharSheetChanged(true);
  2787. }
  2788. return 0;
  2789. }
  2790. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2791. if (!lua_interface)
  2792. return 0;
  2793. Spawn* spawn = lua_interface->GetSpawn(state);
  2794. if (spawn) {
  2795. lua_interface->SetInt32Value(state, spawn->GetHP());
  2796. return 1;
  2797. }
  2798. return 0;
  2799. }
  2800. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2801. if (!lua_interface)
  2802. return 0;
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. if (spawn) {
  2805. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2806. return 1;
  2807. }
  2808. return 0;
  2809. }
  2810. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2811. if (!lua_interface)
  2812. return 0;
  2813. Spawn* spawn = lua_interface->GetSpawn(state);
  2814. if (spawn) {
  2815. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2816. return 1;
  2817. }
  2818. return 0;
  2819. }
  2820. int EQ2Emu_lua_GetName(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. if (spawn) {
  2825. lua_interface->SetStringValue(state, spawn->GetName());
  2826. return 1;
  2827. }
  2828. return 0;
  2829. }
  2830. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2831. Spawn* spawn = lua_interface->GetSpawn(state);
  2832. if (spawn) {
  2833. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2834. return 1;
  2835. }
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* spawn = lua_interface->GetSpawn(state);
  2842. if (spawn) {
  2843. lua_interface->SetInt32Value(state, spawn->GetPower());
  2844. return 1;
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Spawn* spawn = lua_interface->GetSpawn(state);
  2852. if (spawn) {
  2853. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2854. return 1;
  2855. }
  2856. return 0;
  2857. }
  2858. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2859. if (!lua_interface)
  2860. return 0;
  2861. Spawn* spawn = lua_interface->GetSpawn(state);
  2862. if (spawn) {
  2863. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2864. return 1;
  2865. }
  2866. return 0;
  2867. }
  2868. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2869. if (!lua_interface)
  2870. return 0;
  2871. Spawn* spawn = lua_interface->GetSpawn(state);
  2872. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2873. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2874. if (spawn && spawn2) {
  2875. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2876. lua_interface->SetFloatValue(state, distance);
  2877. return 1;
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_GetX(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Spawn* spawn = lua_interface->GetSpawn(state);
  2885. if (spawn) {
  2886. lua_interface->SetFloatValue(state, spawn->GetX());
  2887. return 1;
  2888. }
  2889. return 0;
  2890. }
  2891. int EQ2Emu_lua_GetY(lua_State* state) {
  2892. if (!lua_interface)
  2893. return 0;
  2894. Spawn* spawn = lua_interface->GetSpawn(state);
  2895. if (spawn) {
  2896. lua_interface->SetFloatValue(state, spawn->GetY());
  2897. return 1;
  2898. }
  2899. return 0;
  2900. }
  2901. int EQ2Emu_lua_GetZ(lua_State* state) {
  2902. if (!lua_interface)
  2903. return 0;
  2904. Spawn* spawn = lua_interface->GetSpawn(state);
  2905. if (spawn) {
  2906. lua_interface->SetFloatValue(state, spawn->GetZ());
  2907. return 1;
  2908. }
  2909. return 0;
  2910. }
  2911. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2912. if (!lua_interface)
  2913. return 0;
  2914. Spawn* spawn = lua_interface->GetSpawn(state);
  2915. if (spawn) {
  2916. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2917. return 1;
  2918. }
  2919. return 0;
  2920. }
  2921. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2922. if (!lua_interface)
  2923. return 0;
  2924. Spawn* spawn = lua_interface->GetSpawn(state);
  2925. if (spawn) {
  2926. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2927. return 1;
  2928. }
  2929. return 0;
  2930. }
  2931. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2932. if (!lua_interface)
  2933. return 0;
  2934. Spawn* spawn = lua_interface->GetSpawn(state);
  2935. if (spawn) {
  2936. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2937. return 1;
  2938. }
  2939. return 0;
  2940. }
  2941. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2942. if (!lua_interface)
  2943. return 0;
  2944. Spawn* spawn = lua_interface->GetSpawn(state);
  2945. if (spawn && spawn->IsEntity()) {
  2946. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2947. return 1;
  2948. }
  2949. return 0;
  2950. }
  2951. int EQ2Emu_lua_GetInt(lua_State* state) {
  2952. if (!lua_interface)
  2953. return 0;
  2954. Spawn* spawn = lua_interface->GetSpawn(state);
  2955. if (spawn && spawn->IsEntity()) {
  2956. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2957. return 1;
  2958. }
  2959. return 0;
  2960. }
  2961. int EQ2Emu_lua_GetWis(lua_State* state) {
  2962. if (!lua_interface)
  2963. return 0;
  2964. Spawn* spawn = lua_interface->GetSpawn(state);
  2965. if (spawn && spawn->IsEntity()) {
  2966. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2967. return 1;
  2968. }
  2969. return 0;
  2970. }
  2971. int EQ2Emu_lua_GetSta(lua_State* state) {
  2972. if (!lua_interface)
  2973. return 0;
  2974. Spawn* spawn = lua_interface->GetSpawn(state);
  2975. if (spawn && spawn->IsEntity()) {
  2976. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2977. return 1;
  2978. }
  2979. return 0;
  2980. }
  2981. int EQ2Emu_lua_GetStr(lua_State* state) {
  2982. if (!lua_interface)
  2983. return 0;
  2984. Spawn* spawn = lua_interface->GetSpawn(state);
  2985. if (spawn && spawn->IsEntity()) {
  2986. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2987. return 1;
  2988. }
  2989. return 0;
  2990. }
  2991. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2992. if (!lua_interface)
  2993. return 0;
  2994. Spawn* spawn = lua_interface->GetSpawn(state);
  2995. if (spawn && spawn->IsEntity()) {
  2996. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2997. return 1;
  2998. }
  2999. return 0;
  3000. }
  3001. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3002. if (!lua_interface)
  3003. return 0;
  3004. Spawn* spawn = lua_interface->GetSpawn(state);
  3005. if (spawn && spawn->IsEntity()) {
  3006. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3007. return 1;
  3008. }
  3009. return 0;
  3010. }
  3011. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3012. if (!lua_interface)
  3013. return 0;
  3014. Spawn* spawn = lua_interface->GetSpawn(state);
  3015. if (spawn && spawn->IsEntity()) {
  3016. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3017. return 1;
  3018. }
  3019. return 0;
  3020. }
  3021. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3022. if (!lua_interface)
  3023. return 0;
  3024. Spawn* spawn = lua_interface->GetSpawn(state);
  3025. if (spawn && spawn->IsEntity()) {
  3026. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3027. return 1;
  3028. }
  3029. return 0;
  3030. }
  3031. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3032. if (!lua_interface)
  3033. return 0;
  3034. Spawn* spawn = lua_interface->GetSpawn(state);
  3035. if (spawn && spawn->IsEntity()) {
  3036. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3037. return 1;
  3038. }
  3039. return 0;
  3040. }
  3041. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3042. if (!lua_interface)
  3043. return 0;
  3044. Spawn* spawn = lua_interface->GetSpawn(state);
  3045. if (spawn && spawn->IsEntity()) {
  3046. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3047. return 1;
  3048. }
  3049. return 0;
  3050. }
  3051. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3052. if (!lua_interface)
  3053. return 0;
  3054. Spawn* player = lua_interface->GetSpawn(state);
  3055. if (!player || !player->IsPlayer()) {
  3056. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3057. return 0;
  3058. }
  3059. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3060. if (quest_id <= 0) {
  3061. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3062. return 0;
  3063. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3064. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3065. return 0;
  3066. }
  3067. int32 step = lua_interface->GetInt32Value(state, 3);
  3068. if (step > 0) {
  3069. Client* client = player->GetZone()->GetClientBySpawn(player);
  3070. if (client)
  3071. client->AddPendingQuestUpdate(quest_id, step);
  3072. } else {
  3073. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3074. }
  3075. return 0;
  3076. }
  3077. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3078. Spawn* player = lua_interface->GetSpawn(state);
  3079. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3080. int32 step = lua_interface->GetInt32Value(state, 3);
  3081. int32 progress = lua_interface->GetInt32Value(state, 4);
  3082. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3083. Client* client = player->GetZone()->GetClientBySpawn(player);
  3084. if (client)
  3085. client->AddPendingQuestUpdate(quest_id, step, progress);
  3086. }
  3087. return 0;
  3088. }
  3089. int EQ2Emu_lua_GetTaskGroupStep(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->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3096. return 1;
  3097. }
  3098. return 0;
  3099. }
  3100. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3101. if (!lua_interface)
  3102. return 0;
  3103. Spawn* player = lua_interface->GetSpawn(state);
  3104. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3105. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3106. if (player && player->IsPlayer() && quest_id > 0) {
  3107. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3108. return 1;
  3109. }
  3110. return 0;
  3111. }
  3112. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3113. if (!lua_interface)
  3114. return 0;
  3115. Spawn* player = lua_interface->GetSpawn(state);
  3116. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3117. if (player && player->IsPlayer() && quest_id > 0) {
  3118. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3119. return 1;
  3120. }
  3121. return 0;
  3122. }
  3123. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3124. if (!lua_interface)
  3125. return 0;
  3126. Quest* quest = lua_interface->GetQuest(state);
  3127. string name = lua_interface->GetStringValue(state, 2);
  3128. string type = lua_interface->GetStringValue(state, 3);
  3129. string zone = lua_interface->GetStringValue(state, 4);
  3130. int16 level = lua_interface->GetInt16Value(state, 5);
  3131. string description = lua_interface->GetStringValue(state, 6);
  3132. bool load = true;
  3133. if (!quest) {
  3134. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3135. load = false;
  3136. }
  3137. if (load && name.length() == 0) {
  3138. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3139. load = false;
  3140. }
  3141. if (load && type.length() == 0) {
  3142. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3143. load = false;
  3144. }
  3145. if (load && zone.length() == 0) {
  3146. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3147. load = false;
  3148. }
  3149. if (load && description.length() == 0) {
  3150. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3151. load = false;
  3152. }
  3153. if (load && level == 0) {
  3154. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3155. load = false;
  3156. }
  3157. if (load)
  3158. quest->RegisterQuest(name, type, zone, level, description);
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Quest* quest = lua_interface->GetQuest(state);
  3165. if (quest) {
  3166. int8 level = lua_interface->GetInt16Value(state, 2);
  3167. quest->SetPrereqLevel(level);
  3168. }
  3169. return 0;
  3170. }
  3171. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3172. if (!lua_interface)
  3173. return 0;
  3174. Quest* quest = lua_interface->GetQuest(state);
  3175. if (quest) {
  3176. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3177. quest->AddPrereqQuest(quest_id);
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Quest* quest = lua_interface->GetQuest(state);
  3185. if (quest) {
  3186. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3187. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3188. if (quantity == 0)
  3189. quantity = 1;
  3190. Item* master_item = master_item_list.GetItem(item_id);
  3191. if (master_item) {
  3192. Item* item = new Item(master_item);
  3193. item->details.count = quantity;
  3194. quest->AddPrereqItem(item);
  3195. }
  3196. }
  3197. return 0;
  3198. }
  3199. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3200. if (!lua_interface)
  3201. return 0;
  3202. Spawn* player = lua_interface->GetSpawn(state);
  3203. if(!player || !player->IsPlayer()) {
  3204. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3205. return 0;
  3206. }
  3207. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3208. if (quest_id > 0) {
  3209. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3210. return 1;
  3211. } else {
  3212. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3213. }
  3214. return 0;
  3215. }
  3216. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3217. if (!lua_interface)
  3218. return 0;
  3219. Quest* quest = lua_interface->GetQuest(state);
  3220. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3221. lua_interface->ResetFunctionStack(state);
  3222. if (quest && spawn_id > 0)
  3223. quest->SetQuestReturnNPC(spawn_id);
  3224. return 0;
  3225. }
  3226. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3227. if (!lua_interface)
  3228. return 0;
  3229. Spawn* spawn = lua_interface->GetSpawn(state);
  3230. int32 time = lua_interface->GetInt32Value(state, 2);
  3231. string function = lua_interface->GetStringValue(state, 3);
  3232. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3233. Spawn* player = lua_interface->GetSpawn(state, 5);
  3234. lua_interface->ResetFunctionStack(state);
  3235. if (!spawn) {
  3236. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3237. return 0;
  3238. }
  3239. if (time <= 0) {
  3240. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3241. return 0;
  3242. }
  3243. if (function.length() == 0) {
  3244. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3245. return 0;
  3246. }
  3247. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3248. if ( time < 10)
  3249. time = 10;
  3250. timer->timer = Timer::GetCurrentTime2() + time;
  3251. timer->function = function;
  3252. timer->spawn = spawn->GetID();
  3253. timer->player = player ? player->GetID() : 0;
  3254. if (max_count == 0)
  3255. max_count = 1;
  3256. timer->max_count = max_count;
  3257. timer->current_count = 0;
  3258. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3259. return 0;
  3260. }
  3261. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3262. if (!lua_interface)
  3263. return 0;
  3264. Spawn* spawn = lua_interface->GetSpawn(state);
  3265. string function = lua_interface->GetStringValue(state, 2);
  3266. lua_interface->ResetFunctionStack(state);
  3267. if (!spawn) {
  3268. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3269. return 0;
  3270. }
  3271. if(!spawn->GetZone()) {
  3272. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3273. return 0;
  3274. }
  3275. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3276. return 0;
  3277. }
  3278. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3279. if (!lua_interface)
  3280. return 0;
  3281. Spawn* player = lua_interface->GetSpawn(state);
  3282. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3283. lua_interface->ResetFunctionStack(state);
  3284. if (player && player->IsPlayer() && quest_id > 0) {
  3285. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3286. return 1;
  3287. }
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Spawn* player = lua_interface->GetSpawn(state);
  3294. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3295. lua_interface->ResetFunctionStack(state);
  3296. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3297. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3298. if (quest)
  3299. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3300. return 1;
  3301. }
  3302. return 0;
  3303. }
  3304. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3305. if (!lua_interface)
  3306. return 0;
  3307. Spawn* player = lua_interface->GetSpawn(state);
  3308. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3309. lua_interface->ResetFunctionStack(state);
  3310. if (player && player->IsPlayer() && quest_id > 0) {
  3311. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3312. return 1;
  3313. }
  3314. return 0;
  3315. }
  3316. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3317. if (!lua_interface)
  3318. return 0;
  3319. Spawn* npc = lua_interface->GetSpawn(state);
  3320. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3321. lua_interface->ResetFunctionStack(state);
  3322. if (npc && !npc->IsPlayer() && quest_id > 0)
  3323. npc->AddProvidedQuest(quest_id);
  3324. return 0;
  3325. }
  3326. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3327. if (!lua_interface)
  3328. return 0;
  3329. Spawn* npc = lua_interface->GetSpawn(state);
  3330. Spawn* player = lua_interface->GetSpawn(state, 2);
  3331. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3332. bool forced = lua_interface->GetBooleanValue(state, 4);
  3333. lua_interface->ResetFunctionStack(state);
  3334. /* NPC is allowed to be null */
  3335. if (player && player->IsPlayer() && quest_id > 0) {
  3336. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3337. if (master_quest) {
  3338. Client* client = player->GetZone()->GetClientBySpawn(player);
  3339. if (!client) {
  3340. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3341. }
  3342. Quest* quest = new Quest(master_quest);
  3343. if (!quest) {
  3344. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3345. }
  3346. if (client && quest) {
  3347. if (npc)
  3348. quest->SetQuestGiver(npc->GetDatabaseID());
  3349. else
  3350. quest->SetQuestGiver(0);
  3351. client->AddPendingQuest(quest, forced);
  3352. }
  3353. }
  3354. else {
  3355. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3356. }
  3357. }
  3358. else {
  3359. 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);
  3360. }
  3361. return 0;
  3362. }
  3363. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3364. if (!lua_interface)
  3365. return 0;
  3366. Quest* quest = lua_interface->GetQuest(state);
  3367. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3368. lua_interface->ResetFunctionStack(state);
  3369. if (quest) {
  3370. quest->AddPrereqClass(class_id);
  3371. }
  3372. return 0;
  3373. }
  3374. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3375. if (!lua_interface)
  3376. return 0;
  3377. Quest* quest = lua_interface->GetQuest(state);
  3378. int8 race = lua_interface->GetInt8Value(state, 2);
  3379. lua_interface->ResetFunctionStack(state);
  3380. if (quest) {
  3381. quest->AddPrereqRace(race);
  3382. }
  3383. return 0;
  3384. }
  3385. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3386. if (!lua_interface)
  3387. return 0;
  3388. Quest* quest = lua_interface->GetQuest(state);
  3389. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3390. lua_interface->ResetFunctionStack(state);
  3391. if (quest) {
  3392. quest->AddPrereqModelType(model_type);
  3393. }
  3394. return 0;
  3395. }
  3396. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3397. if (!lua_interface)
  3398. return 0;
  3399. Quest* quest = lua_interface->GetQuest(state);
  3400. int8 level = lua_interface->GetInt8Value(state, 2);
  3401. lua_interface->ResetFunctionStack(state);
  3402. if (!quest) {
  3403. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3404. return 0;
  3405. }
  3406. quest->SetPrereqTSLevel(level);
  3407. return 0;
  3408. }
  3409. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3410. if (!lua_interface)
  3411. return 0;
  3412. Quest* quest = lua_interface->GetQuest(state);
  3413. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3414. lua_interface->ResetFunctionStack(state);
  3415. if (!quest) {
  3416. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3417. return 0;
  3418. }
  3419. quest->AddPrereqTradeskillClass(class_id);
  3420. return 0;
  3421. }
  3422. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3423. if (!lua_interface)
  3424. return 0;
  3425. Quest* quest = lua_interface->GetQuest(state);
  3426. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3427. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3428. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3429. lua_interface->ResetFunctionStack(state);
  3430. if (quest) {
  3431. quest->AddPrereqFaction(faction_id, min, max);
  3432. }
  3433. return 0;
  3434. }
  3435. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3436. if (!lua_interface)
  3437. return 0;
  3438. Quest* quest = lua_interface->GetQuest(state);
  3439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3440. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3441. lua_interface->ResetFunctionStack(state);
  3442. if (quest) {
  3443. if (quantity == 0)
  3444. quantity = 1;
  3445. Item* master_item = master_item_list.GetItem(item_id);
  3446. if (master_item) {
  3447. Item* item = new Item(master_item);
  3448. item->details.count = quantity;
  3449. quest->AddSelectableRewardItem(item);
  3450. }
  3451. }
  3452. return 0;
  3453. }
  3454. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3455. if (!lua_interface)
  3456. return 0;
  3457. Quest* quest = lua_interface->GetQuest(state);
  3458. if (quest) {
  3459. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3460. vector<Item*>* items = quest->GetRewardItems();
  3461. if (items) {
  3462. vector<Item*>::iterator itr;
  3463. for (itr = items->begin(); itr != items->end(); itr++) {
  3464. if (*itr && (*itr)->details.item_id == item_id) {
  3465. lua_interface->SetBooleanValue(state, true);
  3466. return 1;
  3467. }
  3468. }
  3469. }
  3470. }
  3471. lua_interface->SetBooleanValue(state, false);
  3472. return 1;
  3473. }
  3474. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3475. if (!lua_interface)
  3476. return 0;
  3477. Quest* quest = lua_interface->GetQuest(state);
  3478. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3479. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3480. lua_interface->ResetFunctionStack(state);
  3481. if (quest) {
  3482. if (quantity == 0)
  3483. quantity = 1;
  3484. Item* master_item = master_item_list.GetItem(item_id);
  3485. if (master_item) {
  3486. Item* item = new Item(master_item);
  3487. item->details.count = quantity;
  3488. quest->AddRewardItem(item);
  3489. }
  3490. }
  3491. return 0;
  3492. }
  3493. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3494. if (!lua_interface)
  3495. return 0;
  3496. Quest* quest = lua_interface->GetQuest(state);
  3497. int32 copper = lua_interface->GetInt32Value(state, 2);
  3498. int32 silver = lua_interface->GetInt32Value(state, 3);
  3499. int32 gold = lua_interface->GetInt32Value(state, 4);
  3500. int32 plat = lua_interface->GetInt32Value(state, 5);
  3501. lua_interface->ResetFunctionStack(state);
  3502. if (quest) {
  3503. quest->AddRewardCoins(copper, silver, gold, plat);
  3504. }
  3505. return 0;
  3506. }
  3507. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3508. if (!lua_interface)
  3509. return 0;
  3510. Quest* quest = lua_interface->GetQuest(state);
  3511. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3512. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3513. lua_interface->ResetFunctionStack(state);
  3514. if (quest && faction_id > 0 && amount != 0)
  3515. quest->AddRewardFaction(faction_id, amount);
  3516. return 0;
  3517. }
  3518. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3519. if (!lua_interface)
  3520. return 0;
  3521. Quest* quest = lua_interface->GetQuest(state);
  3522. int32 status = lua_interface->GetInt32Value(state, 2);
  3523. lua_interface->ResetFunctionStack(state);
  3524. if (quest) {
  3525. quest->SetRewardStatus(status);
  3526. }
  3527. return 0;
  3528. }
  3529. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3530. if (!lua_interface)
  3531. return 0;
  3532. Quest* quest = lua_interface->GetQuest(state);
  3533. int32 status = lua_interface->GetInt32Value(state, 2);
  3534. lua_interface->ResetFunctionStack(state);
  3535. if (quest) {
  3536. quest->SetStatusTmpReward(status);
  3537. }
  3538. return 0;
  3539. }
  3540. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3541. if (!lua_interface)
  3542. return 0;
  3543. Quest* quest = lua_interface->GetQuest(state);
  3544. int64 coins = lua_interface->GetInt64Value(state, 2);
  3545. lua_interface->ResetFunctionStack(state);
  3546. if (quest) {
  3547. quest->SetCoinTmpReward(coins);
  3548. }
  3549. return 0;
  3550. }
  3551. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3552. if (!lua_interface)
  3553. return 0;
  3554. Quest* quest = lua_interface->GetQuest(state);
  3555. string comment = lua_interface->GetStringValue(state, 2);
  3556. lua_interface->ResetFunctionStack(state);
  3557. if (quest) {
  3558. quest->SetRewardComment(comment);
  3559. }
  3560. return 0;
  3561. }
  3562. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3563. if (!lua_interface)
  3564. return 0;
  3565. Quest* quest = lua_interface->GetQuest(state);
  3566. int32 exp = lua_interface->GetInt32Value(state, 2);
  3567. lua_interface->ResetFunctionStack(state);
  3568. if (quest) {
  3569. quest->SetRewardXP(exp);
  3570. }
  3571. return 0;
  3572. }
  3573. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3574. Quest* quest = lua_interface->GetQuest(state);
  3575. int32 step = lua_interface->GetInt32Value(state, 2);
  3576. string description = lua_interface->GetStringValue(state, 3);
  3577. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3578. float percentage = lua_interface->GetFloatValue(state, 5);
  3579. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3580. int16 icon = lua_interface->GetInt16Value(state, 7);
  3581. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3582. if (quest) {
  3583. const char* taskgroup = 0;
  3584. if (str_taskgroup.length() > 0)
  3585. taskgroup = str_taskgroup.c_str();
  3586. int32 id = 0;
  3587. vector<int32>* ids = 0;
  3588. int i = 0;
  3589. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3590. if (ids == 0)
  3591. ids = new vector<int32>;
  3592. ids->push_back(id);
  3593. i++;
  3594. }
  3595. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3596. if (quest_step && icon && quantity > 0)
  3597. quest_step->SetIcon(icon);
  3598. if (quest->GetPlayer()) {
  3599. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3600. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3601. }
  3602. }
  3603. lua_interface->ResetFunctionStack(state);
  3604. return 0;
  3605. }
  3606. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3607. {
  3608. if (!lua_interface)
  3609. return 0;
  3610. Quest* quest = lua_interface->GetQuest(state);
  3611. int32 step = lua_interface->GetInt32Value(state, 2);
  3612. string description = lua_interface->GetStringValue(state, 3);
  3613. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3614. float percentage = lua_interface->GetFloatValue(state, 5);
  3615. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3616. int16 icon = lua_interface->GetInt16Value(state, 7);
  3617. if (quest) {
  3618. const char* taskgroup = 0;
  3619. if (str_taskgroup.length() > 0)
  3620. taskgroup = str_taskgroup.c_str();
  3621. int32 id = 0;
  3622. vector<int32>* ids = 0;
  3623. int i = 0;
  3624. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3625. if (ids == 0)
  3626. ids = new vector<int32>;
  3627. ids->push_back(id);
  3628. i++;
  3629. }
  3630. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3631. if (quest_step && icon > 0 && quantity > 0)
  3632. quest_step->SetIcon(icon);
  3633. if (quest->GetPlayer()) {
  3634. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3635. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3636. }
  3637. safe_delete(ids);
  3638. }
  3639. lua_interface->ResetFunctionStack(state);
  3640. return 0;
  3641. }
  3642. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3643. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3644. }
  3645. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3646. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3647. }
  3648. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3649. if (!lua_interface)
  3650. return 0;
  3651. Quest* quest = lua_interface->GetQuest(state);
  3652. int32 step = lua_interface->GetInt32Value(state, 2);
  3653. string description = lua_interface->GetStringValue(state, 3);
  3654. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3655. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3656. int16 icon = lua_interface->GetInt16Value(state, 6);
  3657. if (quest) {
  3658. const char* taskgroup = 0;
  3659. if (str_taskgroup.length() > 0)
  3660. taskgroup = str_taskgroup.c_str();
  3661. int32 npc_id = 0;
  3662. vector<int32>* ids = 0;
  3663. int i = 0;
  3664. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3665. if (ids == 0)
  3666. ids = new vector<int32>;
  3667. ids->push_back(npc_id);
  3668. i++;
  3669. }
  3670. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3671. if (quest_step && icon > 0)
  3672. quest_step->SetIcon(icon);
  3673. if (quest->GetPlayer()) {
  3674. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3675. if(client)
  3676. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3677. }
  3678. safe_delete(ids);
  3679. }
  3680. lua_interface->ResetFunctionStack(state);
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 step = lua_interface->GetInt32Value(state, 2);
  3688. string description = lua_interface->GetStringValue(state, 3);
  3689. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3690. float percentage = lua_interface->GetFloatValue(state, 5);
  3691. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3692. int16 icon = lua_interface->GetInt16Value(state, 7);
  3693. if (quest) {
  3694. const char* taskgroup = 0;
  3695. if (str_taskgroup.length() > 0)
  3696. taskgroup = str_taskgroup.c_str();
  3697. int32 item_id = 0;
  3698. vector<int32>* ids = 0;
  3699. int i = 0;
  3700. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3701. if (ids == 0)
  3702. ids = new vector<int32>;
  3703. ids->push_back(item_id);
  3704. i++;
  3705. }
  3706. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3707. if (quest_step && icon > 0 && quantity > 0)
  3708. quest_step->SetIcon(icon);
  3709. if (quest->GetPlayer()) {
  3710. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3711. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3712. }
  3713. safe_delete(ids);
  3714. }
  3715. lua_interface->ResetFunctionStack(state);
  3716. return 0;
  3717. }
  3718. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3719. if (!lua_interface)
  3720. return 0;
  3721. Quest* quest = lua_interface->GetQuest(state);
  3722. int32 step = lua_interface->GetInt32Value(state, 2);
  3723. string description = lua_interface->GetStringValue(state, 3);
  3724. float max_variation = lua_interface->GetFloatValue(state, 4);
  3725. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3726. int16 icon = lua_interface->GetInt16Value(state, 6);
  3727. if (quest) {
  3728. const char* taskgroup = 0;
  3729. if (str_taskgroup.length() > 0)
  3730. taskgroup = str_taskgroup.c_str();
  3731. vector<Location>* locations = 0;
  3732. int8 i = 7;
  3733. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3734. while (true) {
  3735. Location loc;
  3736. loc.x = lua_interface->GetFloatValue(state, i);
  3737. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3738. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3739. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3740. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3741. break;
  3742. if (locations == 0)
  3743. locations = new vector<Location>;
  3744. locations->push_back(loc);
  3745. i += 4;
  3746. }
  3747. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3748. if (quest_step && icon > 0)
  3749. quest_step->SetIcon(icon);
  3750. if (quest->GetPlayer()) {
  3751. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3752. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3753. }
  3754. }
  3755. lua_interface->ResetFunctionStack(state);
  3756. return 0;
  3757. }
  3758. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3759. if (!lua_interface)
  3760. return 0;
  3761. Quest* quest = lua_interface->GetQuest(state);
  3762. int32 step = lua_interface->GetInt32Value(state, 2);
  3763. string description = lua_interface->GetStringValue(state, 3);
  3764. float max_variation = lua_interface->GetFloatValue(state, 4);
  3765. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3766. int16 icon = lua_interface->GetInt16Value(state, 6);
  3767. if (quest) {
  3768. const char* taskgroup = 0;
  3769. if (str_taskgroup.length() > 0)
  3770. taskgroup = str_taskgroup.c_str();
  3771. vector<Location>* locations = 0;
  3772. int8 i = 7;
  3773. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3774. while (true) {
  3775. Location loc;
  3776. loc.x = lua_interface->GetFloatValue(state, i);
  3777. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3778. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3779. loc.zone_id = 0;
  3780. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3781. break;
  3782. if (locations == 0)
  3783. locations = new vector<Location>;
  3784. locations->push_back(loc);
  3785. i += 3;
  3786. }
  3787. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3788. if (quest_step && icon > 0)
  3789. quest_step->SetIcon(icon);
  3790. if (quest->GetPlayer()) {
  3791. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3792. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3793. }
  3794. }
  3795. lua_interface->ResetFunctionStack(state);
  3796. return 0;
  3797. }
  3798. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3799. if (!lua_interface)
  3800. return 0;
  3801. Quest* quest = lua_interface->GetQuest(state);
  3802. int32 step = lua_interface->GetInt32Value(state, 2);
  3803. string description = lua_interface->GetStringValue(state, 3);
  3804. float max_variation = lua_interface->GetFloatValue(state, 4);
  3805. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3806. int16 icon = lua_interface->GetInt16Value(state, 6);
  3807. if (quest) {
  3808. const char* taskgroup = 0;
  3809. if (str_taskgroup.length() > 0)
  3810. taskgroup = str_taskgroup.c_str();
  3811. vector<Location>* locations = 0;
  3812. int i = 7;
  3813. while (true) {
  3814. Location loc;
  3815. loc.x = lua_interface->GetFloatValue(state, i);
  3816. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3817. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3818. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3819. break;
  3820. if (locations == 0)
  3821. locations = new vector<Location>;
  3822. locations->push_back(loc);
  3823. i += 3;
  3824. }
  3825. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3826. if (quest_step && icon > 0)
  3827. quest_step->SetIcon(icon);
  3828. if (quest->GetPlayer()) {
  3829. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3830. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3831. }
  3832. }
  3833. lua_interface->ResetFunctionStack(state);
  3834. return 0;
  3835. }
  3836. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3837. Quest* quest = lua_interface->GetQuest(state);
  3838. int32 step = lua_interface->GetInt32Value(state, 2);
  3839. string description = lua_interface->GetStringValue(state, 3);
  3840. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3841. float percentage = lua_interface->GetFloatValue(state, 5);
  3842. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3843. int16 icon = lua_interface->GetInt16Value(state, 7);
  3844. if (quest) {
  3845. const char* taskgroup = 0;
  3846. if (str_taskgroup.length() > 0)
  3847. taskgroup = str_taskgroup.c_str();
  3848. int32 spell_id = 0;
  3849. vector<int32>* ids = 0;
  3850. int i = 0;
  3851. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3852. if (ids == 0)
  3853. ids = new vector<int32>;
  3854. ids->push_back(spell_id);
  3855. i++;
  3856. }
  3857. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3858. if (quest_step && icon > 0 && quantity > 0)
  3859. quest_step->SetIcon(icon);
  3860. if (quest->GetPlayer()) {
  3861. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3862. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3863. }
  3864. safe_delete(ids);
  3865. }
  3866. lua_interface->ResetFunctionStack(state);
  3867. return 0;
  3868. }
  3869. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3870. if (!lua_interface)
  3871. return 0;
  3872. Quest* quest = lua_interface->GetQuest(state);
  3873. int32 step = lua_interface->GetInt32Value(state, 2);
  3874. string description = lua_interface->GetStringValue(state, 3);
  3875. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3876. float percentage = lua_interface->GetFloatValue(state, 5);
  3877. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3878. int16 icon = lua_interface->GetInt16Value(state, 7);
  3879. if (quest) {
  3880. const char* taskgroup = 0;
  3881. if (str_taskgroup.length() > 0)
  3882. taskgroup = str_taskgroup.c_str();
  3883. int32 item_id = 0;
  3884. vector<int32>* ids = 0;
  3885. int i = 0;
  3886. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3887. if (ids == 0)
  3888. ids = new vector<int32>;
  3889. ids->push_back(item_id);
  3890. i++;
  3891. }
  3892. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3893. if (quest_step && icon > 0 && quantity > 0)
  3894. quest_step->SetIcon(icon);
  3895. if (quest->GetPlayer()) {
  3896. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3897. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3898. }
  3899. safe_delete(ids);
  3900. }
  3901. lua_interface->ResetFunctionStack(state);
  3902. return 0;
  3903. }
  3904. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3905. if (!lua_interface)
  3906. return 0;
  3907. Quest* quest = lua_interface->GetQuest(state);
  3908. int32 step = lua_interface->GetInt32Value(state, 2);
  3909. string description = lua_interface->GetStringValue(state, 3);
  3910. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3911. float percentage = lua_interface->GetFloatValue(state, 5);
  3912. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3913. int16 icon = lua_interface->GetInt16Value(state, 7);
  3914. if (quest) {
  3915. const char* taskgroup = 0;
  3916. if (str_taskgroup.length() > 0)
  3917. taskgroup = str_taskgroup.c_str();
  3918. int32 item_id = 0;
  3919. vector<int32>* ids = 0;
  3920. int i = 0;
  3921. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3922. if (ids == 0)
  3923. ids = new vector<int32>;
  3924. ids->push_back(item_id);
  3925. i++;
  3926. }
  3927. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3928. if (quest_step && icon > 0 && quantity > 0)
  3929. quest_step->SetIcon(icon);
  3930. if (quest->GetPlayer()) {
  3931. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3932. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3933. }
  3934. safe_delete(ids);
  3935. }
  3936. lua_interface->ResetFunctionStack(state);
  3937. return 0;
  3938. }
  3939. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3940. if (!lua_interface)
  3941. return 0;
  3942. Quest* quest = lua_interface->GetQuest(state);
  3943. string action = lua_interface->GetStringValue(state, 2);
  3944. lua_interface->ResetFunctionStack(state);
  3945. if (quest) {
  3946. if (action.length() > 0)
  3947. quest->SetCompleteAction(action);
  3948. }
  3949. return 0;
  3950. }
  3951. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3952. if (!lua_interface)
  3953. return 0;
  3954. Quest* quest = lua_interface->GetQuest(state);
  3955. int32 step = lua_interface->GetInt32Value(state, 2);
  3956. string action = lua_interface->GetStringValue(state, 3);
  3957. lua_interface->ResetFunctionStack(state);
  3958. if (quest) {
  3959. if (step > 0 && action.length() > 0)
  3960. quest->AddCompleteAction(step, action);
  3961. }
  3962. return 0;
  3963. }
  3964. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3965. if (!lua_interface)
  3966. return 0;
  3967. Quest* quest = lua_interface->GetQuest(state);
  3968. int32 step = lua_interface->GetInt32Value(state, 2);
  3969. string action = lua_interface->GetStringValue(state, 3);
  3970. lua_interface->ResetFunctionStack(state);
  3971. if (quest) {
  3972. if (step > 0 && action.length() > 0)
  3973. quest->AddProgressAction(step, action);
  3974. }
  3975. return 0;
  3976. }
  3977. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3978. if (!lua_interface)
  3979. return 0;
  3980. Quest* quest = lua_interface->GetQuest(state);
  3981. string description = lua_interface->GetStringValue(state, 2);
  3982. lua_interface->ResetFunctionStack(state);
  3983. if (quest && description.length() > 0)
  3984. quest->SetDescription(description);
  3985. return 0;
  3986. }
  3987. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3988. if (!lua_interface)
  3989. return 0;
  3990. Quest* quest = lua_interface->GetQuest(state);
  3991. string description = lua_interface->GetStringValue(state, 2);
  3992. lua_interface->ResetFunctionStack(state);
  3993. if (quest && description.length() > 0)
  3994. quest->SetCompletedDescription(description);
  3995. return 0;
  3996. }
  3997. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3998. if (!lua_interface)
  3999. return 0;
  4000. Quest* quest = lua_interface->GetQuest(state);
  4001. int32 step = lua_interface->GetInt32Value(state, 2);
  4002. string description = lua_interface->GetStringValue(state, 3);
  4003. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4004. lua_interface->ResetFunctionStack(state);
  4005. if (quest && step > 0 && description.length() > 0) {
  4006. quest->SetTaskGroupDescription(step, description, display_bullets);
  4007. /* if (quest->GetPlayer()) {
  4008. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4009. if (client)
  4010. client->SendQuestUpdateStep(quest, step, false);
  4011. }*/
  4012. }
  4013. return 0;
  4014. }
  4015. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4016. if (!lua_interface)
  4017. return 0;
  4018. Quest* quest = lua_interface->GetQuest(state);
  4019. int32 step = lua_interface->GetInt32Value(state, 2);
  4020. string description = lua_interface->GetStringValue(state, 3);
  4021. lua_interface->ResetFunctionStack(state);
  4022. if (quest && step > 0 && description.length() > 0) {
  4023. quest->SetStepDescription(step, description);
  4024. /*if (quest->GetPlayer()) {
  4025. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4026. if (client)
  4027. client->SendQuestUpdateStepImmediately(quest, step);
  4028. }*/
  4029. }
  4030. return 0;
  4031. }
  4032. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4033. Quest* quest = lua_interface->GetQuest(state);
  4034. string zone = lua_interface->GetStringValue(state, 2);
  4035. lua_interface->ResetFunctionStack(state);
  4036. if (quest && zone.length() > 0)
  4037. quest->SetZone(zone);
  4038. return 0;
  4039. }
  4040. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4041. if (!lua_interface)
  4042. return 0;
  4043. Quest* quest = lua_interface->GetQuest(state);
  4044. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4045. lua_interface->ResetFunctionStack(state);
  4046. if (quest && spawn) {
  4047. if (spawn->IsPlayer()) {
  4048. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4049. if (client)
  4050. {
  4051. client->AddPendingQuestAcceptReward(quest);
  4052. client->AddPendingQuestReward(quest);
  4053. }
  4054. }
  4055. }
  4056. return 0;
  4057. }
  4058. int EQ2Emu_lua_Harvest(lua_State* state) {
  4059. if (!lua_interface)
  4060. return 0;
  4061. Spawn* player = lua_interface->GetSpawn(state);
  4062. Spawn* node = lua_interface->GetSpawn(state, 2);
  4063. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4064. Client* client = player->GetZone()->GetClientBySpawn(player);
  4065. if (client) {
  4066. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4067. ((GroundSpawn*)node)->ProcessHarvest(client);
  4068. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4069. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4070. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4071. }
  4072. }
  4073. }
  4074. else if (player && player->IsPlayer()) {
  4075. Client* client = player->GetZone()->GetClientBySpawn(player);
  4076. if (client)
  4077. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4078. }
  4079. lua_interface->ResetFunctionStack(state);
  4080. return 0;
  4081. }
  4082. int EQ2Emu_lua_Bind(lua_State* state) {
  4083. if (!lua_interface)
  4084. return 0;
  4085. Spawn* spawn = lua_interface->GetSpawn(state);
  4086. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4087. float x = lua_interface->GetFloatValue(state, 3);
  4088. float y = lua_interface->GetFloatValue(state, 4);
  4089. float z = lua_interface->GetFloatValue(state, 5);
  4090. float h = lua_interface->GetFloatValue(state, 6);
  4091. lua_interface->ResetFunctionStack(state);
  4092. if (!spawn) {
  4093. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4094. return 0;
  4095. }
  4096. if (!spawn->IsPlayer()) {
  4097. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4098. return 0;
  4099. }
  4100. if (zone_id == 0) {
  4101. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4102. if (!client) {
  4103. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4104. return 0;
  4105. }
  4106. if (!client->Bind())
  4107. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4108. }
  4109. else {
  4110. Player* player = (Player*)spawn;
  4111. player->GetPlayerInfo()->SetBindZone(zone_id);
  4112. player->GetPlayerInfo()->SetBindX(x);
  4113. player->GetPlayerInfo()->SetBindY(y);
  4114. player->GetPlayerInfo()->SetBindZ(z);
  4115. player->GetPlayerInfo()->SetBindHeading(h);
  4116. }
  4117. return 0;
  4118. }
  4119. int EQ2Emu_lua_Gate(lua_State* state) {
  4120. if (!lua_interface)
  4121. return 0;
  4122. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4123. Spawn* spawn = lua_interface->GetSpawn(state);
  4124. lua_interface->ResetFunctionStack(state);
  4125. if (spawn) {
  4126. if (spawn->IsPlayer()) {
  4127. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4128. if (client) {
  4129. if (!client->Gate((spell != nullptr) ? true : false))
  4130. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4131. }
  4132. }
  4133. }
  4134. return 0;
  4135. }
  4136. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4137. if (!lua_interface)
  4138. return 0;
  4139. bool ret = false;
  4140. Spawn* spawn = lua_interface->GetSpawn(state);
  4141. lua_interface->ResetFunctionStack(state);
  4142. if (spawn) {
  4143. if (spawn->IsPlayer()) {
  4144. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4145. if (client)
  4146. ret = client->BindAllowed();
  4147. }
  4148. }
  4149. lua_interface->SetBooleanValue(state, ret);
  4150. return 1;
  4151. }
  4152. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4153. if (!lua_interface)
  4154. return 0;
  4155. bool ret = false;
  4156. Spawn* spawn = lua_interface->GetSpawn(state);
  4157. lua_interface->ResetFunctionStack(state);
  4158. if (spawn) {
  4159. if (spawn->IsPlayer()) {
  4160. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4161. if (client)
  4162. ret = client->GateAllowed();
  4163. }
  4164. }
  4165. lua_interface->SetBooleanValue(state, ret);
  4166. return 1;
  4167. }
  4168. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4169. Spawn* spawn = lua_interface->GetSpawn(state);
  4170. lua_interface->ResetFunctionStack(state);
  4171. if (spawn) {
  4172. lua_interface->SetBooleanValue(state, spawn->Alive());
  4173. return 1;
  4174. }
  4175. return 0;
  4176. }
  4177. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4178. if (!lua_interface)
  4179. return 0;
  4180. Spawn* spawn = lua_interface->GetSpawn(state);
  4181. lua_interface->ResetFunctionStack(state);
  4182. if (spawn && spawn->IsEntity()) {
  4183. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4184. return 1;
  4185. }
  4186. return 0;
  4187. }
  4188. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4189. Spawn* spawn = lua_interface->GetSpawn(state);
  4190. string message = lua_interface->GetStringValue(state, 2);
  4191. string color_str = lua_interface->GetStringValue(state, 3);
  4192. lua_interface->ResetFunctionStack(state);
  4193. int8 color = CHANNEL_NARRATIVE;
  4194. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4195. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4196. if (client) {
  4197. if (color_str.length() > 0) {
  4198. // leave for backwards compat, but all future should just use the number
  4199. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4200. color = CHANNEL_COLOR_RED;
  4201. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4202. color = CHANNEL_COLOR_YELLOW;
  4203. else
  4204. {
  4205. // use a number to specify the channel as per Commands/Commands.h defines
  4206. color = (int8)atoul(color_str.c_str());
  4207. }
  4208. }
  4209. client->SimpleMessage(color, message.c_str());
  4210. }
  4211. }
  4212. return 0;
  4213. }
  4214. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4215. Spawn* spawn = lua_interface->GetSpawn(state);
  4216. string message = lua_interface->GetStringValue(state, 2);
  4217. int8 red = lua_interface->GetInt8Value(state, 3);
  4218. int8 green = lua_interface->GetInt8Value(state, 4);
  4219. int8 blue = lua_interface->GetInt8Value(state, 5);
  4220. lua_interface->ResetFunctionStack(state);
  4221. if (!spawn) {
  4222. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4223. return 0;
  4224. }
  4225. int32 words = ::CountWordsInString(message.c_str());
  4226. if (words < 5)
  4227. words = 5;
  4228. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4229. if (client)
  4230. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4231. return 0;
  4232. }
  4233. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4234. Spawn* spawn = lua_interface->GetSpawn(state);
  4235. int8 param = lua_interface->GetInt8Value(state, 2);
  4236. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4237. int8 value = lua_interface->GetInt8Value(state, 4);
  4238. lua_interface->ResetFunctionStack(state);
  4239. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4240. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4241. if (client) {
  4242. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4243. switch (param) {
  4244. case 1: {
  4245. packet->setDataByName("parameter1", param_value);
  4246. break;
  4247. }
  4248. case 2: {
  4249. packet->setDataByName("parameter2", param_value);
  4250. break;
  4251. }
  4252. case 3: {
  4253. packet->setDataByName("parameter3", param_value);
  4254. break;
  4255. }
  4256. case 4: {
  4257. packet->setDataByName("parameter4", param_value);
  4258. break;
  4259. }
  4260. case 5: {
  4261. packet->setDataByName("parameter5", param_value);
  4262. break;
  4263. }
  4264. }
  4265. packet->setDataByName("value", value);
  4266. client->QueuePacket(packet->serialize());
  4267. safe_delete(packet);
  4268. }
  4269. }
  4270. return 0;
  4271. }
  4272. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4273. Spawn* spawn = lua_interface->GetSpawn(state);
  4274. lua_interface->ResetFunctionStack(state);
  4275. if (spawn && spawn->IsPlayer()) {
  4276. if (((Player*)spawn)->GetIsTracking())
  4277. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4278. else
  4279. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4280. }
  4281. return 0;
  4282. }
  4283. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4284. Spawn* player = lua_interface->GetSpawn(state);
  4285. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4286. string name = lua_interface->GetStringValue(state, 3);
  4287. float distance = lua_interface->GetFloatValue(state, 4);
  4288. string command = lua_interface->GetStringValue(state, 5);
  4289. string error_text = lua_interface->GetStringValue(state, 6);
  4290. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4291. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4292. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4293. lua_interface->ResetFunctionStack(state);
  4294. if (spawn) {
  4295. if (distance == 0)
  4296. distance = 10.0f;
  4297. if (command.length() == 0)
  4298. command = name;
  4299. if (command.length() < 1 && name.length() < 1)
  4300. {
  4301. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4302. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4303. spawn->RemovePrimaryCommands();
  4304. }
  4305. else
  4306. {
  4307. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4308. }
  4309. }
  4310. return 0;
  4311. }
  4312. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4313. if (!lua_interface)
  4314. return 0;
  4315. Spawn* player = lua_interface->GetSpawn(state);
  4316. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4317. int16 tier = lua_interface->GetInt16Value(state, 3);
  4318. lua_interface->ResetFunctionStack(state);
  4319. if (player && player->IsPlayer()) {
  4320. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4321. return 1;
  4322. }
  4323. return 0;
  4324. }
  4325. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4326. if (!lua_interface)
  4327. return 0;
  4328. Spawn* player = lua_interface->GetSpawn(state);
  4329. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4330. int16 tier = lua_interface->GetInt16Value(state, 3);
  4331. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4332. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4333. bool add_to_hotbar = true;
  4334. if (num_args > 4) {
  4335. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4336. }
  4337. lua_interface->ResetFunctionStack(state);
  4338. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4339. if (player && spell && player->IsPlayer()) {
  4340. Client* client = player->GetClient();
  4341. if (client) {
  4342. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4343. {
  4344. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4345. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4346. client->GetPlayer()->UnlockSpell(spell);
  4347. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4348. }
  4349. else
  4350. {
  4351. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4352. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4353. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4354. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4355. client->GetPlayer()->UnlockSpell(spell);
  4356. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4357. }
  4358. //if (client ) {
  4359. // ((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);
  4360. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4361. if (outapp)
  4362. client->QueuePacket(outapp);
  4363. }
  4364. }
  4365. return 0;
  4366. }
  4367. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4368. if (!lua_interface)
  4369. return 0;
  4370. Spawn* player = lua_interface->GetSpawn(state);
  4371. lua_interface->ResetFunctionStack(state);
  4372. if (player && player->IsPlayer()) {
  4373. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4374. return 1;
  4375. }
  4376. return 0;
  4377. }
  4378. int EQ2Emu_lua_Attack(lua_State* state) {
  4379. if (lua_interface) {
  4380. Spawn* npc = lua_interface->GetSpawn(state);
  4381. Spawn* player = lua_interface->GetSpawn(state, 2);
  4382. lua_interface->ResetFunctionStack(state);
  4383. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4384. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4385. }
  4386. return 0;
  4387. }
  4388. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4389. if (lua_interface) {
  4390. Spawn* target = lua_interface->GetSpawn(state);
  4391. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4392. lua_interface->ResetFunctionStack(state);
  4393. if (target && target->GetZone())
  4394. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4395. }
  4396. return 0;
  4397. }
  4398. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4399. Spawn* player;
  4400. if (lua_interface) {
  4401. player = lua_interface->GetSpawn(state);
  4402. lua_interface->ResetFunctionStack(state);
  4403. if (player && player->IsPlayer()) {
  4404. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4405. return 1;
  4406. }
  4407. }
  4408. return 0;
  4409. }
  4410. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4411. Spawn* player;
  4412. Client* client;
  4413. if (lua_interface) {
  4414. player = lua_interface->GetSpawn(state);
  4415. lua_interface->ResetFunctionStack(state);
  4416. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4417. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4418. client->HandInCollections();
  4419. }
  4420. return 0;
  4421. }
  4422. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4423. Spawn* widget;
  4424. if (lua_interface) {
  4425. widget = lua_interface->GetSpawn(state);
  4426. lua_interface->ResetFunctionStack(state);
  4427. if (widget && widget->IsWidget())
  4428. ((Widget*)widget)->HandleUse(nullptr, "");
  4429. }
  4430. return 0;
  4431. }
  4432. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4433. Spawn* spawn = 0;
  4434. int32 primary_list = 0;
  4435. int32 secondary_list = 0;
  4436. if (lua_interface) {
  4437. spawn = lua_interface->GetSpawn(state);
  4438. primary_list = lua_interface->GetInt32Value(state, 2);
  4439. secondary_list = lua_interface->GetInt32Value(state, 3);
  4440. lua_interface->ResetFunctionStack(state);
  4441. if (!spawn->IsNPC()) {
  4442. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4443. return 0;
  4444. }
  4445. NPC* npc = (NPC*)spawn;
  4446. npc->SetPrimarySpellList(primary_list);
  4447. npc->SetSecondarySpellList(secondary_list);
  4448. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4449. }
  4450. return 0;
  4451. }
  4452. int EQ2Emu_lua_GetPet(lua_State* state) {
  4453. if (!lua_interface)
  4454. return 0;
  4455. Spawn* spawn = lua_interface->GetSpawn(state);
  4456. lua_interface->ResetFunctionStack(state);
  4457. if (spawn) {
  4458. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4459. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4460. return 1;
  4461. }
  4462. }
  4463. return 0;
  4464. }
  4465. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4466. if (!lua_interface)
  4467. return 0;
  4468. Spawn* spawn = lua_interface->GetSpawn(state);
  4469. lua_interface->ResetFunctionStack(state);
  4470. if (spawn) {
  4471. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4472. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4473. return 1;
  4474. }
  4475. }
  4476. return 0;
  4477. }
  4478. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4479. if (!lua_interface)
  4480. return 0;
  4481. Spawn* spawn = lua_interface->GetSpawn(state);
  4482. lua_interface->ResetFunctionStack(state);
  4483. if (spawn) {
  4484. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4485. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4486. return 1;
  4487. }
  4488. }
  4489. return 0;
  4490. }
  4491. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4492. if (!lua_interface)
  4493. return 0;
  4494. Spawn* spawn = lua_interface->GetSpawn(state);
  4495. lua_interface->ResetFunctionStack(state);
  4496. if (spawn) {
  4497. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4498. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4499. return 1;
  4500. }
  4501. }
  4502. return 0;
  4503. }
  4504. int EQ2Emu_lua_Charm(lua_State* state) {
  4505. if (!lua_interface)
  4506. return 0;
  4507. Spawn* owner = lua_interface->GetSpawn(state);
  4508. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4509. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4510. lua_interface->ResetFunctionStack(state);
  4511. if (!luaspell) {
  4512. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4513. return 0;
  4514. }
  4515. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4516. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4517. pet->SetPet(true);
  4518. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4519. ((NPC*)pet)->SetOwner((Entity*)owner);
  4520. // If owner is player and player does not have a summoned pet set the players charsheet
  4521. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4522. Player* player = (Player*)owner;
  4523. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4524. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4525. player->GetInfoStruct()->set_pet_movement(2);
  4526. player->GetInfoStruct()->set_pet_behavior(3);
  4527. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4528. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4529. // Make sure the values get sent to the client
  4530. player->SetCharSheetChanged(true);
  4531. }
  4532. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4533. pet->SetSpawnScript("");
  4534. // Set faction to the same as the owner
  4535. pet->SetFactionID(owner->GetFactionID());
  4536. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4537. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4538. // Clear hate list
  4539. ((NPC*)pet)->Brain()->ClearHate();
  4540. // Set the brain to a pet brain
  4541. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4542. }
  4543. return 0;
  4544. }
  4545. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4546. if (!lua_interface)
  4547. return 0;
  4548. Spawn* spawn = lua_interface->GetSpawn(state);
  4549. lua_interface->ResetFunctionStack(state);
  4550. if (!spawn) {
  4551. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4552. return 0;
  4553. }
  4554. vector<Spawn*> groupMembers;
  4555. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4556. groupMembers = *spawn->GetSpawnGroup();
  4557. }
  4558. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4559. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4560. deque<GroupMemberInfo*>::iterator itr;
  4561. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4562. if (group)
  4563. {
  4564. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4565. deque<GroupMemberInfo*>* members = group->GetMembers();
  4566. GroupMemberInfo* info = 0;
  4567. for (itr = members->begin(); itr != members->end(); itr++) {
  4568. info = *itr;
  4569. if (info->client)
  4570. groupMembers.push_back(info->client->GetPlayer());
  4571. }
  4572. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4573. }
  4574. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4575. }
  4576. else
  4577. return 0;
  4578. lua_createtable(state, groupMembers.size(), 0);
  4579. int newTable = lua_gettop(state);
  4580. for (int32 i = 0; i < groupMembers.size(); i++) {
  4581. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4582. lua_rawseti(state, newTable, i + 1);
  4583. }
  4584. return 1;
  4585. }
  4586. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4587. if (!lua_interface)
  4588. return 0;
  4589. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4590. lua_interface->SetOptionWindowValue(state, option_window);
  4591. return 1;
  4592. }
  4593. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4597. if (option_window) {
  4598. OptionWindowOption option_window_option;
  4599. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4600. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4601. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4602. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4603. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4604. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4605. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4606. option_window->push_back(option_window_option);
  4607. }
  4608. return 0;
  4609. }
  4610. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4611. if (!lua_interface)
  4612. return 0;
  4613. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4614. Spawn* player = lua_interface->GetSpawn(state, 2);
  4615. string window_title = lua_interface->GetStringValue(state, 3);
  4616. string cancel_command = lua_interface->GetStringValue(state, 4);
  4617. Client* client = player->GetZone()->GetClientBySpawn(player);
  4618. if (option_window && window_title.length() > 0 && client) {
  4619. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4620. if (!packet)
  4621. return 0;
  4622. packet->setDataByName("title_text", window_title.c_str());
  4623. if (cancel_command.length() > 0)
  4624. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4625. packet->setArrayLengthByName("num_selections", option_window->size());
  4626. vector<OptionWindowOption>::iterator itr;
  4627. int8 i = 0;
  4628. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4629. OptionWindowOption opt = *itr;
  4630. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4631. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4632. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4633. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4634. if (opt.optionCommand.length() > 0)
  4635. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4636. if (opt.optionConfirmTitle.length() > 0)
  4637. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4638. i++;
  4639. }
  4640. client->QueuePacket(packet->serialize());
  4641. safe_delete(option_window);
  4642. safe_delete(packet);
  4643. }
  4644. return 0;
  4645. }
  4646. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4647. if (!lua_interface)
  4648. return 0;
  4649. Spawn* spawn = lua_interface->GetSpawn(state);
  4650. if (spawn) {
  4651. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4652. return 1;
  4653. }
  4654. else
  4655. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4656. return 0;
  4657. }
  4658. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4659. if (!lua_interface)
  4660. return 0;
  4661. Spawn* spawn = lua_interface->GetSpawn(state);
  4662. if (spawn) {
  4663. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4664. return 1;
  4665. }
  4666. else
  4667. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4668. return 0;
  4669. }
  4670. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4671. if (!lua_interface)
  4672. return 0;
  4673. Spawn* spawn = lua_interface->GetSpawn(state);
  4674. if (spawn) {
  4675. int8 class_id = spawn->GetTradeskillClass();
  4676. // Need to add 42 for the offset in the array
  4677. class_id += 44;
  4678. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4679. return 1;
  4680. }
  4681. else
  4682. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4683. return 0;
  4684. }
  4685. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4686. if (!lua_interface)
  4687. return 0;
  4688. Spawn* spawn = lua_interface->GetSpawn(state);
  4689. int16 level = lua_interface->GetInt8Value(state, 2);
  4690. if (spawn) {
  4691. if (spawn->IsPlayer())
  4692. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4693. else
  4694. spawn->SetTSLevel(level);
  4695. }
  4696. else
  4697. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4698. return 0;
  4699. }
  4700. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4701. if (!lua_interface)
  4702. return 0;
  4703. Spawn* spawn = lua_interface->GetSpawn(state);
  4704. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4705. if (spawn) {
  4706. spawn->SetAttackable(attackable);
  4707. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4708. }
  4709. return 0;
  4710. }
  4711. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4712. // Check to see if we have a valid lua_interface
  4713. if (!lua_interface)
  4714. return 0;
  4715. // Get the spawn that is getting the pet
  4716. Spawn* spawn = lua_interface->GetSpawn(state);
  4717. // Get the DB ID of the pet
  4718. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4719. // The max level the pet can gain
  4720. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4721. // Get the spell that this command was called from
  4722. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4723. // Check to make sure the spawn pointer is valid
  4724. if (!spawn) {
  4725. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4726. return 0;
  4727. }
  4728. // Check to make sure the spawn is an entity
  4729. if (!spawn->IsEntity()) {
  4730. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4731. return 0;
  4732. }
  4733. // Check to make sure the spawn doesn't already have a pet of this type
  4734. if (((Entity*)spawn)->GetPet()) {
  4735. if (spawn->IsPlayer()) {
  4736. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4737. if (client)
  4738. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4739. }
  4740. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4741. return 0;
  4742. }
  4743. // Check to see if the DB ID for the pet is set
  4744. if (pet_id == 0) {
  4745. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4746. return 0;
  4747. }
  4748. // Check to see if the pointer to the spell is valid
  4749. if (!luaspell) {
  4750. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4751. return 0;
  4752. }
  4753. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4754. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4755. if (!pet) {
  4756. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4757. return 0;
  4758. }
  4759. // Check to make sure the pet is an npc
  4760. if (!pet->IsNPC()) {
  4761. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4762. return 0;
  4763. }
  4764. // Spawn the pet at the same location as the owner
  4765. pet->SetX(spawn->GetX());
  4766. pet->SetY(spawn->GetY());
  4767. pet->SetZ(spawn->GetZ());
  4768. pet->SetLocation(spawn->GetLocation());
  4769. pet->SetHeading(spawn->GetHeading());
  4770. spawn->GetZone()->AddSpawn(pet);
  4771. /*
  4772. const char* spawn_script = world.GetSpawnScript(pet_id);
  4773. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4774. spawn->SetSpawnScript(string(spawn_script));
  4775. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4776. }*/
  4777. // Get a random pet name
  4778. string random_pet_name;
  4779. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4780. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4781. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4782. // If player set various values for the char sheet (pet window)
  4783. if (spawn->IsPlayer()) {
  4784. Player* player = (Player*)spawn;
  4785. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4786. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4787. player->GetInfoStruct()->set_pet_movement(2);
  4788. player->GetInfoStruct()->set_pet_behavior(3);
  4789. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4790. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4791. // Make sure the values get sent to the client
  4792. player->SetCharSheetChanged(true);
  4793. }
  4794. // Set the pets name
  4795. pet->SetName(random_pet_name.c_str());
  4796. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4797. if (max_level > 0)
  4798. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4799. else
  4800. pet->SetLevel(spawn->GetLevel());
  4801. // Set the max level this pet can reach
  4802. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4803. // Set the faction of the pet to the same faction as the owner
  4804. pet->SetFactionID(spawn->GetFactionID());
  4805. // Set the spawn as a pet
  4806. pet->SetPet(true);
  4807. // Give a pointer of the owner to the pet
  4808. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4809. // Give a pointer of the pet to the owner
  4810. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4811. // Set the pet type
  4812. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4813. // Set the spell id used to create this pet
  4814. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4815. // Set the spell tier used to create this pet
  4816. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4817. // Set the pets spawn type to 6
  4818. pet->SetSpawnType(6);
  4819. // Set the pets brain
  4820. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4821. // Check to see if the pet has a subtitle
  4822. if (strlen(pet->GetSubTitle()) > 0) {
  4823. // Add the players name to the front of the sub title
  4824. string pet_subtitle;
  4825. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4826. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4827. // Set the pets subtitle to the new one
  4828. pet->SetSubTitle(pet_subtitle.c_str());
  4829. }
  4830. // Add the "Pet Options" entity command to the pet
  4831. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4832. // Set the pet as the return value for this function
  4833. lua_interface->SetSpawnValue(state, pet);
  4834. return 1;
  4835. }
  4836. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4837. if (!lua_interface)
  4838. return 0;
  4839. Spawn* spawn = lua_interface->GetSpawn(state);
  4840. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4841. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4842. if (!spawn) {
  4843. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4844. return 0;
  4845. }
  4846. if (!spawn->IsEntity()) {
  4847. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4848. return 0;
  4849. }
  4850. if (((Entity*)spawn)->GetDeityPet()) {
  4851. if (spawn->IsPlayer()) {
  4852. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4853. if (client)
  4854. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4855. }
  4856. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4857. return 0;
  4858. }
  4859. if (pet_id == 0) {
  4860. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4861. return 0;
  4862. }
  4863. if (!luaspell) {
  4864. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4865. return 0;
  4866. }
  4867. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4868. if (!pet) {
  4869. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4870. return 0;
  4871. }
  4872. if (!pet->IsNPC()) {
  4873. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4874. return 0;
  4875. }
  4876. pet->SetX(spawn->GetX());
  4877. pet->SetY(spawn->GetY());
  4878. pet->SetZ(spawn->GetZ());
  4879. pet->SetLocation(spawn->GetLocation());
  4880. pet->SetHeading(spawn->GetHeading());
  4881. spawn->GetZone()->AddSpawn(pet);
  4882. string random_pet_name;
  4883. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4884. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4885. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4886. pet->SetName(random_pet_name.c_str());
  4887. pet->SetLevel(spawn->GetLevel());
  4888. pet->SetFactionID(spawn->GetFactionID());
  4889. pet->SetPet(true);
  4890. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4891. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4892. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4893. pet->SetSpawnType(6);
  4894. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4895. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4896. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4897. if (strlen(pet->GetSubTitle()) > 0) {
  4898. string pet_subtitle;
  4899. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4900. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4901. pet->SetSubTitle(pet_subtitle.c_str());
  4902. }
  4903. // deity and cosmetic pets are not attackable
  4904. pet->SetAttackable(false);
  4905. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4906. lua_interface->SetSpawnValue(state, pet);
  4907. return 1;
  4908. }
  4909. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4910. if (!lua_interface)
  4911. return 0;
  4912. Spawn* spawn = lua_interface->GetSpawn(state);
  4913. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4914. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4915. if (!spawn) {
  4916. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4917. return 0;
  4918. }
  4919. if (!spawn->IsEntity()) {
  4920. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4921. return 0;
  4922. }
  4923. if (((Entity*)spawn)->GetCosmeticPet()) {
  4924. if (spawn->IsPlayer()) {
  4925. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4926. if (client)
  4927. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4928. }
  4929. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4930. return 0;
  4931. }
  4932. if (pet_id == 0) {
  4933. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4934. return 0;
  4935. }
  4936. if (!luaspell) {
  4937. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4938. return 0;
  4939. }
  4940. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4941. if (!pet) {
  4942. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4943. return 0;
  4944. }
  4945. if (!pet->IsNPC()) {
  4946. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4947. return 0;
  4948. }
  4949. pet->SetX(spawn->GetX());
  4950. pet->SetY(spawn->GetY());
  4951. pet->SetZ(spawn->GetZ());
  4952. pet->SetLocation(spawn->GetLocation());
  4953. pet->SetHeading(spawn->GetHeading());
  4954. spawn->GetZone()->AddSpawn(pet);
  4955. string random_pet_name;
  4956. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4957. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4958. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4959. pet->SetName(random_pet_name.c_str());
  4960. pet->SetLevel(spawn->GetLevel());
  4961. pet->SetFactionID(spawn->GetFactionID());
  4962. pet->SetPet(true);
  4963. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4964. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4965. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4966. pet->SetSpawnType(6);
  4967. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4968. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4969. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4970. if (strlen(pet->GetSubTitle()) > 0) {
  4971. string pet_subtitle;
  4972. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4973. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4974. pet->SetSubTitle(pet_subtitle.c_str());
  4975. }
  4976. pet->SetAttackable(false);
  4977. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4978. lua_interface->SetSpawnValue(state, pet);
  4979. return 1;
  4980. }
  4981. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4982. if (!lua_interface)
  4983. return 0;
  4984. Spawn* spawn = lua_interface->GetSpawn(state);
  4985. if (!spawn) {
  4986. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4987. return 0;
  4988. }
  4989. if (!spawn->IsPet()) {
  4990. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4991. return 0;
  4992. }
  4993. if (!((NPC*)spawn)->IsDismissing())
  4994. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4995. return 0;
  4996. }
  4997. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4998. if (!lua_interface)
  4999. return 0;
  5000. Quest* quest = lua_interface->GetQuest(state);
  5001. if (!quest) {
  5002. 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));
  5003. return 0;
  5004. }
  5005. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5006. if (feather_color > 0)
  5007. quest->SetFeatherColor(feather_color);
  5008. return 0;
  5009. }
  5010. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5011. if (!lua_interface)
  5012. return 0;
  5013. Spawn* spawn = lua_interface->GetSpawn(state);
  5014. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5015. if (!spawn) {
  5016. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5017. return 0;
  5018. }
  5019. if (!spawn2) {
  5020. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5021. return 0;
  5022. }
  5023. spawn->RemoveSpawnAccess(spawn2);
  5024. return 0;
  5025. }
  5026. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5027. if (!lua_interface)
  5028. return 0;
  5029. ZoneServer* zone = lua_interface->GetZone(state);
  5030. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5031. if (!zone) {
  5032. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5033. return 0;
  5034. }
  5035. if (location_id == 0) {
  5036. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5037. return 0;
  5038. }
  5039. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5040. if (!location) {
  5041. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5042. return 0;
  5043. }
  5044. Spawn* spawn = 0;
  5045. if (location->entities[0]) {
  5046. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5047. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5048. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5049. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5050. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5051. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5052. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5053. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5054. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5055. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5056. if(spawn && spawn->IsOmittedByDBFlag())
  5057. {
  5058. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5059. safe_delete(spawn);
  5060. spawn = 0;
  5061. return 0;
  5062. }
  5063. if (spawn) {
  5064. const char* script = 0;
  5065. for (int x = 0; x < 3; x++) {
  5066. switch (x) {
  5067. case 0:
  5068. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5069. break;
  5070. case 1:
  5071. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5072. break;
  5073. case 2:
  5074. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5075. break;
  5076. }
  5077. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5078. spawn->SetSpawnScript(string(script));
  5079. break;
  5080. }
  5081. }
  5082. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5083. lua_interface->SetSpawnValue(state, spawn);
  5084. return 1;
  5085. }
  5086. else {
  5087. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5088. safe_delete(spawn);
  5089. }
  5090. }
  5091. return 0;
  5092. }
  5093. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5094. if (!lua_interface)
  5095. return 0;
  5096. Spawn* caster = lua_interface->GetSpawn(state);
  5097. Spawn* target = lua_interface->GetSpawn(state, 2);
  5098. int32 id = lua_interface->GetInt32Value(state, 3);
  5099. string command = lua_interface->GetStringValue(state, 4);
  5100. if (!caster) {
  5101. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5102. return 0;
  5103. }
  5104. if (!target) {
  5105. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5106. return 0;
  5107. }
  5108. if (!caster->IsPlayer()) {
  5109. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5110. return 0;
  5111. }
  5112. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5113. if (!entity_command) {
  5114. 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());
  5115. return 0;
  5116. }
  5117. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5118. if (!client) {
  5119. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5120. return 0;
  5121. }
  5122. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5123. return 0;
  5124. }
  5125. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5126. if (!lua_interface)
  5127. return 0;
  5128. Spawn* spawn = lua_interface->GetSpawn(state);
  5129. if (!spawn) {
  5130. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5131. return 0;
  5132. }
  5133. if (!spawn->IsNPC()) {
  5134. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5135. return 0;
  5136. }
  5137. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5138. return 0;
  5139. }
  5140. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5141. if (!lua_interface)
  5142. return 0;
  5143. Spawn* spawn = lua_interface->GetSpawn(state);
  5144. int16 tick = lua_interface->GetInt16Value(state, 2);
  5145. if (!spawn) {
  5146. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5147. return 0;
  5148. }
  5149. if (!spawn->IsNPC()) {
  5150. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5151. return 0;
  5152. }
  5153. if (tick < 20) {
  5154. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5155. return 0;
  5156. }
  5157. ((NPC*)spawn)->Brain()->SetTick(tick);
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. Spawn* spawn = lua_interface->GetSpawn(state);
  5164. Spawn* target = lua_interface->GetSpawn(state, 2);
  5165. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5166. if (!spawn) {
  5167. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5168. return 0;
  5169. }
  5170. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5171. spawn->SetFollowTarget(target, follow_distance);
  5172. return 0;
  5173. }
  5174. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5175. if (!lua_interface)
  5176. return 0;
  5177. Spawn* spawn = lua_interface->GetSpawn(state);
  5178. if (!spawn) {
  5179. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5180. return 0;
  5181. }
  5182. Spawn* target = spawn->GetFollowTarget();
  5183. if (target) {
  5184. lua_interface->SetSpawnValue(state, target);
  5185. return 1;
  5186. }
  5187. return 0;
  5188. }
  5189. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5190. if (!lua_interface)
  5191. return 0;
  5192. Spawn* spawn = lua_interface->GetSpawn(state);
  5193. if (!spawn) {
  5194. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5195. return 0;
  5196. }
  5197. if (spawn->following)
  5198. spawn->following = false;
  5199. else
  5200. spawn->following = true;
  5201. return 0;
  5202. }
  5203. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5204. if (!lua_interface)
  5205. return 0;
  5206. Spawn* spawn = lua_interface->GetSpawn(state);
  5207. if (!spawn) {
  5208. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5209. return 0;
  5210. }
  5211. lua_interface->SetBooleanValue(state, spawn->following);
  5212. return 1;
  5213. }
  5214. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5215. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5216. // I will attempt to explain how this function works for future refrence
  5217. // Fist lets make sure lua_interface is valid, if not return out
  5218. if (!lua_interface)
  5219. return 0;
  5220. // Next we grab the first 2 params same as we usually would
  5221. Spawn* spawn = lua_interface->GetSpawn(state);
  5222. string var = lua_interface->GetStringValue(state, 2);
  5223. // 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
  5224. // 1 = Spawn
  5225. // 2 = Zone
  5226. // 3 = Item
  5227. // 4 = Quest
  5228. // 5 = String
  5229. // 6 = nil (null)
  5230. int8 dataType = 0;
  5231. // Define pointers for each potential type
  5232. Spawn* spawnVal = 0;
  5233. ZoneServer* zone = 0;
  5234. Item* item = 0;
  5235. Quest* quest = 0;
  5236. string val;
  5237. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5238. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5239. // options window are also light user data be we do not handle those.
  5240. // We check with lua_islightuserdata(lua_State*, index)
  5241. if (lua_islightuserdata(state, 3)) {
  5242. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5243. // and convert it to LUAUserData*
  5244. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5245. // Check to make sure the data we got is valid, if not give an error
  5246. if (!data || !data->IsCorrectlyInitialized()) {
  5247. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5248. }
  5249. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5250. else if (data->IsSpawn()) {
  5251. spawnVal = data->spawn;
  5252. dataType = 1;
  5253. }
  5254. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5255. else if (data->IsZone()) {
  5256. zone = data->zone;
  5257. dataType = 2;
  5258. }
  5259. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5260. else if (data->IsItem()) {
  5261. item = data->item;
  5262. dataType = 3;
  5263. }
  5264. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5265. else if (data->IsQuest()) {
  5266. quest = data->quest;
  5267. dataType = 4;
  5268. }
  5269. }
  5270. // Wasn't light user data, check if it is nil(null)
  5271. else if (lua_isnil(state, 3)) {
  5272. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5273. dataType = 6;
  5274. }
  5275. // Wasn't light user data or nil (null), must be a string
  5276. else {
  5277. // Set the string and dataType variable
  5278. val = lua_interface->GetStringValue(state, 3);
  5279. dataType = 5;
  5280. }
  5281. // We now have all the params, lets check to make sure they are valid
  5282. if (!spawn) {
  5283. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5284. return 0;
  5285. }
  5286. if (var.length() == 0) {
  5287. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5288. return 0;
  5289. }
  5290. if (dataType == 0) {
  5291. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5292. return 0;
  5293. }
  5294. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5295. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5296. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5297. switch (dataType) {
  5298. case 1:
  5299. // 1 = Spawn
  5300. spawn->AddTempVariable(var, spawnVal);
  5301. break;
  5302. case 2:
  5303. // 2 = Zone
  5304. spawn->AddTempVariable(var, zone);
  5305. break;
  5306. case 3:
  5307. // 3 = Item
  5308. spawn->AddTempVariable(var, item);
  5309. break;
  5310. case 4:
  5311. // 4 = Quest
  5312. spawn->AddTempVariable(var, quest);
  5313. break;
  5314. case 5:
  5315. // 5 = String
  5316. spawn->AddTempVariable(var, val);
  5317. break;
  5318. case 6:
  5319. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5320. spawn->DeleteTempVariable(var);
  5321. break;
  5322. }
  5323. // And we are done so return out
  5324. return 0;
  5325. }
  5326. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5327. if (!lua_interface)
  5328. return 0;
  5329. Spawn* spawn = lua_interface->GetSpawn(state);
  5330. string var = lua_interface->GetStringValue(state, 2);
  5331. if (!spawn) {
  5332. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5333. return 0;
  5334. }
  5335. if (var.length() == 0) {
  5336. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5337. return 0;
  5338. }
  5339. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5340. int8 type = spawn->GetTempVariableType(var);
  5341. Spawn* spawn2 = 0;
  5342. ZoneServer* zone = 0;
  5343. Item* item = 0;
  5344. Quest* quest = 0;
  5345. // Set the lua function return value based on the type of data the variable contains
  5346. switch (type) {
  5347. case 1:
  5348. spawn2 = spawn->GetTempVariableSpawn(var);
  5349. if (!spawn2)
  5350. return 0;
  5351. lua_interface->SetSpawnValue(state, spawn2);
  5352. break;
  5353. case 2:
  5354. zone = spawn->GetTempVariableZone(var);
  5355. if (!zone)
  5356. return 0;
  5357. lua_interface->SetZoneValue(state, zone);
  5358. break;
  5359. case 3:
  5360. item = spawn->GetTempVariableItem(var);
  5361. if (!item)
  5362. return 0;
  5363. lua_interface->SetItemValue(state, item);
  5364. break;
  5365. case 4:
  5366. quest = spawn->GetTempVariableQuest(var);
  5367. if (!quest)
  5368. return 0;
  5369. lua_interface->SetQuestValue(state, quest);
  5370. break;
  5371. case 5:
  5372. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5373. break;
  5374. default:
  5375. // Not a valid type then the variable was not set so return out
  5376. return 0;
  5377. }
  5378. // Return value was set so return out
  5379. return 1;
  5380. }
  5381. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5382. {
  5383. if (!lua_interface)
  5384. return 0;
  5385. Quest* quest = lua_interface->GetQuest(state);
  5386. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5387. string description = lua_interface->GetStringValue(state, 3);
  5388. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5389. if (!quest) {
  5390. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5391. lua_interface->SetBooleanValue(state, false);
  5392. return 1;
  5393. }
  5394. if (!spawn) {
  5395. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5396. lua_interface->SetBooleanValue(state, false);
  5397. return 1;
  5398. }
  5399. if (!spawn->IsPlayer()) {
  5400. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5401. lua_interface->SetBooleanValue(state, false);
  5402. return 1;
  5403. }
  5404. if (item_id == 0) {
  5405. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5406. lua_interface->SetBooleanValue(state, false);
  5407. return 1;
  5408. }
  5409. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5410. if (!client) {
  5411. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5412. lua_interface->SetBooleanValue(state, false);
  5413. return 1;
  5414. }
  5415. Item* item = master_item_list.GetItem(item_id);
  5416. if (!item) {
  5417. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5418. lua_interface->SetBooleanValue(state, false);
  5419. return 1;
  5420. }
  5421. Item* firstItem = new Item(item);
  5422. quest->AddTmpRewardItem(firstItem);
  5423. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5424. bool itemsAddedSuccessfully = true;
  5425. if(num_args > 4)
  5426. {
  5427. for(int8 n=5;n<num_args+1;n++)
  5428. {
  5429. int32 new_item = lua_interface->GetInt32Value(state, n);
  5430. Item* tmpItem = master_item_list.GetItem(new_item);
  5431. if(tmpItem)
  5432. {
  5433. Item* newTmpItem = new Item(tmpItem);
  5434. quest->AddTmpRewardItem(newTmpItem);
  5435. }
  5436. else
  5437. itemsAddedSuccessfully = false;
  5438. }
  5439. }
  5440. client->AddPendingQuestAcceptReward(quest);
  5441. client->DisplayQuestComplete(quest, true, description);
  5442. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5443. return 1;
  5444. }
  5445. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5446. if (!lua_interface)
  5447. return 0;
  5448. Quest* quest = lua_interface->GetQuest(state);
  5449. if (!quest) {
  5450. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5451. return 0;
  5452. }
  5453. quest->SetRepeatable(true);
  5454. return 0;
  5455. }
  5456. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5457. if (!lua_interface)
  5458. return 0;
  5459. Spawn* spawn = lua_interface->GetSpawn(state);
  5460. if (!spawn) {
  5461. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5462. return 0;
  5463. }
  5464. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5465. string ret = classes.GetClassNameCase(base_class);
  5466. if (ret.length() > 0) {
  5467. lua_interface->SetStringValue(state, ret.c_str());
  5468. return 1;
  5469. }
  5470. return 0;
  5471. }
  5472. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5473. if (!lua_interface)
  5474. return 0;
  5475. Spawn* player = lua_interface->GetSpawn(state);
  5476. if (player && player->IsPlayer()) {
  5477. Client* client = player->GetClient();
  5478. if (client)
  5479. client->SendWaypoints();
  5480. }
  5481. return 0;
  5482. }
  5483. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5484. if (!lua_interface)
  5485. return 0;
  5486. Spawn* player = lua_interface->GetSpawn(state);
  5487. string name = lua_interface->GetStringValue(state, 2);
  5488. int32 type = lua_interface->GetInt32Value(state, 3);
  5489. if (type == 0)
  5490. type = 2;
  5491. if (name.length() > 0) {
  5492. if (player && player->IsPlayer()) {
  5493. Client* client = player->GetClient();
  5494. if (client)
  5495. client->AddWaypoint(name, type);
  5496. }
  5497. }
  5498. return 0;
  5499. }
  5500. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5501. if (!lua_interface)
  5502. return 0;
  5503. Spawn* player = lua_interface->GetSpawn(state);
  5504. string name = lua_interface->GetStringValue(state, 2);
  5505. if (name.length() > 0) {
  5506. if (player && player->IsPlayer()) {
  5507. Client* client = player->GetClient();
  5508. if (client)
  5509. client->RemoveWaypoint(name);
  5510. }
  5511. }
  5512. return 0;
  5513. }
  5514. int EQ2Emu_lua_AddWard(lua_State* state) {
  5515. if (!lua_interface)
  5516. return 0;
  5517. int32 damage = lua_interface->GetInt32Value(state);
  5518. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5519. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5520. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5521. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5522. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5523. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5524. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5525. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5526. bool ward_was_added = false;
  5527. ZoneServer* zone = spell->caster->GetZone();
  5528. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5529. for (int32 i = 0; i < spell->targets.size(); i++) {
  5530. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5531. if (!target)
  5532. continue;
  5533. if (target->IsEntity()) {
  5534. // If the ward is already active remove it
  5535. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5536. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5537. // Create new ward info
  5538. WardInfo* ward = new WardInfo;
  5539. ward->Spell = spell;
  5540. ward->BaseDamage = damage;
  5541. ward->DamageLeft = damage;
  5542. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5543. ward->keepWard = keepWard;
  5544. ward->WardType = wardType;
  5545. if (damageAbsorptionPercent > 100)
  5546. damageAbsorptionPercent = 100;
  5547. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5548. if (damageAbsorptionMaxHealthPercent > 100)
  5549. damageAbsorptionMaxHealthPercent = 100;
  5550. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5551. ward->RedirectDamagePercent = redirectDamagePercent;
  5552. ward->LastRedirectDamage = 0;
  5553. ward->LastAbsorbedDamage = 0;
  5554. ward->HitCount = 0;
  5555. spell->num_triggers = maxHitCount;
  5556. spell->had_triggers = true;
  5557. spell->cancel_after_all_triggers = false;
  5558. ward->MaxHitCount = maxHitCount;
  5559. if (wardType == WARD_TYPE_MAGICAL)
  5560. ward->DamageType = damageTypes;
  5561. // Add the ward to the entity
  5562. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5563. ward_was_added = true;
  5564. }
  5565. }
  5566. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5567. if (ward_was_added && spell->caster->IsPlayer()) {
  5568. spell->had_dmg_remaining = true;
  5569. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5570. }
  5571. return 0;
  5572. }
  5573. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5574. if (!lua_interface)
  5575. return 0;
  5576. int32 amount = lua_interface->GetInt32Value(state);
  5577. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5578. WardInfo* ward = 0;
  5579. ZoneServer* zone = spell->caster->GetZone();
  5580. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5581. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5582. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5583. ward = target->GetWard(spell->spell->GetSpellID());
  5584. if (target && ward) {
  5585. ward->DamageLeft += amount;
  5586. if (ward->DamageLeft > ward->BaseDamage)
  5587. ward->DamageLeft = ward->BaseDamage;
  5588. for (int32 i = 0; i < spell->targets.size(); i++) {
  5589. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5590. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5591. }
  5592. }
  5593. }
  5594. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5595. if (ward && spell->caster->IsPlayer())
  5596. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5597. return 0;
  5598. }
  5599. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5600. if (!lua_interface)
  5601. return 0;
  5602. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5603. if (!spell) {
  5604. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5605. return 0;
  5606. }
  5607. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5608. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5609. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5610. if (ward) {
  5611. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5612. return 1;
  5613. }
  5614. }
  5615. return 0;
  5616. }
  5617. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5618. if (!lua_interface)
  5619. return 0;
  5620. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5621. if (!spell) {
  5622. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5623. return 0;
  5624. }
  5625. string type = lua_interface->GetStringValue(state, 2);
  5626. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5627. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5628. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5629. if (ward) {
  5630. if (boost::iequals(type, "damageleft"))
  5631. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5632. else if (boost::iequals(type, "basedamage"))
  5633. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5634. else if (boost::iequals(type, "keepward"))
  5635. lua_interface->SetBooleanValue(state, ward->keepWard);
  5636. else if (boost::iequals(type, "wardtype"))
  5637. lua_interface->SetInt32Value(state, ward->WardType);
  5638. else if (boost::iequals(type, "dmgabsorptionpct"))
  5639. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5640. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5641. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5642. else if (boost::iequals(type, "redirectdamagepercent"))
  5643. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5644. else if (boost::iequals(type, "lastredirectdamage"))
  5645. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5646. else if (boost::iequals(type, "lastabsorbeddamage"))
  5647. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5648. else if (boost::iequals(type, "hitcount"))
  5649. lua_interface->SetInt32Value(state, ward->HitCount);
  5650. else if (boost::iequals(type, "maxhitcount"))
  5651. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5652. else
  5653. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5654. return 1;
  5655. }
  5656. }
  5657. return 0;
  5658. }
  5659. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5660. if (!lua_interface)
  5661. return 0;
  5662. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5663. ZoneServer* zone = spell->caster->GetZone();
  5664. Spawn* target = 0;
  5665. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5666. for (int32 i = 0; i < spell->targets.size(); i++) {
  5667. target = zone->GetSpawnByID(spell->targets.at(i));
  5668. if (target && target->IsEntity()) {
  5669. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5670. }
  5671. }
  5672. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5673. return 0;
  5674. }
  5675. int EQ2Emu_lua_Interrupt(lua_State* state)
  5676. {
  5677. if (!lua_interface)
  5678. return 0;
  5679. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5680. Spawn* target = lua_interface->GetSpawn(state, 2);
  5681. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5682. if (!caster)
  5683. {
  5684. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5685. return 0;
  5686. }
  5687. if (!target)
  5688. {
  5689. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5690. return 0;
  5691. }
  5692. if (!spell) {
  5693. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5694. return 0;
  5695. }
  5696. if (!target->IsEntity() && !spell)
  5697. {
  5698. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5699. return 0;
  5700. }
  5701. if (!target && spell) {
  5702. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5703. for (int8 i = 0; i < spell->targets.size(); i++) {
  5704. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5705. if (!target || !target->IsEntity())
  5706. continue;
  5707. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5708. }
  5709. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5710. }
  5711. else
  5712. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5713. return 0;
  5714. }
  5715. int EQ2Emu_lua_Stealth(lua_State* state) {
  5716. if (!lua_interface)
  5717. return 0;
  5718. int8 type = lua_interface->GetInt8Value(state);
  5719. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5720. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5721. if (!spell) {
  5722. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5723. return 0;
  5724. }
  5725. ZoneServer* zone = spell->caster->GetZone();
  5726. if (spawn) {
  5727. if (spawn->IsEntity()) {
  5728. if (type == 1) {
  5729. ((Entity*)spawn)->AddStealthSpell(spell);
  5730. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5731. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5732. }
  5733. else if (type == 2) {
  5734. ((Entity*)spawn)->AddInvisSpell(spell);
  5735. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5736. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5737. }
  5738. return 0;
  5739. }
  5740. else {
  5741. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5742. return 0;
  5743. }
  5744. }
  5745. else {
  5746. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5747. for (int32 i = 0; i < spell->targets.size(); i++) {
  5748. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5749. if (!spawn || !spawn->IsEntity())
  5750. continue;
  5751. if (type == 1) {
  5752. ((Entity*)spawn)->AddStealthSpell(spell);
  5753. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5754. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5755. }
  5756. else if (type == 2) {
  5757. ((Entity*)spawn)->AddInvisSpell(spell);
  5758. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5759. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5760. }
  5761. else {
  5762. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5763. break;
  5764. }
  5765. }
  5766. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5767. }
  5768. return 0;
  5769. }
  5770. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5771. if (!lua_interface)
  5772. return 0;
  5773. Spawn* spawn = lua_interface->GetSpawn(state);
  5774. if (!spawn) {
  5775. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5776. return 0;
  5777. }
  5778. if (spawn->IsEntity()) {
  5779. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5780. return 1;
  5781. }
  5782. else
  5783. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5784. return 0;
  5785. }
  5786. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5787. if (!lua_interface)
  5788. return 0;
  5789. Spawn* spawn = lua_interface->GetSpawn(state);
  5790. if (!spawn) {
  5791. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5792. return 0;
  5793. }
  5794. if (spawn->IsEntity()) {
  5795. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5796. return 1;
  5797. }
  5798. else
  5799. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5800. return 0;
  5801. }
  5802. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5803. if (!lua_interface)
  5804. return 0;
  5805. Spawn* player = lua_interface->GetSpawn(state);
  5806. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5807. lua_interface->ResetFunctionStack(state);
  5808. if (!player->IsPlayer()) {
  5809. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5810. return 0;
  5811. }
  5812. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5813. return 1;
  5814. }
  5815. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5816. if (!lua_interface)
  5817. return 0;
  5818. Spawn* player = lua_interface->GetSpawn(state);
  5819. int8 slot = lua_interface->GetInt8Value(state, 2);
  5820. lua_interface->ResetFunctionStack(state);
  5821. if (!player) {
  5822. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5823. return 0;
  5824. }
  5825. if (!player->IsPlayer()) {
  5826. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5827. return 0;
  5828. }
  5829. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5830. if (!item) {
  5831. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5832. return 0;
  5833. }
  5834. lua_interface->SetItemValue(state, item);
  5835. return 1;
  5836. }
  5837. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5838. if (!lua_interface)
  5839. return 0;
  5840. Spawn* player = lua_interface->GetSpawn(state);
  5841. int32 id = lua_interface->GetInt32Value(state, 2);
  5842. lua_interface->ResetFunctionStack(state);
  5843. if (!player) {
  5844. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5845. return 0;
  5846. }
  5847. if (!player->IsPlayer()) {
  5848. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5849. return 0;
  5850. }
  5851. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5852. if (!item) {
  5853. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5854. return 0;
  5855. }
  5856. lua_interface->SetItemValue(state, item);
  5857. return 1;
  5858. }
  5859. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5860. if (!lua_interface)
  5861. return 0;
  5862. Spawn* spawn = lua_interface->GetSpawn(state);
  5863. int8 slot = lua_interface->GetInt8Value(state, 2);
  5864. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5865. lua_interface->ResetFunctionStack(state);
  5866. if (!spawn) {
  5867. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5868. return 0;
  5869. }
  5870. if (!spawn->IsEntity()) {
  5871. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5872. return 0;
  5873. }
  5874. Item* item = master_item_list.GetItem(item_id);
  5875. if (!item) {
  5876. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5877. return 0;
  5878. }
  5879. Item* copy = new Item(item);
  5880. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5881. if(result)
  5882. {
  5883. ((Entity*)spawn)->SetEquipment(copy, slot);
  5884. spawn->vis_changed = true;
  5885. if(spawn->IsPlayer())
  5886. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5887. }
  5888. else
  5889. {
  5890. safe_delete(copy);
  5891. }
  5892. lua_interface->SetBooleanValue(state, result);
  5893. return 1;
  5894. }
  5895. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5896. if (!lua_interface)
  5897. return 0;
  5898. Spawn* spawn = lua_interface->GetSpawn(state);
  5899. int8 slot = lua_interface->GetInt8Value(state, 2);
  5900. Item* item = lua_interface->GetItem(state, 3);
  5901. lua_interface->ResetFunctionStack(state);
  5902. if (!spawn) {
  5903. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5904. return 0;
  5905. }
  5906. if (!spawn->IsEntity()) {
  5907. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5908. return 0;
  5909. }
  5910. if (!item) {
  5911. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5912. return 0;
  5913. }
  5914. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5915. if(result)
  5916. {
  5917. ((Entity*)spawn)->SetEquipment(item, slot);
  5918. spawn->vis_changed = true;
  5919. if(spawn->IsPlayer())
  5920. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5921. }
  5922. lua_interface->SetBooleanValue(state, result);
  5923. return 1;
  5924. }
  5925. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5926. if (!lua_interface)
  5927. return 0;
  5928. Spawn* spawn = lua_interface->GetSpawn(state);
  5929. int8 slot = lua_interface->GetInt8Value(state, 2);
  5930. 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
  5931. lua_interface->ResetFunctionStack(state);
  5932. if (!spawn) {
  5933. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5934. return 0;
  5935. }
  5936. if (!spawn->IsEntity()) {
  5937. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5938. return 0;
  5939. }
  5940. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5941. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5942. spawn->vis_changed = true;
  5943. if(spawn->IsPlayer())
  5944. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5945. lua_interface->SetBooleanValue(state, true);
  5946. return 1;
  5947. }
  5948. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5949. if (!lua_interface)
  5950. return 0;
  5951. Spawn* spawn = lua_interface->GetSpawn(state);
  5952. int8 slot = lua_interface->GetInt8Value(state, 2);
  5953. int16 type = lua_interface->GetInt16Value(state, 3);
  5954. int8 r = lua_interface->GetInt8Value(state, 4);
  5955. int8 g = lua_interface->GetInt8Value(state, 5);
  5956. int8 b = lua_interface->GetInt8Value(state, 6);
  5957. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5958. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5959. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5960. lua_interface->ResetFunctionStack(state);
  5961. if (!spawn) {
  5962. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5963. return 0;
  5964. }
  5965. if (!spawn->IsEntity()) {
  5966. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5967. return 0;
  5968. }
  5969. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5970. spawn->vis_changed = true;
  5971. lua_interface->SetBooleanValue(state, true);
  5972. return 1;
  5973. }
  5974. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5975. if (!lua_interface)
  5976. return 0;
  5977. Spawn* player = lua_interface->GetSpawn(state);
  5978. int32 id = lua_interface->GetInt32Value(state, 2);
  5979. int8 count = lua_interface->GetInt8Value(state, 3);
  5980. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5981. lua_interface->ResetFunctionStack(state);
  5982. if (!player) {
  5983. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5984. return 0;
  5985. }
  5986. if (!player->IsPlayer()) {
  5987. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5988. return 0;
  5989. }
  5990. if (!count)
  5991. count = 1;
  5992. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5993. if (!item) {
  5994. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5995. return 0;
  5996. }
  5997. lua_interface->SetItemValue(state, item);
  5998. return 1;
  5999. }
  6000. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6001. if (!lua_interface)
  6002. return 0;
  6003. Spawn* spawn = lua_interface->GetSpawn(state);
  6004. int32 anim = lua_interface->GetInt32Value(state, 2);
  6005. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6006. int8 type = lua_interface->GetInt8Value(state, 4);
  6007. if (!spawn) {
  6008. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6009. return 0;
  6010. }
  6011. if (spawn2) {
  6012. if (spawn2->IsPlayer()) {
  6013. if (type != 1 && type != 2)
  6014. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6015. else
  6016. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6017. return 0;
  6018. }
  6019. else {
  6020. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6021. return 0;
  6022. }
  6023. }
  6024. else
  6025. spawn->GetZone()->PlayAnimation(spawn, anim);
  6026. return 0;
  6027. }
  6028. int EQ2Emu_lua_IsPet(lua_State* state) {
  6029. if (!lua_interface)
  6030. return 0;
  6031. Spawn* spawn = lua_interface->GetSpawn(state);
  6032. if (!spawn) {
  6033. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6034. return 0;
  6035. }
  6036. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6037. return 1;
  6038. }
  6039. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6040. if (!lua_interface)
  6041. return 0;
  6042. Spawn* spawn = lua_interface->GetSpawn(state);
  6043. if (!spawn) {
  6044. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6045. return 0;
  6046. }
  6047. if (!spawn->IsNPC()) {
  6048. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6049. return 0;
  6050. }
  6051. if (((NPC*)spawn)->GetOwner()) {
  6052. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6053. return 1;
  6054. }
  6055. return 0;
  6056. }
  6057. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6058. if (!lua_interface)
  6059. return 0;
  6060. Spawn* spawn = lua_interface->GetSpawn(state);
  6061. Spawn* target = lua_interface->GetSpawn(state, 2);
  6062. if (!spawn) {
  6063. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6064. return 0;
  6065. }
  6066. if (!spawn) {
  6067. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6068. return 0;
  6069. }
  6070. spawn->SetTarget(target);
  6071. return 0;
  6072. }
  6073. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6074. if (!lua_interface)
  6075. return 0;
  6076. Spawn* spawn = lua_interface->GetSpawn(state);
  6077. bool val = lua_interface->GetBooleanValue(state, 2);
  6078. if (!spawn) {
  6079. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6080. return 0;
  6081. }
  6082. if (!spawn->IsEntity()) {
  6083. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6084. return 0;
  6085. }
  6086. ((Entity*)spawn)->InCombat(val);
  6087. if (val) {
  6088. spawn->ClearRunningLocations();
  6089. spawn->CalculateRunningLocation(true);
  6090. }
  6091. return 0;
  6092. }
  6093. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6094. if (!lua_interface)
  6095. return 0;
  6096. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6097. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6098. if (!spawn1) {
  6099. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6100. return 0;
  6101. }
  6102. if (!spawn2) {
  6103. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6104. return 0;
  6105. }
  6106. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6107. return 1;
  6108. }
  6109. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6110. if (!lua_interface)
  6111. return 0;
  6112. Spawn* spawn = lua_interface->GetSpawn(state);
  6113. if (!spawn) {
  6114. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6115. return 0;
  6116. }
  6117. if (!spawn->IsNPC()) {
  6118. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6119. return 0;
  6120. }
  6121. ((NPC*)spawn)->ClearRunback();
  6122. return 0;
  6123. }
  6124. int EQ2Emu_lua_Runback(lua_State* state) {
  6125. if (!lua_interface)
  6126. return 0;
  6127. Spawn* spawn = lua_interface->GetSpawn(state);
  6128. if (!spawn) {
  6129. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6130. return 0;
  6131. }
  6132. if (!spawn->IsNPC()) {
  6133. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6134. return 0;
  6135. }
  6136. ((NPC*)spawn)->Runback();
  6137. return 0;
  6138. }
  6139. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6140. if (!lua_interface)
  6141. return 0;
  6142. Spawn* spawn = lua_interface->GetSpawn(state);
  6143. if (!spawn) {
  6144. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6145. return 0;
  6146. }
  6147. if (!spawn->IsNPC()) {
  6148. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6149. return 0;
  6150. }
  6151. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6152. return 1;
  6153. }
  6154. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6155. if (!lua_interface)
  6156. return 0;
  6157. Spawn* spawn = lua_interface->GetSpawn(state);
  6158. if (!spawn) {
  6159. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6160. return 0;
  6161. }
  6162. if (!spawn->IsEntity()) {
  6163. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6164. return 0;
  6165. }
  6166. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6167. return 1;
  6168. }
  6169. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6170. if (!lua_interface)
  6171. return 0;
  6172. Spawn* spawn = lua_interface->GetSpawn(state);
  6173. if (!spawn) {
  6174. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6175. return 0;
  6176. }
  6177. if (!spawn->IsEntity()) {
  6178. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6179. return 0;
  6180. }
  6181. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6182. return 1;
  6183. }
  6184. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6185. if (!lua_interface)
  6186. return 0;
  6187. Spawn* spawn = lua_interface->GetSpawn(state);
  6188. if (!spawn) {
  6189. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6190. return 0;
  6191. }
  6192. if (!spawn->IsEntity()) {
  6193. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6194. return 0;
  6195. }
  6196. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6197. return 1;
  6198. }
  6199. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6200. if (!lua_interface)
  6201. return 0;
  6202. Spawn* spawn = lua_interface->GetSpawn(state);
  6203. if (!spawn) {
  6204. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6205. return 0;
  6206. }
  6207. if (!spawn->IsEntity()) {
  6208. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6209. return 0;
  6210. }
  6211. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6212. return 1;
  6213. }
  6214. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6215. if (!lua_interface)
  6216. return 0;
  6217. Spawn* spawn = lua_interface->GetSpawn(state);
  6218. Spawn* target = lua_interface->GetSpawn(state, 2);
  6219. float distance = lua_interface->GetFloatValue(state, 3);
  6220. if (!spawn) {
  6221. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6222. return 0;
  6223. }
  6224. if (!target) {
  6225. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. if (!spawn->IsNPC()) {
  6229. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6230. return 0;
  6231. }
  6232. if (!target->IsEntity()) {
  6233. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6234. return 0;
  6235. }
  6236. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6237. return 1;
  6238. }
  6239. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6240. if (!lua_interface)
  6241. return 0;
  6242. Spawn* spawn = lua_interface->GetSpawn(state);
  6243. Spawn* target = lua_interface->GetSpawn(state, 2);
  6244. float distance = lua_interface->GetFloatValue(state, 3);
  6245. if (!spawn) {
  6246. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6247. return 0;
  6248. }
  6249. if (!target) {
  6250. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6251. return 0;
  6252. }
  6253. if (!spawn->IsNPC()) {
  6254. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6255. return 0;
  6256. }
  6257. if (!target->IsEntity()) {
  6258. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6259. return 0;
  6260. }
  6261. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6262. return 0;
  6263. }
  6264. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6265. if (!lua_interface)
  6266. return 0;
  6267. Spawn* spawn = lua_interface->GetSpawn(state);
  6268. if (!spawn) {
  6269. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. if (!spawn->IsNPC()) {
  6273. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6274. return 0;
  6275. }
  6276. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6277. return 1;
  6278. }
  6279. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6280. if (!lua_interface)
  6281. return 0;
  6282. Spawn* spawn = lua_interface->GetSpawn(state);
  6283. if (!spawn) {
  6284. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6285. return 0;
  6286. }
  6287. if (!spawn->IsNPC()) {
  6288. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6289. return 0;
  6290. }
  6291. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6292. return 1;
  6293. }
  6294. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6295. if (!lua_interface)
  6296. return 0;
  6297. Spawn* spawn = lua_interface->GetSpawn(state);
  6298. if (!spawn) {
  6299. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6300. return 0;
  6301. }
  6302. if (!spawn->IsNPC()) {
  6303. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6304. return 0;
  6305. }
  6306. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6307. if (hated) {
  6308. lua_interface->SetSpawnValue(state, hated);
  6309. return 1;
  6310. }
  6311. return 0;
  6312. }
  6313. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6314. if (!lua_interface)
  6315. return 0;
  6316. Spawn* spawn = lua_interface->GetSpawn(state);
  6317. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6318. if (!spawn) {
  6319. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6320. return 0;
  6321. }
  6322. if (!spawn->IsNPC()) {
  6323. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6324. return 0;
  6325. }
  6326. if (!hated) {
  6327. ((NPC*)spawn)->Brain()->ClearHate();
  6328. return 0;
  6329. }
  6330. else
  6331. {
  6332. if (!hated->IsEntity()) {
  6333. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6334. return 0;
  6335. }
  6336. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6337. return 0;
  6338. }
  6339. return 0;
  6340. }
  6341. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6342. if (!lua_interface)
  6343. return 0;
  6344. Spawn* spawn = lua_interface->GetSpawn(state);
  6345. if (!spawn) {
  6346. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6347. return 0;
  6348. }
  6349. if (!spawn->IsNPC()) {
  6350. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6351. return 0;
  6352. }
  6353. ((NPC*)spawn)->Brain()->ClearEncounter();
  6354. return 0;
  6355. }
  6356. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6357. if (!lua_interface)
  6358. return 0;
  6359. Spawn* spawn = lua_interface->GetSpawn(state);
  6360. if (!spawn) {
  6361. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6362. return 0;
  6363. }
  6364. if (!spawn->IsNPC()) {
  6365. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6366. return 0;
  6367. }
  6368. // Temp list to store hate list
  6369. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6370. if (encounterList->size() == 0) {
  6371. safe_delete(encounterList);
  6372. return 0;
  6373. }
  6374. lua_createtable(state, encounterList->size(), 0);
  6375. int newTable = lua_gettop(state);
  6376. for (int32 i = 0; i < encounterList->size(); i++) {
  6377. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6378. if (temp)
  6379. lua_interface->SetSpawnValue(state, temp);
  6380. lua_rawseti(state, newTable, i + 1);
  6381. }
  6382. safe_delete(encounterList);
  6383. return 1;
  6384. }
  6385. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6386. if (!lua_interface)
  6387. return 0;
  6388. Spawn* spawn = lua_interface->GetSpawn(state);
  6389. if (!spawn) {
  6390. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6391. return 0;
  6392. }
  6393. if (!spawn->IsNPC()) {
  6394. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6395. return 0;
  6396. }
  6397. // Temp list to store hate list
  6398. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6399. if (hateList->size() == 0) {
  6400. safe_delete(hateList);
  6401. return 0;
  6402. }
  6403. lua_createtable(state, hateList->size(), 0);
  6404. int newTable = lua_gettop(state);
  6405. for (int32 i = 0; i < hateList->size(); i++) {
  6406. lua_interface->SetSpawnValue(state, hateList->at(i));
  6407. lua_rawseti(state, newTable, i + 1);
  6408. }
  6409. safe_delete(hateList);
  6410. return 1;
  6411. }
  6412. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6413. if (!lua_interface)
  6414. return 0;
  6415. Spawn* spawn = lua_interface->GetSpawn(state);
  6416. if (!spawn) {
  6417. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6418. return 0;
  6419. }
  6420. if (spawn->IsPlayer()) {
  6421. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6422. lua_interface->SetBooleanValue(state, true);
  6423. else
  6424. lua_interface->SetBooleanValue(state, false);
  6425. return 1;
  6426. }
  6427. else {
  6428. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6429. return 1;
  6430. }
  6431. }
  6432. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6433. if (!lua_interface)
  6434. return 0;
  6435. Quest* quest = lua_interface->GetQuest(state);
  6436. if (!quest) {
  6437. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6438. return 0;
  6439. }
  6440. quest->SetCompletedFlag(true);
  6441. return 0;
  6442. }
  6443. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6444. if (!lua_interface)
  6445. return 0;
  6446. Spawn* spawn = lua_interface->GetSpawn(state);
  6447. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6448. int8 tier = lua_interface->GetInt8Value(state, 3);
  6449. if (!spawn) {
  6450. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6451. return 0;
  6452. }
  6453. if (!spawn->IsEntity()) {
  6454. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6455. return 0;
  6456. }
  6457. if (spellID == 0) {
  6458. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6459. return 0;
  6460. }
  6461. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6462. if (effect) {
  6463. if (tier > 0) {
  6464. // If a tier was passed chec to see if it is the same as the effect
  6465. if (tier == effect->tier)
  6466. lua_interface->SetBooleanValue(state, true);
  6467. else
  6468. lua_interface->SetBooleanValue(state, false);
  6469. return 1;
  6470. }
  6471. else {
  6472. // Have an effect but no tier was passed so return true
  6473. lua_interface->SetBooleanValue(state, true);
  6474. }
  6475. return 1;
  6476. }
  6477. // no effect so return false
  6478. lua_interface->SetBooleanValue(state, false);
  6479. return 1;
  6480. }
  6481. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6482. if (!lua_interface)
  6483. return 0;
  6484. Spawn* spawn = lua_interface->GetSpawn(state);
  6485. int32 id = lua_interface->GetInt32Value(state, 2);
  6486. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6487. Spawn* spawn2 = 0;
  6488. vector<Spawn*> list;
  6489. if (!spawn) {
  6490. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. //If zone not provided, use spawn's zone
  6494. if (!zone)
  6495. zone = spawn->GetZone();
  6496. list = zone->GetSpawnsByID(id);
  6497. if (list.size() == 0) {
  6498. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6499. return 0;
  6500. }
  6501. vector<Spawn*>::iterator itr = list.begin();
  6502. for (int8 i = 0; i < list.size(); i++) {
  6503. spawn2 = itr[i];
  6504. if (spawn2)
  6505. spawn2->AddAllowAccessSpawn(spawn);
  6506. }
  6507. return 0;
  6508. }
  6509. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6510. if (!lua_interface)
  6511. return 0;
  6512. Spawn* spawn = lua_interface->GetSpawn(state);
  6513. int32 id = lua_interface->GetInt32Value(state, 2);
  6514. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6515. Spawn* spawn2 = 0;
  6516. if (!spawn) {
  6517. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6518. return 0;
  6519. }
  6520. //If zone not provided, use spawn's zone
  6521. if (!zone)
  6522. zone = spawn->GetZone();
  6523. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6524. vector<Spawn*>::iterator itr = list.begin();
  6525. if (list.size() == 0) {
  6526. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6527. return 0;
  6528. }
  6529. for (int8 i = 0; i < list.size(); i++) {
  6530. spawn2 = itr[i];
  6531. if (spawn2)
  6532. spawn2->RemoveSpawnAccess(spawn);
  6533. }
  6534. return 0;
  6535. }
  6536. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6537. if (!lua_interface)
  6538. return 0;
  6539. Quest* quest = lua_interface->GetQuest(state);
  6540. if (!quest) {
  6541. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6542. return 0;
  6543. }
  6544. quest->SetYellowName(true);
  6545. return 0;
  6546. }
  6547. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6548. if (!lua_interface)
  6549. return 0;
  6550. Spawn* spawn = lua_interface->GetSpawn(state);
  6551. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6552. if (!spawn) {
  6553. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. if (!spawn->IsPlayer()) {
  6557. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6558. return 0;
  6559. }
  6560. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6561. return 1;
  6562. }
  6563. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6564. if (!lua_interface)
  6565. return 0;
  6566. Spawn* spawn = lua_interface->GetSpawn(state);
  6567. if (!spawn) {
  6568. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6569. return 0;
  6570. }
  6571. if (!spawn->IsPlayer()) {
  6572. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6573. return 0;
  6574. }
  6575. ZoneServer* zone = spawn->GetZone();
  6576. if (!zone) {
  6577. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6578. return 0;
  6579. }
  6580. Instance_Type iType = zone->GetInstanceType();
  6581. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6582. iType == GROUP_LOCKOUT_INSTANCE ||
  6583. iType == RAID_LOCKOUT_INSTANCE ||
  6584. iType == SOLO_PERSIST_INSTANCE ||
  6585. iType == GROUP_PERSIST_INSTANCE ||
  6586. iType == RAID_PERSIST_INSTANCE) {
  6587. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6588. if (data) {
  6589. // Check to see if the timer has already been set, if it has return out.
  6590. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6591. return 0;
  6592. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6593. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6594. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6595. if (client) {
  6596. string time_msg = "";
  6597. int32 time = data->success_lockout_time;
  6598. int16 hour;
  6599. int8 min;
  6600. int8 sec;
  6601. hour = time / 3600;
  6602. time = time % 3600;
  6603. min = time / 60;
  6604. time = time % 60;
  6605. sec = time;
  6606. if (hour > 0) {
  6607. char temp[10];
  6608. sprintf(temp, " %i", hour);
  6609. time_msg.append(temp);
  6610. time_msg.append(" hour");
  6611. time_msg.append((hour > 1) ? "s" : "");
  6612. }
  6613. if (min > 0) {
  6614. char temp[5];
  6615. sprintf(temp, " %i", min);
  6616. time_msg.append(temp);
  6617. time_msg.append(" minute");
  6618. time_msg.append((min > 1) ? "s" : "");
  6619. }
  6620. // Only add seconds if minutes and hours are 0
  6621. if (hour == 0 && min == 0 && sec > 0) {
  6622. char temp[5];
  6623. sprintf(temp, " %i", sec);
  6624. time_msg.append(temp);
  6625. time_msg.append(" second");
  6626. time_msg.append((sec > 1) ? "s" : "");
  6627. }
  6628. 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());
  6629. }
  6630. }
  6631. else
  6632. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6633. }
  6634. else
  6635. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6636. return 0;
  6637. }
  6638. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6639. if (!lua_interface)
  6640. return 0;
  6641. Spawn* spawn = lua_interface->GetSpawn(state);
  6642. if (!spawn) {
  6643. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6644. return 0;
  6645. }
  6646. if (!spawn->IsPlayer()) {
  6647. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6648. return 0;
  6649. }
  6650. ZoneServer* zone = spawn->GetZone();
  6651. if (!zone) {
  6652. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6653. return 0;
  6654. }
  6655. Instance_Type iType = zone->GetInstanceType();
  6656. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6657. iType == GROUP_LOCKOUT_INSTANCE ||
  6658. iType == RAID_LOCKOUT_INSTANCE ||
  6659. iType == SOLO_PERSIST_INSTANCE ||
  6660. iType == GROUP_PERSIST_INSTANCE ||
  6661. iType == RAID_PERSIST_INSTANCE) {
  6662. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6663. if (data) {
  6664. // Check to see if the timer has already been set, if it has return out.
  6665. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6666. return 0;
  6667. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6668. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6669. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6670. if (client) {
  6671. string time_msg = "";
  6672. int32 time = data->failure_lockout_time;
  6673. int16 hour;
  6674. int8 min;
  6675. int8 sec;
  6676. hour = time / 3600;
  6677. time = time % 3600;
  6678. min = time / 60;
  6679. time = time % 60;
  6680. sec = time;
  6681. if (hour > 0) {
  6682. char temp[10];
  6683. sprintf(temp, " %i", hour);
  6684. time_msg.append(temp);
  6685. time_msg.append(" hour");
  6686. time_msg.append((hour > 1) ? "s" : "");
  6687. }
  6688. if (min > 0) {
  6689. char temp[5];
  6690. sprintf(temp, " %i", min);
  6691. time_msg.append(temp);
  6692. time_msg.append(" minute");
  6693. time_msg.append((min > 1) ? "s" : "");
  6694. }
  6695. // Only add seconds if minutes and hours are 0
  6696. if (hour == 0 && min == 0 && sec > 0) {
  6697. char temp[5];
  6698. sprintf(temp, " %i", sec);
  6699. time_msg.append(temp);
  6700. time_msg.append(" second");
  6701. time_msg.append((sec > 1) ? "s" : "");
  6702. }
  6703. 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());
  6704. }
  6705. }
  6706. else
  6707. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6708. }
  6709. else
  6710. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6711. return 0;
  6712. }
  6713. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6714. if (!lua_interface)
  6715. return 0;
  6716. Spawn* spawn = lua_interface->GetSpawn(state);
  6717. if (!spawn) {
  6718. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6719. return 0;
  6720. }
  6721. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6722. return 1;
  6723. }
  6724. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6725. if (!lua_interface)
  6726. return 0;
  6727. Spawn* player = lua_interface->GetSpawn(state);
  6728. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6729. if (!player) {
  6730. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6731. return 0;
  6732. }
  6733. if (!player->IsPlayer()) {
  6734. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6735. return 0;
  6736. }
  6737. if (!ground) {
  6738. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6739. return 0;
  6740. }
  6741. if (!ground->IsGroundSpawn()) {
  6742. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6743. return 0;
  6744. }
  6745. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6746. if (!groundspawn_entries) {
  6747. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6748. return 0;
  6749. }
  6750. Skill* skill = 0;
  6751. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6752. if (collection_skill == "Collecting")
  6753. skill = ((Player*)player)->GetSkillByName("Gathering");
  6754. else
  6755. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6756. if (!skill) {
  6757. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6758. return 0;
  6759. }
  6760. vector<GroundSpawnEntry*>::iterator itr;
  6761. GroundSpawnEntry* entry = 0;
  6762. bool can_harvest = false;
  6763. sint32 min_skill = -1;
  6764. int16 totalSkill = skill->current_val;
  6765. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6766. if(skillID != 0xFFFFFFFF)
  6767. {
  6768. ((Entity*)player)->MStats.lock();
  6769. totalSkill += ((Entity*)player)->stats[skillID];
  6770. ((Entity*)player)->MStats.unlock();
  6771. }
  6772. // first, iterate through groundspawn_entries, discard tables player cannot use
  6773. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6774. {
  6775. entry = *itr;
  6776. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6777. min_skill = entry->min_skill_level;
  6778. // if player lacks skill, skip table
  6779. if (entry->min_skill_level > totalSkill)
  6780. continue;
  6781. // if bonus, but player lacks level, skip table
  6782. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6783. continue;
  6784. can_harvest = true;
  6785. break;
  6786. }
  6787. lua_interface->SetBooleanValue(state, can_harvest);
  6788. // If false, send the message to the client
  6789. if (!can_harvest) {
  6790. Client* client = player->GetZone()->GetClientBySpawn(player);
  6791. if (client) {
  6792. string msg = "You do not have enough skill to ";
  6793. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6794. msg.append("gather");
  6795. else if (collection_skill == "Mining")
  6796. msg.append("mine");
  6797. else if (collection_skill == "Trapping")
  6798. msg.append("trap");
  6799. else if (collection_skill == "Foresting")
  6800. msg.append("forest");
  6801. else if (collection_skill == "Fishing")
  6802. msg.append("catch");
  6803. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6804. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6805. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6806. }
  6807. }
  6808. return 1;
  6809. }
  6810. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6811. if (!lua_interface)
  6812. return 0;
  6813. Spawn* player = lua_interface->GetSpawn(state);
  6814. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6815. if (!player) {
  6816. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6817. return 0;
  6818. }
  6819. if (!player->IsPlayer()) {
  6820. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6821. return 0;
  6822. }
  6823. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6824. lua_interface->SetBooleanValue(state, ret);
  6825. return 1;
  6826. }
  6827. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6828. // Check to see if we have a valid lua_interface
  6829. if (!lua_interface)
  6830. return 0;
  6831. // Get the spawn that is getting the pet
  6832. Spawn* spawn = lua_interface->GetSpawn(state);
  6833. Spawn* target = lua_interface->GetSpawn(state, 2);
  6834. // Get the DB ID of the pet
  6835. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6836. float x = lua_interface->GetFloatValue(state, 4);
  6837. float y = lua_interface->GetFloatValue(state, 5);
  6838. float z = lua_interface->GetFloatValue(state, 6);
  6839. // Get the spell that this command was called from
  6840. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6841. // Check to make sure the spawn pointer is valid
  6842. if (!spawn) {
  6843. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6844. return 0;
  6845. }
  6846. // Check to make sure the spawn is an entity
  6847. if (!spawn->IsEntity()) {
  6848. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6849. return 0;
  6850. }
  6851. if (!target) {
  6852. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6853. return 0;
  6854. }
  6855. if (!target->IsEntity()) {
  6856. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6857. return 0;
  6858. }
  6859. // Check to see if the DB ID for the pet is set
  6860. if (pet_id == 0) {
  6861. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6862. return 0;
  6863. }
  6864. // Check to see if the pointer to the spell is valid
  6865. if (!luaspell) {
  6866. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6867. return 0;
  6868. }
  6869. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6870. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6871. if (!pet) {
  6872. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6873. return 0;
  6874. }
  6875. // Check to make sure the pet is an npc
  6876. if (!pet->IsNPC()) {
  6877. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6878. return 0;
  6879. }
  6880. if (x == 0)
  6881. x = spawn->GetX();
  6882. if (y == 0)
  6883. y = spawn->GetY();
  6884. if (z == 0)
  6885. z = spawn->GetZ();
  6886. // Spawn the pet at the same location as the owner
  6887. pet->SetX(x);
  6888. pet->SetY(y);
  6889. pet->SetZ(z);
  6890. pet->SetLocation(spawn->GetLocation());
  6891. pet->SetHeading(spawn->GetHeading());
  6892. spawn->GetZone()->AddSpawn(pet);
  6893. /*
  6894. const char* spawn_script = world.GetSpawnScript(pet_id);
  6895. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6896. spawn->SetSpawnScript(string(spawn_script));
  6897. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6898. }*/
  6899. // Get a random pet name
  6900. string random_pet_name;
  6901. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6902. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6903. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6904. // Set the pets name
  6905. pet->SetName(random_pet_name.c_str());
  6906. // Set the level of the pet to the owners level
  6907. pet->SetLevel(spawn->GetLevel());
  6908. // Set the faction of the pet to the same faction as the owner
  6909. pet->SetFactionID(spawn->GetFactionID());
  6910. // Set the spawn as a pet
  6911. pet->SetPet(true);
  6912. // Give a pointer of the owner to the pet
  6913. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6914. // Set the pet type
  6915. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6916. // Set the spell id used to create this pet
  6917. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6918. // Set the spell tier used to create this pet
  6919. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6920. // Set the pets spawn type to 6
  6921. pet->SetSpawnType(6);
  6922. // Set the pets brain
  6923. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6924. // Check to see if the pet has a subtitle
  6925. if (strlen(pet->GetSubTitle()) > 0) {
  6926. // Add the players name to the front of the sub title
  6927. string pet_subtitle;
  6928. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6929. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6930. // Set the pets subtitle to the new one
  6931. pet->SetSubTitle(pet_subtitle.c_str());
  6932. }
  6933. // Set the pet as the return value for this function
  6934. lua_interface->SetSpawnValue(state, pet);
  6935. return 1;
  6936. }
  6937. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6938. if (!lua_interface)
  6939. return 0;
  6940. Spawn* spawn = lua_interface->GetSpawn(state);
  6941. Spawn* player = lua_interface->GetSpawn(state, 2);
  6942. float max_distance = lua_interface->GetFloatValue(state, 3);
  6943. string type = lua_interface->GetStringValue(state, 4);
  6944. if (!spawn || (spawn && spawn->IsPlayer())) {
  6945. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6946. return 0;
  6947. }
  6948. if (!player || (player && !player->IsPlayer())) {
  6949. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6950. return 0;
  6951. }
  6952. Client* client = 0;
  6953. if (player->GetZone())
  6954. client = player->GetZone()->GetClientBySpawn(player);
  6955. if (!client) {
  6956. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6957. return 0;
  6958. }
  6959. //Set max_distance to default if not set or not proper value
  6960. if (max_distance <= 0)
  6961. max_distance = 500;
  6962. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6963. if (packet) {
  6964. float unknown2_3 = 0;
  6965. int8 placement_mode = 0;
  6966. if (type == "wall") {
  6967. placement_mode = 2;
  6968. unknown2_3 = 150;
  6969. }
  6970. else if (type == "ceiling")
  6971. placement_mode = 1;
  6972. packet->setDataByName("placement_mode", placement_mode);
  6973. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6974. packet->setDataByName("model_type", spawn->GetModelType());
  6975. packet->setDataByName("unknown", 1); //size
  6976. packet->setDataByName("unknown2", 1); //size 2
  6977. packet->setDataByName("unknown2", .5, 1); //size 3
  6978. packet->setDataByName("unknown2", 3, 2);
  6979. packet->setDataByName("unknown2", unknown2_3, 3);
  6980. packet->setDataByName("max_distance", max_distance);
  6981. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6982. client->QueuePacket(packet->serialize());
  6983. safe_delete(packet);
  6984. }
  6985. return 0;
  6986. }
  6987. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6988. if (!lua_interface)
  6989. return 0;
  6990. Item* item = lua_interface->GetItem(state);
  6991. if (!item) {
  6992. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6996. return 1;
  6997. }
  6998. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6999. if (!lua_interface)
  7000. return 0;
  7001. Spawn* spawn = lua_interface->GetSpawn(state);
  7002. if (!spawn) {
  7003. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7004. return 0;
  7005. }
  7006. if (spawn->GetZone())
  7007. spawn->GetZone()->AddTransportSpawn(spawn);
  7008. return 0;
  7009. }
  7010. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7011. if (!lua_interface)
  7012. return 0;
  7013. Spawn* spawn = lua_interface->GetSpawn(state);
  7014. if (!spawn) {
  7015. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7016. return 0;
  7017. }
  7018. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7019. return 1;
  7020. }
  7021. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7022. if (!lua_interface)
  7023. return 0;
  7024. Skill* skill = lua_interface->GetSkill(state);
  7025. if (!skill) {
  7026. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7027. return 0;
  7028. }
  7029. lua_interface->SetInt32Value(state, skill->current_val);
  7030. return 1;
  7031. }
  7032. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7033. if (!lua_interface)
  7034. return 0;
  7035. Skill* skill = lua_interface->GetSkill(state);
  7036. if (!skill) {
  7037. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7038. return 0;
  7039. }
  7040. lua_interface->SetInt32Value(state, skill->max_val);
  7041. return 1;
  7042. }
  7043. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7044. if (!lua_interface)
  7045. return 0;
  7046. Skill* skill = lua_interface->GetSkill(state);
  7047. if (!skill) {
  7048. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7049. return 0;
  7050. }
  7051. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7052. return 1;
  7053. }
  7054. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7055. if (!lua_interface)
  7056. return 0;
  7057. Skill* skill = lua_interface->GetSkill(state);
  7058. int16 value = lua_interface->GetInt16Value(state, 2);
  7059. if (!skill) {
  7060. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7061. return 0;
  7062. }
  7063. skill->max_val = value;
  7064. if (skill->max_val < skill->current_val)
  7065. skill->current_val = skill->max_val;
  7066. return 0;
  7067. }
  7068. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7069. if (!lua_interface)
  7070. return 0;
  7071. Skill* skill = lua_interface->GetSkill(state);
  7072. int16 value = lua_interface->GetInt16Value(state, 2);
  7073. if (!skill) {
  7074. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7075. return 0;
  7076. }
  7077. if (value > skill->max_val)
  7078. skill->current_val = skill->max_val;
  7079. else
  7080. skill->current_val = value;
  7081. return 0;
  7082. }
  7083. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7084. if (!lua_interface)
  7085. return 0;
  7086. Spawn* player = lua_interface->GetSpawn(state);
  7087. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7088. if (skill_id > 0 && player && player->IsPlayer()) {
  7089. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7090. return 1;
  7091. }
  7092. return 0;
  7093. }
  7094. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7095. if (!lua_interface)
  7096. return 0;
  7097. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7098. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7099. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7100. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7101. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7102. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7103. if (player_spawn && player_spawn->IsPlayer()) {
  7104. Player* player = (Player*)player_spawn;
  7105. bool added = false;
  7106. if (!player->skill_list.HasSkill(skill_id)) {
  7107. player->AddSkill(skill_id, current_val, max_val, true);
  7108. added = true;
  7109. }
  7110. 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
  7111. Client* client = player->GetClient();
  7112. if (client) {
  7113. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7114. if (packet)
  7115. client->QueuePacket(packet);
  7116. }
  7117. }
  7118. if (added) {
  7119. lua_interface->SetBooleanValue(state, true);
  7120. return 1;
  7121. }
  7122. }
  7123. else {
  7124. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7125. }
  7126. }
  7127. else {
  7128. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7129. }
  7130. lua_interface->SetBooleanValue(state, false);
  7131. return 1;
  7132. }
  7133. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7134. if (!lua_interface)
  7135. return 0;
  7136. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7137. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7138. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7139. if (skill_id > 0) {
  7140. if (player_spawn && player_spawn->IsPlayer()) {
  7141. Player* player = (Player*)player_spawn;
  7142. if (player->skill_list.HasSkill(skill_id)) {
  7143. player->RemovePlayerSkill(skill_id);
  7144. if (!more_to_remove) {
  7145. Client* client = player->GetClient();
  7146. if (client) {
  7147. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7148. if (packet)
  7149. client->QueuePacket(packet);
  7150. }
  7151. }
  7152. }
  7153. }
  7154. else {
  7155. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7156. }
  7157. }
  7158. else {
  7159. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7160. }
  7161. return 0;
  7162. }
  7163. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7164. if (!lua_interface)
  7165. return 0;
  7166. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7167. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7168. int16 amount = lua_interface->GetInt8Value(state, 3);
  7169. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7170. if (amount > 0 && skill_type < 100) {
  7171. if (player_spawn && player_spawn->IsPlayer()) {
  7172. Player* player = (Player*)player_spawn;
  7173. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7174. if (!more_to_increase) {
  7175. Client* client = player->GetClient();
  7176. if (client) {
  7177. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7178. if (packet)
  7179. client->QueuePacket(packet);
  7180. }
  7181. }
  7182. }
  7183. else {
  7184. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7185. }
  7186. }
  7187. else {
  7188. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7189. }
  7190. return 0;
  7191. }
  7192. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7193. if (!lua_interface)
  7194. return 0;
  7195. Spawn* spawn = lua_interface->GetSpawn(state);
  7196. string name = lua_interface->GetStringValue(state, 2);
  7197. if (!spawn) {
  7198. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7199. return 0;
  7200. }
  7201. if (!spawn->IsEntity()) {
  7202. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7206. if (skill) {
  7207. lua_interface->SetSkillValue(state, skill);
  7208. return 1;
  7209. }
  7210. return 0;
  7211. }
  7212. int EQ2Emu_lua_AddProc(lua_State* state) {
  7213. if (!lua_interface)
  7214. return 0;
  7215. Spawn* spawn = lua_interface->GetSpawn(state);
  7216. int8 type = lua_interface->GetInt8Value(state, 2);
  7217. float chance = lua_interface->GetFloatValue(state, 3);
  7218. Item* item = lua_interface->GetItem(state, 4);
  7219. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7220. LuaSpell* spell = 0;
  7221. if (!spawn && (!spell || !use_all_spelltargets)) {
  7222. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7223. return 0;
  7224. }
  7225. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7226. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7227. return 0;
  7228. }
  7229. if (!item)
  7230. spell = lua_interface->GetCurrentSpell(state);
  7231. if (!item && !spell) {
  7232. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7233. return 0;
  7234. }
  7235. if (spell && use_all_spelltargets) {
  7236. Spawn* target;
  7237. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7238. for (int8 i = 0; i < spell->targets.size(); i++) {
  7239. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7240. if (!target || !target->IsEntity())
  7241. continue;
  7242. ((Entity*)target)->AddProc(type, chance, item, spell);
  7243. }
  7244. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7245. }
  7246. else
  7247. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7248. return 0;
  7249. }
  7250. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7251. if (!lua_interface)
  7252. return 0;
  7253. Spawn* spawn = lua_interface->GetSpawn(state);
  7254. Item* item = lua_interface->GetItem(state, 2);
  7255. LuaSpell* spell = 0;
  7256. if (!spawn) {
  7257. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7258. return 0;
  7259. }
  7260. if (!spawn->IsEntity()) {
  7261. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7262. return 0;
  7263. }
  7264. if (!item)
  7265. spell = lua_interface->GetCurrentSpell(state);
  7266. if (!item && !spell) {
  7267. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7268. return 0;
  7269. }
  7270. if (spell) {
  7271. Spawn* target;
  7272. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7273. for (int8 i = 0; i < spell->targets.size(); i++) {
  7274. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7275. if (!target || !target->IsEntity())
  7276. continue;
  7277. ((Entity*)target)->RemoveProc(item, spell);
  7278. }
  7279. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7280. spell->caster->RemoveProc(item, spell);
  7281. }
  7282. else
  7283. ((Entity*)spawn)->RemoveProc(item, spell);
  7284. return 0;
  7285. }
  7286. int EQ2Emu_lua_Knockback(lua_State* state) {
  7287. if (!lua_interface)
  7288. return 0;
  7289. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7290. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7291. int32 duration = lua_interface->GetInt32Value(state, 3);
  7292. float vertical = lua_interface->GetFloatValue(state, 4);
  7293. float horizontal = lua_interface->GetFloatValue(state, 5);
  7294. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7295. if (!target_spawn) {
  7296. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7297. return 0;
  7298. }
  7299. if (!spawn) {
  7300. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7301. return 0;
  7302. }
  7303. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7304. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7305. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7306. if (packet) {
  7307. packet->setDataByName("target_x", target_spawn->GetX());
  7308. packet->setDataByName("target_y", target_spawn->GetY());
  7309. packet->setDataByName("target_z", target_spawn->GetZ());
  7310. packet->setDataByName("vertical_movement", vertical);
  7311. packet->setDataByName("horizontal_movement", horizontal);
  7312. if (use_heading)
  7313. packet->setDataByName("use_player_heading", 1);
  7314. client->QueuePacket(packet->serialize());
  7315. }
  7316. safe_delete(packet);
  7317. }
  7318. return 0;
  7319. }
  7320. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7321. if (!lua_interface)
  7322. return 0;
  7323. Spawn* spawn = lua_interface->GetSpawn(state);
  7324. if (!spawn) {
  7325. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7326. return 0;
  7327. }
  7328. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7329. return 1;
  7330. }
  7331. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7332. if (!lua_interface)
  7333. return 0;
  7334. Spawn* caster = lua_interface->GetSpawn(state);
  7335. Spawn* target = lua_interface->GetSpawn(state, 2);
  7336. string name = lua_interface->GetStringValue(state, 3);
  7337. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7338. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7339. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7340. string success_msg = lua_interface->GetStringValue(state, 7);
  7341. string effect_msg = lua_interface->GetStringValue(state, 8);
  7342. if (!caster) {
  7343. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7344. return 0;
  7345. }
  7346. if (!caster->IsEntity()) {
  7347. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7348. return 0;
  7349. }
  7350. if (!target) {
  7351. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7352. return 0;
  7353. }
  7354. if (!target->IsEntity()) {
  7355. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7356. return 0;
  7357. }
  7358. if (name.length() == 0) {
  7359. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7360. return 0;
  7361. }
  7362. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7363. return 0;
  7364. }
  7365. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7366. if (!lua_interface)
  7367. return 0;
  7368. string name = lua_interface->GetStringValue(state);
  7369. if (name.length() == 0) {
  7370. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7371. return 0;
  7372. }
  7373. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7374. if (!skill) {
  7375. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7376. return 0;
  7377. }
  7378. lua_interface->SetInt32Value(state, skill->skill_id);
  7379. return 1;
  7380. }
  7381. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7382. if (!lua_interface)
  7383. return 0;
  7384. Spawn* spawn = lua_interface->GetSpawn(state);
  7385. if (!spawn) {
  7386. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7387. return 0;
  7388. }
  7389. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7390. return 1;
  7391. }
  7392. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7393. if (!lua_interface)
  7394. return 0;
  7395. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7396. if (!luaspell) {
  7397. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7398. return 0;
  7399. }
  7400. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7401. return 1;
  7402. }
  7403. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7404. if (!lua_interface)
  7405. return 0;
  7406. Spawn* spawn = lua_interface->GetSpawn(state);
  7407. Spawn* target = lua_interface->GetSpawn(state, 2);
  7408. if (!spawn) {
  7409. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7410. return 0;
  7411. }
  7412. if (!spawn->IsEntity()) {
  7413. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7414. return 0;
  7415. }
  7416. if (!target) {
  7417. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7418. return 0;
  7419. }
  7420. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7421. return 1;
  7422. }
  7423. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7424. if (!lua_interface)
  7425. return 0;
  7426. Spawn* spawn = lua_interface->GetSpawn(state);
  7427. Spawn* target = lua_interface->GetSpawn(state, 2);
  7428. if (!spawn) {
  7429. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7430. return 0;
  7431. }
  7432. if (!spawn->IsEntity()) {
  7433. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7434. return 0;
  7435. }
  7436. if (!target) {
  7437. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7438. return 0;
  7439. }
  7440. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7441. return 1;
  7442. }
  7443. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7444. if (!lua_interface)
  7445. return 0;
  7446. Item* item = lua_interface->GetItem(state);
  7447. if (!item) {
  7448. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7449. return 0;
  7450. }
  7451. lua_interface->SetInt32Value(state, item->details.count);
  7452. return 1;
  7453. }
  7454. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7455. if (!lua_interface)
  7456. return 0;
  7457. Item* item = lua_interface->GetItem(state);
  7458. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7459. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7460. if (!item) {
  7461. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7462. return 0;
  7463. }
  7464. if (!owner) {
  7465. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7466. return 0;
  7467. }
  7468. if (!owner->IsPlayer()) {
  7469. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7470. return 0;
  7471. }
  7472. if (item->stack_count < new_count) {
  7473. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7474. return 0;
  7475. }
  7476. if (new_count > 0) {
  7477. item->details.count = new_count;
  7478. item->save_needed = true;
  7479. }
  7480. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7481. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7482. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7483. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7484. else
  7485. {
  7486. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7490. if (!client)
  7491. return 0;
  7492. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7493. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7494. if (app)
  7495. client->QueuePacket(app);
  7496. return 0;
  7497. }
  7498. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7499. if (!lua_interface)
  7500. return 0;
  7501. int32 time = lua_interface->GetInt32Value(state);
  7502. string function = lua_interface->GetStringValue(state, 2);
  7503. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7504. Spawn* target = lua_interface->GetSpawn(state, 4);
  7505. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7506. if (time == 0) {
  7507. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7508. return 0;
  7509. }
  7510. if (function.length() == 0) {
  7511. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7512. return 0;
  7513. }
  7514. if (!spell) {
  7515. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7516. return 0;
  7517. }
  7518. SpellScriptTimer* timer = new SpellScriptTimer;
  7519. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7520. #ifdef WIN32
  7521. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7522. #else
  7523. bzero(timer, sizeof(SpellScriptTimer));
  7524. #endif*/
  7525. timer->caster = 0;
  7526. timer->deleteWhenDone = false;
  7527. timer->target = 0;
  7528. timer->time = Timer::GetCurrentTime2() + time;
  7529. timer->customFunction = function;
  7530. timer->spell = spell;
  7531. if (caster)
  7532. timer->caster = caster->GetID();
  7533. if (target)
  7534. timer->target = target->GetID();
  7535. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7536. return 0;
  7537. }
  7538. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7539. if (!lua_interface)
  7540. return 0;
  7541. float hp_perc = lua_interface->GetFloatValue(state);
  7542. float power_perc = lua_interface->GetFloatValue(state, 2);
  7543. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7544. Spawn* target = lua_interface->GetSpawn(state, 4);
  7545. string heal_name = lua_interface->GetStringValue(state, 5);
  7546. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7547. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7548. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7549. if (!spell) {
  7550. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7551. return 0;
  7552. }
  7553. Entity* caster = spell->caster;
  7554. if (!caster) {
  7555. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7556. return 0;
  7557. }
  7558. Client* client = 0;
  7559. PendingResurrection* rez = 0;
  7560. ZoneServer* zone = spell->caster->GetZone();
  7561. if (!target) {
  7562. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7563. if (spell->targets.size() > 0) {
  7564. vector<int32> spell_targets = spell->targets;
  7565. for (int8 i = 0; i < spell_targets.size(); i++) {
  7566. target = zone->GetSpawnByID(spell_targets.at(i));
  7567. if (!target)
  7568. continue;
  7569. if (!target->IsPlayer())
  7570. continue;
  7571. client = target->GetZone()->GetClientBySpawn(target);
  7572. if (!client)
  7573. continue;
  7574. rez = client->GetCurrentRez();
  7575. if (rez->active)
  7576. continue;
  7577. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7578. rez->active = true;
  7579. rez->caster = caster;
  7580. rez->expire_timer = new Timer;
  7581. int32 duration = spell->spell->GetSpellDuration();
  7582. rez->expire_timer->Start(duration * 100);
  7583. rez->hp_perc = hp_perc;
  7584. rez->mp_perc = power_perc;
  7585. rez->range = spell->spell->GetSpellData()->range;
  7586. rez->spell_name = spell->spell->GetName();
  7587. if (heal_name.length() > 0)
  7588. rez->heal_name = heal_name;
  7589. else
  7590. rez->heal_name = rez->spell_name;
  7591. rez->no_calcs = no_calcs;
  7592. rez->crit_mod = crit_mod;
  7593. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7594. if (send_window)
  7595. client->SendResurrectionWindow();
  7596. else {
  7597. target->GetZone()->ResurrectSpawn(target, client);
  7598. rez->should_delete = true;
  7599. }
  7600. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7601. }
  7602. }
  7603. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7604. }
  7605. else {
  7606. client = target->GetZone()->GetClientBySpawn(target);
  7607. if (!client)
  7608. return 0;
  7609. rez = client->GetCurrentRez();
  7610. if (rez->active)
  7611. return 0;
  7612. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7613. rez->active = true;
  7614. rez->caster = caster;
  7615. rez->expire_timer = new Timer;
  7616. int32 duration = spell->spell->GetSpellDuration();
  7617. rez->expire_timer->Start(duration * 100);
  7618. rez->hp_perc = hp_perc;
  7619. rez->mp_perc = power_perc;
  7620. rez->range = spell->spell->GetSpellData()->range;
  7621. rez->spell_name = spell->spell->GetName();
  7622. if (heal_name.length() > 0)
  7623. rez->heal_name = heal_name;
  7624. else
  7625. rez->heal_name = rez->spell_name;
  7626. rez->no_calcs = no_calcs;
  7627. rez->crit_mod = crit_mod;
  7628. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7629. if (send_window)
  7630. client->SendResurrectionWindow();
  7631. else {
  7632. target->GetZone()->ResurrectSpawn(target, client);
  7633. rez->should_delete = true;
  7634. }
  7635. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7636. }
  7637. return 0;
  7638. }
  7639. int EQ2Emu_lua_SetVision(lua_State* state) {
  7640. if (!lua_interface)
  7641. return 0;
  7642. Spawn* spawn = lua_interface->GetSpawn(state);
  7643. int8 vision = lua_interface->GetInt8Value(state, 2);
  7644. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7645. if (!spawn) {
  7646. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7647. return 0;
  7648. }
  7649. if (!spawn->IsEntity()) {
  7650. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7651. return 0;
  7652. }
  7653. if (spell && spell->targets.size() > 0) {
  7654. ZoneServer* zone = spell->caster->GetZone();
  7655. for (int8 i = 0; i < spell->targets.size(); i++) {
  7656. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7657. if (target && target->IsEntity()) {
  7658. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7659. if (target->IsPlayer())
  7660. ((Player*)target)->SetCharSheetChanged(true);
  7661. }
  7662. }
  7663. }
  7664. else {
  7665. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7666. if (spawn->IsPlayer())
  7667. ((Player*)spawn)->SetCharSheetChanged(true);
  7668. }
  7669. return 0;
  7670. }
  7671. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7672. if (!lua_interface)
  7673. return 0;
  7674. Spawn* spawn = lua_interface->GetSpawn(state);
  7675. float intensity = lua_interface->GetFloatValue(state, 2);
  7676. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7677. if (!spawn) {
  7678. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7679. return 0;
  7680. }
  7681. if (!spawn->IsEntity()) {
  7682. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7683. return 0;
  7684. }
  7685. if (spell && spell->targets.size() > 0) {
  7686. ZoneServer* zone = spell->caster->GetZone();
  7687. for (int8 i = 0; i < spell->targets.size(); i++) {
  7688. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7689. if (target && target->IsEntity()) {
  7690. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7691. if (target->IsPlayer())
  7692. ((Player*)target)->SetCharSheetChanged(true);
  7693. }
  7694. }
  7695. }
  7696. else {
  7697. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7698. if (spawn->IsPlayer())
  7699. ((Player*)spawn)->SetCharSheetChanged(true);
  7700. }
  7701. return 0;
  7702. }
  7703. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7704. if (!lua_interface)
  7705. return 0;
  7706. Spawn* spawn = lua_interface->GetSpawn(state);
  7707. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7708. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7709. if (!spawn) {
  7710. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7711. return 0;
  7712. }
  7713. if (!spawn->IsEntity()) {
  7714. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7715. return 0;
  7716. }
  7717. if (spell && spell->targets.size() > 0) {
  7718. ZoneServer* zone = spell->caster->GetZone();
  7719. for (int8 i = 0; i < spell->targets.size(); i++) {
  7720. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7721. if (target && target->IsEntity()) {
  7722. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7723. if (target->IsPlayer())
  7724. ((Player*)target)->SetCharSheetChanged(true);
  7725. }
  7726. }
  7727. }
  7728. else {
  7729. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7730. if (spawn->IsPlayer())
  7731. ((Player*)spawn)->SetCharSheetChanged(true);
  7732. }
  7733. return 0;
  7734. }
  7735. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7736. if (!lua_interface)
  7737. return 0;
  7738. Item* item = lua_interface->GetItem(state);
  7739. int8 type = lua_interface->GetInt32Value(state, 2);
  7740. if (!item) {
  7741. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7742. return 0;
  7743. }
  7744. if (type == 1)
  7745. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7746. else if (type == 2)
  7747. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7748. return 1;
  7749. }
  7750. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7751. if (!lua_interface)
  7752. return 0;
  7753. Spawn* target = lua_interface->GetSpawn(state);
  7754. float val = lua_interface->GetFloatValue(state, 2);
  7755. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7756. // Added from Gangrenous post
  7757. if (spell && spell->resisted)
  7758. return 0;
  7759. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7760. if (val > 1.0f)
  7761. val = 1.0f - (val / 100.0f);
  7762. if (spell && spell->spell && spell->targets.size() > 0) {
  7763. ZoneServer* zone = spell->caster->GetZone();
  7764. for (int32 i = 0; i != spell->targets.size(); i++) {
  7765. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7766. if (spawn && spawn->IsEntity()) {
  7767. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7768. if (spawn->IsPlayer())
  7769. ((Player*)spawn)->SetCharSheetChanged(true);
  7770. }
  7771. }
  7772. }
  7773. else {
  7774. if (target && target->IsEntity()) {
  7775. ((Entity*)target)->SetSpeedMultiplier(val);
  7776. if (target->IsPlayer())
  7777. ((Player*)target)->SetCharSheetChanged(true);
  7778. }
  7779. }
  7780. return 0;
  7781. }
  7782. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7783. if (!lua_interface)
  7784. return 0;
  7785. Spawn* spawn = lua_interface->GetSpawn(state);
  7786. int16 model = lua_interface->GetInt16Value(state, 2);
  7787. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7788. if (spell && spell->spell && spell->targets.size() > 0) {
  7789. ZoneServer* zone = spell->caster->GetZone();
  7790. for (int32 i = 0; i < spell->targets.size(); i++) {
  7791. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7792. if (target)
  7793. target->SetIllusionModel(model);
  7794. }
  7795. }
  7796. else {
  7797. if (!spawn) {
  7798. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7799. return 0;
  7800. }
  7801. spawn->SetIllusionModel(model);
  7802. }
  7803. return 0;
  7804. }
  7805. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7806. if (!lua_interface)
  7807. return 0;
  7808. Spawn* spawn = lua_interface->GetSpawn(state);
  7809. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7810. if (spell && spell->spell && spell->targets.size() > 0) {
  7811. ZoneServer* zone = spell->caster->GetZone();
  7812. for (int32 i = 0; i < spell->targets.size(); i++) {
  7813. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7814. if (target)
  7815. target->SetIllusionModel(0);
  7816. }
  7817. }
  7818. else {
  7819. if (!spawn) {
  7820. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7821. return 0;
  7822. }
  7823. spawn->SetIllusionModel(0);
  7824. }
  7825. return 0;
  7826. }
  7827. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7828. if (!lua_interface)
  7829. return 0;
  7830. Spawn* caster = lua_interface->GetSpawn(state);
  7831. Spawn* target = lua_interface->GetSpawn(state, 2);
  7832. float chance = lua_interface->GetFloatValue(state, 3);
  7833. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7834. if (!caster) {
  7835. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7836. return 0;
  7837. }
  7838. if (!caster->IsEntity()) {
  7839. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7840. return 0;
  7841. }
  7842. if (!target) {
  7843. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7844. return 0;
  7845. }
  7846. if (!target->IsEntity()) {
  7847. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7848. return 0;
  7849. }
  7850. if (chance <= 0) {
  7851. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7852. return 0;
  7853. }
  7854. if (!spell) {
  7855. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7856. return 0;
  7857. }
  7858. if (((Entity*)caster)->GetThreatTransfer()) {
  7859. return 0;
  7860. }
  7861. ThreatTransfer* transfer = new ThreatTransfer;
  7862. transfer->Target = target->GetID();
  7863. transfer->Amount = chance;
  7864. transfer->Spell = spell;
  7865. ((Entity*)caster)->SetThreatTransfer(transfer);
  7866. return 0;
  7867. }
  7868. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7869. if (!lua_interface)
  7870. return 0;
  7871. Spawn* spawn = lua_interface->GetSpawn(state);
  7872. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7873. if (!spawn) {
  7874. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7875. return 0;
  7876. }
  7877. if (!spell) {
  7878. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7879. return 0;
  7880. }
  7881. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7882. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7883. ((Entity*)spawn)->SetThreatTransfer(0);
  7884. safe_delete(transfer);
  7885. }
  7886. return 0;
  7887. }
  7888. int EQ2Emu_lua_CureByType(lua_State* state) {
  7889. if (!lua_interface)
  7890. return 0;
  7891. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7892. if (!spell) {
  7893. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7894. return 0;
  7895. }
  7896. int8 cure_count = lua_interface->GetInt8Value(state);
  7897. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7898. string cure_name = lua_interface->GetStringValue(state, 3);
  7899. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7900. Spawn* target = lua_interface->GetSpawn(state, 5);
  7901. if (target) {
  7902. if (!target->IsEntity()) {
  7903. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7904. return 0;
  7905. }
  7906. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7907. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7908. }
  7909. else {
  7910. ZoneServer* zone = spell->caster->GetZone();
  7911. vector<int32> targets = spell->targets;
  7912. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7913. for (int8 i = 0; i < targets.size(); i++) {
  7914. target = zone->GetSpawnByID(targets.at(i));
  7915. if (!target || !target->IsEntity())
  7916. continue;
  7917. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7918. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7919. }
  7920. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7921. }
  7922. return 0;
  7923. }
  7924. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7925. if (!lua_interface)
  7926. return 0;
  7927. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7928. if (!spell) {
  7929. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7930. return 0;
  7931. }
  7932. int8 cure_count = lua_interface->GetInt8Value(state);
  7933. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7934. string cure_name = lua_interface->GetStringValue(state, 3);
  7935. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7936. Spawn* target = lua_interface->GetSpawn(state, 5);
  7937. if (target) {
  7938. if (!target->IsEntity()) {
  7939. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7940. return 0;
  7941. }
  7942. if (((Entity*)target)->GetDetCount() > 0)
  7943. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7944. }
  7945. else {
  7946. ZoneServer* zone = spell->caster->GetZone();
  7947. vector<int32> targets = spell->targets;
  7948. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7949. for (int8 i = 0; i < targets.size(); i++) {
  7950. target = zone->GetSpawnByID(targets.at(i));
  7951. if (!target || !target->IsEntity())
  7952. continue;
  7953. if (((Entity*)target)->GetDetCount() > 0)
  7954. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7955. }
  7956. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7957. }
  7958. return 0;
  7959. }
  7960. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7961. if (!lua_interface)
  7962. return 0;
  7963. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7964. if (!spell) {
  7965. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7966. return 0;
  7967. }
  7968. if (!spell->caster) {
  7969. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7970. return 0;
  7971. }
  7972. if (!spell->caster->GetZone()) {
  7973. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7974. return 0;
  7975. }
  7976. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7977. return 0;
  7978. }
  7979. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7980. if (!lua_interface)
  7981. return 0;
  7982. Spawn* spawn = lua_interface->GetSpawn(state);
  7983. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7984. if (!spell) {
  7985. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7986. return 0;
  7987. }
  7988. if (spawn && spawn->IsEntity())
  7989. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7990. else {
  7991. ZoneServer* zone = spell->caster->GetZone();
  7992. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7993. for (int32 i = 0; i < spell->targets.size(); i++) {
  7994. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7995. if (!spawn || !spawn->IsEntity())
  7996. continue;
  7997. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7998. }
  7999. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8000. }
  8001. return 0;
  8002. }
  8003. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8004. if (!lua_interface)
  8005. return 0;
  8006. Spawn* spawn = lua_interface->GetSpawn(state);
  8007. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8008. if (!spell) {
  8009. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8010. return 0;
  8011. }
  8012. if (spawn && spawn->IsEntity())
  8013. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8014. else {
  8015. ZoneServer* zone = spell->caster->GetZone();
  8016. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8017. for (int32 i = 0; i < spell->targets.size(); i++) {
  8018. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8019. if (!spawn || !spawn->IsEntity())
  8020. continue;
  8021. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8022. }
  8023. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8024. }
  8025. return 0;
  8026. }
  8027. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8028. if (!lua_interface)
  8029. return 0;
  8030. Spawn* caster = lua_interface->GetSpawn(state);
  8031. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8032. if (!caster) {
  8033. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8034. return 0;
  8035. }
  8036. if (!caster->IsPlayer()) {
  8037. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8038. return 0;
  8039. }
  8040. Spawn* target = caster->GetTarget();
  8041. if (!target) {
  8042. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8043. return 0;
  8044. }
  8045. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8046. if (!client) {
  8047. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8048. return 0;
  8049. }
  8050. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8051. if (ho) {
  8052. ho->SetTarget(target->GetID());
  8053. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8054. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8055. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8056. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8057. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8058. deque<GroupMemberInfo*>::iterator itr;
  8059. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8060. if (group)
  8061. {
  8062. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8063. deque<GroupMemberInfo*>* members = group->GetMembers();
  8064. for (itr = members->begin(); itr != members->end(); itr++) {
  8065. if ((*itr)->client)
  8066. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8067. }
  8068. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8069. }
  8070. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8071. }
  8072. else
  8073. safe_delete(ho);
  8074. }
  8075. else {
  8076. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8077. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8078. }
  8079. else
  8080. safe_delete(ho);
  8081. }
  8082. }
  8083. return 0;
  8084. }
  8085. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8086. if (!lua_interface)
  8087. return 0;
  8088. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8089. if (!spell) {
  8090. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8091. return 0;
  8092. }
  8093. int16 triggerCount = lua_interface->GetInt16Value(state);
  8094. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8095. if (!triggerCount) {
  8096. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8097. return 0;
  8098. }
  8099. spell->num_triggers = triggerCount;
  8100. spell->had_triggers = true;
  8101. spell->cancel_after_all_triggers = cancel_after_triggers;
  8102. return 0;
  8103. }
  8104. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8105. if (!lua_interface)
  8106. return 0;
  8107. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8108. if (!spell) {
  8109. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8110. return 0;
  8111. }
  8112. lua_interface->SetInt32Value(state, spell->num_triggers);
  8113. return 1;
  8114. }
  8115. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8116. if (!lua_interface)
  8117. return 0;
  8118. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8119. if (!spell) {
  8120. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8121. return 0;
  8122. }
  8123. int16 remove_count = lua_interface->GetInt16Value(state);
  8124. if (!remove_count)
  8125. remove_count = 1;
  8126. if (remove_count >= spell->num_triggers) {
  8127. spell->num_triggers = 0;
  8128. if (spell->cancel_after_all_triggers)
  8129. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8130. }
  8131. else {
  8132. spell->num_triggers -= remove_count;
  8133. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8134. }
  8135. return 0;
  8136. }
  8137. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8138. if (!lua_interface)
  8139. return 0;
  8140. Spawn* spawn = lua_interface->GetSpawn(state);
  8141. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8142. if (!spawn) {
  8143. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8144. return 0;
  8145. }
  8146. if (!copy_spawn) {
  8147. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8148. return 0;
  8149. }
  8150. spawn->CopySpawnAppearance(copy_spawn);
  8151. return 0;
  8152. }
  8153. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8154. Spawn* spawn = lua_interface->GetSpawn(state);
  8155. int8 type = lua_interface->GetInt8Value(state, 2);
  8156. if (!spawn) {
  8157. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8158. return 0;
  8159. }
  8160. else if (!spawn->IsEntity()) {
  8161. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8162. return 0;
  8163. }
  8164. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8165. return 1;
  8166. }
  8167. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8168. if (!lua_interface)
  8169. return 0;
  8170. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8171. int8 type = lua_interface->GetInt8Value(state);
  8172. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8173. if (!spell) {
  8174. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8175. return 0;
  8176. }
  8177. if (spawn) {
  8178. if (!spawn->IsEntity()) {
  8179. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8180. return 0;
  8181. }
  8182. Entity* entity = ((Entity*)spawn);
  8183. entity->AddImmunity(spell, type);
  8184. }
  8185. else {
  8186. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8187. for (int8 i = 0; i < spell->targets.size(); i++) {
  8188. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8189. if (!spawn || !spawn->IsEntity())
  8190. continue;
  8191. Entity* entity = ((Entity*)spawn);
  8192. entity->AddImmunity(spell, type);
  8193. }
  8194. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8195. }
  8196. return 0;
  8197. }
  8198. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8199. if (!lua_interface)
  8200. return 0;
  8201. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8202. int8 type = lua_interface->GetInt8Value(state);
  8203. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8204. if (!spell) {
  8205. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8206. return 0;
  8207. }
  8208. if (spawn) {
  8209. if (!spawn->IsEntity()) {
  8210. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8211. return 0;
  8212. }
  8213. Entity* entity = ((Entity*)spawn);
  8214. entity->RemoveImmunity(spell, type);
  8215. }
  8216. else {
  8217. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8218. for (int8 i = 0; i < spell->targets.size(); i++) {
  8219. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8220. if (!spawn || !spawn->IsEntity())
  8221. continue;
  8222. Entity* entity = ((Entity*)spawn);
  8223. entity->RemoveImmunity(spell, type);
  8224. }
  8225. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8226. }
  8227. return 0;
  8228. }
  8229. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8230. if (!lua_interface)
  8231. return 0;
  8232. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8233. if (!spell) {
  8234. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8235. return 0;
  8236. }
  8237. float snare = lua_interface->GetFloatValue(state);
  8238. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8239. // convert the val to the speed multipler value (100 - val)
  8240. float val = 100.0 - snare;
  8241. val /= 100.0;
  8242. if (spawn) {
  8243. if (!spawn->IsEntity()) {
  8244. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. ((Entity*)spawn)->SetSnareValue(spell, val);
  8248. }
  8249. else {
  8250. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8251. for (int8 i = 0; i < spell->targets.size(); i++) {
  8252. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8253. if (!spawn || !spawn->IsEntity())
  8254. continue;
  8255. ((Entity*)spawn)->SetSnareValue(spell, val);
  8256. }
  8257. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8258. }
  8259. return 0;
  8260. }
  8261. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8262. if (!lua_interface)
  8263. return 0;
  8264. Spawn* spawn = lua_interface->GetSpawn(state);
  8265. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8266. if (!spawn) {
  8267. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8268. return 0;
  8269. }
  8270. if (race_id == 0) {
  8271. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8272. return 0;
  8273. }
  8274. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8275. return 1;
  8276. }
  8277. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8278. if (!lua_interface)
  8279. return 0;
  8280. Spawn* spawn = lua_interface->GetSpawn(state);
  8281. if (!spawn) {
  8282. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8283. return 0;
  8284. }
  8285. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8286. return 1;
  8287. }
  8288. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8289. if (!lua_interface)
  8290. return 0;
  8291. Spawn* spawn = lua_interface->GetSpawn(state);
  8292. if (!spawn) {
  8293. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8294. return 0;
  8295. }
  8296. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8297. return 1;
  8298. }
  8299. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8300. if (!lua_interface)
  8301. return 0;
  8302. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8303. if (!spell) {
  8304. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8305. return 0;
  8306. }
  8307. lua_interface->SetStringValue(state, spell->spell->GetName());
  8308. return 1;
  8309. }
  8310. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8311. if (!lua_interface)
  8312. return 0;
  8313. Quest* quest = lua_interface->GetQuest(state);
  8314. if (!quest) {
  8315. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8316. return 0;
  8317. }
  8318. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8319. return 1;
  8320. }
  8321. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8322. if (!lua_interface)
  8323. return 0;
  8324. Quest* quest = lua_interface->GetQuest(state);
  8325. int32 flags = lua_interface->GetInt32Value(state, 2);
  8326. if (!quest) {
  8327. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8328. return 0;
  8329. }
  8330. quest->SetQuestFlags(flags);
  8331. return 0;
  8332. }
  8333. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8334. if (!lua_interface)
  8335. return 0;
  8336. Quest* quest = lua_interface->GetQuest(state);
  8337. Spawn* player = lua_interface->GetSpawn(state, 2);
  8338. int32 step = lua_interface->GetInt32Value(state, 3);
  8339. int32 duration = lua_interface->GetInt32Value(state, 4);
  8340. string action = lua_interface->GetStringValue(state, 5);
  8341. if (!quest) {
  8342. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8343. return 0;
  8344. }
  8345. if (!player) {
  8346. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8347. return 0;
  8348. }
  8349. if (!player->IsPlayer()) {
  8350. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8351. return 0;
  8352. }
  8353. if (step == 0) {
  8354. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8355. return 0;
  8356. }
  8357. if (duration == 0) {
  8358. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8359. return 0;
  8360. }
  8361. if (action.length() == 0) {
  8362. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8363. return 0;
  8364. }
  8365. Client* client = player->GetZone()->GetClientBySpawn(player);
  8366. if (!client) {
  8367. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8368. return 0;
  8369. }
  8370. quest->SetTimerStep(step);
  8371. quest->AddFailedAction(step, action);
  8372. quest->SetStepTimer(duration);
  8373. client->AddQuestTimer(quest->GetQuestID());
  8374. return 0;
  8375. }
  8376. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8377. if (!lua_interface)
  8378. return 0;
  8379. Quest* quest = lua_interface->GetQuest(state);
  8380. Spawn* player = lua_interface->GetSpawn(state, 2);
  8381. if (!quest) {
  8382. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8383. return 0;
  8384. }
  8385. if (!player) {
  8386. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8387. return 0;
  8388. }
  8389. if (!player->IsPlayer()) {
  8390. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. Client* client = player->GetZone()->GetClientBySpawn(player);
  8394. if (!client) {
  8395. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8396. return 0;
  8397. }
  8398. quest->SetTimerStep(0);
  8399. quest->SetStepTimer(0);
  8400. client->RemoveQuestTimer(quest->GetQuestID());
  8401. return 0;
  8402. }
  8403. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8404. if (!lua_interface)
  8405. return 0;
  8406. Spawn* player = lua_interface->GetSpawn(state);
  8407. Quest* quest = lua_interface->GetQuest(state, 2);
  8408. int32 step = lua_interface->GetInt32Value(state, 3);
  8409. if (!player) {
  8410. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8411. return 0;
  8412. }
  8413. if (!player->IsPlayer()) {
  8414. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8415. return 0;
  8416. }
  8417. if (!quest) {
  8418. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8419. return 0;
  8420. }
  8421. if (step == 0) {
  8422. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. Client* client = player->GetZone()->GetClientBySpawn(player);
  8426. if (!client) {
  8427. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8428. return 0;
  8429. }
  8430. if (quest->RemoveQuestStep(step, client)) {
  8431. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8432. client->GetCurrentZone()->SendQuestUpdates(client);
  8433. }
  8434. else
  8435. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8436. return 0;
  8437. }
  8438. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8439. if (!lua_interface)
  8440. return 0;
  8441. Quest* quest = lua_interface->GetQuest(state, 1);
  8442. int32 step = lua_interface->GetInt32Value(state, 2);
  8443. string desc = lua_interface->GetStringValue(state, 3);
  8444. string task_group = lua_interface->GetStringValue(state, 4);
  8445. if (!quest) {
  8446. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. if (step == 0) {
  8450. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8451. return 0;
  8452. }
  8453. QuestStep* quest_step = quest->GetQuestStep(step);
  8454. if (!quest_step) {
  8455. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. quest_step->SetStepProgress(0);
  8459. quest_step->SetTaskGroup(task_group);
  8460. quest_step->SetDescription(desc);
  8461. return 0;
  8462. }
  8463. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8464. if (!lua_interface)
  8465. return 0;
  8466. Quest* quest = lua_interface->GetQuest(state);
  8467. int32 step = lua_interface->GetInt32Value(state, 2);
  8468. string action = lua_interface->GetStringValue(state, 3);
  8469. if (!quest) {
  8470. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8471. return 0;
  8472. }
  8473. if (step == 0) {
  8474. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8475. return 0;
  8476. }
  8477. if (action.length() == 0) {
  8478. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8479. return 0;
  8480. }
  8481. quest->AddFailedAction(step, action);
  8482. return 0;
  8483. }
  8484. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8485. if (!lua_interface)
  8486. return 0;
  8487. Spawn* player = lua_interface->GetSpawn(state);
  8488. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8489. int32 step = lua_interface->GetInt32Value(state, 3);
  8490. if (!player) {
  8491. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8492. return 0;
  8493. }
  8494. if (!player->IsPlayer()) {
  8495. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8496. return 0;
  8497. }
  8498. if (quest_id == 0) {
  8499. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8500. return 0;
  8501. }
  8502. if (step == 0) {
  8503. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8504. return 0;
  8505. }
  8506. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8507. if (!quest) {
  8508. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8509. return 0;
  8510. }
  8511. quest->StepFailed(step);
  8512. return 0;
  8513. }
  8514. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8515. if (!lua_interface)
  8516. return 0;
  8517. Spawn* player = lua_interface->GetSpawn(state);
  8518. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8519. if (!player) {
  8520. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8521. return 0;
  8522. }
  8523. if (!player->IsPlayer()) {
  8524. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8525. return 0;
  8526. }
  8527. if (quest_id == 0) {
  8528. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8529. return 0;
  8530. }
  8531. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8532. if (!quest) {
  8533. lua_interface->SetInt32Value(state, 0);
  8534. return 1;
  8535. }
  8536. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8537. return 1;
  8538. }
  8539. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8540. if (!lua_interface)
  8541. return 0;
  8542. string name = lua_interface->GetStringValue(state);
  8543. string value = lua_interface->GetStringValue(state, 2);
  8544. string comment = lua_interface->GetStringValue(state, 3);
  8545. if (name.length() == 0) {
  8546. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8547. return 0;
  8548. }
  8549. if (value.length() == 0) {
  8550. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8551. return 0;
  8552. }
  8553. string varname = string("lua_").append(name);
  8554. Variable* var = variables.FindVariable(varname);
  8555. if (var)
  8556. var->SetValue(value.c_str());
  8557. else {
  8558. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8559. variables.AddVariable(var);
  8560. }
  8561. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8562. return 0;
  8563. }
  8564. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8565. if (!lua_interface)
  8566. return 0;
  8567. string name = lua_interface->GetStringValue(state);
  8568. if (name.length() == 0) {
  8569. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8570. return 0;
  8571. }
  8572. string varname = string("lua_").append(name);
  8573. Variable* var = variables.FindVariable(varname);
  8574. if (var)
  8575. lua_interface->SetStringValue(state, var->GetValue());
  8576. else
  8577. lua_interface->SetStringValue(state, "NULL");
  8578. return 1;
  8579. }
  8580. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8581. if (!lua_interface)
  8582. return 0;
  8583. Spawn* player = lua_interface->GetSpawn(state);
  8584. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8585. if (!player) {
  8586. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8587. return 0;
  8588. }
  8589. if (!player->IsPlayer()) {
  8590. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8591. return 0;
  8592. }
  8593. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8594. return 1;
  8595. }
  8596. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8597. if (!lua_interface)
  8598. return 0;
  8599. Spawn* player = lua_interface->GetSpawn(state);
  8600. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8601. if (!player) {
  8602. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8603. return 0;
  8604. }
  8605. if (!player->IsPlayer()) {
  8606. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8607. return 0;
  8608. }
  8609. Language* language = master_languages_list.GetLanguage(language_id);
  8610. if (language)
  8611. {
  8612. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8613. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8614. }
  8615. return 0;
  8616. }
  8617. int EQ2Emu_lua_IsNight(lua_State* state) {
  8618. if (!lua_interface)
  8619. return 0;
  8620. ZoneServer* zone = lua_interface->GetZone(state);
  8621. if (!zone) {
  8622. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8623. return 0;
  8624. }
  8625. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8626. return 1;
  8627. }
  8628. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8629. if (!lua_interface)
  8630. return 0;
  8631. Spawn* spawn = lua_interface->GetSpawn(state);
  8632. if (!spawn) {
  8633. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8634. return 0;
  8635. }
  8636. if (!spawn->IsWidget()) {
  8637. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8638. return 0;
  8639. }
  8640. ((Widget*)spawn)->SetMultiFloorLift(true);
  8641. if (spawn->GetZone())
  8642. spawn->GetZone()->AddTransportSpawn(spawn);
  8643. return 0;
  8644. }
  8645. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8646. if (!lua_interface)
  8647. return 0;
  8648. Spawn* player = lua_interface->GetSpawn(state);
  8649. int32 path = lua_interface->GetInt32Value(state, 2);
  8650. if (!player) {
  8651. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8652. return 0;
  8653. }
  8654. if (!player->IsPlayer()) {
  8655. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. if (path == 0) {
  8659. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8660. return 0;
  8661. }
  8662. Client* client = player->GetZone()->GetClientBySpawn(player);
  8663. if (!client) {
  8664. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8665. return 0;
  8666. }
  8667. client->SendFlightAutoMount(path);
  8668. return 0;
  8669. }
  8670. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8671. if (!lua_interface)
  8672. return 0;
  8673. Spawn* player = lua_interface->GetSpawn(state);
  8674. if (!player) {
  8675. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8676. return 0;
  8677. }
  8678. if (!player->IsPlayer()) {
  8679. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8680. return 0;
  8681. }
  8682. Client* client = player->GetZone()->GetClientBySpawn(player);
  8683. if (!client) {
  8684. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8685. return 0;
  8686. }
  8687. client->EndAutoMount();
  8688. return 0;
  8689. }
  8690. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8691. if (!lua_interface)
  8692. return 0;
  8693. Spawn* player = lua_interface->GetSpawn(state);
  8694. if (!player) {
  8695. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8696. return 0;
  8697. }
  8698. if (!player->IsPlayer()) {
  8699. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8700. return 0;
  8701. }
  8702. Client* client = player->GetZone()->GetClientBySpawn(player);
  8703. if (!client) {
  8704. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8705. return 0;
  8706. }
  8707. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8708. return 1;
  8709. }
  8710. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8711. if (!lua_interface)
  8712. return 0;
  8713. Spawn* player = lua_interface->GetSpawn(state);
  8714. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8715. int32 value = lua_interface->GetInt32Value(state, 3);
  8716. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8717. if (!player) {
  8718. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8719. return 0;
  8720. }
  8721. if (!player->IsPlayer()) {
  8722. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8723. return 0;
  8724. }
  8725. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8726. return 0;
  8727. }
  8728. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8729. if (!lua_interface)
  8730. return 0;
  8731. Spawn* player = lua_interface->GetSpawn(state);
  8732. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8733. if (!player) {
  8734. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8735. return 0;
  8736. }
  8737. if (!player->IsPlayer()) {
  8738. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8739. return 0;
  8740. }
  8741. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8742. if (!hd)
  8743. return 0;
  8744. lua_interface->SetInt32Value(state, hd->Value);
  8745. lua_interface->SetInt32Value(state, hd->Value2);
  8746. return 2;
  8747. }
  8748. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8749. if (!lua_interface)
  8750. return 0;
  8751. Spawn* spawn = lua_interface->GetSpawn(state);
  8752. int32 grid = lua_interface->GetInt32Value(state, 2);
  8753. if (!spawn) {
  8754. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8755. return 0;
  8756. }
  8757. if (grid == 0) {
  8758. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8759. return 0;
  8760. }
  8761. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8762. return 0;
  8763. }
  8764. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8765. if (!lua_interface)
  8766. return 0;
  8767. Spawn* spawn = lua_interface->GetSpawn(state);
  8768. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8769. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8770. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8771. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8772. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8773. if (!spawn) {
  8774. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8775. return 0;
  8776. }
  8777. //Add this quest to the list of required quests for this spawn
  8778. spawn->SetRequiredHistory(event_id, value1, value2);
  8779. //If private spawn value set
  8780. if (private_spawn) {
  8781. //Set the spawn to be private when not granted access via history
  8782. spawn->AddAllowAccessSpawn(spawn);
  8783. spawn->SetPrivateQuestSpawn(true);
  8784. }
  8785. //This value will override vis_flags in the vis packet
  8786. if (flag_override > 0)
  8787. spawn->SetQuestsRequiredOverride(flag_override);
  8788. return 0;
  8789. }
  8790. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8791. if (!lua_interface)
  8792. return 0;
  8793. Spawn* player = lua_interface->GetSpawn(state);
  8794. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8795. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8796. if (!player) {
  8797. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8798. return 0;
  8799. }
  8800. if (!player->IsPlayer()) {
  8801. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8802. return 0;
  8803. }
  8804. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8805. return 1;
  8806. }
  8807. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8808. if (!lua_interface)
  8809. return 0;
  8810. Spawn* player = lua_interface->GetSpawn(state);
  8811. int8 level = lua_interface->GetInt8Value(state, 2);
  8812. if (!player) {
  8813. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8814. return 0;
  8815. }
  8816. if (!player->IsPlayer()) {
  8817. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8818. return 0;
  8819. }
  8820. if (level == 0) {
  8821. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8822. return 0;
  8823. }
  8824. Client* client = player->GetZone()->GetClientBySpawn(player);
  8825. if (!client) {
  8826. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8827. return 0;
  8828. }
  8829. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8830. return 0;
  8831. }
  8832. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8833. if (!lua_interface)
  8834. return 0;
  8835. Spawn* player = lua_interface->GetSpawn(state);
  8836. int32 amount = lua_interface->GetInt32Value(state, 2);
  8837. if (!player) {
  8838. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8839. return 0;
  8840. }
  8841. if (!player->IsPlayer()) {
  8842. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8843. return 0;
  8844. }
  8845. if (amount == 0) {
  8846. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8847. return 0;
  8848. }
  8849. ((Player*)player)->AddCoins(amount);
  8850. return 0;
  8851. }
  8852. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8853. if (!lua_interface)
  8854. return 0;
  8855. Spawn* player = lua_interface->GetSpawn(state);
  8856. int32 amount = lua_interface->GetInt32Value(state, 2);
  8857. if (!player) {
  8858. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8859. return 0;
  8860. }
  8861. if (!player->IsPlayer()) {
  8862. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8863. return 0;
  8864. }
  8865. if (amount == 0) {
  8866. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8867. return 0;
  8868. }
  8869. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8870. return 1;
  8871. }
  8872. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8873. if (!lua_interface)
  8874. return 0;
  8875. ZoneServer* zone = lua_interface->GetZone(state);
  8876. if (!zone) {
  8877. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8878. return 0;
  8879. }
  8880. vector<Entity*> players = zone->GetPlayers();
  8881. if (players.size() == 0)
  8882. return 0;
  8883. lua_createtable(state, players.size(), 0);
  8884. int newTable = lua_gettop(state);
  8885. for (int32 i = 0; i < players.size(); i++) {
  8886. lua_interface->SetSpawnValue(state, players.at(i));
  8887. lua_rawseti(state, newTable, i + 1);
  8888. }
  8889. return 1;
  8890. }
  8891. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8892. if (!lua_interface)
  8893. return 0;
  8894. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8895. if (!zone) {
  8896. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8897. return 0;
  8898. }
  8899. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8900. //Map of <placement_id, location_id>
  8901. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8902. map<int32, int32>::iterator itr;
  8903. vector<Spawn*> group;
  8904. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8905. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8906. if (!location) {
  8907. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8908. return 0;
  8909. }
  8910. Spawn* spawn = 0;
  8911. if (location->entities[0]) {
  8912. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8913. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8914. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8915. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8916. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8917. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8918. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8919. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8920. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8921. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8922. if(spawn && spawn->IsOmittedByDBFlag())
  8923. {
  8924. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  8925. safe_delete(spawn);
  8926. continue;
  8927. }
  8928. if (spawn) {
  8929. const char* script = 0;
  8930. for (int x = 0; x < 3; x++) {
  8931. switch (x) {
  8932. case 0:
  8933. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8934. break;
  8935. case 1:
  8936. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8937. break;
  8938. case 2:
  8939. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8940. break;
  8941. }
  8942. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8943. spawn->SetSpawnScript(string(script));
  8944. break;
  8945. }
  8946. }
  8947. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8948. lua_interface->SetSpawnValue(state, spawn);
  8949. group.push_back(spawn);
  8950. }
  8951. else {
  8952. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  8953. safe_delete(spawn);
  8954. }
  8955. }
  8956. }
  8957. if (!group.empty()) {
  8958. lua_createtable(state, group.size(), 0);
  8959. int newTable = lua_gettop(state);
  8960. for (int32 i = 0; i < group.size(); i++) {
  8961. lua_interface->SetSpawnValue(state, group[i]);
  8962. lua_rawseti(state, newTable, i + 1);
  8963. }
  8964. }
  8965. else
  8966. lua_pushnil(state);
  8967. return 1;
  8968. }
  8969. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8970. if (!lua_interface)
  8971. return 0;
  8972. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8973. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8974. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8975. if (!spawn) {
  8976. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8977. return 0;
  8978. }
  8979. if (anim_id == 0) {
  8980. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8981. return 0;
  8982. }
  8983. if (leeway == 0)
  8984. leeway = 5000;
  8985. spawn->SetSpawnAnim(anim_id);
  8986. spawn->SetSpawnAnimLeeway(leeway);
  8987. return 0;
  8988. }
  8989. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8990. if (!lua_interface)
  8991. return 0;
  8992. Spawn* player = lua_interface->GetSpawn(state);
  8993. if (!player) {
  8994. return 0;
  8995. }
  8996. Client* client = player->GetZone()->GetClientBySpawn(player);
  8997. if (!client) {
  8998. return 0;
  8999. }
  9000. lua_interface->SetInt32Value(state, client->GetVersion());
  9001. return 1;
  9002. }
  9003. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9004. if (!lua_interface)
  9005. return 0;
  9006. Item* item = lua_interface->GetItem(state);
  9007. if (!item) {
  9008. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9009. return 0;
  9010. }
  9011. lua_interface->SetInt32Value(state, item->details.item_id);
  9012. return 1;
  9013. }
  9014. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9015. if (!lua_interface)
  9016. return 0;
  9017. Spawn* spawn = lua_interface->GetSpawn(state);
  9018. if (!spawn) {
  9019. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9020. return 0;
  9021. }
  9022. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9023. return 1;
  9024. }
  9025. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9026. if (!lua_interface)
  9027. return 0;
  9028. Spawn* spawn = lua_interface->GetSpawn(state);
  9029. if (!spawn) {
  9030. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9031. return 0;
  9032. }
  9033. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9034. return 1;
  9035. }
  9036. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9037. if (!lua_interface)
  9038. return 0;
  9039. Spawn* spawn = lua_interface->GetSpawn(state);
  9040. if (!spawn) {
  9041. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9042. return 0;
  9043. }
  9044. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9045. return 1;
  9046. }
  9047. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9048. if (!lua_interface)
  9049. return 0;
  9050. Spawn* spawn = lua_interface->GetSpawn(state);
  9051. if (!spawn) {
  9052. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9056. return 1;
  9057. }
  9058. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9059. if (!lua_interface)
  9060. return 0;
  9061. Spawn* spawn = lua_interface->GetSpawn(state);
  9062. float pct = lua_interface->GetFloatValue(state, 2);
  9063. if (!spawn) {
  9064. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9065. return 0;
  9066. }
  9067. if (pct == 0) {
  9068. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9069. return 0;
  9070. }
  9071. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9072. lua_interface->SetInt32Value(state, amount);
  9073. return 1;
  9074. }
  9075. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9076. if (!lua_interface)
  9077. return 0;
  9078. Spawn* spawn = lua_interface->GetSpawn(state);
  9079. float pct = lua_interface->GetFloatValue(state, 2);
  9080. if (!spawn) {
  9081. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9082. return 0;
  9083. }
  9084. if (pct == 0) {
  9085. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9086. return 0;
  9087. }
  9088. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9089. lua_interface->SetInt32Value(state, amount);
  9090. return 1;
  9091. }
  9092. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9093. if (!lua_interface)
  9094. return 0;
  9095. Spawn* spawn = lua_interface->GetSpawn(state);
  9096. if (!spawn) {
  9097. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9098. return 0;
  9099. }
  9100. if (!spawn->IsPlayer()) {
  9101. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9102. return 0;
  9103. }
  9104. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9105. return 1;
  9106. }
  9107. int EQ2Emu_lua_Evac(lua_State* state) {
  9108. if (!lua_interface)
  9109. return 0;
  9110. Spawn* target = lua_interface->GetSpawn(state);
  9111. if (target) {
  9112. float x = target->GetZone()->GetSafeX();
  9113. float y = target->GetZone()->GetSafeY();
  9114. float z = target->GetZone()->GetSafeZ();
  9115. float h = target->GetZone()->GetSafeHeading();
  9116. target->SetX(x);
  9117. target->SetY(y);
  9118. target->SetZ(z);
  9119. target->SetHeading(h);
  9120. target->SetSpawnOrigX(x);
  9121. target->SetSpawnOrigY(y);
  9122. target->SetSpawnOrigZ(z);
  9123. target->SetSpawnOrigHeading(h);
  9124. if (target->IsPlayer()) {
  9125. Client* client = target->GetZone()->GetClientBySpawn(target);
  9126. if (client) {
  9127. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9128. int numargs = lua_interface->GetNumberOfArgs(state);
  9129. if(numargs == 4) {
  9130. x = lua_interface->GetFloatValue(state,1);
  9131. y = lua_interface->GetFloatValue(state,2);
  9132. z = lua_interface->GetFloatValue(state,3);
  9133. h = lua_interface->GetFloatValue(state,4);
  9134. }
  9135. client->SetReloadingZone(true);
  9136. target->SetX(x);
  9137. target->SetY(y);
  9138. target->SetZ(z);
  9139. target->SetHeading(h);
  9140. target->SetSpawnOrigX(x);
  9141. target->SetSpawnOrigY(y);
  9142. target->SetSpawnOrigZ(z);
  9143. target->SetSpawnOrigHeading(h);
  9144. target->SetAppearancePosition(x,y,z);
  9145. client->SetZoningCoords(x,y,z,h);
  9146. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9147. if (packet)
  9148. {
  9149. packet->setDataByName("x", x);
  9150. packet->setDataByName("y", y);
  9151. packet->setDataByName("z", z);
  9152. client->QueuePacket(packet->serialize());
  9153. safe_delete(packet);
  9154. }
  9155. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9156. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9157. }
  9158. }
  9159. }
  9160. else {
  9161. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9162. ZoneServer* zone = spell->caster->GetZone();
  9163. float x = spell->caster->GetZone()->GetSafeX();
  9164. float y = spell->caster->GetZone()->GetSafeY();
  9165. float z = spell->caster->GetZone()->GetSafeZ();
  9166. float h = spell->caster->GetZone()->GetSafeHeading();
  9167. int numargs = lua_interface->GetNumberOfArgs(state);
  9168. if(numargs == 4) {
  9169. x = lua_interface->GetFloatValue(state,1);
  9170. y = lua_interface->GetFloatValue(state,2);
  9171. z = lua_interface->GetFloatValue(state,3);
  9172. h = lua_interface->GetFloatValue(state,4);
  9173. }
  9174. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9175. for (int32 i = 0; i < spell->targets.size(); i++) {
  9176. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9177. if (!target2)
  9178. continue;
  9179. if (target2->IsPlayer()) {
  9180. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9181. if (client) {
  9182. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9183. client->SetReloadingZone(true);
  9184. target2->SetX(x);
  9185. target2->SetY(y);
  9186. target2->SetZ(z);
  9187. target2->SetHeading(h);
  9188. target2->SetSpawnOrigX(x);
  9189. target2->SetSpawnOrigY(y);
  9190. target2->SetSpawnOrigZ(z);
  9191. target2->SetSpawnOrigHeading(h);
  9192. target2->SetAppearancePosition(x,y,z);
  9193. client->SetZoningCoords(x,y,z,h);
  9194. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9195. if (packet)
  9196. {
  9197. packet->setDataByName("x", x);
  9198. packet->setDataByName("y", y);
  9199. packet->setDataByName("z", z);
  9200. client->QueuePacket(packet->serialize());
  9201. safe_delete(packet);
  9202. }
  9203. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9204. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9205. }
  9206. }
  9207. }
  9208. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9209. }
  9210. return 0;
  9211. }
  9212. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9213. if (!lua_interface)
  9214. return 0;
  9215. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9216. if (!luaspell) {
  9217. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9218. return 0;
  9219. }
  9220. int8 tier = luaspell->spell->GetSpellTier();
  9221. lua_interface->SetInt32Value(state, tier);
  9222. return 1;
  9223. }
  9224. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9225. if (!lua_interface)
  9226. return 0;
  9227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9228. if (!luaspell) {
  9229. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9230. return 0;
  9231. }
  9232. int32 spell_id = luaspell->spell->GetSpellID();
  9233. lua_interface->SetInt32Value(state, spell_id);
  9234. return 1;
  9235. }
  9236. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9237. if (!lua_interface)
  9238. return 0;
  9239. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9240. if (!spawn) {
  9241. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9242. return 0;
  9243. }
  9244. if (!spawn->IsPlayer()) {
  9245. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9246. return 0;
  9247. }
  9248. ZoneServer* zone = spawn->GetZone();
  9249. if (!zone) {
  9250. return 0;
  9251. }
  9252. Client* client = zone->GetClientBySpawn(spawn);
  9253. if (!client) {
  9254. return 0;
  9255. }
  9256. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9257. return 0;
  9258. }
  9259. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9260. if (!lua_interface)
  9261. return 0;
  9262. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9263. if (!spawn) {
  9264. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9265. return 0;
  9266. }
  9267. if (!spawn->IsPlayer()) {
  9268. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9269. return 0;
  9270. }
  9271. ZoneServer* zone = spawn->GetZone();
  9272. if (!zone) {
  9273. return 0;
  9274. }
  9275. Client* client = zone->GetClientBySpawn(spawn);
  9276. if (!client) {
  9277. return 0;
  9278. }
  9279. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9280. return 0;
  9281. }
  9282. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9283. if (!lua_interface)
  9284. return 0;
  9285. Spawn* caster = lua_interface->GetSpawn(state);
  9286. Spawn* target = lua_interface->GetSpawn(state, 2);
  9287. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9288. string spell_name = lua_interface->GetStringValue(state, 4);
  9289. if (!caster) {
  9290. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9291. return 0;
  9292. }
  9293. if (!caster->IsEntity()) {
  9294. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9295. return 0;
  9296. }
  9297. if (!target) {
  9298. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9299. return 0;
  9300. }
  9301. if (!target->IsEntity()) {
  9302. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9303. return 0;
  9304. }
  9305. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9306. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9307. return 0;
  9308. }
  9309. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9310. if (!lua_interface)
  9311. return 0;
  9312. Spawn* player = lua_interface->GetSpawn(state);
  9313. int32 amount = lua_interface->GetInt32Value(state, 2);
  9314. if (player && player->IsPlayer() && amount > 0) {
  9315. ((Player*)player)->AddXP(amount);
  9316. ((Player*)player)->SetCharSheetChanged(true);
  9317. Client* client = player->GetZone()->GetClientBySpawn(player);
  9318. if (client) {
  9319. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9320. }
  9321. }
  9322. return 0;
  9323. }
  9324. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9325. if (!lua_interface)
  9326. return 0;
  9327. Spawn* player = lua_interface->GetSpawn(state);
  9328. int8 type = lua_interface->GetInt8Value(state, 2);
  9329. string text = lua_interface->GetStringValue(state, 3);
  9330. Client* client = 0;
  9331. if (player && player->IsPlayer())
  9332. client = player->GetZone()->GetClientBySpawn(player);
  9333. if (!client || text.length() == 0) {
  9334. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9335. return 0;
  9336. }
  9337. client->SimpleMessage(type, text.c_str());
  9338. return 0;
  9339. }
  9340. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9341. if (!lua_interface)
  9342. return 0;
  9343. Spawn* player = lua_interface->GetSpawn(state);
  9344. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9345. Client* client = 0;
  9346. if (player && player->IsPlayer())
  9347. client = player->GetZone()->GetClientBySpawn(player);
  9348. if (!client || !spawn) {
  9349. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9350. return 0;
  9351. }
  9352. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9353. if (!items) {
  9354. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9355. return 0;
  9356. }
  9357. client->Loot(spawn->GetLootCoins(), items, spawn);
  9358. return 0;
  9359. }
  9360. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9361. if (!lua_interface)
  9362. return 0;
  9363. Spawn* spawnref = lua_interface->GetSpawn(state);
  9364. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9365. if (spawn_id > 0 && spawnref) {
  9366. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9367. if (spawns.size() == 0) {
  9368. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9369. return 0;
  9370. }
  9371. Spawn* spawn = 0;
  9372. int16 index = MakeRandomInt(0, spawns.size());
  9373. if (index >= spawns.size() || index < 0)
  9374. index = 0;
  9375. spawn = spawns[index];
  9376. lua_interface->SetSpawnValue(state, spawn);
  9377. return 1;
  9378. }
  9379. else {
  9380. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9381. }
  9382. return 0;
  9383. }
  9384. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9385. Spawn* player = lua_interface->GetSpawn(state);
  9386. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9387. string name = lua_interface->GetStringValue(state, 3);
  9388. float distance = lua_interface->GetFloatValue(state, 4);
  9389. string command = lua_interface->GetStringValue(state, 5);
  9390. string error_text = lua_interface->GetStringValue(state, 6);
  9391. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9392. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9393. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9394. if (distance == 0)
  9395. distance = 10.0f;
  9396. if (command.length() == 0)
  9397. command = name;
  9398. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9399. if (spawns.size() == 0) {
  9400. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9401. return 0;
  9402. }
  9403. Spawn* spawn = 0;
  9404. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9405. spawn = *itr;
  9406. if (spawn) {
  9407. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9408. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9409. }
  9410. }
  9411. }
  9412. return 0;
  9413. }
  9414. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9415. if (!lua_interface)
  9416. return 0;
  9417. Client* client = 0;
  9418. Spawn* player = lua_interface->GetSpawn(state);
  9419. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9420. if (player && player->IsPlayer() && player->GetZone())
  9421. client = player->GetZone()->GetClientBySpawn(player);
  9422. else{
  9423. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9424. return 0;
  9425. }
  9426. if (client) {
  9427. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9428. if (packet) {
  9429. packet->setDataByName("goal_num", goal_num);
  9430. client->QueuePacket(packet->serialize());
  9431. safe_delete(packet);
  9432. }
  9433. }
  9434. return 0;
  9435. }
  9436. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9437. if (!lua_interface)
  9438. return 0;
  9439. Client* client = 0;
  9440. Spawn* player = lua_interface->GetSpawn(state);
  9441. if (player && player->IsPlayer() && player->GetZone())
  9442. client = player->GetZone()->GetClientBySpawn(player);
  9443. else {
  9444. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9445. return 0;
  9446. }
  9447. if (client) {
  9448. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9449. }
  9450. return 0;
  9451. }
  9452. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9453. if (!lua_interface)
  9454. return 0;
  9455. Client* client = 0;
  9456. Spawn* player = lua_interface->GetSpawn(state);
  9457. float duration = lua_interface->GetFloatValue(state, 2);
  9458. string text = lua_interface->GetStringValue(state, 3);
  9459. string voice = lua_interface->GetStringValue(state, 4);
  9460. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9461. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9462. string signal = lua_interface->GetStringValue(state, 7);
  9463. string goal1 = lua_interface->GetStringValue(state, 8);
  9464. string task1 = lua_interface->GetStringValue(state, 9);
  9465. string goal2 = lua_interface->GetStringValue(state, 10);
  9466. string task2 = lua_interface->GetStringValue(state, 11);
  9467. string goal3 = lua_interface->GetStringValue(state, 12);
  9468. string task3 = lua_interface->GetStringValue(state, 13);
  9469. string goal4 = lua_interface->GetStringValue(state, 14);
  9470. string task4 = lua_interface->GetStringValue(state, 15);
  9471. if (!player) {
  9472. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9473. return 0;
  9474. }
  9475. if (!player->IsPlayer()) {
  9476. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9477. return 0;
  9478. }
  9479. else
  9480. client = ((Player*)player)->GetClient();
  9481. if (!client) {
  9482. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9483. return 0;
  9484. }
  9485. if (text.length() == 0) {
  9486. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9487. return 0;
  9488. }
  9489. if (duration >= 0 && duration < 2)
  9490. duration = 2;
  9491. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9492. if (packet) {
  9493. packet->setDataByName("open_seconds_max", duration);
  9494. packet->setDataByName("text", text.c_str());
  9495. packet->setDataByName("voice", voice.c_str());
  9496. int8 num_goals = 1;
  9497. if (task2.length() > 0)
  9498. num_goals++;
  9499. if (task3.length() > 0)
  9500. num_goals++;
  9501. if (task4.length() > 0)
  9502. num_goals++;
  9503. packet->setArrayLengthByName("num_goals", num_goals);
  9504. for (int8 i = 0; i < num_goals; i++) {
  9505. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9506. }
  9507. if (goal1.length() > 0)
  9508. packet->setArrayDataByName("goal_text", goal1.c_str());
  9509. if (goal2.length() > 0)
  9510. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9511. if (goal3.length() > 0)
  9512. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9513. if (goal4.length() > 0)
  9514. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9515. packet->setSubArrayDataByName("task_text", task1.c_str());
  9516. if (task2.length() > 0)
  9517. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9518. if (task3.length() > 0)
  9519. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9520. if (task4.length() > 0)
  9521. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9522. packet->setDataByName("complete_sound", "click");
  9523. packet->setDataByName("signal", signal.c_str());
  9524. packet->setDataByName("voice_key1", voice_key1);
  9525. packet->setDataByName("voice_key2", voice_key2);
  9526. client->QueuePacket(packet->serialize());
  9527. safe_delete(packet);
  9528. }
  9529. return 0;
  9530. }
  9531. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9532. if (!lua_interface)
  9533. return 0;
  9534. Client* client = 0;
  9535. Spawn* player = lua_interface->GetSpawn(state);
  9536. string window = lua_interface->GetStringValue(state, 2);
  9537. int8 show = lua_interface->GetInt8Value(state, 3);
  9538. if (!player) {
  9539. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9540. return 0;
  9541. }
  9542. if (!player->IsPlayer()) {
  9543. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9544. return 0;
  9545. }
  9546. else
  9547. client = ((Player*)player)->GetClient();
  9548. if (!client) {
  9549. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9550. return 0;
  9551. }
  9552. if (window.length() == 0) {
  9553. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9554. return 0;
  9555. }
  9556. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9557. if (packet) {
  9558. packet->setDataByName("window", window.c_str());
  9559. packet->setDataByName("show", show);
  9560. client->QueuePacket(packet->serialize());
  9561. safe_delete(packet);
  9562. }
  9563. return 0;
  9564. }
  9565. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9566. //See GameEvents.txt for options that can be used for this function
  9567. if (!lua_interface)
  9568. return 0;
  9569. Client* client = 0;
  9570. Spawn* player = lua_interface->GetSpawn(state);
  9571. string event_name = lua_interface->GetStringValue(state, 2);
  9572. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9573. if (!player || !player->IsPlayer()) {
  9574. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9575. return 0;
  9576. }
  9577. if (player->GetZone())
  9578. client = player->GetZone()->GetClientBySpawn(player);
  9579. if (!client) {
  9580. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9581. return 0;
  9582. }
  9583. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9584. if (packet) {
  9585. packet->setDataByName("event_name", event_name.c_str());
  9586. packet->setDataByName("enabled", enabled);
  9587. client->QueuePacket(packet->serialize());
  9588. safe_delete(packet);
  9589. }
  9590. return 0;
  9591. }
  9592. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9593. if (!lua_interface)
  9594. return 0;
  9595. Spawn* player = lua_interface->GetSpawn(state);
  9596. if (player && player->IsPlayer()) {
  9597. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9598. return 1;
  9599. }
  9600. return 0;
  9601. }
  9602. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9603. if (!lua_interface)
  9604. return 0;
  9605. Spawn* player = lua_interface->GetSpawn(state);
  9606. int8 step = lua_interface->GetInt8Value(state, 2);
  9607. if (player && player->IsPlayer() && step > 0) {
  9608. ((Player*)player)->SetTutorialStep(step);
  9609. }
  9610. return 0;
  9611. }
  9612. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9613. if (!lua_interface)
  9614. return 0;
  9615. Client* client = 0;
  9616. Spawn* player = lua_interface->GetSpawn(state);
  9617. string window = lua_interface->GetStringValue(state, 2);
  9618. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9619. if (!player) {
  9620. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9621. return 0;
  9622. }
  9623. if (!player->IsPlayer()) {
  9624. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9625. return 0;
  9626. }
  9627. else
  9628. client = ((Player*)player)->GetClient();
  9629. if (!client) {
  9630. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9631. return 0;
  9632. }
  9633. if (window.length() == 0) {
  9634. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9635. return 0;
  9636. }
  9637. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9638. if (packet) {
  9639. packet->setDataByName("window", window.c_str());
  9640. packet->setDataByName("flash_seconds", flash_seconds);
  9641. client->QueuePacket(packet->serialize());
  9642. safe_delete(packet);
  9643. }
  9644. return 0;
  9645. }
  9646. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9647. if (!lua_interface)
  9648. return 0;
  9649. Spawn* spawn = lua_interface->GetSpawn(state);
  9650. Spawn* target = lua_interface->GetSpawn(state, 2);
  9651. if (spawn && target)
  9652. return spawn->CheckLoS(target);
  9653. return 0;
  9654. }
  9655. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9656. if (!lua_interface)
  9657. return 0;
  9658. Spawn* spawn = lua_interface->GetSpawn(state);
  9659. float x = lua_interface->GetFloatValue(state, 2);
  9660. float y = lua_interface->GetFloatValue(state, 3);
  9661. float z = lua_interface->GetFloatValue(state, 4);
  9662. if (spawn)
  9663. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9664. return 0;
  9665. }
  9666. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9667. if (!lua_interface)
  9668. return 0;
  9669. ZoneServer* zone = lua_interface->GetZone(state);
  9670. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9671. if (zone)
  9672. zone->SetExpansionFlag(xpackFlag);
  9673. return 0;
  9674. }
  9675. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9676. if (!lua_interface)
  9677. return 0;
  9678. ZoneServer* zone = lua_interface->GetZone(state);
  9679. if (zone) {
  9680. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9681. return 1;
  9682. }
  9683. return 0;
  9684. }
  9685. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9686. if (!lua_interface)
  9687. return 0;
  9688. ZoneServer* zone = lua_interface->GetZone(state);
  9689. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9690. if (zone)
  9691. zone->SetHolidayFlag(holidayFlag);
  9692. return 0;
  9693. }
  9694. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9695. if (!lua_interface)
  9696. return 0;
  9697. ZoneServer* zone = lua_interface->GetZone(state);
  9698. if (zone) {
  9699. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9700. return 1;
  9701. }
  9702. return 0;
  9703. }
  9704. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  9705. if (!lua_interface)
  9706. return 0;
  9707. Spawn* player = lua_interface->GetSpawn(state);
  9708. ZoneServer* zone = player->GetZone();
  9709. bool canbind = lua_interface->GetInt32Value(state, 2);
  9710. if (zone)
  9711. zone->SetCanBind(canbind);
  9712. return 0;
  9713. }
  9714. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  9715. if (!lua_interface)
  9716. return 0;
  9717. Spawn* player = lua_interface->GetSpawn(state);
  9718. ZoneServer* zone = player->GetZone();
  9719. if (zone) {
  9720. lua_interface->SetInt32Value(state, zone->GetCanBind());
  9721. return 1;
  9722. }
  9723. return 0;
  9724. }
  9725. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9726. if (!lua_interface)
  9727. return 0;
  9728. Spawn* spawn = lua_interface->GetSpawn(state);
  9729. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9730. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9731. float distance = lua_interface->GetFloatValue(state, 4);
  9732. string in_range_function = lua_interface->GetStringValue(state, 5);
  9733. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9734. if (spawn && distance > 0 && in_range_function.length() > 0)
  9735. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9736. return 0;
  9737. }
  9738. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9739. if (!lua_interface)
  9740. return 0;
  9741. Spawn* spawn = lua_interface->GetSpawn(state);
  9742. Spawn* target = lua_interface->GetSpawn(state, 2);
  9743. if (spawn && target)
  9744. {
  9745. if (spawn->IsPlayer() && target->IsEntity())
  9746. {
  9747. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9748. return 1;
  9749. }
  9750. else if (spawn->IsEntity() && target->IsEntity())
  9751. {
  9752. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9753. return 1;
  9754. }
  9755. }
  9756. return 0;
  9757. }
  9758. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9759. if (!lua_interface)
  9760. return 0;
  9761. Spawn* spawn = lua_interface->GetSpawn(state);
  9762. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9763. if (spawn && spawn->IsEntity())
  9764. {
  9765. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9766. if (spawn->IsPlayer())
  9767. {
  9768. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9769. if (client)
  9770. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9771. }
  9772. }
  9773. return 0;
  9774. }
  9775. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9776. if (!lua_interface)
  9777. return 0;
  9778. Spawn* spawn = lua_interface->GetSpawn(state);
  9779. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9780. if (spawn && spawn->IsEntity())
  9781. {
  9782. ((Entity*)spawn)->SetSeeHideSpell(val);
  9783. if (spawn->IsPlayer())
  9784. {
  9785. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9786. if (client)
  9787. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9788. }
  9789. }
  9790. return 0;
  9791. }
  9792. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9793. {
  9794. if (!lua_interface)
  9795. return 0;
  9796. Spawn* player = lua_interface->GetSpawn(state);
  9797. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9798. string command = lua_interface->GetStringValue(state, 3);
  9799. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9800. lua_interface->ResetFunctionStack(state);
  9801. if (spawn && player && player->IsPlayer())
  9802. {
  9803. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9804. bool res = false;
  9805. if (cmd)
  9806. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9807. lua_interface->SetBooleanValue(state, res);
  9808. return 1;
  9809. }
  9810. return 0;
  9811. }
  9812. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9813. {
  9814. if (!lua_interface)
  9815. return 0;
  9816. Spawn* spawn = lua_interface->GetSpawn(state);
  9817. int32 charID = lua_interface->GetInt32Value(state, 2);
  9818. string command = lua_interface->GetStringValue(state, 3);
  9819. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9820. lua_interface->ResetFunctionStack(state);
  9821. if (spawn && charID)
  9822. {
  9823. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9824. bool res = false;
  9825. if (cmd)
  9826. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9827. lua_interface->SetBooleanValue(state, res);
  9828. return 1;
  9829. }
  9830. return 0;
  9831. }
  9832. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9833. {
  9834. if (!lua_interface)
  9835. return 0;
  9836. Spawn* spawn = lua_interface->GetSpawn(state);
  9837. string command = lua_interface->GetStringValue(state, 2);
  9838. lua_interface->ResetFunctionStack(state);
  9839. if (spawn && command.length() > 0)
  9840. spawn->RemovePrimaryEntityCommand(command.c_str());
  9841. return 0;
  9842. }
  9843. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9844. if (!lua_interface)
  9845. return 0;
  9846. Spawn* spawn = lua_interface->GetSpawn(state);
  9847. float distance = lua_interface->GetFloatValue(state, 2);
  9848. string command = lua_interface->GetStringValue(state, 3);
  9849. Spawn* player = lua_interface->GetSpawn(state, 4);
  9850. lua_interface->ResetFunctionStack(state);
  9851. if (spawn) {
  9852. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9853. }
  9854. return 0;
  9855. }
  9856. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9857. if (!lua_interface)
  9858. return 0;
  9859. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9860. Spawn* spawn = lua_interface->GetSpawn(state);
  9861. Spawn* player = lua_interface->GetSpawn(state, 2);
  9862. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9863. lua_interface->ResetFunctionStack(state);
  9864. if (spawn && player && transport_id && player->IsPlayer()) {
  9865. Client* client = 0;
  9866. if (player && player->IsPlayer())
  9867. client = player->GetZone()->GetClientBySpawn(player);
  9868. if (!client)
  9869. return 0;
  9870. vector<TransportDestination*> destinations;
  9871. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9872. if (destinations.size())
  9873. {
  9874. client->SetTemporaryTransportID(transport_id);
  9875. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9876. }
  9877. else
  9878. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9879. }
  9880. return 0;
  9881. }
  9882. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9883. if (!lua_interface)
  9884. return 0;
  9885. Spawn* player = lua_interface->GetSpawn(state);
  9886. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9887. lua_interface->ResetFunctionStack(state);
  9888. if (player && player->IsPlayer()) {
  9889. Client* client = 0;
  9890. if (player && player->IsPlayer())
  9891. client = player->GetZone()->GetClientBySpawn(player);
  9892. if (!client)
  9893. return 0;
  9894. client->SetTemporaryTransportID(transport_id);
  9895. }
  9896. return 0;
  9897. }
  9898. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9899. if (!lua_interface)
  9900. return 0;
  9901. Spawn* player = lua_interface->GetSpawn(state);
  9902. lua_interface->ResetFunctionStack(state);
  9903. if (player && player->IsPlayer()) {
  9904. Client* client = 0;
  9905. if (player && player->IsPlayer())
  9906. client = player->GetZone()->GetClientBySpawn(player);
  9907. if (!client)
  9908. return 0;
  9909. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9910. return 1;
  9911. }
  9912. return 0;
  9913. }
  9914. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9915. if (!lua_interface)
  9916. return 0;
  9917. Spawn* spawn = lua_interface->GetSpawn(state);
  9918. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9919. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9920. if (!spawn) {
  9921. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9922. return 0;
  9923. }
  9924. if (!spawn->IsEntity()) {
  9925. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9926. return 0;
  9927. }
  9928. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9929. {
  9930. 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);
  9931. return 0;
  9932. }
  9933. lua_interface->ResetFunctionStack(state);
  9934. if (spell && spell->targets.size() > 0) {
  9935. ZoneServer* zone = spell->caster->GetZone();
  9936. for (int8 i = 0; i < spell->targets.size(); i++) {
  9937. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9938. if (target && target->IsEntity()) {
  9939. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9940. if (target->IsPlayer())
  9941. ((Player*)target)->SetCharSheetChanged(true);
  9942. }
  9943. }
  9944. }
  9945. else {
  9946. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9947. if (spawn->IsPlayer())
  9948. ((Player*)spawn)->SetCharSheetChanged(true);
  9949. }
  9950. return 0;
  9951. }
  9952. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9953. if (!lua_interface)
  9954. return 0;
  9955. Spawn* spawn = lua_interface->GetSpawn(state);
  9956. lua_interface->ResetFunctionStack(state);
  9957. if (!spawn) {
  9958. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9959. return 0;
  9960. }
  9961. if (!spawn->IsEntity()) {
  9962. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9963. return 0;
  9964. }
  9965. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9966. return 1;
  9967. }
  9968. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9969. if (!lua_interface)
  9970. return 0;
  9971. int32 spell_id = lua_interface->GetInt32Value(state);
  9972. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9973. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9974. if (spell_id > 0) {
  9975. if (spell_tier == 0)
  9976. spell_tier = 1;
  9977. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9978. LuaSpell* lua_spell = 0;
  9979. if(custom_lua_script.size() > 0)
  9980. {
  9981. // attempt to load the custom script since it isn't already loaded
  9982. // we will re-obtain the lua_spell further below
  9983. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9984. {
  9985. 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());
  9986. lua_interface->LoadLuaSpell(custom_lua_script);
  9987. }
  9988. }
  9989. else
  9990. custom_lua_script = spell->GetSpellData()->lua_script;
  9991. if (!lua_spell && lua_interface)
  9992. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9993. if (!lua_spell)
  9994. {
  9995. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9996. return 0;
  9997. }
  9998. lua_spell->spell = new Spell(spell);
  9999. lua_interface->AddCustomSpell(lua_spell);
  10000. lua_interface->SetSpellValue(state, lua_spell);
  10001. return 1;
  10002. }
  10003. return 0;
  10004. }
  10005. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10006. if (!lua_interface)
  10007. return 0;
  10008. LuaSpell* spell = lua_interface->GetSpell(state);
  10009. string field = lua_interface->GetStringValue(state, 2);
  10010. if (!spell) {
  10011. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10012. return 0;
  10013. }
  10014. if (!spell->spell || !spell->spell->GetSpellData()) {
  10015. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10016. return 0;
  10017. }
  10018. boost::to_lower(field);
  10019. return spell->spell->GetSpellData(state, field);
  10020. }
  10021. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10022. if (!lua_interface)
  10023. return 0;
  10024. LuaSpell* spell = lua_interface->GetSpell(state);
  10025. string field = lua_interface->GetStringValue(state, 2);
  10026. int8 fieldArg = 3; // field value after the initial set
  10027. if (!spell) {
  10028. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10029. return 0;
  10030. }
  10031. if (!spell->spell || !spell->spell->GetSpellData()) {
  10032. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10033. return 0;
  10034. }
  10035. boost::to_lower(field);
  10036. bool valSet = false;
  10037. spell->spell->SetSpellData(state, field, fieldArg);
  10038. return valSet;
  10039. }
  10040. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10041. if (!lua_interface)
  10042. return 0;
  10043. LuaSpell* spell = lua_interface->GetSpell(state);
  10044. int8 idx = lua_interface->GetInt32Value(state, 2);
  10045. if (!spell) {
  10046. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10047. return 0;
  10048. }
  10049. if (!spell->spell || !spell->spell->GetSpellData()) {
  10050. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10051. return 0;
  10052. }
  10053. if (spell->spell->lua_data.size() <= idx)
  10054. {
  10055. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10056. return 0;
  10057. }
  10058. bool setVal = true;
  10059. LUAData* data = spell->spell->lua_data[idx];
  10060. switch (data->type)
  10061. {
  10062. case 0:
  10063. {
  10064. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10065. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10066. data->int_value = value;
  10067. data->int_value2 = value2;
  10068. break;
  10069. }
  10070. case 1:
  10071. {
  10072. float value = lua_interface->GetFloatValue(state, 3);
  10073. float value2 = lua_interface->GetFloatValue(state, 4);
  10074. data->float_value = value;
  10075. data->float_value2 = value2;
  10076. break;
  10077. }
  10078. case 2:
  10079. {
  10080. bool value = lua_interface->GetBooleanValue(state, 3);
  10081. data->bool_value = value;
  10082. break;
  10083. }
  10084. case 3:
  10085. {
  10086. string value = lua_interface->GetStringValue(state, 3);
  10087. string value2 = lua_interface->GetStringValue(state, 4);
  10088. data->string_value = value;
  10089. data->string_value2 = value2;
  10090. break;
  10091. }
  10092. default:
  10093. setVal = false;
  10094. }
  10095. return setVal;
  10096. }
  10097. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10098. if (!lua_interface)
  10099. return 0;
  10100. LuaSpell* spell = lua_interface->GetSpell(state);
  10101. int8 idx = lua_interface->GetInt32Value(state, 2);
  10102. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10103. if (!spell) {
  10104. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10105. return 0;
  10106. }
  10107. if (!spell->spell || !spell->spell->GetSpellData()) {
  10108. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10109. return 0;
  10110. }
  10111. if (spell->spell->lua_data.size() <= idx)
  10112. {
  10113. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10114. return 0;
  10115. }
  10116. bool setVal = true;
  10117. LUAData* data = spell->spell->lua_data[idx];
  10118. switch (data->type)
  10119. {
  10120. case 0:
  10121. {
  10122. if(!secondfield)
  10123. lua_interface->SetSInt32Value(state, data->int_value);
  10124. else
  10125. lua_interface->SetSInt32Value(state, data->int_value2);
  10126. break;
  10127. }
  10128. case 1:
  10129. {
  10130. if (!secondfield)
  10131. lua_interface->SetFloatValue(state, data->float_value);
  10132. else
  10133. lua_interface->SetFloatValue(state, data->float_value2);
  10134. break;
  10135. }
  10136. case 2:
  10137. {
  10138. lua_interface->SetBooleanValue(state, data->bool_value);
  10139. break;
  10140. }
  10141. case 3:
  10142. {
  10143. if (!secondfield)
  10144. lua_interface->SetStringValue(state, data->string_value.c_str());
  10145. else
  10146. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10147. break;
  10148. }
  10149. default:
  10150. setVal = false;
  10151. }
  10152. return setVal;
  10153. }
  10154. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10155. if (!lua_interface)
  10156. return 0;
  10157. LuaSpell* spell = lua_interface->GetSpell(state);
  10158. int8 idx = lua_interface->GetInt32Value(state, 2);
  10159. string field = lua_interface->GetStringValue(state, 3);
  10160. boost::to_lower(field);
  10161. if (!spell) {
  10162. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10163. return 0;
  10164. }
  10165. if (!spell->spell || !spell->spell->GetSpellData()) {
  10166. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10167. return 0;
  10168. }
  10169. if (spell->spell->effects.size() <= idx)
  10170. {
  10171. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10172. return 0;
  10173. }
  10174. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10175. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10176. if (field == "description")
  10177. effect->description = string(lua_interface->GetStringValue(state, 4));
  10178. else if (field == "bullet")
  10179. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10180. else if (field == "percentage")
  10181. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10182. else // no match
  10183. return 0;
  10184. return 1;
  10185. }
  10186. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10187. if (!lua_interface)
  10188. return 0;
  10189. LuaSpell* spell = lua_interface->GetSpell(state);
  10190. int8 idx = lua_interface->GetInt32Value(state, 2);
  10191. string field = lua_interface->GetStringValue(state, 3);
  10192. boost::to_lower(field);
  10193. if (!spell) {
  10194. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10195. return 0;
  10196. }
  10197. if (!spell->spell || !spell->spell->GetSpellData()) {
  10198. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10199. return 0;
  10200. }
  10201. if (spell->spell->effects.size() <= idx)
  10202. {
  10203. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10204. return 0;
  10205. }
  10206. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10207. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10208. if (field == "description")
  10209. lua_interface->SetStringValue(state, effect->description.c_str());
  10210. else if (field == "bullet")
  10211. lua_interface->SetInt32Value(state, effect->subbullet);
  10212. else if (field == "percentage")
  10213. lua_interface->SetInt32Value(state, effect->percentage);
  10214. else // no match
  10215. return 0;
  10216. return 1;
  10217. }
  10218. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10219. if (!lua_interface)
  10220. return 0;
  10221. LuaSpell* spell = lua_interface->GetSpell(state);
  10222. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10223. Spawn* target = lua_interface->GetSpawn(state, 3);
  10224. if (!target) {
  10225. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10226. return 0;
  10227. }
  10228. if (!target->IsEntity()) {
  10229. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10230. return 0;
  10231. }
  10232. if (!spell) {
  10233. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10234. return 0;
  10235. }
  10236. if (caster && !caster->IsEntity()) {
  10237. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10238. return 0;
  10239. }
  10240. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10241. return 0;
  10242. }
  10243. int EQ2Emu_lua_InWater(lua_State* state) {
  10244. if (!lua_interface)
  10245. return 0;
  10246. Spawn* spawn = lua_interface->GetSpawn(state);
  10247. lua_interface->ResetFunctionStack(state);
  10248. if (spawn) {
  10249. lua_interface->SetBooleanValue(state, spawn->InWater());
  10250. return 1;
  10251. }
  10252. return 0;
  10253. }
  10254. int EQ2Emu_lua_InLava(lua_State* state) {
  10255. if (!lua_interface)
  10256. return 0;
  10257. Spawn* spawn = lua_interface->GetSpawn(state);
  10258. lua_interface->ResetFunctionStack(state);
  10259. if (spawn) {
  10260. lua_interface->SetBooleanValue(state, spawn->InLava());
  10261. return 1;
  10262. }
  10263. return 0;
  10264. }
  10265. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10266. if (!lua_interface)
  10267. return 0;
  10268. Spawn* attacker = lua_interface->GetSpawn(state);
  10269. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10270. int8 type = lua_interface->GetInt8Value(state, 3);
  10271. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10272. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10273. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10274. string spell_name = lua_interface->GetStringValue(state, 7);
  10275. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10276. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10277. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10278. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10279. lua_interface->ResetFunctionStack(state);
  10280. if (!attacker) {
  10281. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10282. return 0;
  10283. }
  10284. if (!attacker->IsEntity()) {
  10285. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10286. return 0;
  10287. }
  10288. if (!victim) {
  10289. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10290. return 0;
  10291. }
  10292. if (!victim->IsEntity()) {
  10293. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10294. return 0;
  10295. }
  10296. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10297. return 0;
  10298. }
  10299. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10300. if (!lua_interface)
  10301. return 0;
  10302. Spawn* spawn = lua_interface->GetSpawn(state);
  10303. lua_interface->ResetFunctionStack(state);
  10304. if (spawn) {
  10305. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10306. return 1;
  10307. }
  10308. return 0;
  10309. }
  10310. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10311. if (!lua_interface)
  10312. return 0;
  10313. Spawn* spawn = lua_interface->GetSpawn(state);
  10314. bool invul = lua_interface->GetBooleanValue(state, 2);
  10315. lua_interface->ResetFunctionStack(state);
  10316. if (spawn) {
  10317. spawn->SetInvulnerable(invul);
  10318. }
  10319. return 0;
  10320. }
  10321. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10322. if (!lua_interface)
  10323. return 0;
  10324. string category = lua_interface->GetStringValue(state);
  10325. string name = lua_interface->GetStringValue(state, 2);
  10326. lua_interface->ResetFunctionStack(state);
  10327. Rule *ret = 0;
  10328. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10329. lua_interface->SetBooleanValue(state, ret->GetBool());
  10330. return 1;
  10331. }
  10332. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10333. return 0;
  10334. }
  10335. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10336. if (!lua_interface)
  10337. return 0;
  10338. string category = lua_interface->GetStringValue(state);
  10339. string name = lua_interface->GetStringValue(state, 2);
  10340. lua_interface->ResetFunctionStack(state);
  10341. Rule *ret = 0;
  10342. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10343. lua_interface->SetInt32Value(state, ret->GetInt32());
  10344. return 1;
  10345. }
  10346. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10347. return 0;
  10348. }
  10349. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10350. if (!lua_interface)
  10351. return 0;
  10352. string category = lua_interface->GetStringValue(state);
  10353. string name = lua_interface->GetStringValue(state, 2);
  10354. lua_interface->ResetFunctionStack(state);
  10355. Rule *ret = 0;
  10356. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10357. lua_interface->SetFloatValue(state, ret->GetFloat());
  10358. return 1;
  10359. }
  10360. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10361. return 0;
  10362. }
  10363. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10364. if (!lua_interface)
  10365. return 0;
  10366. Spawn* spawn = lua_interface->GetSpawn(state);
  10367. string type = lua_interface->GetStringValue(state, 2);
  10368. lua_interface->ResetFunctionStack(state);
  10369. if (spawn) {
  10370. int res = 1;
  10371. boost::to_lower(type);
  10372. if(type == "assigned_aa")
  10373. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10374. else if ( type == "unassigned_aa")
  10375. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10376. else if ( type == "assigned_tradeskill_aa")
  10377. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10378. else if ( type == "unassigned_tradeskill_aa")
  10379. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10380. else if ( type == "assigned_prestige_aa")
  10381. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10382. else if ( type == "unassigned_prestige_aa")
  10383. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10384. else if ( type == "assigned_tradeskill_prestige_aa")
  10385. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10386. else if ( type == "unassigned_tradeskill_prestige_aa")
  10387. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10388. else
  10389. res = 0;
  10390. return res;
  10391. }
  10392. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10393. return 0;
  10394. }
  10395. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10396. if (!lua_interface)
  10397. return 0;
  10398. Spawn* spawn = lua_interface->GetSpawn(state);
  10399. string type = lua_interface->GetStringValue(state, 2);
  10400. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10401. lua_interface->ResetFunctionStack(state);
  10402. if (spawn) {
  10403. boost::to_lower(type);
  10404. if(type == "assigned_aa")
  10405. spawn->SetAssignedAA((sint16)value);
  10406. else if ( type == "unassigned_aa")
  10407. spawn->SetUnassignedAA((sint16)value);
  10408. else if ( type == "assigned_tradeskill_aa")
  10409. spawn->SetTradeskillAA((sint16)value);
  10410. else if ( type == "unassigned_tradeskill_aa")
  10411. spawn->SetUnassignedTradeskillAA((sint16)value);
  10412. else if ( type == "assigned_prestige_aa")
  10413. spawn->SetPrestigeAA((sint16)value);
  10414. else if ( type == "unassigned_prestige_aa")
  10415. spawn->SetUnassignedPrestigeAA((sint16)value);
  10416. else if ( type == "assigned_tradeskill_prestige_aa")
  10417. spawn->SetTradeskillPrestigeAA((sint16)value);
  10418. else if ( type == "unassigned_tradeskill_prestige_aa")
  10419. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10420. if(spawn->IsPlayer())
  10421. ((Player*)spawn)->SetCharSheetChanged(true);
  10422. }
  10423. return 0;
  10424. }
  10425. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10426. if (!lua_interface)
  10427. return 0;
  10428. string titleName = lua_interface->GetStringValue(state);
  10429. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10430. lua_interface->ResetFunctionStack(state);
  10431. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10432. lua_interface->SetSInt32Value(state, index);
  10433. return 1;
  10434. }
  10435. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10436. if (!lua_interface)
  10437. return 0;
  10438. Spawn* spawn = lua_interface->GetSpawn(state);
  10439. string titleName = lua_interface->GetStringValue(state, 2);
  10440. lua_interface->ResetFunctionStack(state);
  10441. if(!spawn->IsPlayer())
  10442. {
  10443. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10444. lua_interface->SetSInt32Value(state, -1);
  10445. return 1;
  10446. }
  10447. Player* player = (Player*)spawn;
  10448. // check if player already has the title, don't need to add twice
  10449. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10450. if ( playerHasTitle)
  10451. {
  10452. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10453. return 1;
  10454. }
  10455. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10456. if(!title)
  10457. {
  10458. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10459. lua_interface->SetSInt32Value(state, -1);
  10460. return 1;
  10461. }
  10462. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10463. if(returnIdx < 0)
  10464. {
  10465. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10466. }
  10467. lua_interface->SetSInt32Value(state, returnIdx);
  10468. player->GetClient()->SendTitleUpdate();
  10469. return 1;
  10470. }
  10471. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10472. if (!lua_interface)
  10473. return 0;
  10474. Spawn* spawn = lua_interface->GetSpawn(state);
  10475. string titleName = lua_interface->GetStringValue(state, 2);
  10476. lua_interface->ResetFunctionStack(state);
  10477. if(!spawn->IsPlayer())
  10478. {
  10479. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10480. return 0;
  10481. }
  10482. Player* player = (Player*)spawn;
  10483. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10484. if(!title)
  10485. {
  10486. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10487. return 0;
  10488. }
  10489. if(title->GetPrefix())
  10490. {
  10491. 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());
  10492. return 0;
  10493. }
  10494. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10495. player->GetClient()->SendTitleUpdate();
  10496. return 1;
  10497. }
  10498. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10499. if (!lua_interface)
  10500. return 0;
  10501. Spawn* spawn = lua_interface->GetSpawn(state);
  10502. string titleName = lua_interface->GetStringValue(state, 2);
  10503. lua_interface->ResetFunctionStack(state);
  10504. if(!spawn->IsPlayer())
  10505. {
  10506. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10507. return 0;
  10508. }
  10509. Player* player = (Player*)spawn;
  10510. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10511. if(!title)
  10512. {
  10513. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10514. return 0;
  10515. }
  10516. if(!title->GetPrefix())
  10517. {
  10518. 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());
  10519. return 0;
  10520. }
  10521. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10522. player->GetClient()->SendTitleUpdate();
  10523. return 1;
  10524. }
  10525. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10526. if (!lua_interface)
  10527. return 0;
  10528. Spawn* spawn = lua_interface->GetSpawn(state);
  10529. lua_interface->ResetFunctionStack(state);
  10530. if(!spawn->IsPlayer())
  10531. {
  10532. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10533. return 0;
  10534. }
  10535. Player* player = (Player*)spawn;
  10536. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10537. player->GetClient()->SendTitleUpdate();
  10538. return 1;
  10539. }
  10540. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10541. if (!lua_interface)
  10542. return 0;
  10543. Spawn* spawn = lua_interface->GetSpawn(state);
  10544. lua_interface->ResetFunctionStack(state);
  10545. if(!spawn->IsPlayer())
  10546. {
  10547. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10548. return 0;
  10549. }
  10550. Player* player = (Player*)spawn;
  10551. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10552. player->GetClient()->SendTitleUpdate();
  10553. return 1;
  10554. }
  10555. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10556. if (!lua_interface)
  10557. return 0;
  10558. Spawn* spawn = lua_interface->GetSpawn(state);
  10559. string field = lua_interface->GetStringValue(state, 2);
  10560. lua_interface->ResetFunctionStack(state);
  10561. if(!spawn || !spawn->IsEntity())
  10562. {
  10563. 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));
  10564. return 0;
  10565. }
  10566. Entity* ent = (Entity*)spawn;
  10567. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10568. return 1;
  10569. }
  10570. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10571. if (!lua_interface)
  10572. return 0;
  10573. Spawn* spawn = lua_interface->GetSpawn(state);
  10574. string field = lua_interface->GetStringValue(state, 2);
  10575. lua_interface->ResetFunctionStack(state);
  10576. if(!spawn || !spawn->IsEntity())
  10577. {
  10578. 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));
  10579. return 0;
  10580. }
  10581. Entity* ent = (Entity*)spawn;
  10582. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10583. return 1;
  10584. }
  10585. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10586. if (!lua_interface)
  10587. return 0;
  10588. Spawn* spawn = lua_interface->GetSpawn(state);
  10589. string field = lua_interface->GetStringValue(state, 2);
  10590. lua_interface->ResetFunctionStack(state);
  10591. if(!spawn || !spawn->IsEntity())
  10592. {
  10593. 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));
  10594. return 0;
  10595. }
  10596. Entity* ent = (Entity*)spawn;
  10597. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10598. return 1;
  10599. }
  10600. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10601. if (!lua_interface)
  10602. return 0;
  10603. Spawn* spawn = lua_interface->GetSpawn(state);
  10604. string field = lua_interface->GetStringValue(state, 2);
  10605. lua_interface->ResetFunctionStack(state);
  10606. if(!spawn || !spawn->IsEntity())
  10607. {
  10608. 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));
  10609. return 0;
  10610. }
  10611. Entity* ent = (Entity*)spawn;
  10612. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10613. return 1;
  10614. }
  10615. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10616. if (!lua_interface)
  10617. return 0;
  10618. Spawn* spawn = lua_interface->GetSpawn(state);
  10619. string field = lua_interface->GetStringValue(state, 2);
  10620. string value = lua_interface->GetStringValue(state, 3);
  10621. lua_interface->ResetFunctionStack(state);
  10622. if(!spawn || !spawn->IsEntity())
  10623. {
  10624. 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));
  10625. return 0;
  10626. }
  10627. Entity* ent = (Entity*)spawn;
  10628. bool set_ = ent->SetInfoStructString(field, value);
  10629. lua_interface->SetBooleanValue(state, set_);
  10630. return 1;
  10631. }
  10632. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10633. if (!lua_interface)
  10634. return 0;
  10635. Spawn* spawn = lua_interface->GetSpawn(state);
  10636. string field = lua_interface->GetStringValue(state, 2);
  10637. int64 value = lua_interface->GetInt64Value(state, 3);
  10638. lua_interface->ResetFunctionStack(state);
  10639. if(!spawn || !spawn->IsEntity())
  10640. {
  10641. 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));
  10642. return 0;
  10643. }
  10644. Entity* ent = (Entity*)spawn;
  10645. bool set_ = ent->SetInfoStructUInt(field, value);
  10646. lua_interface->SetBooleanValue(state, set_);
  10647. return 1;
  10648. }
  10649. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10650. if (!lua_interface)
  10651. return 0;
  10652. Spawn* spawn = lua_interface->GetSpawn(state);
  10653. string field = lua_interface->GetStringValue(state, 2);
  10654. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10655. lua_interface->ResetFunctionStack(state);
  10656. if(!spawn || !spawn->IsEntity())
  10657. {
  10658. 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));
  10659. return 0;
  10660. }
  10661. Entity* ent = (Entity*)spawn;
  10662. bool set_ = ent->SetInfoStructSInt(field, value);
  10663. lua_interface->SetBooleanValue(state, set_);
  10664. return 1;
  10665. }
  10666. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10667. if (!lua_interface)
  10668. return 0;
  10669. Spawn* spawn = lua_interface->GetSpawn(state);
  10670. string field = lua_interface->GetStringValue(state, 2);
  10671. float value = lua_interface->GetFloatValue(state, 3);
  10672. lua_interface->ResetFunctionStack(state);
  10673. if(!spawn || !spawn->IsEntity())
  10674. {
  10675. 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));
  10676. return 0;
  10677. }
  10678. Entity* ent = (Entity*)spawn;
  10679. bool set_ = ent->SetInfoStructFloat(field, value);
  10680. lua_interface->SetBooleanValue(state, set_);
  10681. return 1;
  10682. }
  10683. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10684. if (!lua_interface)
  10685. return 0;
  10686. Spawn* spawn = lua_interface->GetSpawn(state);
  10687. bool value = lua_interface->GetBooleanValue(state, 2);
  10688. lua_interface->ResetFunctionStack(state);
  10689. if(!spawn || !spawn->IsPlayer())
  10690. {
  10691. 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));
  10692. return 0;
  10693. }
  10694. ((Player*)spawn)->SetCharSheetChanged(value);
  10695. return 0;
  10696. }
  10697. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10698. if (!lua_interface)
  10699. return 0;
  10700. Spawn* spawn = lua_interface->GetSpawn(state);
  10701. std::string fromName = lua_interface->GetStringValue(state, 2);
  10702. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10703. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10704. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10705. int32 copper = lua_interface->GetInt32Value(state, 6);
  10706. int32 silver = lua_interface->GetInt32Value(state, 7);
  10707. int32 gold = lua_interface->GetInt32Value(state, 8);
  10708. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10709. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10710. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10711. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10712. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10713. lua_interface->ResetFunctionStack(state);
  10714. if(!spawn || !spawn->IsPlayer())
  10715. {
  10716. 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));
  10717. lua_interface->SetBooleanValue(state, false);
  10718. return 1;
  10719. }
  10720. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10721. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10722. lua_interface->SetBooleanValue(state, true);
  10723. return 1;
  10724. }
  10725. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10726. if (!lua_interface)
  10727. return 0;
  10728. int32 char_id = lua_interface->GetInt32Value(state);
  10729. std::string fromName = lua_interface->GetStringValue(state, 2);
  10730. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10731. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10732. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10733. int32 copper = lua_interface->GetInt32Value(state, 6);
  10734. int32 silver = lua_interface->GetInt32Value(state, 7);
  10735. int32 gold = lua_interface->GetInt32Value(state, 8);
  10736. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10737. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10738. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10739. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10740. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10741. lua_interface->ResetFunctionStack(state);
  10742. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10743. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10744. lua_interface->SetBooleanValue(state, true);
  10745. return 1;
  10746. }
  10747. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10748. Spawn* widget;
  10749. if (lua_interface) {
  10750. widget = lua_interface->GetSpawn(state);
  10751. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10752. lua_interface->ResetFunctionStack(state);
  10753. if (widget && widget->IsWidget())
  10754. {
  10755. ((Widget*)widget)->OpenDoor();
  10756. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10757. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10758. }
  10759. else
  10760. 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));
  10761. }
  10762. return 0;
  10763. }
  10764. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10765. Spawn* widget;
  10766. if (lua_interface) {
  10767. widget = lua_interface->GetSpawn(state);
  10768. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10769. lua_interface->ResetFunctionStack(state);
  10770. if (widget && widget->IsWidget())
  10771. {
  10772. ((Widget*)widget)->CloseDoor();
  10773. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10774. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10775. }
  10776. else
  10777. 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));
  10778. }
  10779. return 0;
  10780. }
  10781. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10782. if (!lua_interface)
  10783. return 0;
  10784. Spawn* widget = lua_interface->GetSpawn(state);
  10785. lua_interface->ResetFunctionStack(state);
  10786. if (widget && widget->IsWidget())
  10787. {
  10788. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10789. return 1;
  10790. }
  10791. return 0;
  10792. }
  10793. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10794. if (!lua_interface)
  10795. return 0;
  10796. sint32 min = lua_interface->GetSInt32Value(state);
  10797. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10798. lua_interface->ResetFunctionStack(state);
  10799. sint32 result = MakeRandomInt(min, max);
  10800. lua_interface->SetSInt32Value(state, result);
  10801. return 1;
  10802. }
  10803. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10804. if (!lua_interface)
  10805. return 0;
  10806. float min = lua_interface->GetFloatValue(state);
  10807. float max = lua_interface->GetFloatValue(state, 2);
  10808. lua_interface->ResetFunctionStack(state);
  10809. float result = MakeRandomFloat(min, max);
  10810. lua_interface->SetFloatValue(state, result);
  10811. return 1;
  10812. }
  10813. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10814. if (!lua_interface)
  10815. return 0;
  10816. Spawn* spawn = lua_interface->GetSpawn(state);
  10817. int32 value = lua_interface->GetInt32Value(state, 2);
  10818. lua_interface->ResetFunctionStack(state);
  10819. if(!spawn)
  10820. {
  10821. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10822. lua_interface->SetBooleanValue(state, false);
  10823. return 1;
  10824. }
  10825. spawn->AddIconValue(value);
  10826. lua_interface->SetBooleanValue(state, true);
  10827. return 1;
  10828. }
  10829. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10830. if (!lua_interface)
  10831. return 0;
  10832. Spawn* spawn = lua_interface->GetSpawn(state);
  10833. int32 value = lua_interface->GetInt32Value(state, 2);
  10834. lua_interface->ResetFunctionStack(state);
  10835. if(!spawn)
  10836. {
  10837. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10838. lua_interface->SetBooleanValue(state, false);
  10839. return 1;
  10840. }
  10841. spawn->RemoveIconValue(value);
  10842. lua_interface->SetBooleanValue(state, true);
  10843. return 1;
  10844. }
  10845. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10846. Spawn* npc = lua_interface->GetSpawn(state);
  10847. lua_interface->ResetFunctionStack(state);
  10848. if (npc && npc->IsNPC()) {
  10849. NPC* shard = (NPC*)npc;
  10850. int32 shardid = shard->GetShardID();
  10851. lua_interface->SetInt32Value(state, shardid);
  10852. return 1;
  10853. }
  10854. lua_interface->SetInt32Value(state, 0);
  10855. return 1;
  10856. }
  10857. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10858. Spawn* npc = lua_interface->GetSpawn(state);
  10859. lua_interface->ResetFunctionStack(state);
  10860. if (npc && npc->IsNPC()) {
  10861. NPC* shard = (NPC*)npc;
  10862. int32 charid = shard->GetShardCharID();
  10863. lua_interface->SetInt32Value(state, charid);
  10864. return 1;
  10865. }
  10866. lua_interface->SetInt32Value(state, 0);
  10867. return 1;
  10868. }
  10869. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10870. Spawn* npc = lua_interface->GetSpawn(state);
  10871. lua_interface->ResetFunctionStack(state);
  10872. if (npc && npc->IsNPC()) {
  10873. NPC* shard = (NPC*)npc;
  10874. int64 timestamp = shard->GetShardCreatedTimestamp();
  10875. lua_interface->SetSInt64Value(state, timestamp);
  10876. return 1;
  10877. }
  10878. lua_interface->SetSInt64Value(state, 0);
  10879. return 1;
  10880. }
  10881. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10882. if (!lua_interface)
  10883. return 0;
  10884. int32 shardid = lua_interface->GetInt32Value(state);
  10885. lua_interface->ResetFunctionStack(state);
  10886. if(shardid < 1)
  10887. lua_interface->SetBooleanValue(state, false);
  10888. else
  10889. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10890. return 1;
  10891. }
  10892. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10893. if (!lua_interface)
  10894. return 0;
  10895. Spawn* spawn = lua_interface->GetSpawn(state);
  10896. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10897. if (spawn) {
  10898. spawn->PauseMovement(delay_in_ms);
  10899. }
  10900. lua_interface->ResetFunctionStack(state);
  10901. return 0;
  10902. }
  10903. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10904. if (!lua_interface)
  10905. return 0;
  10906. Spawn* spawn = lua_interface->GetSpawn(state);
  10907. if (spawn) {
  10908. spawn->StopMovement();
  10909. }
  10910. lua_interface->ResetFunctionStack(state);
  10911. return 0;
  10912. }
  10913. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10914. Player* player = (Player*)lua_interface->GetSpawn(state);
  10915. int8 level = lua_interface->GetInt8Value(state, 2);
  10916. lua_interface->ResetFunctionStack(state);
  10917. if (player && player->IsPlayer() && level > 0) {
  10918. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10919. return 1;
  10920. }
  10921. return 0;
  10922. }
  10923. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10924. Player* player = (Player*)lua_interface->GetSpawn(state);
  10925. int8 level = lua_interface->GetInt8Value(state, 2);
  10926. lua_interface->ResetFunctionStack(state);
  10927. if (player && player->IsPlayer() && level > 0) {
  10928. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10929. return 1;
  10930. }
  10931. return 0;
  10932. }
  10933. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10934. ZoneServer* zone = lua_interface->GetZone(state);
  10935. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10936. lua_interface->ResetFunctionStack(state);
  10937. if (zone) {
  10938. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10939. if (spawn) {
  10940. lua_interface->SetSpawnValue(state, spawn);
  10941. return 1;
  10942. }
  10943. }
  10944. return 0;
  10945. }
  10946. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10947. if (!lua_interface)
  10948. return 0;
  10949. Spawn* spawn = lua_interface->GetSpawn(state);
  10950. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10951. lua_interface->ResetFunctionStack(state);
  10952. bool res = false;
  10953. if(spawn && spawn->IsTransportSpawn())
  10954. {
  10955. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10956. spawn->SetRailID(rail_id);
  10957. res = true;
  10958. }
  10959. else if (!spawn) {
  10960. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10961. }
  10962. else if(!spawn->IsTransportSpawn()) {
  10963. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  10964. }
  10965. lua_interface->SetBooleanValue(state, res);
  10966. return 1;
  10967. }
  10968. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10969. if (!lua_interface)
  10970. return 0;
  10971. ZoneServer* zone = lua_interface->GetZone(state);
  10972. lua_interface->ResetFunctionStack(state);
  10973. if (zone) {
  10974. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10975. return 1;
  10976. }
  10977. return 0;
  10978. }
  10979. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10980. if (!lua_interface)
  10981. return 0;
  10982. Spawn* spawn = lua_interface->GetSpawn(state);
  10983. lua_interface->ResetFunctionStack(state);
  10984. if (spawn) {
  10985. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10986. return 1;
  10987. }
  10988. return 0;
  10989. }
  10990. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  10991. if (!lua_interface)
  10992. return 0;
  10993. Spawn* player = lua_interface->GetSpawn(state);
  10994. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  10995. bool displayClient = lua_interface->GetInt32Value(state, 3);
  10996. lua_interface->ResetFunctionStack(state);
  10997. if (!player || !player->IsPlayer() || !player->GetClient()) {
  10998. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  10999. }
  11000. else if(!zoneID) {
  11001. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11002. }
  11003. else
  11004. {
  11005. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11006. return 1;
  11007. }
  11008. return 0;
  11009. }
  11010. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11011. if (!lua_interface)
  11012. return 0;
  11013. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11014. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11015. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11016. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11017. lua_interface->ResetFunctionStack(state);
  11018. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11019. world.GetWorldTimeStruct()->year = newYear;
  11020. world.GetWorldTimeStruct()->month = newMonth;
  11021. world.GetWorldTimeStruct()->hour = newHour;
  11022. world.GetWorldTimeStruct()->minute = newMinute;
  11023. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11024. return 0;
  11025. }
  11026. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11027. if (!lua_interface)
  11028. return 0;
  11029. lua_interface->ResetFunctionStack(state);
  11030. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11031. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11032. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11033. return 1;
  11034. }
  11035. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11036. if (!lua_interface)
  11037. return 0;
  11038. lua_interface->ResetFunctionStack(state);
  11039. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11040. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11041. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11042. return 1;
  11043. }
  11044. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11045. if (!lua_interface)
  11046. return 0;
  11047. lua_interface->ResetFunctionStack(state);
  11048. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11049. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11050. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11051. return 1;
  11052. }
  11053. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11054. if (!lua_interface)
  11055. return 0;
  11056. lua_interface->ResetFunctionStack(state);
  11057. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11058. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11059. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11060. return 1;
  11061. }
  11062. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11063. if (!lua_interface)
  11064. return 0;
  11065. lua_interface->ResetFunctionStack(state);
  11066. world.SendTimeUpdate();
  11067. return 0;
  11068. }
  11069. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11070. bool update_result = false;
  11071. Faction* faction = 0;
  11072. Player* player = (Player*)lua_interface->GetSpawn(state);
  11073. Client* client = player->GetZone()->GetClientBySpawn(player);
  11074. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11075. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11076. lua_interface->ResetFunctionStack(state);
  11077. if (player && player->IsPlayer() && faction_id > 0) {
  11078. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11079. if(hasfaction == 0) {
  11080. //they do not have the faction. Lets get the default value and feed it in.
  11081. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11082. //add the default faction for the player.
  11083. player->SetFactionValue(faction_id, defaultfaction);
  11084. }
  11085. if(increase >= 0) {
  11086. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11087. faction = master_faction_list.GetFaction(faction_id);
  11088. if(faction && update_result)
  11089. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11090. else if(faction)
  11091. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11092. lua_interface->SetBooleanValue(state, true);
  11093. return 1;
  11094. }
  11095. if(increase < 0){
  11096. //change the negative to a positive, since thats how decreasefaction() likes it.
  11097. increase *= -1;
  11098. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11099. faction = master_faction_list.GetFaction(faction_id);
  11100. if(faction && update_result)
  11101. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11102. else if(faction)
  11103. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11104. lua_interface->SetBooleanValue(state, true);
  11105. return 1;
  11106. }
  11107. }
  11108. lua_interface->SetBooleanValue(state, false);
  11109. return 1;
  11110. }
  11111. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11112. bool hascoin = 0;
  11113. Player* player = (Player*)lua_interface->GetSpawn(state);
  11114. int32 coins = lua_interface->GetInt32Value(state, 2);
  11115. lua_interface->ResetFunctionStack(state);
  11116. if (player && player->IsPlayer()) {
  11117. hascoin = player->HasCoins(coins);
  11118. if(hascoin == 0) {
  11119. lua_interface->SetBooleanValue(state, false);
  11120. return 1;
  11121. }
  11122. if(hascoin == 1) {
  11123. lua_interface->SetBooleanValue(state, true);
  11124. return 1;
  11125. }
  11126. }
  11127. }
  11128. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11129. int32 loot_tier = 0;
  11130. Spawn* spawn = lua_interface->GetSpawn(state);
  11131. lua_interface->ResetFunctionStack(state);
  11132. if (spawn) {
  11133. loot_tier = spawn->GetLootTier();
  11134. lua_interface->SetInt32Value(state, loot_tier);
  11135. return 1;
  11136. }
  11137. return 0;
  11138. }
  11139. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11140. if (!lua_interface)
  11141. return 0;
  11142. Spawn* spawn = lua_interface->GetSpawn(state);
  11143. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11144. lua_interface->ResetFunctionStack(state);
  11145. if (spawn) {
  11146. spawn->SetLootTier(loot_tier);
  11147. lua_interface->SetBooleanValue(state, true);
  11148. return 1;
  11149. }
  11150. lua_interface->SetBooleanValue(state, false);
  11151. return 1;
  11152. }
  11153. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11154. int32 loot_drop_type = 0;
  11155. Spawn* spawn = lua_interface->GetSpawn(state);
  11156. lua_interface->ResetFunctionStack(state);
  11157. if (spawn) {
  11158. loot_drop_type = spawn->GetLootDropType();
  11159. lua_interface->SetInt32Value(state, loot_drop_type);
  11160. return 1;
  11161. }
  11162. return 0;
  11163. }
  11164. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11165. if (!lua_interface)
  11166. return 0;
  11167. Spawn* spawn = lua_interface->GetSpawn(state);
  11168. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11169. lua_interface->ResetFunctionStack(state);
  11170. if (spawn) {
  11171. spawn->SetLootDropType(loot_drop_type);
  11172. lua_interface->SetBooleanValue(state, true);
  11173. return 1;
  11174. }
  11175. lua_interface->SetBooleanValue(state, false);
  11176. return 1;
  11177. }