LuaFunctions.cpp 371 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. if (spawn) {
  156. const char* mp3 = 0;
  157. const char* text = 0;
  158. const char* emote = 0;
  159. if (mp3_string.length() > 0)
  160. mp3 = mp3_string.c_str();
  161. if (text_string.length() > 0)
  162. text = text_string.c_str();
  163. if (emote_string.length() > 0)
  164. emote = emote_string.c_str();
  165. Client* client = 0;
  166. if (player && player->IsPlayer())
  167. client = spawn->GetZone()->GetClientBySpawn(player);
  168. if (client) {
  169. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  170. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  171. }
  172. else
  173. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  174. }
  175. return 0;
  176. }
  177. int EQ2Emu_lua_PlaySound(lua_State* state) {
  178. if (!lua_interface)
  179. return 0;
  180. Spawn* spawn = lua_interface->GetSpawn(state);
  181. string sound_string = lua_interface->GetStringValue(state, 2);
  182. float x = lua_interface->GetFloatValue(state, 3);
  183. float y = lua_interface->GetFloatValue(state, 4);
  184. float z = lua_interface->GetFloatValue(state, 5);
  185. Spawn* player = lua_interface->GetSpawn(state, 6);
  186. if (spawn && sound_string.length() > 0) {
  187. Client* client = 0;
  188. if (player && player->IsPlayer())
  189. client = spawn->GetZone()->GetClientBySpawn(player);
  190. if (client)
  191. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  192. else
  193. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  194. }
  195. return 0;
  196. }
  197. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  202. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  203. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  204. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  205. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  206. if (!spawn) {
  207. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  208. return 0;
  209. }
  210. if (quest_id > 0) {
  211. //Add this quest to the list of required quests for this spawn
  212. spawn->SetQuestsRequired(quest_id, quest_step);
  213. //If private spawn value set
  214. if (private_spawn) {
  215. //Set the spawn to be private when not granted access through this quest
  216. spawn->AddAllowAccessSpawn(spawn);
  217. spawn->SetPrivateQuestSpawn(true);
  218. }
  219. //This value allows access after a quest step, or the whole quest has been completed
  220. if (continued_access)
  221. spawn->SetQuestsRequiredContinuedAccess(true);
  222. //This value will override vis_flags in the vis packet
  223. if (flag_override > 0)
  224. spawn->SetQuestsRequiredOverride(flag_override);
  225. }
  226. return 0;
  227. }
  228. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  229. if (!lua_interface)
  230. return 0;
  231. Spawn* spawn = lua_interface->GetSpawn(state);
  232. float max_distance = lua_interface->GetFloatValue(state, 2);
  233. string variable = lua_interface->GetStringValue(state, 3);
  234. string value = lua_interface->GetStringValue(state, 4);
  235. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  236. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  237. return 0;
  238. }
  239. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  240. if (!lua_interface)
  241. return 0;
  242. Client* client = 0;
  243. Spawn* player = lua_interface->GetSpawn(state);
  244. if (!player) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  246. return 0;
  247. }
  248. if (!player->IsPlayer()) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  250. return 0;
  251. }
  252. if (player->GetZone())
  253. client = player->GetZone()->GetClientBySpawn(player);
  254. if (!client) {
  255. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  256. return 0;
  257. }
  258. float intensity = lua_interface->GetFloatValue(state, 2);
  259. int8 direction = lua_interface->GetInt8Value(state, 3);
  260. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  261. if (packet) {
  262. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  263. v1 = *(float *)(a1 + 4);
  264. if ( v1 > 0.0 )
  265. v2 = fminf(v1, 1.0);
  266. else
  267. v2 = 0.1;
  268. */
  269. packet->setDataByName("intensity", intensity);
  270. if ( client->GetVersion() > 546 )
  271. packet->setDataByName("direction", direction);
  272. client->QueuePacket(packet->serialize());
  273. safe_delete(packet);
  274. }
  275. return 0;
  276. }
  277. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  278. if (!lua_interface)
  279. return 0;
  280. Spawn* dead = lua_interface->GetSpawn(state);
  281. Spawn* killer = lua_interface->GetSpawn(state, 2);
  282. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  283. if (dead && dead->Alive() && dead->GetZone())
  284. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  285. return 0;
  286. }
  287. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  288. if (!lua_interface)
  289. return 0;
  290. Spawn* spawn = lua_interface->GetSpawn(state);
  291. float max_distance = lua_interface->GetFloatValue(state, 2);
  292. bool include_players = lua_interface->GetInt8Value(state, 3);
  293. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  294. if (max_distance > 0 && spawn && spawn->GetZone())
  295. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  296. return 0;
  297. }
  298. int EQ2Emu_lua_Despawn(lua_State* state) {
  299. if (!lua_interface)
  300. return 0;
  301. Spawn* spawn = lua_interface->GetSpawn(state);
  302. int32 delay = lua_interface->GetInt32Value(state, 2);
  303. if (spawn && spawn->GetZone())
  304. spawn->GetZone()->Despawn(spawn, delay);
  305. return 0;
  306. }
  307. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* spawn = lua_interface->GetSpawn(state);
  311. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  312. if (spawn) {
  313. spawn->info_changed = true;
  314. spawn->SetShowHandIcon(displayHandIcon);
  315. }
  316. return 0;
  317. }
  318. //this function is used to force an update packet to be sent.
  319. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  320. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  321. if (!lua_interface)
  322. return 0;
  323. Spawn* spawn = lua_interface->GetSpawn(state);
  324. if (spawn) {
  325. spawn->vis_changed = true;
  326. spawn->GetZone()->AddChangedSpawn(spawn);
  327. }
  328. return 0;
  329. }
  330. //this function is used to force an update packet to be sent.
  331. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  332. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  333. if (!lua_interface)
  334. return 0;
  335. Spawn* spawn = lua_interface->GetSpawn(state);
  336. if (spawn) {
  337. spawn->info_changed = true;
  338. spawn->GetZone()->AddChangedSpawn(spawn);
  339. }
  340. return 0;
  341. }
  342. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. int32 new_state = lua_interface->GetInt32Value(state, 2);
  347. Spawn* player = lua_interface->GetSpawn(state, 3);
  348. lua_interface->ResetFunctionStack(state);
  349. if (spawn) {
  350. if(player)
  351. {
  352. if(player->IsPlayer())
  353. {
  354. Client* client = ((Player*)player)->GetClient();
  355. if(client)
  356. {
  357. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  358. lua_interface->SetBooleanValue(state, true);
  359. return 1;
  360. }
  361. else
  362. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  363. }
  364. else
  365. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  366. }
  367. else
  368. {
  369. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  370. lua_interface->SetBooleanValue(state, true);
  371. return 1;
  372. }
  373. }
  374. lua_interface->SetBooleanValue(state, false);
  375. return 1;
  376. }
  377. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. Spawn* spawn = lua_interface->GetSpawn(state);
  381. string variable = lua_interface->GetStringValue(state, 2);
  382. string value = lua_interface->GetStringValue(state, 3);
  383. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  384. bool temporary_flag = true;
  385. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  386. if(num_args >= 5)
  387. 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
  388. int32 type = commands.GetSpawnSetType(variable);
  389. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  390. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  391. return 0;
  392. }
  393. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  394. if (!lua_interface)
  395. return 0;
  396. Spawn* spawn = lua_interface->GetSpawn(state);
  397. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  398. if (spawn && spawn_id > 0) {
  399. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  400. if (closest_spawn) {
  401. lua_interface->SetSpawnValue(state, closest_spawn);
  402. return 1;
  403. }
  404. }
  405. return 0;
  406. }
  407. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  408. if (!lua_interface)
  409. return 0;
  410. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  411. int32 position = lua_interface->GetInt32Value(state, 2);
  412. if (spawnList) {
  413. if (spawnList->size() > position) {
  414. lua_interface->SetSpawnValue(state, spawnList->at(position));
  415. return 1;
  416. }
  417. else {
  418. return 0;
  419. }
  420. return spawnList->size();
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. if (spawnList) {
  429. return spawnList->size();
  430. }
  431. return 0;
  432. }
  433. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  434. if (!lua_interface)
  435. return 0;
  436. vector<Spawn*>* spawnList = new vector<Spawn*>();
  437. lua_interface->SetSpawnListValue(state, spawnList);
  438. return 1;
  439. }
  440. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  441. if (!lua_interface)
  442. return 0;
  443. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  444. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  445. if (spawnList) {
  446. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  447. if (it == spawnList->end())
  448. spawnList->push_back(spawn);
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  456. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  457. if (spawnList) {
  458. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  459. if(it != spawnList->end())
  460. spawnList->erase(it);
  461. }
  462. return 0;
  463. }
  464. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  465. if (!lua_interface)
  466. return 0;
  467. Spawn* spawn = lua_interface->GetSpawn(state);
  468. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  469. if (spawn) {
  470. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  471. if (spawns.size() > 0) {
  472. vector<Spawn*>* spawnList = new vector<Spawn*>();
  473. vector<Spawn*>::iterator itr;
  474. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  475. spawnList->push_back(*itr);
  476. }
  477. lua_interface->SetSpawnListValue(state, spawnList);
  478. return 1;
  479. }
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. string variable_name = lua_interface->GetStringValue(state);
  487. Variable* var = variables.FindVariable(variable_name);
  488. if (var) {
  489. lua_interface->SetStringValue(state, var->GetValue());
  490. return 1;
  491. }
  492. return 0;
  493. }
  494. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  495. if (!lua_interface)
  496. return 0;
  497. int32 total_coins = lua_interface->GetInt32Value(state);
  498. if (total_coins == 0) {
  499. lua_interface->SetStringValue(state, "0 copper");
  500. return 1;
  501. }
  502. char tmp[64] = { 0 };
  503. string message = "";
  504. int32 val = 0;
  505. if (total_coins >= 1000000) {
  506. val = total_coins / 1000000;
  507. total_coins -= 1000000 * val;
  508. sprintf(tmp, " %u Platinum", val);
  509. message.append(tmp);
  510. memset(tmp, 0, 64);
  511. }
  512. if (total_coins >= 10000) {
  513. val = total_coins / 10000;
  514. total_coins -= 10000 * val;
  515. sprintf(tmp, " %u Gold", val);
  516. message.append(tmp);
  517. memset(tmp, 0, 64);
  518. }
  519. if (total_coins >= 100) {
  520. val = total_coins / 100;
  521. total_coins -= 100 * val;
  522. sprintf(tmp, " %u Silver", val);
  523. message.append(tmp);
  524. memset(tmp, 0, 64);
  525. }
  526. if (total_coins > 0) {
  527. sprintf(tmp, " %u Copper", (int32)total_coins);
  528. message.append(tmp);
  529. }
  530. lua_interface->SetStringValue(state, message.c_str());
  531. return 1;
  532. }
  533. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  534. ZoneServer* zone = lua_interface->GetZone(state);
  535. int32 group_id = lua_interface->GetInt32Value(state, 2);
  536. if (zone) {
  537. Spawn* spawn = zone->GetSpawnGroup(group_id);
  538. if (spawn) {
  539. lua_interface->SetSpawnValue(state, spawn);
  540. return 1;
  541. }
  542. }
  543. return 0;
  544. }
  545. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  546. ZoneServer* zone = lua_interface->GetZone(state);
  547. int32 location_id = lua_interface->GetInt32Value(state, 2);
  548. if (zone) {
  549. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  550. if (spawn) {
  551. lua_interface->SetSpawnValue(state, spawn);
  552. return 1;
  553. }
  554. }
  555. return 0;
  556. }
  557. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  558. Spawn* spawn = lua_interface->GetSpawn(state);
  559. if (spawn) {
  560. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  561. return 1;
  562. }
  563. return 0;
  564. }
  565. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  566. Spawn* spawn = lua_interface->GetSpawn(state);
  567. if (spawn) {
  568. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  569. return 1;
  570. }
  571. return 0;
  572. }
  573. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  574. if (!lua_interface)
  575. return 0;
  576. Spawn* spawn = lua_interface->GetSpawn(state);
  577. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  578. lua_interface->ResetFunctionStack(state);
  579. if (spawn) {
  580. spawn->SetSpawnGroupID(new_group_id);
  581. lua_interface->SetBooleanValue(state, true);
  582. return 1;
  583. }
  584. lua_interface->SetBooleanValue(state, false);
  585. return 1;
  586. }
  587. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  588. if (!lua_interface)
  589. return 0;
  590. Spawn* spawn = lua_interface->GetSpawn(state);
  591. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  592. lua_interface->ResetFunctionStack(state);
  593. if (spawn) {
  594. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  595. lua_interface->SetBooleanValue(state, true);
  596. return 1;
  597. }
  598. lua_interface->SetBooleanValue(state, false);
  599. return 1;
  600. }
  601. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  602. Spawn* spawn = lua_interface->GetSpawn(state);
  603. if (spawn) {
  604. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  605. return 1;
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  610. Spawn* spawn = lua_interface->GetSpawn(state);
  611. if (spawn) {
  612. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  613. return 1;
  614. }
  615. return 0;
  616. }
  617. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  618. Player* player = (Player*)lua_interface->GetSpawn(state);
  619. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  620. if (player && player->IsPlayer() && faction_id > 0) {
  621. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  622. return 1;
  623. }
  624. return 0;
  625. }
  626. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  627. if (!lua_interface)
  628. return 0;
  629. Spawn* spawn = lua_interface->GetSpawn(state);
  630. int32 value = lua_interface->GetInt32Value(state, 2);
  631. if (spawn) {
  632. spawn->SetFactionID(value);
  633. }
  634. return 0;
  635. }
  636. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  637. Spawn* spawn = lua_interface->GetSpawn(state);
  638. if (spawn) {
  639. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  640. return 1;
  641. }
  642. return 0;
  643. }
  644. int EQ2Emu_lua_GetGender(lua_State* state) {
  645. Spawn* spawn = lua_interface->GetSpawn(state);
  646. if (spawn) {
  647. lua_interface->SetInt32Value(state, spawn->GetGender());
  648. return 1;
  649. }
  650. return 0;
  651. }
  652. int EQ2Emu_lua_GetTarget(lua_State* state) {
  653. Spawn* spawn = lua_interface->GetSpawn(state);
  654. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  655. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  656. return 1;
  657. }
  658. return 0;
  659. }
  660. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  661. if (!lua_interface)
  662. return 0;
  663. Spawn* spawn = lua_interface->GetSpawn(state);
  664. string mp3_string = lua_interface->GetStringValue(state, 2);
  665. int32 key1 = lua_interface->GetInt32Value(state, 3);
  666. int32 key2 = lua_interface->GetInt32Value(state, 4);
  667. Spawn* player = lua_interface->GetSpawn(state, 5);
  668. if (spawn && mp3_string.length() > 0) {
  669. Client* client = 0;
  670. if (player && player->IsPlayer())
  671. client = spawn->GetZone()->GetClientBySpawn(player);
  672. if (client) {
  673. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  674. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  675. }
  676. else
  677. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  678. }
  679. return 0;
  680. }
  681. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  682. if (!lua_interface)
  683. return 0;
  684. Spawn* spawn = lua_interface->GetSpawn(state);
  685. if (spawn) {
  686. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  687. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  688. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  689. return 3;
  690. }
  691. return 0;
  692. }
  693. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  694. if (!lua_interface)
  695. return 0;
  696. Spawn* spawn = lua_interface->GetSpawn(state);
  697. if (spawn) {
  698. int32 item_id = lua_interface->GetInt32Value(state, 2);
  699. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  700. return 1;
  701. }
  702. return 0;
  703. }
  704. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  705. if (!lua_interface)
  706. return 0;
  707. Spawn* spawn = lua_interface->GetSpawn(state);
  708. if (spawn && spawn->IsEntity()) {
  709. int32 item_id = lua_interface->GetInt32Value(state, 2);
  710. int16 charges = lua_interface->GetInt16Value(state, 3);
  711. if (charges == 0)
  712. charges = 1;
  713. ((Entity*)spawn)->AddLootItem(item_id, charges);
  714. }
  715. return 0;
  716. }
  717. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  718. if (!lua_interface)
  719. return 0;
  720. Spawn* spawn = lua_interface->GetSpawn(state);
  721. if (spawn && spawn->IsEntity()) {
  722. int32 item_id = lua_interface->GetInt32Value(state, 2);
  723. Item* item = spawn->LootItem(item_id);
  724. safe_delete(item);
  725. }
  726. return 0;
  727. }
  728. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  729. if (!lua_interface)
  730. return 0;
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. if (spawn) {
  733. int32 val = lua_interface->GetInt32Value(state, 2);
  734. spawn->AddLootCoins(val);
  735. }
  736. return 0;
  737. }
  738. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  739. if (!lua_interface)
  740. return 0;
  741. Spawn* entity = lua_interface->GetSpawn(state);
  742. Spawn* player = lua_interface->GetSpawn(state, 2);
  743. if (entity && player && player->IsPlayer()) {
  744. int32 coins = lua_interface->GetInt32Value(state, 3);
  745. vector<Item*>* items = 0;
  746. int i = 0;
  747. int32 item_id = 0;
  748. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  749. if (items == 0)
  750. items = new vector<Item*>;
  751. if (master_item_list.GetItem(item_id))
  752. items->push_back(master_item_list.GetItem(item_id));
  753. i++;
  754. }
  755. Client* client = 0;
  756. client = player->GetZone()->GetClientBySpawn(player);
  757. if (client)
  758. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  759. if(coins > 0)
  760. entity->AddLootCoins(coins);
  761. safe_delete(items);
  762. }
  763. return 0;
  764. }
  765. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  766. if (!lua_interface)
  767. return 0;
  768. Spawn* entity = lua_interface->GetSpawn(state);
  769. Spawn* player = lua_interface->GetSpawn(state, 2);
  770. int32 item_id = lua_interface->GetInt32Value(state, 3);
  771. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  772. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  773. return 1;
  774. }
  775. return 0;
  776. }
  777. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  778. if (!lua_interface)
  779. return 0;
  780. Spawn* entity = lua_interface->GetSpawn(state);
  781. Spawn* player = lua_interface->GetSpawn(state, 2);
  782. if (entity && player && player->IsPlayer()) {
  783. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  784. return 1;
  785. }
  786. return 0;
  787. }
  788. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  789. if (!lua_interface)
  790. return 0;
  791. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  792. safe_delete(conversation);
  793. conversation = new vector<ConversationOption>();
  794. lua_interface->SetConversationValue(state, conversation);
  795. return 1;
  796. }
  797. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  798. if (!lua_interface)
  799. return 0;
  800. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  801. if (conversation) {
  802. ConversationOption conv_option;
  803. conv_option.option = lua_interface->GetStringValue(state, 2);
  804. conv_option.function = lua_interface->GetStringValue(state, 3);
  805. if (conv_option.option.length() > 0)
  806. conversation->push_back(conv_option);
  807. }
  808. return 0;
  809. }
  810. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  811. if (!lua_interface)
  812. return 0;
  813. Spawn* npc = lua_interface->GetSpawn(state);
  814. Spawn* player = lua_interface->GetSpawn(state, 2);
  815. if (npc && player && player->IsPlayer() && player->GetZone()) {
  816. Client* client = player->GetZone()->GetClientBySpawn(player);
  817. if (client) {
  818. int32 conversation_id = client->GetConversationID(npc, 0);
  819. client->CloseDialog(conversation_id);
  820. }
  821. }
  822. return 0;
  823. }
  824. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  825. if (!lua_interface)
  826. return 0;
  827. Item* item = lua_interface->GetItem(state);
  828. Spawn* player = lua_interface->GetSpawn(state, 2);
  829. if (item && player && player->IsPlayer() && player->GetZone()) {
  830. Client* client = player->GetZone()->GetClientBySpawn(player);
  831. if (client) {
  832. int32 conversation_id = client->GetConversationID(0, item);
  833. client->CloseDialog(conversation_id);
  834. }
  835. }
  836. return 0;
  837. }
  838. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  839. if (!lua_interface)
  840. return 0;
  841. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  842. Spawn* spawn = 0;
  843. Item* item = 0;
  844. int8 type = lua_interface->GetInt8Value(state, 2);
  845. if (type == 1 || type == 3)
  846. spawn = lua_interface->GetSpawn(state, 3);
  847. else if (type == 2 || type == 4)
  848. item = lua_interface->GetItem(state, 3);
  849. Spawn* player = lua_interface->GetSpawn(state, 4);
  850. string text = lua_interface->GetStringValue(state, 5);
  851. string mp3 = lua_interface->GetStringValue(state, 6);
  852. int32 key1 = lua_interface->GetInt32Value(state, 7);
  853. int32 key2 = lua_interface->GetInt32Value(state, 8);
  854. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  855. Client* client = player->GetZone()->GetClientBySpawn(player);
  856. if (client) {
  857. if (spawn) {
  858. // Need to do this so the function works the same as it did before
  859. if (type == 1)
  860. type++;
  861. if (mp3.length() > 0)
  862. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  863. else
  864. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  865. }
  866. else {
  867. if (mp3.length() > 0)
  868. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  869. else
  870. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  871. }
  872. }
  873. }
  874. safe_delete(conversation);
  875. lua_interface->SetConversationValue(state, NULL);
  876. return 0;
  877. }
  878. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  879. if(!lua_interface)
  880. return 0;
  881. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  882. Item* item = lua_interface->GetItem(state, 2);
  883. Spawn* player = lua_interface->GetSpawn(state, 3);
  884. string text = lua_interface->GetStringValue(state, 4);
  885. string mp3 = lua_interface->GetStringValue(state, 5);
  886. int32 key1 = lua_interface->GetInt32Value(state, 6);
  887. int32 key2 = lua_interface->GetInt32Value(state, 7);
  888. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  889. Client* client = player->GetZone()->GetClientBySpawn(player);
  890. if(client){
  891. if(mp3.length() > 0)
  892. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  893. else
  894. client->DisplayConversation(item, conversation, (char*)text.c_str());
  895. }
  896. safe_delete(conversation);
  897. }
  898. return 0;
  899. }*/
  900. int EQ2Emu_lua_StartConversation(lua_State* state) {
  901. if (!lua_interface)
  902. return 0;
  903. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  904. Spawn* source = lua_interface->GetSpawn(state, 2);
  905. Spawn* player = lua_interface->GetSpawn(state, 3);
  906. string text = lua_interface->GetStringValue(state, 4);
  907. string mp3 = lua_interface->GetStringValue(state, 5);
  908. int32 key1 = lua_interface->GetInt32Value(state, 6);
  909. int32 key2 = lua_interface->GetInt32Value(state, 7);
  910. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  911. Client* client = source->GetZone()->GetClientBySpawn(player);
  912. if (mp3.length() > 0)
  913. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  914. else
  915. client->DisplayConversation(source, 1, conversation, text.c_str());
  916. safe_delete(conversation);
  917. lua_interface->SetConversationValue(state, NULL);
  918. }
  919. else
  920. 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);
  921. return 0;
  922. }
  923. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  924. if (!lua_interface)
  925. return 0;
  926. Spawn* spawn = lua_interface->GetSpawn(state);
  927. float distance = lua_interface->GetFloatValue(state, 2);
  928. string in_range_function = lua_interface->GetStringValue(state, 3);
  929. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  930. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  931. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  932. return 0;
  933. }
  934. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  935. ZoneServer* zone = lua_interface->GetZone(state);
  936. float x = lua_interface->GetFloatValue(state, 2);
  937. float y = lua_interface->GetFloatValue(state, 3);
  938. float z = lua_interface->GetFloatValue(state, 4);
  939. float max_variation = lua_interface->GetFloatValue(state, 5);
  940. string in_range_function = lua_interface->GetStringValue(state, 6);
  941. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  942. if (zone && in_range_function.length() > 0)
  943. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  944. return 0;
  945. }
  946. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  947. if (!lua_interface)
  948. return 0;
  949. Spawn* spawn = lua_interface->GetSpawn(state);
  950. if (spawn && spawn->IsEntity()) {
  951. int32 val = lua_interface->GetInt32Value(state, 2);
  952. ((Entity*)spawn)->SetLootCoins(val);
  953. }
  954. return 0;
  955. }
  956. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  957. if (!lua_interface)
  958. return 0;
  959. Spawn* spawn = lua_interface->GetSpawn(state);
  960. if (spawn && spawn->IsEntity()) {
  961. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  962. return 1;
  963. }
  964. return 0;
  965. }
  966. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  967. if (!lua_interface)
  968. return 0;
  969. Spawn* spawn = lua_interface->GetSpawn(state);
  970. float x = lua_interface->GetFloatValue(state, 2);
  971. float y = lua_interface->GetFloatValue(state, 3);
  972. float z = lua_interface->GetFloatValue(state, 4);
  973. float speed = lua_interface->GetFloatValue(state, 5);
  974. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  975. string function = lua_interface->GetStringValue(state, 7);
  976. if (spawn) {
  977. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  978. spawn->GetZone()->AddMovementNPC(spawn);
  979. }
  980. lua_interface->ResetFunctionStack(state);
  981. return 0;
  982. }
  983. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  984. if (!lua_interface)
  985. return 0;
  986. Spawn* spawn = lua_interface->GetSpawn(state);
  987. if (spawn) {
  988. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  989. return 1;
  990. }
  991. return 0;
  992. }
  993. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  994. if (!lua_interface)
  995. return 0;
  996. Spawn* spawn = lua_interface->GetSpawn(state);
  997. if (spawn && spawn->IsPlayer()) {
  998. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  999. return 1;
  1000. }
  1001. lua_interface->SetInt32Value(state, 0);
  1002. return 1;
  1003. }
  1004. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1005. if (!lua_interface)
  1006. return 0;
  1007. Spawn* spawn = lua_interface->GetSpawn(state);
  1008. Spawn* target = lua_interface->GetSpawn(state, 2);
  1009. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1010. bool reset_action_state = true;
  1011. if(num_args > 2)
  1012. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1013. if (spawn && target) {
  1014. if (spawn->IsEntity())
  1015. // ((Entity*)spawn)->FaceTarget(target);
  1016. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1017. }
  1018. lua_interface->ResetFunctionStack(state);
  1019. return 0;
  1020. }
  1021. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1022. if (!lua_interface)
  1023. return 0;
  1024. Spawn* spawn = lua_interface->GetSpawn(state);
  1025. float x = lua_interface->GetFloatValue(state, 2);
  1026. float y = lua_interface->GetFloatValue(state, 3);
  1027. float z = lua_interface->GetFloatValue(state, 4);
  1028. float speed = lua_interface->GetFloatValue(state, 5);
  1029. string lua_function = lua_interface->GetStringValue(state, 6);
  1030. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1031. if (spawn) {
  1032. if (speed == 0)
  1033. speed = spawn->GetSpeed();
  1034. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1035. }
  1036. lua_interface->ResetFunctionStack(state);
  1037. return 0;
  1038. }
  1039. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1040. if (!lua_interface)
  1041. return 0;
  1042. Spawn* spawn = lua_interface->GetSpawn(state);
  1043. if (spawn) {
  1044. spawn->ClearRunningLocations();
  1045. }
  1046. return 0;
  1047. }
  1048. int EQ2Emu_lua_Say(lua_State* state) {
  1049. if (!lua_interface)
  1050. return 0;
  1051. Spawn* spawn = lua_interface->GetSpawn(state);
  1052. string message = lua_interface->GetStringValue(state, 2);
  1053. Spawn* player = lua_interface->GetSpawn(state, 3);
  1054. int32 language = lua_interface->GetInt32Value(state, 4);
  1055. if (spawn && message.length() > 0) {
  1056. Client* client = 0;
  1057. if (player && player->IsPlayer())
  1058. client = spawn->GetZone()->GetClientBySpawn(player);
  1059. if (client)
  1060. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1061. else
  1062. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1063. }
  1064. lua_interface->ResetFunctionStack(state);
  1065. return 0;
  1066. }
  1067. int EQ2Emu_lua_Shout(lua_State* state) {
  1068. if (!lua_interface)
  1069. return 0;
  1070. Spawn* spawn = lua_interface->GetSpawn(state);
  1071. string message = lua_interface->GetStringValue(state, 2);
  1072. Spawn* player = lua_interface->GetSpawn(state, 3);
  1073. if (spawn && message.length() > 0) {
  1074. Client* client = 0;
  1075. if (player && player->IsPlayer())
  1076. client = spawn->GetZone()->GetClientBySpawn(player);
  1077. if (client)
  1078. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1079. else
  1080. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1081. }
  1082. lua_interface->ResetFunctionStack(state);
  1083. return 0;
  1084. }
  1085. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1086. if (!lua_interface)
  1087. return 0;
  1088. Spawn* spawn = lua_interface->GetSpawn(state);
  1089. string message = lua_interface->GetStringValue(state, 2);
  1090. Spawn* player = lua_interface->GetSpawn(state, 3);
  1091. if (spawn && message.length() > 0) {
  1092. Client* client = 0;
  1093. if (player && player->IsPlayer())
  1094. client = spawn->GetZone()->GetClientBySpawn(player);
  1095. if (client)
  1096. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1097. else
  1098. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1099. }
  1100. lua_interface->ResetFunctionStack(state);
  1101. return 0;
  1102. }
  1103. int EQ2Emu_lua_Emote(lua_State* state) {
  1104. if (!lua_interface)
  1105. return 0;
  1106. Spawn* spawn = lua_interface->GetSpawn(state);
  1107. string message = lua_interface->GetStringValue(state, 2);
  1108. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1109. Spawn* player = lua_interface->GetSpawn(state, 4);
  1110. char* to = 0;
  1111. if (spawn2)
  1112. to = spawn2->GetName();
  1113. if (spawn && message.length() > 0) {
  1114. Client* client = 0;
  1115. if (player && player->IsPlayer())
  1116. client = spawn->GetZone()->GetClientBySpawn(player);
  1117. if (client)
  1118. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1119. else
  1120. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1121. }
  1122. lua_interface->ResetFunctionStack(state);
  1123. return 0;
  1124. }
  1125. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1126. if (!lua_interface)
  1127. return 0;
  1128. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1129. if (!luaspell)
  1130. return 0;
  1131. Spawn* caster = luaspell->caster;
  1132. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1133. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1134. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1135. Spawn* target = lua_interface->GetSpawn(state, 4);
  1136. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1137. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1138. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1139. lua_interface->ResetFunctionStack(state);
  1140. boost::to_lower(heal_type);
  1141. if (caster && caster->IsEntity()) {
  1142. bool success = false;
  1143. luaspell->resisted = false;
  1144. if (target) {
  1145. float distance = caster->GetDistance(target, true);
  1146. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1147. success = true;
  1148. }
  1149. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1150. Spawn* target = 0;
  1151. ZoneServer* zone = luaspell->caster->GetZone();
  1152. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1153. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1154. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1155. float distance = caster->GetDistance(target, true);
  1156. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1157. }
  1158. }
  1159. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1160. success = true;
  1161. }
  1162. if (success) {
  1163. if (caster->GetZone())
  1164. caster->GetZone()->TriggerCharSheetTimer();
  1165. }
  1166. }
  1167. return 0;
  1168. }
  1169. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1170. if (!lua_interface)
  1171. return 0;
  1172. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1173. if (!luaspell)
  1174. return 0;
  1175. Spawn* caster = luaspell->caster;
  1176. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1177. float percentage = lua_interface->GetFloatValue(state, 2);
  1178. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1179. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1180. Spawn* target = lua_interface->GetSpawn(state, 5);
  1181. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1182. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1183. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1184. lua_interface->ResetFunctionStack(state);
  1185. boost::to_lower(heal_type);
  1186. int32 min_heal = 0, max_heal = 0;
  1187. if (caster && caster->IsEntity() && target) {
  1188. if(percentage <= 0.0f)
  1189. {
  1190. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1191. return 0;
  1192. }
  1193. if(heal_type == "power")
  1194. {
  1195. if(current_value)
  1196. {
  1197. if(caster_value)
  1198. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1199. else
  1200. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1201. }
  1202. else
  1203. {
  1204. if(caster_value)
  1205. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1206. else
  1207. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1208. }
  1209. }
  1210. else
  1211. {
  1212. if(current_value)
  1213. {
  1214. if(caster_value)
  1215. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1216. else
  1217. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1218. }
  1219. else
  1220. {
  1221. if(caster_value)
  1222. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1223. else
  1224. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1225. }
  1226. }
  1227. bool success = false;
  1228. luaspell->resisted = false;
  1229. if (target) {
  1230. float distance = caster->GetDistance(target, true);
  1231. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1232. success = true;
  1233. }
  1234. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1235. Spawn* target = 0;
  1236. ZoneServer* zone = luaspell->caster->GetZone();
  1237. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1238. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1239. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1240. float distance = caster->GetDistance(target, true);
  1241. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1242. }
  1243. }
  1244. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1245. success = true;
  1246. }
  1247. if (success) {
  1248. if (caster->GetZone())
  1249. caster->GetZone()->TriggerCharSheetTimer();
  1250. }
  1251. }
  1252. return 0;
  1253. }
  1254. int EQ2Emu_lua_AddItem(lua_State* state) {
  1255. if (!lua_interface)
  1256. return 0;
  1257. Spawn* spawn = lua_interface->GetSpawn(state);
  1258. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1259. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1260. // default of 1 quantity to add
  1261. if (quantity == 0)
  1262. quantity = 1;
  1263. if (spawn && spawn->IsPlayer()) {
  1264. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1265. if (client && item_id > 0) {
  1266. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1267. return 1;
  1268. }
  1269. }
  1270. lua_interface->SetBooleanValue(state, false);
  1271. return 1;
  1272. }
  1273. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1274. if (!lua_interface)
  1275. return 0;
  1276. Spawn* spawn = lua_interface->GetSpawn(state);
  1277. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1278. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1279. string location = lua_interface->GetStringValue(state, 4);
  1280. if (spawn && spawn->IsPlayer()) {
  1281. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1282. if (client && item_id > 0) {
  1283. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1284. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1285. else
  1286. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1287. if (send_messages) {
  1288. Item* item = master_item_list.GetItem(item_id);
  1289. if (item) {
  1290. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1291. string popup_text = "You receive " + item->name;
  1292. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1293. }
  1294. }
  1295. return 1;
  1296. }
  1297. }
  1298. lua_interface->SetBooleanValue(state, false);
  1299. return 1;
  1300. }
  1301. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1302. Spawn* spawn = lua_interface->GetSpawn(state);
  1303. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1304. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1305. // default of 1 to remove
  1306. if (quantity == 0)
  1307. quantity = 1;
  1308. Client* client;
  1309. Item* item;
  1310. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1311. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1312. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1313. if (client->RemoveItem(item, quantity)) {
  1314. lua_interface->SetBooleanValue(state, true);
  1315. return 1;
  1316. }
  1317. }
  1318. }
  1319. }
  1320. lua_interface->SetBooleanValue(state, false);
  1321. return 1;
  1322. }
  1323. int EQ2Emu_lua_HasItem(lua_State* state) {
  1324. Spawn* player = lua_interface->GetSpawn(state);
  1325. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1326. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1327. if (player && player->IsPlayer()) {
  1328. bool hasItem = false;
  1329. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1330. if (!hasItem)
  1331. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1332. lua_interface->SetBooleanValue(state, hasItem);
  1333. return 1;
  1334. }
  1335. lua_interface->SetBooleanValue(state, false);
  1336. return 1;
  1337. }
  1338. int EQ2Emu_lua_Spawn(lua_State* state) {
  1339. if (!lua_interface)
  1340. return 0;
  1341. ZoneServer* zone = lua_interface->GetZone(state);
  1342. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1343. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1344. float x = lua_interface->GetFloatValue(state, 4);
  1345. float y = lua_interface->GetFloatValue(state, 5);
  1346. float z = lua_interface->GetFloatValue(state, 6);
  1347. float heading = lua_interface->GetFloatValue(state, 7);
  1348. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1349. Spawn* spawn = zone->GetSpawn(spawn_id);
  1350. if (!spawn)
  1351. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1352. else {
  1353. spawn->SetX(x);
  1354. spawn->SetZ(z);
  1355. spawn->SetY(y,true,true);
  1356. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1357. spawn->SetHeading(heading);
  1358. if (restricted_npc)
  1359. spawn->AddAllowAccessSpawn(spawn);
  1360. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1361. bool scriptActive = false;
  1362. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1363. scriptActive = true;
  1364. spawn->SetSpawnScript(string(spawn_script));
  1365. }
  1366. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1367. zone->AddSpawn(spawn);
  1368. if (scriptActive) {
  1369. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1370. }
  1371. lua_interface->SetSpawnValue(state, spawn);
  1372. return 1;
  1373. }
  1374. }
  1375. else {
  1376. string output = "Invalid paramaters to LUA Spawn command: \n";
  1377. if (!zone)
  1378. output = output.append("\t").append("Missing zone reference. \n");
  1379. if (spawn_id == 0)
  1380. output = output.append("\t").append("Missing spawn_id.");
  1381. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1382. }
  1383. return 0;
  1384. }
  1385. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1386. if (!lua_interface)
  1387. return 0;
  1388. ZoneServer* zone = lua_interface->GetZone(state);
  1389. if (zone) {
  1390. lua_interface->SetStringValue(state, zone->GetZoneName());
  1391. return 1;
  1392. }
  1393. return 0;
  1394. }
  1395. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1396. if (!lua_interface)
  1397. return 0;
  1398. ZoneServer* zone = lua_interface->GetZone(state);
  1399. if (zone) {
  1400. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1401. return 1;
  1402. }
  1403. return 0;
  1404. }
  1405. int EQ2Emu_lua_GetZone(lua_State* state) {
  1406. if (!lua_interface)
  1407. return 0;
  1408. int32 zone_id = lua_interface->GetInt32Value(state);
  1409. ZoneServer* zone = 0;
  1410. if (zone_id > 0)
  1411. zone = zone_list.Get(zone_id);
  1412. else {
  1413. string zone_name = lua_interface->GetStringValue(state);
  1414. if (zone_name.length() > 0) {
  1415. zone = zone_list.Get(zone_name.c_str());
  1416. }
  1417. else {
  1418. Spawn* spawn = lua_interface->GetSpawn(state);
  1419. if (spawn)
  1420. zone = spawn->GetZone();
  1421. }
  1422. }
  1423. if (zone) {
  1424. lua_interface->SetZoneValue(state, zone);
  1425. return 1;
  1426. }
  1427. return 0;
  1428. }
  1429. int EQ2Emu_lua_AddHate(lua_State* state) {
  1430. Spawn* entity = lua_interface->GetSpawn(state);
  1431. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1432. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1433. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1434. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1435. if (entity && entity->IsEntity() && amount != 0) {
  1436. if (luaspell) {
  1437. ZoneServer* zone = luaspell->caster->GetZone();
  1438. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1439. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1440. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1441. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1442. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1443. if (send_packet)
  1444. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1445. }
  1446. }
  1447. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1448. }
  1449. else if (npc && npc->IsNPC() && npc->GetZone())
  1450. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1451. }
  1452. return 0;
  1453. }
  1454. int EQ2Emu_lua_Zone(lua_State* state) {
  1455. if (!lua_interface)
  1456. return 0;
  1457. ZoneServer* zone = lua_interface->GetZone(state);
  1458. Spawn* player = lua_interface->GetSpawn(state, 2);
  1459. Client* client = 0;
  1460. if (player && player->IsPlayer())
  1461. client = player->GetZone()->GetClientBySpawn(player);
  1462. float x = lua_interface->GetFloatValue(state, 3);
  1463. float y = lua_interface->GetFloatValue(state, 4);
  1464. float z = lua_interface->GetFloatValue(state, 5);
  1465. float heading = lua_interface->GetFloatValue(state, 6);
  1466. if (zone && client) {
  1467. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1468. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1469. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1470. {
  1471. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1472. return 0;
  1473. }
  1474. if (x != 0 || y != 0 || z != 0) {
  1475. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1476. player->SetX(x);
  1477. player->SetY(y);
  1478. player->SetZ(z);
  1479. player->SetHeading(heading);
  1480. client->Zone(zone->GetZoneName(), false);
  1481. }
  1482. else
  1483. client->Zone(zone->GetZoneName());
  1484. }
  1485. else
  1486. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1487. return 0;
  1488. }
  1489. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1490. if (!lua_interface)
  1491. return 0;
  1492. Spawn* spawn = lua_interface->GetSpawn(state);
  1493. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1494. if (spawn && spawn2)
  1495. spawn->AddAllowAccessSpawn(spawn2);
  1496. return 0;
  1497. }
  1498. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1499. if (!lua_interface)
  1500. return 0;
  1501. Spawn* target = lua_interface->GetSpawn(state);
  1502. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1503. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1504. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1505. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1506. if (!target) {
  1507. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1508. return 0;
  1509. }
  1510. if (!target->IsEntity()) {
  1511. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1512. return 0;
  1513. }
  1514. if (spell_id <= 0) {
  1515. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1516. return 0;
  1517. }
  1518. if (caster && !caster->IsEntity()) {
  1519. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1520. return 0;
  1521. }
  1522. if (spell_tier == 0)
  1523. spell_tier = 1;
  1524. if (!caster)
  1525. caster = target;
  1526. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1527. return 0;
  1528. }
  1529. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1530. if (!lua_interface)
  1531. return 0;
  1532. Spawn* target = lua_interface->GetSpawn(state);
  1533. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1534. if (!luaspell)
  1535. return 0;
  1536. Spawn* caster = luaspell->caster;
  1537. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1538. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1539. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1540. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1541. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1542. //lua_interface->ResetFunctionStack(state);
  1543. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1544. vector<int16> faction_req;
  1545. vector<int16> race_req;
  1546. int32 class_req = 0;
  1547. int32 i = 0;
  1548. int8 f = 0;
  1549. int8 r = 0;
  1550. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1551. if (class_id < 100) {
  1552. class_req += pow(2.0, double(class_id - 1));
  1553. }
  1554. else if (class_id > 100 && class_id < 1000) {
  1555. race_req.push_back(class_id);
  1556. r++;
  1557. }
  1558. else {
  1559. faction_req.push_back(class_id);
  1560. f++;
  1561. }
  1562. i++;
  1563. }
  1564. if (caster && caster->IsEntity()) {
  1565. bool race_match = false;
  1566. bool success = false;
  1567. luaspell->resisted = false;
  1568. if (luaspell->targets.size() > 0) {
  1569. ZoneServer* zone = luaspell->caster->GetZone();
  1570. Spawn* target = 0;
  1571. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1572. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1573. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1574. if (race_req.size() > 0) {
  1575. for (int8 i = 0; i < race_req.size(); i++) {
  1576. if (target->GetLuaRaceId() == race_req[i]) {
  1577. race_match = true;
  1578. }
  1579. }
  1580. }
  1581. else
  1582. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1583. if (race_match == true) {
  1584. float distance = caster->GetDistance(target, true);
  1585. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1586. }
  1587. }
  1588. }
  1589. success = true;
  1590. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1591. }
  1592. else if (target) {
  1593. //check class and race/faction here
  1594. if (race_req.size() > 0) {
  1595. for (int8 i = 0; i < race_req.size(); i++) {
  1596. if (target->GetLuaRaceId() == race_req[i]) {
  1597. race_match = true;
  1598. }
  1599. }
  1600. }
  1601. else
  1602. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1603. if (race_match == true) {
  1604. float distance = caster->GetDistance(target, true);
  1605. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1606. success = true;
  1607. }
  1608. }
  1609. if (success) {
  1610. Spell* spell = luaspell->spell;
  1611. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1612. ((Player*)caster)->InCombat(true);
  1613. if (caster->GetZone())
  1614. caster->GetZone()->TriggerCharSheetTimer();
  1615. }
  1616. }
  1617. }
  1618. return 0;
  1619. }
  1620. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1621. if (!lua_interface)
  1622. return 0;
  1623. Spawn* spawn = lua_interface->GetSpawn(state);
  1624. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1625. lua_interface->ResetFunctionStack(state);
  1626. if (spawn && value != 0) {
  1627. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1628. spawn->SetPower(spawn->GetTotalPower());
  1629. else
  1630. spawn->SetPower(spawn->GetPower() + value);
  1631. }
  1632. return 0;
  1633. }
  1634. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1635. if (!lua_interface)
  1636. return 0;
  1637. Spawn* spawn = lua_interface->GetSpawn(state);
  1638. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1639. lua_interface->ResetFunctionStack(state);
  1640. if (spawn && value != 0) {
  1641. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1642. spawn->SetHP(spawn->GetTotalHP());
  1643. else
  1644. spawn->SetHP(spawn->GetHP() + value);
  1645. }
  1646. return 0;
  1647. }
  1648. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1649. if (!lua_interface)
  1650. return 0;
  1651. Spawn* spawn = lua_interface->GetSpawn(state);
  1652. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1653. lua_interface->ResetFunctionStack(state);
  1654. if (spawn && value != 0) {
  1655. spawn->SetPower(spawn->GetPower() + value);
  1656. if (value > spawn->GetTotalHPBase())
  1657. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1658. }
  1659. return 0;
  1660. }
  1661. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1662. if (!lua_interface)
  1663. return 0;
  1664. Spawn* spawn = lua_interface->GetSpawn(state);
  1665. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1666. lua_interface->ResetFunctionStack(state);
  1667. if (spawn && value != 0) {
  1668. spawn->SetHP(spawn->GetHP() + value);
  1669. if (value > spawn->GetTotalHPBase())
  1670. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1671. }
  1672. return 0;
  1673. }
  1674. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1675. if (!lua_interface)
  1676. return 0;
  1677. Spawn* spawn = lua_interface->GetSpawn(state);
  1678. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1679. lua_interface->ResetFunctionStack(state);
  1680. if (spawn) {
  1681. spawn->SetHP(value);
  1682. if (value > spawn->GetTotalHPBase())
  1683. spawn->SetTotalHP(value);
  1684. }
  1685. return 0;
  1686. }
  1687. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1688. if (!lua_interface)
  1689. return 0;
  1690. Spawn* spawn = lua_interface->GetSpawn(state);
  1691. float value = lua_interface->GetFloatValue(state, 2);
  1692. lua_interface->ResetFunctionStack(state);
  1693. if (spawn && spawn->IsEntity() && value > 0)
  1694. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1695. if (spawn->IsPlayer())
  1696. ((Player*)spawn)->SetCharSheetChanged(true);
  1697. return 0;
  1698. }
  1699. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1700. if (!lua_interface)
  1701. return 0;
  1702. Spawn* spawn = lua_interface->GetSpawn(state);
  1703. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1704. lua_interface->ResetFunctionStack(state);
  1705. if (spawn && spawn->IsEntity() && value > 0)
  1706. ((Entity*)spawn)->SetTotalHPBase(value);
  1707. return 0;
  1708. }
  1709. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1710. if (!lua_interface)
  1711. return 0;
  1712. Spawn* spawn = lua_interface->GetSpawn(state);
  1713. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1714. lua_interface->ResetFunctionStack(state);
  1715. if (spawn && value > 0) {
  1716. spawn->SetPower(value);
  1717. if (value > spawn->GetTotalPowerBase())
  1718. spawn->SetTotalPower(value);
  1719. }
  1720. return 0;
  1721. }
  1722. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1723. if (!lua_interface)
  1724. return 0;
  1725. Spawn* spawn = lua_interface->GetSpawn(state);
  1726. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1727. lua_interface->ResetFunctionStack(state);
  1728. if (spawn && spawn->IsEntity() && value > 0)
  1729. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1730. return 0;
  1731. }
  1732. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1733. if (!lua_interface)
  1734. return 0;
  1735. Spawn* spawn = lua_interface->GetSpawn(state);
  1736. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1737. lua_interface->ResetFunctionStack(state);
  1738. if (spawn && spawn->IsEntity() && value > 0)
  1739. ((Entity*)spawn)->SetTotalPowerBase(value);
  1740. return 0;
  1741. }
  1742. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1743. if (!lua_interface)
  1744. return 0;
  1745. Spawn* spawn = lua_interface->GetSpawn(state);
  1746. float x = lua_interface->GetFloatValue(state, 2);
  1747. float y = lua_interface->GetFloatValue(state, 3);
  1748. float z = lua_interface->GetFloatValue(state, 4);
  1749. float heading = lua_interface->GetFloatValue(state, 5);
  1750. lua_interface->ResetFunctionStack(state);
  1751. if (spawn) {
  1752. spawn->SetX(x);
  1753. spawn->SetY(y);
  1754. spawn->SetZ(z);
  1755. if (heading != 0)
  1756. spawn->SetHeading(heading);
  1757. spawn->SetSpawnOrigX(spawn->GetX());
  1758. spawn->SetSpawnOrigY(spawn->GetY());
  1759. spawn->SetSpawnOrigZ(spawn->GetZ());
  1760. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1761. if (spawn->IsPlayer()) {
  1762. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1763. if (client) {
  1764. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1765. client->QueuePacket(packet);
  1766. }
  1767. }
  1768. }
  1769. return 0;
  1770. }
  1771. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1772. if (!lua_interface)
  1773. return 0;
  1774. Spawn* spawn = lua_interface->GetSpawn(state);
  1775. float value = lua_interface->GetFloatValue(state, 2);
  1776. lua_interface->ResetFunctionStack(state);
  1777. if (spawn) {
  1778. spawn->SetHeading(value);
  1779. if (spawn->IsPlayer()) {
  1780. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1781. if (client) {
  1782. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1783. client->QueuePacket(packet);
  1784. }
  1785. }
  1786. }
  1787. return 0;
  1788. }
  1789. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1790. if (!lua_interface)
  1791. return 0;
  1792. Spawn* spawn = lua_interface->GetSpawn(state);
  1793. int16 value = lua_interface->GetInt16Value(state, 2);
  1794. lua_interface->ResetFunctionStack(state);
  1795. if (spawn)
  1796. spawn->SetModelType(value);
  1797. return 0;
  1798. }
  1799. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1800. if (!lua_interface)
  1801. return 0;
  1802. Spawn* spawn = lua_interface->GetSpawn(state);
  1803. int8 value = lua_interface->GetInt8Value(state, 2);
  1804. lua_interface->ResetFunctionStack(state);
  1805. if (spawn) {
  1806. if (spawn->IsPlayer())
  1807. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1808. else
  1809. spawn->SetAdventureClass(value);
  1810. }
  1811. return 0;
  1812. }
  1813. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1814. if (!lua_interface)
  1815. return 0;
  1816. Spawn* spawn = lua_interface->GetSpawn(state);
  1817. int8 value = lua_interface->GetInt8Value(state, 2);
  1818. lua_interface->ResetFunctionStack(state);
  1819. if (spawn) {
  1820. spawn->SetTradeskillClass(value);
  1821. if (spawn->IsEntity()) {
  1822. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1823. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1824. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1825. }
  1826. if (spawn->IsPlayer())
  1827. ((Player*)spawn)->SetCharSheetChanged(true);
  1828. }
  1829. return 0;
  1830. }
  1831. int EQ2Emu_lua_SetMount(lua_State* state) {
  1832. if (!lua_interface)
  1833. return 0;
  1834. Spawn* spawn = lua_interface->GetSpawn(state);
  1835. int16 value = lua_interface->GetInt16Value(state, 2);
  1836. if (spawn && spawn->IsEntity()) {
  1837. ((Entity*)spawn)->SetMount(value);
  1838. EQ2_Color color;
  1839. color.red = 255;
  1840. color.green = 255;
  1841. color.blue = 255;
  1842. ((Entity*)spawn)->SetMountColor(&color);
  1843. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1844. }
  1845. return 0;
  1846. }
  1847. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1848. if (!lua_interface)
  1849. return 0;
  1850. Spawn* spawn = lua_interface->GetSpawn(state);
  1851. EQ2_Color mount_color;
  1852. EQ2_Color saddle_color;
  1853. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1854. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1855. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1856. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1857. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1858. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1859. if (spawn && spawn->IsEntity()) {
  1860. ((Entity*)spawn)->SetMountColor(&mount_color);
  1861. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1862. }
  1863. return 0;
  1864. }
  1865. int EQ2Emu_lua_GetMount(lua_State* state) {
  1866. if (!lua_interface)
  1867. return 0;
  1868. Spawn* spawn = lua_interface->GetSpawn(state);
  1869. if (spawn && spawn->IsEntity()) {
  1870. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1871. return 1;
  1872. }
  1873. return 0;
  1874. }
  1875. int EQ2Emu_lua_GetRace(lua_State* state) {
  1876. if (!lua_interface)
  1877. return 0;
  1878. Spawn* spawn = lua_interface->GetSpawn(state);
  1879. if (spawn)
  1880. {
  1881. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1882. lua_interface->SetInt32Value(state, spawn->GetRace());
  1883. return 1;
  1884. }
  1885. return 0;
  1886. }
  1887. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1888. if (!lua_interface)
  1889. return 0;
  1890. Spawn* spawn = lua_interface->GetSpawn(state);
  1891. if (spawn) {
  1892. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1893. return 1;
  1894. }
  1895. return 0;
  1896. }
  1897. int EQ2Emu_lua_GetClass(lua_State* state) {
  1898. Spawn* spawn = lua_interface->GetSpawn(state);
  1899. if (spawn) {
  1900. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1901. return 1;
  1902. }
  1903. return 0;
  1904. }
  1905. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1906. Spawn* spawn = lua_interface->GetSpawn(state);
  1907. if (spawn) {
  1908. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1909. return 1;
  1910. }
  1911. return 0;
  1912. }
  1913. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1914. if (!lua_interface)
  1915. return 0;
  1916. Spawn* spawn = lua_interface->GetSpawn(state);
  1917. float value = lua_interface->GetFloatValue(state, 2);
  1918. lua_interface->ResetFunctionStack(state);
  1919. if (spawn) {
  1920. spawn->SetSpeed(value);
  1921. ((Entity*)spawn)->SetSpeed(value);
  1922. if (spawn->IsPlayer()) {
  1923. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1924. if (client) {
  1925. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1926. if (packet) {
  1927. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1928. packet->setDataByName("speed", value);
  1929. packet->setDataByName("size", 0.51);
  1930. EQ2Packet* app = packet->serialize();
  1931. client->QueuePacket(app);
  1932. safe_delete(packet);
  1933. }
  1934. }
  1935. }
  1936. }
  1937. return 0;
  1938. }
  1939. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1940. if (!lua_interface)
  1941. return 0;
  1942. Spawn* spawn = lua_interface->GetSpawn(state);
  1943. const int16 type = lua_interface->GetInt16Value(state, 2);
  1944. const float value = lua_interface->GetFloatValue(state, 3);
  1945. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1946. int64 class_req = 0;
  1947. int32 class_id = 0;
  1948. vector<int16> faction_req;
  1949. vector<int16> race_req;
  1950. int32 i = 0;
  1951. int8 f = 0;
  1952. int8 r = 0;
  1953. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1954. if (class_id < 100) {
  1955. class_req += pow(2.0, double(class_id - 1));
  1956. }
  1957. else if (class_id > 100 && class_id < 1000) {
  1958. race_req.push_back(class_id);
  1959. r++;
  1960. }
  1961. else {
  1962. faction_req.push_back(class_id);
  1963. f++;
  1964. }
  1965. i++;
  1966. }
  1967. if (value != 0 && type >= 0) {
  1968. if (luaspell && luaspell->spell && luaspell->caster) {
  1969. ZoneServer* zone = luaspell->caster->GetZone();
  1970. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1971. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1972. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1973. if (target) {
  1974. if (target->IsPlayer()) {
  1975. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1976. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1977. if (((Player*)target)->GetGroupMemberInfo())
  1978. ((Player*)target)->UpdateGroupMemberInfo();
  1979. ((Player*)target)->SetCharSheetChanged(true);
  1980. }
  1981. else if (target->IsNPC())
  1982. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1983. else
  1984. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1985. }
  1986. }
  1987. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1988. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1989. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1990. }
  1991. else if (spawn && spawn->IsEntity()) {
  1992. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1993. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1994. if (spawn->IsPlayer())
  1995. ((Player*)spawn)->SetCharSheetChanged(true);
  1996. }
  1997. else
  1998. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1999. }
  2000. else
  2001. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2002. return 0;
  2003. }
  2004. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2005. if (!lua_interface)
  2006. return 0;
  2007. Spawn* spawn = lua_interface->GetSpawn(state);
  2008. int16 type = lua_interface->GetInt16Value(state, 2);
  2009. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2010. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2011. if (!spawn) {
  2012. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2013. return 0;
  2014. }
  2015. if (!spawn->IsEntity()) {
  2016. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2017. return 0;
  2018. }
  2019. if (value == 0) {
  2020. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2021. return 0;
  2022. }
  2023. if (!luaspell || !luaspell->spell) {
  2024. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2025. return 0;
  2026. }
  2027. int32 class_req = 0;
  2028. vector<int16> faction_req;
  2029. vector<int16> race_req;
  2030. int32 class_id = 0;
  2031. int32 i = 0;
  2032. int8 f = 0;
  2033. int8 r = 0;
  2034. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2035. if (class_id < 100) {
  2036. class_req += pow(2.0, double(class_id - 1));
  2037. }
  2038. else if (class_id > 100 && class_id < 1000) {
  2039. race_req.push_back(class_id);
  2040. r++;
  2041. }
  2042. else {
  2043. faction_req.push_back(class_id);
  2044. f++;
  2045. }
  2046. i++;
  2047. }
  2048. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2049. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2050. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2051. if (spawn->IsPlayer())
  2052. ((Player*)spawn)->SetCharSheetChanged(true);
  2053. return 0;
  2054. }
  2055. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2056. if (!lua_interface)
  2057. return 0;
  2058. Spawn* spawn = lua_interface->GetSpawn(state);
  2059. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2060. if (!spawn) {
  2061. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2062. return 0;
  2063. }
  2064. if (!spawn->IsEntity()) {
  2065. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2066. return 0;
  2067. }
  2068. if (!luaspell || !luaspell->spell) {
  2069. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2070. return 0;
  2071. }
  2072. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2073. if (spawn->IsPlayer())
  2074. ((Player*)spawn)->SetCharSheetChanged(true);
  2075. return 0;
  2076. }
  2077. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2078. if (!lua_interface)
  2079. return 0;
  2080. Spawn* spawn = lua_interface->GetSpawn(state);
  2081. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2082. if (luaspell && luaspell->spell) {
  2083. ZoneServer* zone = luaspell->caster->GetZone();
  2084. Spawn* target = 0;
  2085. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2086. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2087. target = zone->GetSpawnByID(luaspell->targets[i]);
  2088. if (target && target->IsEntity()) {
  2089. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2090. if (target->IsPlayer())
  2091. ((Player*)target)->SetCharSheetChanged(true);
  2092. }
  2093. }
  2094. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2095. }
  2096. else if (spawn && spawn->IsEntity()) {
  2097. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2098. if (spawn->IsPlayer())
  2099. ((Player*)spawn)->SetCharSheetChanged(true);
  2100. }
  2101. return 0;
  2102. }
  2103. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2104. if (!lua_interface)
  2105. return 0;
  2106. Spawn* spawn = lua_interface->GetSpawn(state);
  2107. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2108. float value = lua_interface->GetFloatValue(state, 3);
  2109. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2110. if (value != 0) {
  2111. int32 spell_id = 0;
  2112. if (luaspell && luaspell->spell && luaspell->caster) {
  2113. spell_id = luaspell->spell->GetSpellID();
  2114. ZoneServer* zone = luaspell->caster->GetZone();
  2115. Spawn* target = 0;
  2116. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2117. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2118. target = zone->GetSpawnByID(luaspell->targets[i]);
  2119. if (target && target->Alive()) {
  2120. if (target->IsPlayer()) {
  2121. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2122. Client* client = target->GetZone()->GetClientBySpawn(target);
  2123. if (client) {
  2124. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2125. if (packet)
  2126. client->QueuePacket(packet);
  2127. }
  2128. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2129. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2130. }
  2131. else if (target->IsNPC()) {
  2132. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2133. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2134. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2135. }
  2136. else
  2137. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2138. }
  2139. }
  2140. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2141. }
  2142. else if (spawn) {
  2143. if (spawn->IsPlayer()) {
  2144. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2145. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2146. if (client) {
  2147. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2148. if (packet)
  2149. client->QueuePacket(packet);
  2150. }
  2151. }
  2152. else if (spawn->IsNPC())
  2153. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2154. else
  2155. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2156. }
  2157. }
  2158. else
  2159. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2160. return 0;
  2161. }
  2162. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2163. if (!lua_interface)
  2164. return 0;
  2165. Spawn* spawn = lua_interface->GetSpawn(state);
  2166. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2167. if (spawn && spawn->IsPlayer()) {
  2168. int32 spell_id = 0;
  2169. if (luaspell && luaspell->spell) {
  2170. spell_id = luaspell->spell->GetSpellID();
  2171. ZoneServer* zone = luaspell->caster->GetZone();
  2172. Spawn* target = 0;
  2173. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2174. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2175. target = zone->GetSpawnByID(luaspell->targets[i]);
  2176. if (target) {
  2177. if (target->IsPlayer()) {
  2178. ((Player*)target)->RemoveSkillBonus(spell_id);
  2179. Client* client = target->GetZone()->GetClientBySpawn(target);
  2180. if (client) {
  2181. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2182. if (packet)
  2183. client->QueuePacket(packet);
  2184. }
  2185. }
  2186. else if (target->IsNPC())
  2187. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2188. else
  2189. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2190. }
  2191. }
  2192. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2193. }
  2194. else if (spawn) {
  2195. if (spawn->IsPlayer()) {
  2196. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2197. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2198. if (client) {
  2199. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2200. if (packet)
  2201. client->QueuePacket(packet);
  2202. }
  2203. }
  2204. else if (spawn->IsNPC())
  2205. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2206. else
  2207. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2208. }
  2209. }
  2210. return 0;
  2211. }
  2212. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2213. if (!lua_interface)
  2214. return 0;
  2215. Spawn* spawn = lua_interface->GetSpawn(state);
  2216. int8 type = lua_interface->GetInt32Value(state, 2);
  2217. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2218. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2219. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2220. ZoneServer* zone = luaspell->caster->GetZone();
  2221. Spawn* target = 0;
  2222. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2223. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2224. target = zone->GetSpawnByID(luaspell->targets[i]);
  2225. if (target && target->IsEntity()) {
  2226. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2227. ((Entity*)target)->AddMezSpell(luaspell);
  2228. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2229. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2230. if (target->IsNPC())
  2231. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2232. }
  2233. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2234. ((Entity*)target)->AddStifleSpell(luaspell);
  2235. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2236. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2237. if (target->IsNPC())
  2238. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2239. }
  2240. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2241. ((Entity*)target)->AddDazeSpell(luaspell);
  2242. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2243. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2244. if (target->IsNPC())
  2245. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2246. }
  2247. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2248. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2249. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2250. ((Entity*)target)->AddStunSpell(luaspell);
  2251. if (target->IsNPC())
  2252. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2253. }
  2254. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2255. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2256. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2257. ((Entity*)target)->AddRootSpell(luaspell);
  2258. if (target->IsNPC())
  2259. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2260. }
  2261. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2262. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2263. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2264. ((Entity*)target)->AddFearSpell(luaspell);
  2265. if (target->IsNPC())
  2266. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2267. }
  2268. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2269. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2270. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2271. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2272. }
  2273. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2274. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2275. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2276. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2277. }
  2278. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2279. ((Entity*)target)->AddSnareSpell(luaspell);
  2280. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2281. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2282. if (target->IsNPC())
  2283. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2284. }
  2285. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2286. ((Entity*)target)->AddFlightSpell(luaspell);
  2287. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2288. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2289. }
  2290. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2291. ((Entity*)target)->AddGlideSpell(luaspell);
  2292. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2293. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2294. }
  2295. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2296. ((Entity*)target)->AddSafefallSpell(luaspell);
  2297. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2298. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2299. }
  2300. else
  2301. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2302. }
  2303. else
  2304. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2305. }
  2306. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2307. }
  2308. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2309. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2310. ((Entity*)spawn)->AddMezSpell(luaspell);
  2311. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2312. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2313. }
  2314. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2315. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2316. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2317. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2318. }
  2319. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2320. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2321. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2322. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2323. }
  2324. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2325. ((Entity*)spawn)->AddStunSpell(luaspell);
  2326. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2327. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2328. }
  2329. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2330. ((Entity*)spawn)->AddRootSpell(luaspell);
  2331. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2332. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2333. }
  2334. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2335. ((Entity*)spawn)->AddFearSpell(luaspell);
  2336. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2337. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2338. }
  2339. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2340. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2341. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2342. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2343. }
  2344. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2345. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2346. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2347. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2348. }
  2349. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2350. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2351. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2352. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2353. }
  2354. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2355. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2356. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2357. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2358. }
  2359. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2360. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2361. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2362. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2363. }
  2364. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2365. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2366. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2367. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2368. }
  2369. else
  2370. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2371. }
  2372. else
  2373. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2374. return 0;
  2375. }
  2376. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2377. if (!lua_interface)
  2378. return 0;
  2379. Spawn* spawn = lua_interface->GetSpawn(state);
  2380. int8 type = lua_interface->GetInt8Value(state, 2);
  2381. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2382. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2383. if (spawn && spawn->IsEntity()) {
  2384. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2385. ZoneServer* zone = luaspell->caster->GetZone();
  2386. Spawn* target = 0;
  2387. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2388. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2389. target = zone->GetSpawnByID(luaspell->targets[i]);
  2390. if (target) {
  2391. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2392. ((Entity*)target)->RemoveMezSpell(luaspell);
  2393. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2394. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2395. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2396. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2397. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2398. ((Entity*)target)->RemoveStunSpell(luaspell);
  2399. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2400. ((Entity*)target)->RemoveRootSpell(luaspell);
  2401. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2402. ((Entity*)target)->RemoveFearSpell(luaspell);
  2403. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2404. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2405. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2406. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2407. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2408. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2409. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2410. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2411. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2412. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2413. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2414. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2415. else
  2416. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2417. }
  2418. }
  2419. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2420. }
  2421. else if (only_remove_spawn) {
  2422. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2423. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2424. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2425. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2426. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2427. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2428. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2429. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2430. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2431. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2432. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2433. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2434. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2435. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2436. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2437. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2438. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2439. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2440. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2441. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2442. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2443. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2444. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2445. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2446. else
  2447. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2448. }
  2449. }
  2450. return 0;
  2451. }
  2452. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2453. if (!lua_interface)
  2454. return 0;
  2455. Spawn* spawn = lua_interface->GetSpawn(state);
  2456. int8 type = lua_interface->GetInt8Value(state, 2);
  2457. bool hasEffect = false;
  2458. if (!spawn)
  2459. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2460. else if (!spawn->IsEntity())
  2461. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2462. else if (type < CONTROL_MAX_EFFECTS)
  2463. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2464. else
  2465. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2466. lua_interface->SetBooleanValue(state, hasEffect);
  2467. return 1;
  2468. }
  2469. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2470. if (!lua_interface)
  2471. return 0;
  2472. Spawn* spawn = lua_interface->GetSpawn(state);
  2473. float distance = 0.0f;
  2474. if (!spawn)
  2475. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2476. else if (!spawn->IsNPC())
  2477. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2478. else
  2479. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2480. lua_interface->SetFloatValue(state, distance);
  2481. return 1;
  2482. }
  2483. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2484. if (!lua_interface)
  2485. return 0;
  2486. Spawn* spawn = lua_interface->GetSpawn(state);
  2487. float distance = 0.0f;
  2488. if (!spawn)
  2489. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2490. else if (!spawn->IsNPC())
  2491. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2492. else
  2493. distance = ((NPC*)spawn)->GetAggroRadius();
  2494. lua_interface->SetFloatValue(state, distance);
  2495. return 1;
  2496. }
  2497. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2498. if (!lua_interface)
  2499. return 0;
  2500. Spawn* spawn = lua_interface->GetSpawn(state);
  2501. float distance = lua_interface->GetFloatValue(state, 2);
  2502. bool override = lua_interface->GetBooleanValue(state, 3);
  2503. bool result = false;
  2504. lua_interface->ResetFunctionStack(state);
  2505. if (!spawn)
  2506. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2507. else if (!spawn->IsNPC())
  2508. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2509. else
  2510. {
  2511. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2512. result = true;
  2513. }
  2514. lua_interface->SetBooleanValue(state, result);
  2515. return 1;
  2516. }
  2517. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2518. if (!lua_interface)
  2519. return 0;
  2520. Spawn* spawn = lua_interface->GetSpawn(state);
  2521. int16 value = lua_interface->GetInt16Value(state, 2);
  2522. if (spawn && spawn->IsEntity()) {
  2523. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2524. if (spawn->IsPlayer())
  2525. ((Player*)spawn)->SetCharSheetChanged(true);
  2526. }
  2527. return 0;
  2528. }
  2529. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2530. if (!lua_interface)
  2531. return 0;
  2532. Spawn* spawn = lua_interface->GetSpawn(state);
  2533. int16 value = lua_interface->GetInt16Value(state, 2);
  2534. if (spawn && spawn->IsEntity()) {
  2535. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2536. if (spawn->IsPlayer())
  2537. ((Player*)spawn)->SetCharSheetChanged(true);
  2538. }
  2539. return 0;
  2540. }
  2541. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2542. if (!lua_interface)
  2543. return 0;
  2544. Spawn* spawn = lua_interface->GetSpawn(state);
  2545. int16 value = lua_interface->GetInt16Value(state, 2);
  2546. if (spawn && spawn->IsEntity()) {
  2547. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2548. if (spawn->IsPlayer())
  2549. ((Player*)spawn)->SetCharSheetChanged(true);
  2550. }
  2551. return 0;
  2552. }
  2553. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2554. if (!lua_interface)
  2555. return 0;
  2556. Spawn* spawn = lua_interface->GetSpawn(state);
  2557. int16 value = lua_interface->GetInt16Value(state, 2);
  2558. if (spawn && spawn->IsEntity()) {
  2559. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2560. if (spawn->IsPlayer())
  2561. ((Player*)spawn)->SetCharSheetChanged(true);
  2562. }
  2563. return 0;
  2564. }
  2565. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2566. if (!lua_interface)
  2567. return 0;
  2568. Spawn* spawn = lua_interface->GetSpawn(state);
  2569. int16 value = lua_interface->GetInt16Value(state, 2);
  2570. if (spawn && spawn->IsEntity()) {
  2571. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2572. if (spawn->IsPlayer())
  2573. ((Player*)spawn)->SetCharSheetChanged(true);
  2574. }
  2575. return 0;
  2576. }
  2577. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2578. if (!lua_interface)
  2579. return 0;
  2580. Spawn* spawn = lua_interface->GetSpawn(state);
  2581. int8 value = lua_interface->GetInt8Value(state, 2);
  2582. if (spawn && spawn->IsEntity()) {
  2583. ((Entity*)spawn)->SetDeity(value);
  2584. if (spawn->IsPlayer())
  2585. ((Player*)spawn)->SetCharSheetChanged(true);
  2586. }
  2587. lua_interface->ResetFunctionStack(state);
  2588. return 0;
  2589. }
  2590. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2591. if (!lua_interface)
  2592. return 0;
  2593. Spawn* spawn = lua_interface->GetSpawn(state);
  2594. if (spawn && spawn->IsEntity()) {
  2595. int8 deity = ((Entity*)spawn)->GetDeity();
  2596. lua_interface->SetInt32Value(state, deity);
  2597. return 1;
  2598. }
  2599. return 0;
  2600. }
  2601. int EQ2Emu_lua_SetInt(lua_State* state) {
  2602. if (!lua_interface)
  2603. return 0;
  2604. Spawn* spawn = lua_interface->GetSpawn(state);
  2605. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2606. if (spawn && spawn->IsEntity()) {
  2607. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2608. if (spawn->IsPlayer())
  2609. ((Player*)spawn)->SetCharSheetChanged(true);
  2610. }
  2611. return 0;
  2612. }
  2613. int EQ2Emu_lua_SetWis(lua_State* state) {
  2614. if (!lua_interface)
  2615. return 0;
  2616. Spawn* spawn = lua_interface->GetSpawn(state);
  2617. float value = lua_interface->GetFloatValue(state, 2);
  2618. if (spawn && spawn->IsEntity()) {
  2619. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2620. if (spawn->IsPlayer())
  2621. ((Player*)spawn)->SetCharSheetChanged(true);
  2622. }
  2623. return 0;
  2624. }
  2625. int EQ2Emu_lua_SetSta(lua_State* state) {
  2626. if (!lua_interface)
  2627. return 0;
  2628. Spawn* spawn = lua_interface->GetSpawn(state);
  2629. float value = lua_interface->GetFloatValue(state, 2);
  2630. if (spawn && spawn->IsEntity()) {
  2631. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2632. if (spawn->IsPlayer())
  2633. ((Player*)spawn)->SetCharSheetChanged(true);
  2634. }
  2635. return 0;
  2636. }
  2637. int EQ2Emu_lua_SetStr(lua_State* state) {
  2638. if (!lua_interface)
  2639. return 0;
  2640. Spawn* spawn = lua_interface->GetSpawn(state);
  2641. float value = lua_interface->GetFloatValue(state, 2);
  2642. if (spawn && spawn->IsEntity()) {
  2643. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2644. if (spawn->IsPlayer())
  2645. ((Player*)spawn)->SetCharSheetChanged(true);
  2646. }
  2647. return 0;
  2648. }
  2649. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2650. if (!lua_interface)
  2651. return 0;
  2652. Spawn* spawn = lua_interface->GetSpawn(state);
  2653. float value = lua_interface->GetFloatValue(state, 2);
  2654. if (spawn && spawn->IsEntity()) {
  2655. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2656. if (spawn->IsPlayer())
  2657. ((Player*)spawn)->SetCharSheetChanged(true);
  2658. }
  2659. return 0;
  2660. }
  2661. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2662. if (!lua_interface)
  2663. return 0;
  2664. Spawn* spawn = lua_interface->GetSpawn(state);
  2665. if (spawn) {
  2666. lua_interface->SetInt32Value(state, spawn->GetHP());
  2667. return 1;
  2668. }
  2669. return 0;
  2670. }
  2671. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2672. if (!lua_interface)
  2673. return 0;
  2674. Spawn* spawn = lua_interface->GetSpawn(state);
  2675. if (spawn) {
  2676. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2677. return 1;
  2678. }
  2679. return 0;
  2680. }
  2681. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2682. if (!lua_interface)
  2683. return 0;
  2684. Spawn* spawn = lua_interface->GetSpawn(state);
  2685. if (spawn) {
  2686. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2687. return 1;
  2688. }
  2689. return 0;
  2690. }
  2691. int EQ2Emu_lua_GetName(lua_State* state) {
  2692. if (!lua_interface)
  2693. return 0;
  2694. Spawn* spawn = lua_interface->GetSpawn(state);
  2695. if (spawn) {
  2696. lua_interface->SetStringValue(state, spawn->GetName());
  2697. return 1;
  2698. }
  2699. return 0;
  2700. }
  2701. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2702. Spawn* spawn = lua_interface->GetSpawn(state);
  2703. if (spawn) {
  2704. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2705. return 1;
  2706. }
  2707. return 0;
  2708. }
  2709. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2710. if (!lua_interface)
  2711. return 0;
  2712. Spawn* spawn = lua_interface->GetSpawn(state);
  2713. if (spawn) {
  2714. lua_interface->SetInt32Value(state, spawn->GetPower());
  2715. return 1;
  2716. }
  2717. return 0;
  2718. }
  2719. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2720. if (!lua_interface)
  2721. return 0;
  2722. Spawn* spawn = lua_interface->GetSpawn(state);
  2723. if (spawn) {
  2724. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2725. return 1;
  2726. }
  2727. return 0;
  2728. }
  2729. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2730. if (!lua_interface)
  2731. return 0;
  2732. Spawn* spawn = lua_interface->GetSpawn(state);
  2733. if (spawn) {
  2734. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2735. return 1;
  2736. }
  2737. return 0;
  2738. }
  2739. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2740. if (!lua_interface)
  2741. return 0;
  2742. Spawn* spawn = lua_interface->GetSpawn(state);
  2743. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2744. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2745. if (spawn && spawn2) {
  2746. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2747. lua_interface->SetFloatValue(state, distance);
  2748. return 1;
  2749. }
  2750. return 0;
  2751. }
  2752. int EQ2Emu_lua_GetX(lua_State* state) {
  2753. if (!lua_interface)
  2754. return 0;
  2755. Spawn* spawn = lua_interface->GetSpawn(state);
  2756. if (spawn) {
  2757. lua_interface->SetFloatValue(state, spawn->GetX());
  2758. return 1;
  2759. }
  2760. return 0;
  2761. }
  2762. int EQ2Emu_lua_GetY(lua_State* state) {
  2763. if (!lua_interface)
  2764. return 0;
  2765. Spawn* spawn = lua_interface->GetSpawn(state);
  2766. if (spawn) {
  2767. lua_interface->SetFloatValue(state, spawn->GetY());
  2768. return 1;
  2769. }
  2770. return 0;
  2771. }
  2772. int EQ2Emu_lua_GetZ(lua_State* state) {
  2773. if (!lua_interface)
  2774. return 0;
  2775. Spawn* spawn = lua_interface->GetSpawn(state);
  2776. if (spawn) {
  2777. lua_interface->SetFloatValue(state, spawn->GetZ());
  2778. return 1;
  2779. }
  2780. return 0;
  2781. }
  2782. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2783. if (!lua_interface)
  2784. return 0;
  2785. Spawn* spawn = lua_interface->GetSpawn(state);
  2786. if (spawn) {
  2787. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2788. return 1;
  2789. }
  2790. return 0;
  2791. }
  2792. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2793. if (!lua_interface)
  2794. return 0;
  2795. Spawn* spawn = lua_interface->GetSpawn(state);
  2796. if (spawn) {
  2797. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2798. return 1;
  2799. }
  2800. return 0;
  2801. }
  2802. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2803. if (!lua_interface)
  2804. return 0;
  2805. Spawn* spawn = lua_interface->GetSpawn(state);
  2806. if (spawn) {
  2807. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2808. return 1;
  2809. }
  2810. return 0;
  2811. }
  2812. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2813. if (!lua_interface)
  2814. return 0;
  2815. Spawn* spawn = lua_interface->GetSpawn(state);
  2816. if (spawn && spawn->IsEntity()) {
  2817. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2818. return 1;
  2819. }
  2820. return 0;
  2821. }
  2822. int EQ2Emu_lua_GetInt(lua_State* state) {
  2823. if (!lua_interface)
  2824. return 0;
  2825. Spawn* spawn = lua_interface->GetSpawn(state);
  2826. if (spawn && spawn->IsEntity()) {
  2827. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2828. return 1;
  2829. }
  2830. return 0;
  2831. }
  2832. int EQ2Emu_lua_GetWis(lua_State* state) {
  2833. if (!lua_interface)
  2834. return 0;
  2835. Spawn* spawn = lua_interface->GetSpawn(state);
  2836. if (spawn && spawn->IsEntity()) {
  2837. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2838. return 1;
  2839. }
  2840. return 0;
  2841. }
  2842. int EQ2Emu_lua_GetSta(lua_State* state) {
  2843. if (!lua_interface)
  2844. return 0;
  2845. Spawn* spawn = lua_interface->GetSpawn(state);
  2846. if (spawn && spawn->IsEntity()) {
  2847. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2848. return 1;
  2849. }
  2850. return 0;
  2851. }
  2852. int EQ2Emu_lua_GetStr(lua_State* state) {
  2853. if (!lua_interface)
  2854. return 0;
  2855. Spawn* spawn = lua_interface->GetSpawn(state);
  2856. if (spawn && spawn->IsEntity()) {
  2857. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2858. return 1;
  2859. }
  2860. return 0;
  2861. }
  2862. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2863. if (!lua_interface)
  2864. return 0;
  2865. Spawn* spawn = lua_interface->GetSpawn(state);
  2866. if (spawn && spawn->IsEntity()) {
  2867. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2868. return 1;
  2869. }
  2870. return 0;
  2871. }
  2872. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2873. if (!lua_interface)
  2874. return 0;
  2875. Spawn* spawn = lua_interface->GetSpawn(state);
  2876. if (spawn && spawn->IsEntity()) {
  2877. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2878. return 1;
  2879. }
  2880. return 0;
  2881. }
  2882. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2883. if (!lua_interface)
  2884. return 0;
  2885. Spawn* spawn = lua_interface->GetSpawn(state);
  2886. if (spawn && spawn->IsEntity()) {
  2887. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2888. return 1;
  2889. }
  2890. return 0;
  2891. }
  2892. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2893. if (!lua_interface)
  2894. return 0;
  2895. Spawn* spawn = lua_interface->GetSpawn(state);
  2896. if (spawn && spawn->IsEntity()) {
  2897. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2898. return 1;
  2899. }
  2900. return 0;
  2901. }
  2902. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2903. if (!lua_interface)
  2904. return 0;
  2905. Spawn* spawn = lua_interface->GetSpawn(state);
  2906. if (spawn && spawn->IsEntity()) {
  2907. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2908. return 1;
  2909. }
  2910. return 0;
  2911. }
  2912. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2913. if (!lua_interface)
  2914. return 0;
  2915. Spawn* spawn = lua_interface->GetSpawn(state);
  2916. if (spawn && spawn->IsEntity()) {
  2917. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2918. return 1;
  2919. }
  2920. return 0;
  2921. }
  2922. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2923. if (!lua_interface)
  2924. return 0;
  2925. Spawn* player = lua_interface->GetSpawn(state);
  2926. if (!player || !player->IsPlayer()) {
  2927. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2928. return 0;
  2929. }
  2930. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2931. if (quest_id <= 0) {
  2932. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2933. return 0;
  2934. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2935. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2936. return 0;
  2937. }
  2938. int32 step = lua_interface->GetInt32Value(state, 3);
  2939. if (step > 0) {
  2940. Client* client = player->GetZone()->GetClientBySpawn(player);
  2941. if (client)
  2942. client->AddPendingQuestUpdate(quest_id, step);
  2943. } else {
  2944. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2945. }
  2946. return 0;
  2947. }
  2948. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2949. Spawn* player = lua_interface->GetSpawn(state);
  2950. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2951. int32 step = lua_interface->GetInt32Value(state, 3);
  2952. int32 progress = lua_interface->GetInt32Value(state, 4);
  2953. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2954. Client* client = player->GetZone()->GetClientBySpawn(player);
  2955. if (client)
  2956. client->AddPendingQuestUpdate(quest_id, step, progress);
  2957. }
  2958. return 0;
  2959. }
  2960. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2961. if (!lua_interface)
  2962. return 0;
  2963. Spawn* player = lua_interface->GetSpawn(state);
  2964. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2965. if (player && player->IsPlayer() && quest_id > 0) {
  2966. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2967. return 1;
  2968. }
  2969. return 0;
  2970. }
  2971. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2972. if (!lua_interface)
  2973. return 0;
  2974. Spawn* player = lua_interface->GetSpawn(state);
  2975. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2976. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2977. if (player && player->IsPlayer() && quest_id > 0) {
  2978. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2979. return 1;
  2980. }
  2981. return 0;
  2982. }
  2983. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2984. if (!lua_interface)
  2985. return 0;
  2986. Spawn* player = lua_interface->GetSpawn(state);
  2987. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2988. if (player && player->IsPlayer() && quest_id > 0) {
  2989. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2990. return 1;
  2991. }
  2992. return 0;
  2993. }
  2994. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2995. if (!lua_interface)
  2996. return 0;
  2997. Quest* quest = lua_interface->GetQuest(state);
  2998. string name = lua_interface->GetStringValue(state, 2);
  2999. string type = lua_interface->GetStringValue(state, 3);
  3000. string zone = lua_interface->GetStringValue(state, 4);
  3001. int16 level = lua_interface->GetInt16Value(state, 5);
  3002. string description = lua_interface->GetStringValue(state, 6);
  3003. bool load = true;
  3004. if (!quest) {
  3005. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3006. load = false;
  3007. }
  3008. if (load && name.length() == 0) {
  3009. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3010. load = false;
  3011. }
  3012. if (load && type.length() == 0) {
  3013. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3014. load = false;
  3015. }
  3016. if (load && zone.length() == 0) {
  3017. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3018. load = false;
  3019. }
  3020. if (load && description.length() == 0) {
  3021. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3022. load = false;
  3023. }
  3024. if (load && level == 0) {
  3025. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3026. load = false;
  3027. }
  3028. if (load)
  3029. quest->RegisterQuest(name, type, zone, level, description);
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Quest* quest = lua_interface->GetQuest(state);
  3036. if (quest) {
  3037. int8 level = lua_interface->GetInt16Value(state, 2);
  3038. quest->SetPrereqLevel(level);
  3039. }
  3040. return 0;
  3041. }
  3042. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3043. if (!lua_interface)
  3044. return 0;
  3045. Quest* quest = lua_interface->GetQuest(state);
  3046. if (quest) {
  3047. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3048. quest->AddPrereqQuest(quest_id);
  3049. }
  3050. return 0;
  3051. }
  3052. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3053. if (!lua_interface)
  3054. return 0;
  3055. Quest* quest = lua_interface->GetQuest(state);
  3056. if (quest) {
  3057. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3058. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3059. if (quantity == 0)
  3060. quantity = 1;
  3061. Item* master_item = master_item_list.GetItem(item_id);
  3062. if (master_item) {
  3063. Item* item = new Item(master_item);
  3064. item->details.count = quantity;
  3065. quest->AddPrereqItem(item);
  3066. }
  3067. }
  3068. return 0;
  3069. }
  3070. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3071. if (!lua_interface)
  3072. return 0;
  3073. Spawn* player = lua_interface->GetSpawn(state);
  3074. if(!player || !player->IsPlayer()) {
  3075. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3076. return 0;
  3077. }
  3078. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3079. if (quest_id > 0) {
  3080. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3081. return 1;
  3082. } else {
  3083. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3084. }
  3085. return 0;
  3086. }
  3087. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3088. if (!lua_interface)
  3089. return 0;
  3090. Quest* quest = lua_interface->GetQuest(state);
  3091. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3092. if (quest && spawn_id > 0)
  3093. quest->SetQuestReturnNPC(spawn_id);
  3094. return 0;
  3095. }
  3096. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3097. if (!lua_interface)
  3098. return 0;
  3099. Spawn* spawn = lua_interface->GetSpawn(state);
  3100. if (!spawn) {
  3101. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3102. return 0;
  3103. }
  3104. int32 time = lua_interface->GetInt32Value(state, 2);
  3105. if (time <= 0) {
  3106. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3107. return 0;
  3108. }
  3109. string function = lua_interface->GetStringValue(state, 3);
  3110. if (function.length() == 0) {
  3111. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3112. return 0;
  3113. }
  3114. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3115. Spawn* player = lua_interface->GetSpawn(state, 5);
  3116. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3117. timer->timer = Timer::GetCurrentTime2() + time;
  3118. timer->function = function;
  3119. timer->spawn = spawn->GetID();
  3120. timer->player = player ? player->GetID() : 0;
  3121. if (max_count == 0)
  3122. max_count = 1;
  3123. timer->max_count = max_count;
  3124. timer->current_count = 0;
  3125. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3126. return 0;
  3127. }
  3128. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3129. if (!lua_interface)
  3130. return 0;
  3131. Spawn* player = lua_interface->GetSpawn(state);
  3132. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3133. if (player && player->IsPlayer() && quest_id > 0) {
  3134. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3135. return 1;
  3136. }
  3137. return 0;
  3138. }
  3139. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3140. if (!lua_interface)
  3141. return 0;
  3142. Spawn* player = lua_interface->GetSpawn(state);
  3143. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3144. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3145. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3146. if (quest)
  3147. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3148. return 1;
  3149. }
  3150. return 0;
  3151. }
  3152. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3153. if (!lua_interface)
  3154. return 0;
  3155. Spawn* player = lua_interface->GetSpawn(state);
  3156. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3157. if (player && player->IsPlayer() && quest_id > 0) {
  3158. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3159. return 1;
  3160. }
  3161. return 0;
  3162. }
  3163. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3164. if (!lua_interface)
  3165. return 0;
  3166. Spawn* npc = lua_interface->GetSpawn(state);
  3167. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3168. if (npc && !npc->IsPlayer() && quest_id > 0)
  3169. npc->AddProvidedQuest(quest_id);
  3170. return 0;
  3171. }
  3172. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3173. if (!lua_interface)
  3174. return 0;
  3175. Spawn* npc = lua_interface->GetSpawn(state);
  3176. Spawn* player = lua_interface->GetSpawn(state, 2);
  3177. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3178. bool forced = lua_interface->GetBooleanValue(state, 4);
  3179. /* NPC is allowed to be null */
  3180. if (player && player->IsPlayer() && quest_id > 0) {
  3181. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3182. if (master_quest) {
  3183. Client* client = player->GetZone()->GetClientBySpawn(player);
  3184. if (!client) {
  3185. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3186. }
  3187. Quest* quest = new Quest(master_quest);
  3188. if (!quest) {
  3189. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3190. }
  3191. if (client && quest) {
  3192. if (npc)
  3193. quest->SetQuestGiver(npc->GetDatabaseID());
  3194. else
  3195. quest->SetQuestGiver(0);
  3196. client->AddPendingQuest(quest, forced);
  3197. }
  3198. }
  3199. else {
  3200. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3201. }
  3202. }
  3203. else {
  3204. 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);
  3205. }
  3206. return 0;
  3207. }
  3208. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3209. if (!lua_interface)
  3210. return 0;
  3211. Quest* quest = lua_interface->GetQuest(state);
  3212. if (quest) {
  3213. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3214. quest->AddPrereqClass(class_id);
  3215. }
  3216. return 0;
  3217. }
  3218. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3219. if (!lua_interface)
  3220. return 0;
  3221. Quest* quest = lua_interface->GetQuest(state);
  3222. if (quest) {
  3223. int8 race = lua_interface->GetInt8Value(state, 2);
  3224. quest->AddPrereqRace(race);
  3225. }
  3226. return 0;
  3227. }
  3228. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3229. if (!lua_interface)
  3230. return 0;
  3231. Quest* quest = lua_interface->GetQuest(state);
  3232. if (quest) {
  3233. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3234. quest->AddPrereqModelType(model_type);
  3235. }
  3236. return 0;
  3237. }
  3238. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3239. if (!lua_interface)
  3240. return 0;
  3241. Quest* quest = lua_interface->GetQuest(state);
  3242. if (!quest) {
  3243. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3244. return 0;
  3245. }
  3246. int8 level = lua_interface->GetInt8Value(state, 2);
  3247. quest->SetPrereqTSLevel(level);
  3248. return 0;
  3249. }
  3250. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3251. if (!lua_interface)
  3252. return 0;
  3253. Quest* quest = lua_interface->GetQuest(state);
  3254. if (!quest) {
  3255. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3256. return 0;
  3257. }
  3258. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3259. quest->AddPrereqTradeskillClass(class_id);
  3260. return 0;
  3261. }
  3262. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3263. if (!lua_interface)
  3264. return 0;
  3265. Quest* quest = lua_interface->GetQuest(state);
  3266. if (quest) {
  3267. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3268. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3269. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3270. quest->AddPrereqFaction(faction_id, min, max);
  3271. }
  3272. return 0;
  3273. }
  3274. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3275. if (!lua_interface)
  3276. return 0;
  3277. Quest* quest = lua_interface->GetQuest(state);
  3278. if (quest) {
  3279. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3280. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3281. if (quantity == 0)
  3282. quantity = 1;
  3283. Item* master_item = master_item_list.GetItem(item_id);
  3284. if (master_item) {
  3285. Item* item = new Item(master_item);
  3286. item->details.count = quantity;
  3287. quest->AddSelectableRewardItem(item);
  3288. }
  3289. }
  3290. return 0;
  3291. }
  3292. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3293. if (!lua_interface)
  3294. return 0;
  3295. Quest* quest = lua_interface->GetQuest(state);
  3296. if (quest) {
  3297. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3298. vector<Item*>* items = quest->GetRewardItems();
  3299. if (items) {
  3300. vector<Item*>::iterator itr;
  3301. for (itr = items->begin(); itr != items->end(); itr++) {
  3302. if (*itr && (*itr)->details.item_id == item_id) {
  3303. lua_interface->SetBooleanValue(state, true);
  3304. return 1;
  3305. }
  3306. }
  3307. }
  3308. }
  3309. lua_interface->SetBooleanValue(state, false);
  3310. return 1;
  3311. }
  3312. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3313. if (!lua_interface)
  3314. return 0;
  3315. Quest* quest = lua_interface->GetQuest(state);
  3316. if (quest) {
  3317. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3318. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3319. if (quantity == 0)
  3320. quantity = 1;
  3321. Item* master_item = master_item_list.GetItem(item_id);
  3322. if (master_item) {
  3323. Item* item = new Item(master_item);
  3324. item->details.count = quantity;
  3325. quest->AddRewardItem(item);
  3326. }
  3327. }
  3328. return 0;
  3329. }
  3330. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3331. if (!lua_interface)
  3332. return 0;
  3333. Quest* quest = lua_interface->GetQuest(state);
  3334. if (quest) {
  3335. int32 copper = lua_interface->GetInt32Value(state, 2);
  3336. int32 silver = lua_interface->GetInt32Value(state, 3);
  3337. int32 gold = lua_interface->GetInt32Value(state, 4);
  3338. int32 plat = lua_interface->GetInt32Value(state, 5);
  3339. quest->AddRewardCoins(copper, silver, gold, plat);
  3340. }
  3341. return 0;
  3342. }
  3343. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3344. if (!lua_interface)
  3345. return 0;
  3346. Quest* quest = lua_interface->GetQuest(state);
  3347. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3348. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3349. if (quest && faction_id > 0 && amount != 0)
  3350. quest->AddRewardFaction(faction_id, amount);
  3351. return 0;
  3352. }
  3353. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3354. if (!lua_interface)
  3355. return 0;
  3356. Quest* quest = lua_interface->GetQuest(state);
  3357. if (quest) {
  3358. int32 status = lua_interface->GetInt32Value(state, 2);
  3359. quest->SetRewardStatus(status);
  3360. }
  3361. return 0;
  3362. }
  3363. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3364. if (!lua_interface)
  3365. return 0;
  3366. Quest* quest = lua_interface->GetQuest(state);
  3367. if (quest) {
  3368. int32 status = lua_interface->GetInt32Value(state, 2);
  3369. quest->SetStatusTmpReward(status);
  3370. }
  3371. return 0;
  3372. }
  3373. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3374. if (!lua_interface)
  3375. return 0;
  3376. Quest* quest = lua_interface->GetQuest(state);
  3377. if (quest) {
  3378. int64 coins = lua_interface->GetInt64Value(state, 2);
  3379. quest->SetCoinTmpReward(coins);
  3380. }
  3381. return 0;
  3382. }
  3383. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3384. if (!lua_interface)
  3385. return 0;
  3386. Quest* quest = lua_interface->GetQuest(state);
  3387. if (quest) {
  3388. string comment = lua_interface->GetStringValue(state, 2);
  3389. quest->SetRewardComment(comment);
  3390. }
  3391. return 0;
  3392. }
  3393. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3394. if (!lua_interface)
  3395. return 0;
  3396. Quest* quest = lua_interface->GetQuest(state);
  3397. if (quest) {
  3398. int32 exp = lua_interface->GetInt32Value(state, 2);
  3399. quest->SetRewardXP(exp);
  3400. }
  3401. return 0;
  3402. }
  3403. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3404. Quest* quest = lua_interface->GetQuest(state);
  3405. if (quest) {
  3406. int32 step = lua_interface->GetInt32Value(state, 2);
  3407. string description = lua_interface->GetStringValue(state, 3);
  3408. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3409. float percentage = lua_interface->GetFloatValue(state, 5);
  3410. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3411. int16 icon = lua_interface->GetInt16Value(state, 7);
  3412. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3413. const char* taskgroup = 0;
  3414. if (str_taskgroup.length() > 0)
  3415. taskgroup = str_taskgroup.c_str();
  3416. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3417. if (quest_step && icon && quantity > 0)
  3418. quest_step->SetIcon(icon);
  3419. }
  3420. return 0;
  3421. }
  3422. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3423. if (!lua_interface)
  3424. return 0;
  3425. Quest* quest = lua_interface->GetQuest(state);
  3426. if (quest) {
  3427. int32 step = lua_interface->GetInt32Value(state, 2);
  3428. string description = lua_interface->GetStringValue(state, 3);
  3429. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3430. float percentage = lua_interface->GetFloatValue(state, 5);
  3431. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3432. int16 icon = lua_interface->GetInt16Value(state, 7);
  3433. const char* taskgroup = 0;
  3434. if (str_taskgroup.length() > 0)
  3435. taskgroup = str_taskgroup.c_str();
  3436. int32 npc_id = 0;
  3437. vector<int32>* ids = 0;
  3438. int i = 0;
  3439. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3440. if (ids == 0)
  3441. ids = new vector<int32>;
  3442. ids->push_back(npc_id);
  3443. i++;
  3444. }
  3445. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3446. if (quest_step && icon > 0 && quantity > 0)
  3447. quest_step->SetIcon(icon);
  3448. if (quest->GetPlayer()) {
  3449. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3450. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3451. }
  3452. safe_delete(ids);
  3453. }
  3454. return 0;
  3455. }
  3456. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3457. if (!lua_interface)
  3458. return 0;
  3459. Quest* quest = lua_interface->GetQuest(state);
  3460. if (quest) {
  3461. int32 step = lua_interface->GetInt32Value(state, 2);
  3462. string description = lua_interface->GetStringValue(state, 3);
  3463. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3464. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3465. int16 icon = lua_interface->GetInt16Value(state, 6);
  3466. const char* taskgroup = 0;
  3467. if (str_taskgroup.length() > 0)
  3468. taskgroup = str_taskgroup.c_str();
  3469. int32 npc_id = 0;
  3470. vector<int32>* ids = 0;
  3471. int i = 0;
  3472. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3473. if (ids == 0)
  3474. ids = new vector<int32>;
  3475. ids->push_back(npc_id);
  3476. i++;
  3477. }
  3478. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3479. if (quest_step && icon > 0)
  3480. quest_step->SetIcon(icon);
  3481. if (quest->GetPlayer()) {
  3482. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3483. if(client)
  3484. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3485. }
  3486. safe_delete(ids);
  3487. }
  3488. return 0;
  3489. }
  3490. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3491. if (!lua_interface)
  3492. return 0;
  3493. Quest* quest = lua_interface->GetQuest(state);
  3494. if (quest) {
  3495. int32 step = lua_interface->GetInt32Value(state, 2);
  3496. string description = lua_interface->GetStringValue(state, 3);
  3497. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3498. float percentage = lua_interface->GetFloatValue(state, 5);
  3499. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3500. int16 icon = lua_interface->GetInt16Value(state, 7);
  3501. const char* taskgroup = 0;
  3502. if (str_taskgroup.length() > 0)
  3503. taskgroup = str_taskgroup.c_str();
  3504. int32 item_id = 0;
  3505. vector<int32>* ids = 0;
  3506. int i = 0;
  3507. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3508. if (ids == 0)
  3509. ids = new vector<int32>;
  3510. ids->push_back(item_id);
  3511. i++;
  3512. }
  3513. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3514. if (quest_step && icon > 0 && quantity > 0)
  3515. quest_step->SetIcon(icon);
  3516. if (quest->GetPlayer()) {
  3517. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3518. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3519. }
  3520. safe_delete(ids);
  3521. }
  3522. return 0;
  3523. }
  3524. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3525. if (!lua_interface)
  3526. return 0;
  3527. Quest* quest = lua_interface->GetQuest(state);
  3528. if (quest) {
  3529. int32 step = lua_interface->GetInt32Value(state, 2);
  3530. string description = lua_interface->GetStringValue(state, 3);
  3531. float max_variation = lua_interface->GetFloatValue(state, 4);
  3532. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3533. int16 icon = lua_interface->GetInt16Value(state, 6);
  3534. const char* taskgroup = 0;
  3535. if (str_taskgroup.length() > 0)
  3536. taskgroup = str_taskgroup.c_str();
  3537. vector<Location>* locations = 0;
  3538. int i = 7;
  3539. while (true) {
  3540. Location loc;
  3541. loc.x = lua_interface->GetFloatValue(state, i);
  3542. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3543. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3544. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3545. break;
  3546. if (locations == 0)
  3547. locations = new vector<Location>;
  3548. locations->push_back(loc);
  3549. i += 3;
  3550. }
  3551. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3552. if (quest_step && icon > 0)
  3553. quest_step->SetIcon(icon);
  3554. if (quest->GetPlayer()) {
  3555. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3556. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3557. }
  3558. }
  3559. return 0;
  3560. }
  3561. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3562. if (!lua_interface)
  3563. return 0;
  3564. Quest* quest = lua_interface->GetQuest(state);
  3565. if (quest) {
  3566. int32 step = lua_interface->GetInt32Value(state, 2);
  3567. string description = lua_interface->GetStringValue(state, 3);
  3568. float max_variation = lua_interface->GetFloatValue(state, 4);
  3569. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3570. int16 icon = lua_interface->GetInt16Value(state, 6);
  3571. const char* taskgroup = 0;
  3572. if (str_taskgroup.length() > 0)
  3573. taskgroup = str_taskgroup.c_str();
  3574. vector<Location>* locations = 0;
  3575. int i = 7;
  3576. while (true) {
  3577. Location loc;
  3578. loc.x = lua_interface->GetFloatValue(state, i);
  3579. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3580. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3581. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3582. break;
  3583. if (locations == 0)
  3584. locations = new vector<Location>;
  3585. locations->push_back(loc);
  3586. i += 3;
  3587. }
  3588. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3589. if (quest_step && icon > 0)
  3590. quest_step->SetIcon(icon);
  3591. if (quest->GetPlayer()) {
  3592. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3593. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3594. }
  3595. }
  3596. return 0;
  3597. }
  3598. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3599. Quest* quest = lua_interface->GetQuest(state);
  3600. if (quest) {
  3601. int32 step = lua_interface->GetInt32Value(state, 2);
  3602. string description = lua_interface->GetStringValue(state, 3);
  3603. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3604. float percentage = lua_interface->GetFloatValue(state, 5);
  3605. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3606. int16 icon = lua_interface->GetInt16Value(state, 7);
  3607. const char* taskgroup = 0;
  3608. if (str_taskgroup.length() > 0)
  3609. taskgroup = str_taskgroup.c_str();
  3610. int32 spell_id = 0;
  3611. vector<int32>* ids = 0;
  3612. int i = 0;
  3613. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3614. if (ids == 0)
  3615. ids = new vector<int32>;
  3616. ids->push_back(spell_id);
  3617. i++;
  3618. }
  3619. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3620. if (quest_step && icon > 0 && quantity > 0)
  3621. quest_step->SetIcon(icon);
  3622. if (quest->GetPlayer()) {
  3623. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3624. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3625. }
  3626. safe_delete(ids);
  3627. }
  3628. return 0;
  3629. }
  3630. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3631. if (!lua_interface)
  3632. return 0;
  3633. Quest* quest = lua_interface->GetQuest(state);
  3634. if (quest) {
  3635. int32 step = lua_interface->GetInt32Value(state, 2);
  3636. string description = lua_interface->GetStringValue(state, 3);
  3637. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3638. float percentage = lua_interface->GetFloatValue(state, 5);
  3639. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3640. int16 icon = lua_interface->GetInt16Value(state, 7);
  3641. const char* taskgroup = 0;
  3642. if (str_taskgroup.length() > 0)
  3643. taskgroup = str_taskgroup.c_str();
  3644. int32 item_id = 0;
  3645. vector<int32>* ids = 0;
  3646. int i = 0;
  3647. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3648. if (ids == 0)
  3649. ids = new vector<int32>;
  3650. ids->push_back(item_id);
  3651. i++;
  3652. }
  3653. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3654. if (quest_step && icon > 0 && quantity > 0)
  3655. quest_step->SetIcon(icon);
  3656. if (quest->GetPlayer()) {
  3657. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3658. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3659. }
  3660. safe_delete(ids);
  3661. }
  3662. return 0;
  3663. }
  3664. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3665. if (!lua_interface)
  3666. return 0;
  3667. Quest* quest = lua_interface->GetQuest(state);
  3668. if (quest) {
  3669. int32 step = lua_interface->GetInt32Value(state, 2);
  3670. string description = lua_interface->GetStringValue(state, 3);
  3671. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3672. float percentage = lua_interface->GetFloatValue(state, 5);
  3673. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3674. int16 icon = lua_interface->GetInt16Value(state, 7);
  3675. const char* taskgroup = 0;
  3676. if (str_taskgroup.length() > 0)
  3677. taskgroup = str_taskgroup.c_str();
  3678. int32 item_id = 0;
  3679. vector<int32>* ids = 0;
  3680. int i = 0;
  3681. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3682. if (ids == 0)
  3683. ids = new vector<int32>;
  3684. ids->push_back(item_id);
  3685. i++;
  3686. }
  3687. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3688. if (quest_step && icon > 0 && quantity > 0)
  3689. quest_step->SetIcon(icon);
  3690. if (quest->GetPlayer()) {
  3691. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3692. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3693. }
  3694. safe_delete(ids);
  3695. }
  3696. return 0;
  3697. }
  3698. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3699. if (!lua_interface)
  3700. return 0;
  3701. Quest* quest = lua_interface->GetQuest(state);
  3702. if (quest) {
  3703. string action = lua_interface->GetStringValue(state, 2);
  3704. if (action.length() > 0)
  3705. quest->SetCompleteAction(action);
  3706. }
  3707. return 0;
  3708. }
  3709. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3710. if (!lua_interface)
  3711. return 0;
  3712. Quest* quest = lua_interface->GetQuest(state);
  3713. if (quest) {
  3714. int32 step = lua_interface->GetInt32Value(state, 2);
  3715. string action = lua_interface->GetStringValue(state, 3);
  3716. if (step > 0 && action.length() > 0)
  3717. quest->AddCompleteAction(step, action);
  3718. }
  3719. return 0;
  3720. }
  3721. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3722. if (!lua_interface)
  3723. return 0;
  3724. Quest* quest = lua_interface->GetQuest(state);
  3725. if (quest) {
  3726. int32 step = lua_interface->GetInt32Value(state, 2);
  3727. string action = lua_interface->GetStringValue(state, 3);
  3728. if (step > 0 && action.length() > 0)
  3729. quest->AddProgressAction(step, action);
  3730. }
  3731. return 0;
  3732. }
  3733. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3734. if (!lua_interface)
  3735. return 0;
  3736. Quest* quest = lua_interface->GetQuest(state);
  3737. string description = lua_interface->GetStringValue(state, 2);
  3738. if (quest && description.length() > 0)
  3739. quest->SetDescription(description);
  3740. return 0;
  3741. }
  3742. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3743. if (!lua_interface)
  3744. return 0;
  3745. Quest* quest = lua_interface->GetQuest(state);
  3746. string description = lua_interface->GetStringValue(state, 2);
  3747. if (quest && description.length() > 0)
  3748. quest->SetCompletedDescription(description);
  3749. return 0;
  3750. }
  3751. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3752. if (!lua_interface)
  3753. return 0;
  3754. Quest* quest = lua_interface->GetQuest(state);
  3755. int32 step = lua_interface->GetInt32Value(state, 2);
  3756. string description = lua_interface->GetStringValue(state, 3);
  3757. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3758. if (quest && step > 0 && description.length() > 0) {
  3759. quest->SetTaskGroupDescription(step, description, display_bullets);
  3760. /* if (quest->GetPlayer()) {
  3761. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3762. if (client)
  3763. client->SendQuestUpdateStep(quest, step, false);
  3764. }*/
  3765. }
  3766. return 0;
  3767. }
  3768. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3769. if (!lua_interface)
  3770. return 0;
  3771. Quest* quest = lua_interface->GetQuest(state);
  3772. int32 step = lua_interface->GetInt32Value(state, 2);
  3773. string description = lua_interface->GetStringValue(state, 3);
  3774. if (quest && step > 0 && description.length() > 0) {
  3775. quest->SetStepDescription(step, description);
  3776. /*if (quest->GetPlayer()) {
  3777. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3778. if (client)
  3779. client->SendQuestUpdateStepImmediately(quest, step);
  3780. }*/
  3781. }
  3782. return 0;
  3783. }
  3784. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3785. Quest* quest = lua_interface->GetQuest(state);
  3786. string zone = lua_interface->GetStringValue(state, 2);
  3787. if (quest && zone.length() > 0)
  3788. quest->SetZone(zone);
  3789. return 0;
  3790. }
  3791. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3792. if (!lua_interface)
  3793. return 0;
  3794. Quest* quest = lua_interface->GetQuest(state);
  3795. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3796. lua_interface->ResetFunctionStack(state);
  3797. if (quest && spawn) {
  3798. if (spawn->IsPlayer()) {
  3799. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3800. if (client)
  3801. {
  3802. client->AddPendingQuestAcceptReward(quest);
  3803. client->AddPendingQuestReward(quest);
  3804. }
  3805. }
  3806. }
  3807. return 0;
  3808. }
  3809. int EQ2Emu_lua_Harvest(lua_State* state) {
  3810. if (!lua_interface)
  3811. return 0;
  3812. Spawn* player = lua_interface->GetSpawn(state);
  3813. Spawn* node = lua_interface->GetSpawn(state, 2);
  3814. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3815. Client* client = player->GetZone()->GetClientBySpawn(player);
  3816. if (client) {
  3817. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3818. ((GroundSpawn*)node)->ProcessHarvest(client);
  3819. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3820. player->GetZone()->RemoveSpawn(node, true);
  3821. }
  3822. }
  3823. else if (player && player->IsPlayer()) {
  3824. Client* client = player->GetZone()->GetClientBySpawn(player);
  3825. if (client)
  3826. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3827. }
  3828. return 0;
  3829. }
  3830. int EQ2Emu_lua_Bind(lua_State* state) {
  3831. if (!lua_interface)
  3832. return 0;
  3833. Spawn* spawn = lua_interface->GetSpawn(state);
  3834. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3835. float x = lua_interface->GetFloatValue(state, 3);
  3836. float y = lua_interface->GetFloatValue(state, 4);
  3837. float z = lua_interface->GetFloatValue(state, 5);
  3838. float h = lua_interface->GetFloatValue(state, 6);
  3839. if (!spawn) {
  3840. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3841. return 0;
  3842. }
  3843. if (!spawn->IsPlayer()) {
  3844. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3845. return 0;
  3846. }
  3847. if (zone_id == 0) {
  3848. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3849. if (!client) {
  3850. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3851. return 0;
  3852. }
  3853. if (!client->Bind())
  3854. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3855. }
  3856. else {
  3857. Player* player = (Player*)spawn;
  3858. player->GetPlayerInfo()->SetBindZone(zone_id);
  3859. player->GetPlayerInfo()->SetBindX(x);
  3860. player->GetPlayerInfo()->SetBindY(y);
  3861. player->GetPlayerInfo()->SetBindZ(z);
  3862. player->GetPlayerInfo()->SetBindHeading(h);
  3863. }
  3864. return 0;
  3865. }
  3866. int EQ2Emu_lua_Gate(lua_State* state) {
  3867. if (!lua_interface)
  3868. return 0;
  3869. Spawn* spawn = lua_interface->GetSpawn(state);
  3870. if (spawn) {
  3871. if (spawn->IsPlayer()) {
  3872. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3873. if (client) {
  3874. if (!client->Gate())
  3875. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3876. }
  3877. }
  3878. }
  3879. return 0;
  3880. }
  3881. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3882. if (!lua_interface)
  3883. return 0;
  3884. bool ret = false;
  3885. Spawn* spawn = lua_interface->GetSpawn(state);
  3886. if (spawn) {
  3887. if (spawn->IsPlayer()) {
  3888. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3889. if (client)
  3890. ret = client->BindAllowed();
  3891. }
  3892. }
  3893. lua_interface->SetBooleanValue(state, ret);
  3894. return 1;
  3895. }
  3896. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3897. if (!lua_interface)
  3898. return 0;
  3899. bool ret = false;
  3900. Spawn* spawn = lua_interface->GetSpawn(state);
  3901. if (spawn) {
  3902. if (spawn->IsPlayer()) {
  3903. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3904. if (client)
  3905. ret = client->GateAllowed();
  3906. }
  3907. }
  3908. lua_interface->SetBooleanValue(state, ret);
  3909. return 1;
  3910. }
  3911. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3912. Spawn* spawn = lua_interface->GetSpawn(state);
  3913. if (spawn) {
  3914. lua_interface->SetBooleanValue(state, spawn->Alive());
  3915. return 1;
  3916. }
  3917. return 0;
  3918. }
  3919. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3920. if (!lua_interface)
  3921. return 0;
  3922. Spawn* spawn = lua_interface->GetSpawn(state);
  3923. if (spawn && spawn->IsEntity()) {
  3924. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3925. return 1;
  3926. }
  3927. return 0;
  3928. }
  3929. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3930. Spawn* spawn = lua_interface->GetSpawn(state);
  3931. string message = lua_interface->GetStringValue(state, 2);
  3932. string color_str = lua_interface->GetStringValue(state, 3);
  3933. int8 color = CHANNEL_NARRATIVE;
  3934. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3935. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3936. if (client) {
  3937. if (color_str.length() > 0) {
  3938. // leave for backwards compat, but all future should just use the number
  3939. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3940. color = CHANNEL_COLOR_RED;
  3941. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3942. color = CHANNEL_COLOR_YELLOW;
  3943. else
  3944. {
  3945. // use a number to specify the channel as per Commands/Commands.h defines
  3946. color = (int8)atoul(color_str.c_str());
  3947. }
  3948. }
  3949. client->SimpleMessage(color, message.c_str());
  3950. }
  3951. }
  3952. return 0;
  3953. }
  3954. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3955. Spawn* spawn = lua_interface->GetSpawn(state);
  3956. string message = lua_interface->GetStringValue(state, 2);
  3957. int8 red = lua_interface->GetInt8Value(state, 3);
  3958. int8 green = lua_interface->GetInt8Value(state, 4);
  3959. int8 blue = lua_interface->GetInt8Value(state, 5);
  3960. if (!spawn) {
  3961. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3962. return 0;
  3963. }
  3964. int32 words = ::CountWordsInString(message.c_str());
  3965. if (words < 5)
  3966. words = 5;
  3967. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3968. if (client)
  3969. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3970. return 0;
  3971. }
  3972. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3973. Spawn* spawn = lua_interface->GetSpawn(state);
  3974. int8 param = lua_interface->GetInt8Value(state, 2);
  3975. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3976. int8 value = lua_interface->GetInt8Value(state, 4);
  3977. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3978. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3979. if (client) {
  3980. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3981. switch (param) {
  3982. case 1: {
  3983. packet->setDataByName("parameter1", param_value);
  3984. break;
  3985. }
  3986. case 2: {
  3987. packet->setDataByName("parameter2", param_value);
  3988. break;
  3989. }
  3990. case 3: {
  3991. packet->setDataByName("parameter3", param_value);
  3992. break;
  3993. }
  3994. case 4: {
  3995. packet->setDataByName("parameter4", param_value);
  3996. break;
  3997. }
  3998. case 5: {
  3999. packet->setDataByName("parameter5", param_value);
  4000. break;
  4001. }
  4002. }
  4003. packet->setDataByName("value", value);
  4004. client->QueuePacket(packet->serialize());
  4005. safe_delete(packet);
  4006. }
  4007. }
  4008. return 0;
  4009. }
  4010. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4011. Spawn* spawn = lua_interface->GetSpawn(state);
  4012. if (spawn && spawn->IsPlayer()) {
  4013. if (((Player*)spawn)->GetIsTracking())
  4014. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4015. else
  4016. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4017. }
  4018. return 0;
  4019. }
  4020. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4021. Spawn* player = lua_interface->GetSpawn(state);
  4022. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4023. string name = lua_interface->GetStringValue(state, 3);
  4024. float distance = lua_interface->GetFloatValue(state, 4);
  4025. string command = lua_interface->GetStringValue(state, 5);
  4026. string error_text = lua_interface->GetStringValue(state, 6);
  4027. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4028. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4029. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4030. if (spawn) {
  4031. if (distance == 0)
  4032. distance = 10.0f;
  4033. if (command.length() == 0)
  4034. command = name;
  4035. if (command.length() < 1 && name.length() < 1)
  4036. {
  4037. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4038. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4039. spawn->RemovePrimaryCommands();
  4040. }
  4041. else
  4042. {
  4043. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4044. }
  4045. }
  4046. return 0;
  4047. }
  4048. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4049. if (!lua_interface)
  4050. return 0;
  4051. Spawn* player = lua_interface->GetSpawn(state);
  4052. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4053. int16 tier = lua_interface->GetInt16Value(state, 3);
  4054. if (player && player->IsPlayer()) {
  4055. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4056. return 1;
  4057. }
  4058. return 0;
  4059. }
  4060. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4061. if (!lua_interface)
  4062. return 0;
  4063. Spawn* player = lua_interface->GetSpawn(state);
  4064. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4065. int16 tier = lua_interface->GetInt16Value(state, 3);
  4066. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4067. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4068. bool add_to_hotbar = true;
  4069. if (num_args > 4) {
  4070. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4071. }
  4072. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4073. if (player && spell && player->IsPlayer()) {
  4074. Client* client = player->GetClient();
  4075. if (client) {
  4076. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4077. {
  4078. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4079. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4080. client->GetPlayer()->UnlockSpell(spell);
  4081. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4082. }
  4083. else
  4084. {
  4085. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4086. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4087. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4088. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4089. client->GetPlayer()->UnlockSpell(spell);
  4090. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4091. }
  4092. //if (client ) {
  4093. // ((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);
  4094. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4095. if (outapp)
  4096. client->QueuePacket(outapp);
  4097. }
  4098. }
  4099. return 0;
  4100. }
  4101. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4102. if (!lua_interface)
  4103. return 0;
  4104. Spawn* player = lua_interface->GetSpawn(state);
  4105. if (player && player->IsPlayer()) {
  4106. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4107. return 1;
  4108. }
  4109. return 0;
  4110. }
  4111. int EQ2Emu_lua_Attack(lua_State* state) {
  4112. if (lua_interface) {
  4113. Spawn* npc = lua_interface->GetSpawn(state);
  4114. Spawn* player = lua_interface->GetSpawn(state, 2);
  4115. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4116. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4117. }
  4118. return 0;
  4119. }
  4120. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4121. if (lua_interface) {
  4122. Spawn* target = lua_interface->GetSpawn(state);
  4123. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4124. if (target && target->GetZone())
  4125. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4126. }
  4127. return 0;
  4128. }
  4129. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4130. Spawn* player;
  4131. if (lua_interface) {
  4132. player = lua_interface->GetSpawn(state);
  4133. if (player && player->IsPlayer()) {
  4134. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4135. return 1;
  4136. }
  4137. }
  4138. return 0;
  4139. }
  4140. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4141. Spawn* player;
  4142. Client* client;
  4143. if (lua_interface) {
  4144. player = lua_interface->GetSpawn(state);
  4145. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4146. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4147. client->HandInCollections();
  4148. }
  4149. return 0;
  4150. }
  4151. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4152. Spawn* widget;
  4153. if (lua_interface) {
  4154. widget = lua_interface->GetSpawn(state);
  4155. if (widget && widget->IsWidget())
  4156. ((Widget*)widget)->HandleUse(nullptr, "");
  4157. }
  4158. return 0;
  4159. }
  4160. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4161. Spawn* spawn = 0;
  4162. int32 primary_list = 0;
  4163. int32 secondary_list = 0;
  4164. if (lua_interface) {
  4165. spawn = lua_interface->GetSpawn(state);
  4166. primary_list = lua_interface->GetInt32Value(state, 2);
  4167. secondary_list = lua_interface->GetInt32Value(state, 3);
  4168. if (!spawn->IsNPC()) {
  4169. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4170. return 0;
  4171. }
  4172. NPC* npc = (NPC*)spawn;
  4173. npc->SetPrimarySpellList(primary_list);
  4174. npc->SetSecondarySpellList(secondary_list);
  4175. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4176. }
  4177. return 0;
  4178. }
  4179. int EQ2Emu_lua_GetPet(lua_State* state) {
  4180. if (!lua_interface)
  4181. return 0;
  4182. Spawn* spawn = lua_interface->GetSpawn(state);
  4183. if (spawn) {
  4184. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4185. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4186. return 1;
  4187. }
  4188. }
  4189. return 0;
  4190. }
  4191. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4192. if (!lua_interface)
  4193. return 0;
  4194. Spawn* spawn = lua_interface->GetSpawn(state);
  4195. if (spawn) {
  4196. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4197. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4198. return 1;
  4199. }
  4200. }
  4201. return 0;
  4202. }
  4203. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4204. if (!lua_interface)
  4205. return 0;
  4206. Spawn* spawn = lua_interface->GetSpawn(state);
  4207. if (spawn) {
  4208. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4209. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4210. return 1;
  4211. }
  4212. }
  4213. return 0;
  4214. }
  4215. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4216. if (!lua_interface)
  4217. return 0;
  4218. Spawn* spawn = lua_interface->GetSpawn(state);
  4219. if (spawn) {
  4220. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4221. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4222. return 1;
  4223. }
  4224. }
  4225. return 0;
  4226. }
  4227. int EQ2Emu_lua_Charm(lua_State* state) {
  4228. if (!lua_interface)
  4229. return 0;
  4230. Spawn* owner = lua_interface->GetSpawn(state);
  4231. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4232. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4233. if (!luaspell) {
  4234. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4235. return 0;
  4236. }
  4237. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4238. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4239. pet->SetPet(true);
  4240. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4241. ((NPC*)pet)->SetOwner((Entity*)owner);
  4242. // If owner is player and player does not have a summoned pet set the players charsheet
  4243. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4244. Player* player = (Player*)owner;
  4245. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4246. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4247. player->GetInfoStruct()->set_pet_movement(2);
  4248. player->GetInfoStruct()->set_pet_behavior(3);
  4249. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4250. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4251. // Make sure the values get sent to the client
  4252. player->SetCharSheetChanged(true);
  4253. }
  4254. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4255. pet->SetSpawnScript("");
  4256. // Set faction to the same as the owner
  4257. pet->SetFactionID(owner->GetFactionID());
  4258. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4259. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4260. // Clear hate list
  4261. ((NPC*)pet)->Brain()->ClearHate();
  4262. // Set the brain to a pet brain
  4263. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4264. }
  4265. return 0;
  4266. }
  4267. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4268. if (!lua_interface)
  4269. return 0;
  4270. Spawn* spawn = lua_interface->GetSpawn(state);
  4271. if (!spawn) {
  4272. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4273. return 0;
  4274. }
  4275. vector<Spawn*> groupMembers;
  4276. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4277. groupMembers = *spawn->GetSpawnGroup();
  4278. }
  4279. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4280. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4281. deque<GroupMemberInfo*>::iterator itr;
  4282. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4283. if (group)
  4284. {
  4285. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4286. deque<GroupMemberInfo*>* members = group->GetMembers();
  4287. GroupMemberInfo* info = 0;
  4288. for (itr = members->begin(); itr != members->end(); itr++) {
  4289. info = *itr;
  4290. if (info->client)
  4291. groupMembers.push_back(info->client->GetPlayer());
  4292. }
  4293. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4294. }
  4295. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4296. }
  4297. else
  4298. return 0;
  4299. lua_createtable(state, groupMembers.size(), 0);
  4300. int newTable = lua_gettop(state);
  4301. for (int32 i = 0; i < groupMembers.size(); i++) {
  4302. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4303. lua_rawseti(state, newTable, i + 1);
  4304. }
  4305. return 1;
  4306. }
  4307. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4308. if (!lua_interface)
  4309. return 0;
  4310. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4311. lua_interface->SetOptionWindowValue(state, option_window);
  4312. return 1;
  4313. }
  4314. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4315. if (!lua_interface)
  4316. return 0;
  4317. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4318. if (option_window) {
  4319. OptionWindowOption option_window_option;
  4320. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4321. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4322. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4323. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4324. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4325. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4326. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4327. option_window->push_back(option_window_option);
  4328. }
  4329. return 0;
  4330. }
  4331. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4332. if (!lua_interface)
  4333. return 0;
  4334. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4335. Spawn* player = lua_interface->GetSpawn(state, 2);
  4336. string window_title = lua_interface->GetStringValue(state, 3);
  4337. string cancel_command = lua_interface->GetStringValue(state, 4);
  4338. Client* client = player->GetZone()->GetClientBySpawn(player);
  4339. if (option_window && window_title.length() > 0 && client) {
  4340. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4341. if (!packet)
  4342. return 0;
  4343. packet->setDataByName("title_text", window_title.c_str());
  4344. if (cancel_command.length() > 0)
  4345. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4346. packet->setArrayLengthByName("num_selections", option_window->size());
  4347. vector<OptionWindowOption>::iterator itr;
  4348. int8 i = 0;
  4349. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4350. OptionWindowOption opt = *itr;
  4351. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4352. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4353. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4354. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4355. if (opt.optionCommand.length() > 0)
  4356. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4357. if (opt.optionConfirmTitle.length() > 0)
  4358. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4359. i++;
  4360. }
  4361. client->QueuePacket(packet->serialize());
  4362. safe_delete(option_window);
  4363. safe_delete(packet);
  4364. }
  4365. return 0;
  4366. }
  4367. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4368. if (!lua_interface)
  4369. return 0;
  4370. Spawn* spawn = lua_interface->GetSpawn(state);
  4371. if (spawn) {
  4372. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4373. return 1;
  4374. }
  4375. else
  4376. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4377. return 0;
  4378. }
  4379. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4380. if (!lua_interface)
  4381. return 0;
  4382. Spawn* spawn = lua_interface->GetSpawn(state);
  4383. if (spawn) {
  4384. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4385. return 1;
  4386. }
  4387. else
  4388. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4389. return 0;
  4390. }
  4391. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4392. if (!lua_interface)
  4393. return 0;
  4394. Spawn* spawn = lua_interface->GetSpawn(state);
  4395. if (spawn) {
  4396. int8 class_id = spawn->GetTradeskillClass();
  4397. // Need to add 42 for the offset in the array
  4398. class_id += 44;
  4399. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4400. return 1;
  4401. }
  4402. else
  4403. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4404. return 0;
  4405. }
  4406. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4407. if (!lua_interface)
  4408. return 0;
  4409. Spawn* spawn = lua_interface->GetSpawn(state);
  4410. int16 level = lua_interface->GetInt8Value(state, 2);
  4411. if (spawn) {
  4412. if (spawn->IsPlayer())
  4413. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4414. else
  4415. spawn->SetTSLevel(level);
  4416. }
  4417. else
  4418. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4419. return 0;
  4420. }
  4421. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4422. if (!lua_interface)
  4423. return 0;
  4424. Spawn* spawn = lua_interface->GetSpawn(state);
  4425. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4426. if (spawn) {
  4427. spawn->SetAttackable(attackable);
  4428. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4429. }
  4430. return 0;
  4431. }
  4432. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4433. // Check to see if we have a valid lua_interface
  4434. if (!lua_interface)
  4435. return 0;
  4436. // Get the spawn that is getting the pet
  4437. Spawn* spawn = lua_interface->GetSpawn(state);
  4438. // Get the DB ID of the pet
  4439. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4440. // The max level the pet can gain
  4441. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4442. // Get the spell that this command was called from
  4443. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4444. // Check to make sure the spawn pointer is valid
  4445. if (!spawn) {
  4446. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4447. return 0;
  4448. }
  4449. // Check to make sure the spawn is an entity
  4450. if (!spawn->IsEntity()) {
  4451. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4452. return 0;
  4453. }
  4454. // Check to make sure the spawn doesn't already have a pet of this type
  4455. if (((Entity*)spawn)->GetPet()) {
  4456. if (spawn->IsPlayer()) {
  4457. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4458. if (client)
  4459. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4460. }
  4461. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4462. return 0;
  4463. }
  4464. // Check to see if the DB ID for the pet is set
  4465. if (pet_id == 0) {
  4466. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4467. return 0;
  4468. }
  4469. // Check to see if the pointer to the spell is valid
  4470. if (!luaspell) {
  4471. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4472. return 0;
  4473. }
  4474. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4475. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4476. if (!pet) {
  4477. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4478. return 0;
  4479. }
  4480. // Check to make sure the pet is an npc
  4481. if (!pet->IsNPC()) {
  4482. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4483. return 0;
  4484. }
  4485. // Spawn the pet at the same location as the owner
  4486. pet->SetX(spawn->GetX());
  4487. pet->SetY(spawn->GetY());
  4488. pet->SetZ(spawn->GetZ());
  4489. pet->SetLocation(spawn->GetLocation());
  4490. pet->SetHeading(spawn->GetHeading());
  4491. spawn->GetZone()->AddSpawn(pet);
  4492. /*
  4493. const char* spawn_script = world.GetSpawnScript(pet_id);
  4494. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4495. spawn->SetSpawnScript(string(spawn_script));
  4496. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4497. }*/
  4498. // Get a random pet name
  4499. string random_pet_name;
  4500. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4501. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4502. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4503. // If player set various values for the char sheet (pet window)
  4504. if (spawn->IsPlayer()) {
  4505. Player* player = (Player*)spawn;
  4506. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4507. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4508. player->GetInfoStruct()->set_pet_movement(2);
  4509. player->GetInfoStruct()->set_pet_behavior(3);
  4510. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4511. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4512. // Make sure the values get sent to the client
  4513. player->SetCharSheetChanged(true);
  4514. }
  4515. // Set the pets name
  4516. pet->SetName(random_pet_name.c_str());
  4517. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4518. if (max_level > 0)
  4519. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4520. else
  4521. pet->SetLevel(spawn->GetLevel());
  4522. // Set the max level this pet can reach
  4523. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4524. // Set the faction of the pet to the same faction as the owner
  4525. pet->SetFactionID(spawn->GetFactionID());
  4526. // Set the spawn as a pet
  4527. pet->SetPet(true);
  4528. // Give a pointer of the owner to the pet
  4529. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4530. // Give a pointer of the pet to the owner
  4531. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4532. // Set the pet type
  4533. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4534. // Set the spell id used to create this pet
  4535. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4536. // Set the spell tier used to create this pet
  4537. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4538. // Set the pets spawn type to 6
  4539. pet->SetSpawnType(6);
  4540. // Set the pets brain
  4541. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4542. // Check to see if the pet has a subtitle
  4543. if (strlen(pet->GetSubTitle()) > 0) {
  4544. // Add the players name to the front of the sub title
  4545. string pet_subtitle;
  4546. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4547. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4548. // Set the pets subtitle to the new one
  4549. pet->SetSubTitle(pet_subtitle.c_str());
  4550. }
  4551. // Add the "Pet Options" entity command to the pet
  4552. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4553. // Set the pet as the return value for this function
  4554. lua_interface->SetSpawnValue(state, pet);
  4555. return 1;
  4556. }
  4557. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4558. if (!lua_interface)
  4559. return 0;
  4560. Spawn* spawn = lua_interface->GetSpawn(state);
  4561. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4562. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4563. if (!spawn) {
  4564. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4565. return 0;
  4566. }
  4567. if (!spawn->IsEntity()) {
  4568. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4569. return 0;
  4570. }
  4571. if (((Entity*)spawn)->GetDeityPet()) {
  4572. if (spawn->IsPlayer()) {
  4573. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4574. if (client)
  4575. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4576. }
  4577. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4578. return 0;
  4579. }
  4580. if (pet_id == 0) {
  4581. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4582. return 0;
  4583. }
  4584. if (!luaspell) {
  4585. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4586. return 0;
  4587. }
  4588. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4589. if (!pet) {
  4590. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4591. return 0;
  4592. }
  4593. if (!pet->IsNPC()) {
  4594. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4595. return 0;
  4596. }
  4597. pet->SetX(spawn->GetX());
  4598. pet->SetY(spawn->GetY());
  4599. pet->SetZ(spawn->GetZ());
  4600. pet->SetLocation(spawn->GetLocation());
  4601. pet->SetHeading(spawn->GetHeading());
  4602. spawn->GetZone()->AddSpawn(pet);
  4603. string random_pet_name;
  4604. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4605. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4606. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4607. pet->SetName(random_pet_name.c_str());
  4608. pet->SetLevel(spawn->GetLevel());
  4609. pet->SetFactionID(spawn->GetFactionID());
  4610. pet->SetPet(true);
  4611. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4612. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4613. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4614. pet->SetSpawnType(6);
  4615. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4616. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4617. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4618. if (strlen(pet->GetSubTitle()) > 0) {
  4619. string pet_subtitle;
  4620. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4621. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4622. pet->SetSubTitle(pet_subtitle.c_str());
  4623. }
  4624. // deity and cosmetic pets are not attackable
  4625. pet->SetAttackable(false);
  4626. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4627. lua_interface->SetSpawnValue(state, pet);
  4628. return 1;
  4629. }
  4630. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4631. if (!lua_interface)
  4632. return 0;
  4633. Spawn* spawn = lua_interface->GetSpawn(state);
  4634. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4635. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4636. if (!spawn) {
  4637. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4638. return 0;
  4639. }
  4640. if (!spawn->IsEntity()) {
  4641. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4642. return 0;
  4643. }
  4644. if (((Entity*)spawn)->GetCosmeticPet()) {
  4645. if (spawn->IsPlayer()) {
  4646. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4647. if (client)
  4648. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4649. }
  4650. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4651. return 0;
  4652. }
  4653. if (pet_id == 0) {
  4654. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4655. return 0;
  4656. }
  4657. if (!luaspell) {
  4658. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4659. return 0;
  4660. }
  4661. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4662. if (!pet) {
  4663. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4664. return 0;
  4665. }
  4666. if (!pet->IsNPC()) {
  4667. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4668. return 0;
  4669. }
  4670. pet->SetX(spawn->GetX());
  4671. pet->SetY(spawn->GetY());
  4672. pet->SetZ(spawn->GetZ());
  4673. pet->SetLocation(spawn->GetLocation());
  4674. pet->SetHeading(spawn->GetHeading());
  4675. spawn->GetZone()->AddSpawn(pet);
  4676. string random_pet_name;
  4677. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4678. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4679. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4680. pet->SetName(random_pet_name.c_str());
  4681. pet->SetLevel(spawn->GetLevel());
  4682. pet->SetFactionID(spawn->GetFactionID());
  4683. pet->SetPet(true);
  4684. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4685. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4686. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4687. pet->SetSpawnType(6);
  4688. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4689. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4690. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4691. if (strlen(pet->GetSubTitle()) > 0) {
  4692. string pet_subtitle;
  4693. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4694. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4695. pet->SetSubTitle(pet_subtitle.c_str());
  4696. }
  4697. pet->SetAttackable(false);
  4698. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4699. lua_interface->SetSpawnValue(state, pet);
  4700. return 1;
  4701. }
  4702. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4703. if (!lua_interface)
  4704. return 0;
  4705. Spawn* spawn = lua_interface->GetSpawn(state);
  4706. if (!spawn) {
  4707. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4708. return 0;
  4709. }
  4710. if (!spawn->IsPet()) {
  4711. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4712. return 0;
  4713. }
  4714. if (!((NPC*)spawn)->IsDismissing())
  4715. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4716. return 0;
  4717. }
  4718. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4719. if (!lua_interface)
  4720. return 0;
  4721. Quest* quest = lua_interface->GetQuest(state);
  4722. if (!quest) {
  4723. 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));
  4724. return 0;
  4725. }
  4726. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4727. if (feather_color > 0)
  4728. quest->SetFeatherColor(feather_color);
  4729. return 0;
  4730. }
  4731. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4732. if (!lua_interface)
  4733. return 0;
  4734. Spawn* spawn = lua_interface->GetSpawn(state);
  4735. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4736. if (!spawn) {
  4737. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4738. return 0;
  4739. }
  4740. if (!spawn2) {
  4741. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4742. return 0;
  4743. }
  4744. spawn->RemoveSpawnAccess(spawn2);
  4745. return 0;
  4746. }
  4747. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4748. if (!lua_interface)
  4749. return 0;
  4750. ZoneServer* zone = lua_interface->GetZone(state);
  4751. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4752. if (!zone) {
  4753. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4754. return 0;
  4755. }
  4756. if (location_id == 0) {
  4757. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4758. return 0;
  4759. }
  4760. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4761. if (!location) {
  4762. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4763. return 0;
  4764. }
  4765. Spawn* spawn = 0;
  4766. if (location->entities[0]) {
  4767. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4768. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4769. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4770. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4771. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4772. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4773. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4774. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4775. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4776. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4777. if (spawn) {
  4778. const char* script = 0;
  4779. for (int x = 0; x < 3; x++) {
  4780. switch (x) {
  4781. case 0:
  4782. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4783. break;
  4784. case 1:
  4785. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4786. break;
  4787. case 2:
  4788. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4789. break;
  4790. }
  4791. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4792. spawn->SetSpawnScript(string(script));
  4793. break;
  4794. }
  4795. }
  4796. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4797. lua_interface->SetSpawnValue(state, spawn);
  4798. return 1;
  4799. }
  4800. else {
  4801. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4802. safe_delete(spawn);
  4803. }
  4804. }
  4805. return 0;
  4806. }
  4807. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4808. if (!lua_interface)
  4809. return 0;
  4810. Spawn* caster = lua_interface->GetSpawn(state);
  4811. Spawn* target = lua_interface->GetSpawn(state, 2);
  4812. int32 id = lua_interface->GetInt32Value(state, 3);
  4813. string command = lua_interface->GetStringValue(state, 4);
  4814. if (!caster) {
  4815. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4816. return 0;
  4817. }
  4818. if (!target) {
  4819. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4820. return 0;
  4821. }
  4822. if (!caster->IsPlayer()) {
  4823. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4824. return 0;
  4825. }
  4826. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4827. if (!entity_command) {
  4828. 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());
  4829. return 0;
  4830. }
  4831. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4832. if (!client) {
  4833. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4834. return 0;
  4835. }
  4836. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4837. return 0;
  4838. }
  4839. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4840. if (!lua_interface)
  4841. return 0;
  4842. Spawn* spawn = lua_interface->GetSpawn(state);
  4843. if (!spawn) {
  4844. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4845. return 0;
  4846. }
  4847. if (!spawn->IsNPC()) {
  4848. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4849. return 0;
  4850. }
  4851. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4852. return 0;
  4853. }
  4854. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4855. if (!lua_interface)
  4856. return 0;
  4857. Spawn* spawn = lua_interface->GetSpawn(state);
  4858. int16 tick = lua_interface->GetInt16Value(state, 2);
  4859. if (!spawn) {
  4860. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4861. return 0;
  4862. }
  4863. if (!spawn->IsNPC()) {
  4864. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4865. return 0;
  4866. }
  4867. if (tick < 20) {
  4868. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4869. return 0;
  4870. }
  4871. ((NPC*)spawn)->Brain()->SetTick(tick);
  4872. return 0;
  4873. }
  4874. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4875. if (!lua_interface)
  4876. return 0;
  4877. Spawn* spawn = lua_interface->GetSpawn(state);
  4878. Spawn* target = lua_interface->GetSpawn(state, 2);
  4879. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4880. if (!spawn) {
  4881. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4882. return 0;
  4883. }
  4884. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4885. spawn->SetFollowTarget(target, follow_distance);
  4886. return 0;
  4887. }
  4888. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4889. if (!lua_interface)
  4890. return 0;
  4891. Spawn* spawn = lua_interface->GetSpawn(state);
  4892. if (!spawn) {
  4893. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4894. return 0;
  4895. }
  4896. Spawn* target = spawn->GetFollowTarget();
  4897. if (target) {
  4898. lua_interface->SetSpawnValue(state, target);
  4899. return 1;
  4900. }
  4901. return 0;
  4902. }
  4903. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4904. if (!lua_interface)
  4905. return 0;
  4906. Spawn* spawn = lua_interface->GetSpawn(state);
  4907. if (!spawn) {
  4908. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4909. return 0;
  4910. }
  4911. if (spawn->following)
  4912. spawn->following = false;
  4913. else
  4914. spawn->following = true;
  4915. return 0;
  4916. }
  4917. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4918. if (!lua_interface)
  4919. return 0;
  4920. Spawn* spawn = lua_interface->GetSpawn(state);
  4921. if (!spawn) {
  4922. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4923. return 0;
  4924. }
  4925. lua_interface->SetBooleanValue(state, spawn->following);
  4926. return 1;
  4927. }
  4928. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4929. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4930. // I will attempt to explain how this function works for future refrence
  4931. // Fist lets make sure lua_interface is valid, if not return out
  4932. if (!lua_interface)
  4933. return 0;
  4934. // Next we grab the first 2 params same as we usually would
  4935. Spawn* spawn = lua_interface->GetSpawn(state);
  4936. string var = lua_interface->GetStringValue(state, 2);
  4937. // 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
  4938. // 1 = Spawn
  4939. // 2 = Zone
  4940. // 3 = Item
  4941. // 4 = Quest
  4942. // 5 = String
  4943. // 6 = nil (null)
  4944. int8 dataType = 0;
  4945. // Define pointers for each potential type
  4946. Spawn* spawnVal = 0;
  4947. ZoneServer* zone = 0;
  4948. Item* item = 0;
  4949. Quest* quest = 0;
  4950. string val;
  4951. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4952. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4953. // options window are also light user data be we do not handle those.
  4954. // We check with lua_islightuserdata(lua_State*, index)
  4955. if (lua_islightuserdata(state, 3)) {
  4956. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4957. // and convert it to LUAUserData*
  4958. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4959. // Check to make sure the data we got is valid, if not give an error
  4960. if (!data || !data->IsCorrectlyInitialized()) {
  4961. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4962. }
  4963. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4964. else if (data->IsSpawn()) {
  4965. spawnVal = data->spawn;
  4966. dataType = 1;
  4967. }
  4968. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4969. else if (data->IsZone()) {
  4970. zone = data->zone;
  4971. dataType = 2;
  4972. }
  4973. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4974. else if (data->IsItem()) {
  4975. item = data->item;
  4976. dataType = 3;
  4977. }
  4978. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4979. else if (data->IsQuest()) {
  4980. quest = data->quest;
  4981. dataType = 4;
  4982. }
  4983. }
  4984. // Wasn't light user data, check if it is nil(null)
  4985. else if (lua_isnil(state, 3)) {
  4986. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4987. dataType = 6;
  4988. }
  4989. // Wasn't light user data or nil (null), must be a string
  4990. else {
  4991. // Set the string and dataType variable
  4992. val = lua_interface->GetStringValue(state, 3);
  4993. dataType = 5;
  4994. }
  4995. // We now have all the params, lets check to make sure they are valid
  4996. if (!spawn) {
  4997. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4998. return 0;
  4999. }
  5000. if (var.length() == 0) {
  5001. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5002. return 0;
  5003. }
  5004. if (dataType == 0) {
  5005. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5006. return 0;
  5007. }
  5008. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5009. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5010. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5011. switch (dataType) {
  5012. case 1:
  5013. // 1 = Spawn
  5014. spawn->AddTempVariable(var, spawnVal);
  5015. break;
  5016. case 2:
  5017. // 2 = Zone
  5018. spawn->AddTempVariable(var, zone);
  5019. break;
  5020. case 3:
  5021. // 3 = Item
  5022. spawn->AddTempVariable(var, item);
  5023. break;
  5024. case 4:
  5025. // 4 = Quest
  5026. spawn->AddTempVariable(var, quest);
  5027. break;
  5028. case 5:
  5029. // 5 = String
  5030. spawn->AddTempVariable(var, val);
  5031. break;
  5032. case 6:
  5033. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5034. spawn->DeleteTempVariable(var);
  5035. break;
  5036. }
  5037. // And we are done so return out
  5038. return 0;
  5039. }
  5040. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5041. if (!lua_interface)
  5042. return 0;
  5043. Spawn* spawn = lua_interface->GetSpawn(state);
  5044. string var = lua_interface->GetStringValue(state, 2);
  5045. if (!spawn) {
  5046. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5047. return 0;
  5048. }
  5049. if (var.length() == 0) {
  5050. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5051. return 0;
  5052. }
  5053. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5054. int8 type = spawn->GetTempVariableType(var);
  5055. Spawn* spawn2 = 0;
  5056. ZoneServer* zone = 0;
  5057. Item* item = 0;
  5058. Quest* quest = 0;
  5059. // Set the lua function return value based on the type of data the variable contains
  5060. switch (type) {
  5061. case 1:
  5062. spawn2 = spawn->GetTempVariableSpawn(var);
  5063. if (!spawn2)
  5064. return 0;
  5065. lua_interface->SetSpawnValue(state, spawn2);
  5066. break;
  5067. case 2:
  5068. zone = spawn->GetTempVariableZone(var);
  5069. if (!zone)
  5070. return 0;
  5071. lua_interface->SetZoneValue(state, zone);
  5072. break;
  5073. case 3:
  5074. item = spawn->GetTempVariableItem(var);
  5075. if (!item)
  5076. return 0;
  5077. lua_interface->SetItemValue(state, item);
  5078. break;
  5079. case 4:
  5080. quest = spawn->GetTempVariableQuest(var);
  5081. if (!quest)
  5082. return 0;
  5083. lua_interface->SetQuestValue(state, quest);
  5084. break;
  5085. case 5:
  5086. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5087. break;
  5088. default:
  5089. // Not a valid type then the variable was not set so return out
  5090. return 0;
  5091. }
  5092. // Return value was set so return out
  5093. return 1;
  5094. }
  5095. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5096. {
  5097. if (!lua_interface)
  5098. return 0;
  5099. Quest* quest = lua_interface->GetQuest(state);
  5100. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5101. string description = lua_interface->GetStringValue(state, 3);
  5102. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5103. if (!quest) {
  5104. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5105. lua_interface->SetBooleanValue(state, false);
  5106. return 1;
  5107. }
  5108. if (!spawn) {
  5109. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5110. lua_interface->SetBooleanValue(state, false);
  5111. return 1;
  5112. }
  5113. if (!spawn->IsPlayer()) {
  5114. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5115. lua_interface->SetBooleanValue(state, false);
  5116. return 1;
  5117. }
  5118. if (item_id == 0) {
  5119. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5120. lua_interface->SetBooleanValue(state, false);
  5121. return 1;
  5122. }
  5123. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5124. if (!client) {
  5125. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5126. lua_interface->SetBooleanValue(state, false);
  5127. return 1;
  5128. }
  5129. Item* item = master_item_list.GetItem(item_id);
  5130. if (!item) {
  5131. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5132. lua_interface->SetBooleanValue(state, false);
  5133. return 1;
  5134. }
  5135. Item* firstItem = new Item(item);
  5136. quest->AddTmpRewardItem(firstItem);
  5137. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5138. bool itemsAddedSuccessfully = true;
  5139. if(num_args > 4)
  5140. {
  5141. for(int8 n=5;n<num_args+1;n++)
  5142. {
  5143. int32 new_item = lua_interface->GetInt32Value(state, n);
  5144. Item* tmpItem = master_item_list.GetItem(new_item);
  5145. if(tmpItem)
  5146. {
  5147. Item* newTmpItem = new Item(tmpItem);
  5148. quest->AddTmpRewardItem(newTmpItem);
  5149. }
  5150. else
  5151. itemsAddedSuccessfully = false;
  5152. }
  5153. }
  5154. client->AddPendingQuestAcceptReward(quest);
  5155. client->DisplayQuestComplete(quest, true, description);
  5156. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5157. return 1;
  5158. }
  5159. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5160. if (!lua_interface)
  5161. return 0;
  5162. Quest* quest = lua_interface->GetQuest(state);
  5163. if (!quest) {
  5164. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5165. return 0;
  5166. }
  5167. quest->SetRepeatable(true);
  5168. return 0;
  5169. }
  5170. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5171. if (!lua_interface)
  5172. return 0;
  5173. Spawn* spawn = lua_interface->GetSpawn(state);
  5174. if (!spawn) {
  5175. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5176. return 0;
  5177. }
  5178. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5179. string ret = classes.GetClassNameCase(base_class);
  5180. if (ret.length() > 0) {
  5181. lua_interface->SetStringValue(state, ret.c_str());
  5182. return 1;
  5183. }
  5184. return 0;
  5185. }
  5186. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5187. if (!lua_interface)
  5188. return 0;
  5189. Spawn* player = lua_interface->GetSpawn(state);
  5190. if (player && player->IsPlayer()) {
  5191. Client* client = player->GetClient();
  5192. if (client)
  5193. client->SendWaypoints();
  5194. }
  5195. return 0;
  5196. }
  5197. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5198. if (!lua_interface)
  5199. return 0;
  5200. Spawn* player = lua_interface->GetSpawn(state);
  5201. string name = lua_interface->GetStringValue(state, 2);
  5202. int32 type = lua_interface->GetInt32Value(state, 3);
  5203. if (type == 0)
  5204. type = 2;
  5205. if (name.length() > 0) {
  5206. if (player && player->IsPlayer()) {
  5207. Client* client = player->GetClient();
  5208. if (client)
  5209. client->AddWaypoint(name, type);
  5210. }
  5211. }
  5212. return 0;
  5213. }
  5214. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5215. if (!lua_interface)
  5216. return 0;
  5217. Spawn* player = lua_interface->GetSpawn(state);
  5218. string name = lua_interface->GetStringValue(state, 2);
  5219. if (name.length() > 0) {
  5220. if (player && player->IsPlayer()) {
  5221. Client* client = player->GetClient();
  5222. if (client)
  5223. client->RemoveWaypoint(name);
  5224. }
  5225. }
  5226. return 0;
  5227. }
  5228. int EQ2Emu_lua_AddWard(lua_State* state) {
  5229. if (!lua_interface)
  5230. return 0;
  5231. int32 damage = lua_interface->GetInt32Value(state);
  5232. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5233. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5234. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5235. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5236. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5237. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5238. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5239. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5240. bool ward_was_added = false;
  5241. ZoneServer* zone = spell->caster->GetZone();
  5242. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5243. for (int32 i = 0; i < spell->targets.size(); i++) {
  5244. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5245. if (!target)
  5246. continue;
  5247. if (target->IsEntity()) {
  5248. // If the ward is already active remove it
  5249. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5250. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5251. // Create new ward info
  5252. WardInfo* ward = new WardInfo;
  5253. ward->Spell = spell;
  5254. ward->BaseDamage = damage;
  5255. ward->DamageLeft = damage;
  5256. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5257. ward->keepWard = keepWard;
  5258. ward->WardType = wardType;
  5259. if (damageAbsorptionPercent > 100)
  5260. damageAbsorptionPercent = 100;
  5261. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5262. if (damageAbsorptionMaxHealthPercent > 100)
  5263. damageAbsorptionMaxHealthPercent = 100;
  5264. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5265. ward->RedirectDamagePercent = redirectDamagePercent;
  5266. ward->LastRedirectDamage = 0;
  5267. ward->LastAbsorbedDamage = 0;
  5268. ward->HitCount = 0;
  5269. spell->num_triggers = maxHitCount;
  5270. spell->had_triggers = true;
  5271. spell->cancel_after_all_triggers = false;
  5272. ward->MaxHitCount = maxHitCount;
  5273. if (wardType == WARD_TYPE_MAGICAL)
  5274. ward->DamageType = damageTypes;
  5275. // Add the ward to the entity
  5276. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5277. ward_was_added = true;
  5278. }
  5279. }
  5280. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5281. if (ward_was_added && spell->caster->IsPlayer()) {
  5282. spell->had_dmg_remaining = true;
  5283. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5284. }
  5285. return 0;
  5286. }
  5287. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5288. if (!lua_interface)
  5289. return 0;
  5290. int32 amount = lua_interface->GetInt32Value(state);
  5291. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5292. WardInfo* ward = 0;
  5293. ZoneServer* zone = spell->caster->GetZone();
  5294. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5295. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5296. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5297. ward = target->GetWard(spell->spell->GetSpellID());
  5298. if (target && ward) {
  5299. ward->DamageLeft += amount;
  5300. if (ward->DamageLeft > ward->BaseDamage)
  5301. ward->DamageLeft = ward->BaseDamage;
  5302. for (int32 i = 0; i < spell->targets.size(); i++) {
  5303. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5304. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5305. }
  5306. }
  5307. }
  5308. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5309. if (ward && spell->caster->IsPlayer())
  5310. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5311. return 0;
  5312. }
  5313. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5314. if (!lua_interface)
  5315. return 0;
  5316. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5317. if (!spell) {
  5318. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5322. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5323. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5324. if (ward) {
  5325. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5326. return 1;
  5327. }
  5328. }
  5329. return 0;
  5330. }
  5331. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5332. if (!lua_interface)
  5333. return 0;
  5334. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5335. if (!spell) {
  5336. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5337. return 0;
  5338. }
  5339. string type = lua_interface->GetStringValue(state, 2);
  5340. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5341. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5342. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5343. if (ward) {
  5344. if (boost::iequals(type, "damageleft"))
  5345. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5346. else if (boost::iequals(type, "basedamage"))
  5347. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5348. else if (boost::iequals(type, "keepward"))
  5349. lua_interface->SetBooleanValue(state, ward->keepWard);
  5350. else if (boost::iequals(type, "wardtype"))
  5351. lua_interface->SetInt32Value(state, ward->WardType);
  5352. else if (boost::iequals(type, "dmgabsorptionpct"))
  5353. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5354. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5355. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5356. else if (boost::iequals(type, "redirectdamagepercent"))
  5357. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5358. else if (boost::iequals(type, "lastredirectdamage"))
  5359. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5360. else if (boost::iequals(type, "lastabsorbeddamage"))
  5361. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5362. else if (boost::iequals(type, "hitcount"))
  5363. lua_interface->SetInt32Value(state, ward->HitCount);
  5364. else if (boost::iequals(type, "maxhitcount"))
  5365. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5366. else
  5367. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5368. return 1;
  5369. }
  5370. }
  5371. return 0;
  5372. }
  5373. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5374. if (!lua_interface)
  5375. return 0;
  5376. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5377. ZoneServer* zone = spell->caster->GetZone();
  5378. Spawn* target = 0;
  5379. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5380. for (int32 i = 0; i < spell->targets.size(); i++) {
  5381. target = zone->GetSpawnByID(spell->targets.at(i));
  5382. if (target && target->IsEntity()) {
  5383. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5384. }
  5385. }
  5386. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5387. return 0;
  5388. }
  5389. int EQ2Emu_lua_Interrupt(lua_State* state)
  5390. {
  5391. if (!lua_interface)
  5392. return 0;
  5393. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5394. Spawn* target = lua_interface->GetSpawn(state, 2);
  5395. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5396. if (!caster)
  5397. {
  5398. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5399. return 0;
  5400. }
  5401. if (!target)
  5402. {
  5403. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5404. return 0;
  5405. }
  5406. if (!spell) {
  5407. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5408. return 0;
  5409. }
  5410. if (!target->IsEntity() && !spell)
  5411. {
  5412. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5413. return 0;
  5414. }
  5415. if (!target && spell) {
  5416. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5417. for (int8 i = 0; i < spell->targets.size(); i++) {
  5418. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5419. if (!target || !target->IsEntity())
  5420. continue;
  5421. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5422. }
  5423. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5424. }
  5425. else
  5426. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5427. return 0;
  5428. }
  5429. int EQ2Emu_lua_Stealth(lua_State* state) {
  5430. if (!lua_interface)
  5431. return 0;
  5432. int8 type = lua_interface->GetInt8Value(state);
  5433. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5434. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5435. if (!spell) {
  5436. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5437. return 0;
  5438. }
  5439. ZoneServer* zone = spell->caster->GetZone();
  5440. if (spawn) {
  5441. if (spawn->IsEntity()) {
  5442. if (type == 1) {
  5443. ((Entity*)spawn)->AddStealthSpell(spell);
  5444. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5445. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5446. }
  5447. else if (type == 2) {
  5448. ((Entity*)spawn)->AddInvisSpell(spell);
  5449. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5450. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5451. }
  5452. return 0;
  5453. }
  5454. else {
  5455. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5456. return 0;
  5457. }
  5458. }
  5459. else {
  5460. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5461. for (int32 i = 0; i < spell->targets.size(); i++) {
  5462. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5463. if (!spawn || !spawn->IsEntity())
  5464. continue;
  5465. if (type == 1) {
  5466. ((Entity*)spawn)->AddStealthSpell(spell);
  5467. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5468. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5469. }
  5470. else if (type == 2) {
  5471. ((Entity*)spawn)->AddInvisSpell(spell);
  5472. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5473. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5474. }
  5475. else {
  5476. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5477. break;
  5478. }
  5479. }
  5480. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5481. }
  5482. return 0;
  5483. }
  5484. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5485. if (!lua_interface)
  5486. return 0;
  5487. Spawn* spawn = lua_interface->GetSpawn(state);
  5488. if (!spawn) {
  5489. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5490. return 0;
  5491. }
  5492. if (spawn->IsEntity()) {
  5493. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5494. return 1;
  5495. }
  5496. else
  5497. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5498. return 0;
  5499. }
  5500. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5501. if (!lua_interface)
  5502. return 0;
  5503. Spawn* spawn = lua_interface->GetSpawn(state);
  5504. if (!spawn) {
  5505. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5506. return 0;
  5507. }
  5508. if (spawn->IsEntity()) {
  5509. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5510. return 1;
  5511. }
  5512. else
  5513. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5514. return 0;
  5515. }
  5516. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5517. if (!lua_interface)
  5518. return 0;
  5519. Spawn* player = lua_interface->GetSpawn(state);
  5520. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5521. lua_interface->ResetFunctionStack(state);
  5522. if (!player->IsPlayer()) {
  5523. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5524. return 0;
  5525. }
  5526. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5527. return 1;
  5528. }
  5529. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5530. if (!lua_interface)
  5531. return 0;
  5532. Spawn* player = lua_interface->GetSpawn(state);
  5533. int8 slot = lua_interface->GetInt8Value(state, 2);
  5534. lua_interface->ResetFunctionStack(state);
  5535. if (!player) {
  5536. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5537. return 0;
  5538. }
  5539. if (!player->IsPlayer()) {
  5540. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5541. return 0;
  5542. }
  5543. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5544. if (!item) {
  5545. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5546. return 0;
  5547. }
  5548. lua_interface->SetItemValue(state, item);
  5549. return 1;
  5550. }
  5551. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5552. if (!lua_interface)
  5553. return 0;
  5554. Spawn* player = lua_interface->GetSpawn(state);
  5555. int32 id = lua_interface->GetInt32Value(state, 2);
  5556. lua_interface->ResetFunctionStack(state);
  5557. if (!player) {
  5558. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5559. return 0;
  5560. }
  5561. if (!player->IsPlayer()) {
  5562. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5563. return 0;
  5564. }
  5565. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5566. if (!item) {
  5567. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5568. return 0;
  5569. }
  5570. lua_interface->SetItemValue(state, item);
  5571. return 1;
  5572. }
  5573. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5574. if (!lua_interface)
  5575. return 0;
  5576. Spawn* spawn = lua_interface->GetSpawn(state);
  5577. int8 slot = lua_interface->GetInt8Value(state, 2);
  5578. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5579. lua_interface->ResetFunctionStack(state);
  5580. if (!spawn) {
  5581. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5582. return 0;
  5583. }
  5584. if (!spawn->IsEntity()) {
  5585. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5586. return 0;
  5587. }
  5588. Item* item = master_item_list.GetItem(item_id);
  5589. if (!item) {
  5590. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5591. return 0;
  5592. }
  5593. Item* copy = new Item(item);
  5594. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5595. if(result)
  5596. {
  5597. ((Entity*)spawn)->SetEquipment(copy, slot);
  5598. spawn->vis_changed = true;
  5599. if(spawn->IsPlayer())
  5600. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5601. }
  5602. else
  5603. {
  5604. safe_delete(copy);
  5605. }
  5606. lua_interface->SetBooleanValue(state, result);
  5607. return 1;
  5608. }
  5609. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5610. if (!lua_interface)
  5611. return 0;
  5612. Spawn* spawn = lua_interface->GetSpawn(state);
  5613. int8 slot = lua_interface->GetInt8Value(state, 2);
  5614. Item* item = lua_interface->GetItem(state, 3);
  5615. lua_interface->ResetFunctionStack(state);
  5616. if (!spawn) {
  5617. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5618. return 0;
  5619. }
  5620. if (!spawn->IsEntity()) {
  5621. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5622. return 0;
  5623. }
  5624. if (!item) {
  5625. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5626. return 0;
  5627. }
  5628. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5629. if(result)
  5630. {
  5631. ((Entity*)spawn)->SetEquipment(item, slot);
  5632. spawn->vis_changed = true;
  5633. if(spawn->IsPlayer())
  5634. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5635. }
  5636. lua_interface->SetBooleanValue(state, result);
  5637. return 1;
  5638. }
  5639. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5640. if (!lua_interface)
  5641. return 0;
  5642. Spawn* spawn = lua_interface->GetSpawn(state);
  5643. int8 slot = lua_interface->GetInt8Value(state, 2);
  5644. 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
  5645. lua_interface->ResetFunctionStack(state);
  5646. if (!spawn) {
  5647. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5648. return 0;
  5649. }
  5650. if (!spawn->IsEntity()) {
  5651. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5652. return 0;
  5653. }
  5654. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5655. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5656. spawn->vis_changed = true;
  5657. if(spawn->IsPlayer())
  5658. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5659. lua_interface->SetBooleanValue(state, true);
  5660. return 1;
  5661. }
  5662. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5663. if (!lua_interface)
  5664. return 0;
  5665. Spawn* spawn = lua_interface->GetSpawn(state);
  5666. int8 slot = lua_interface->GetInt8Value(state, 2);
  5667. int16 type = lua_interface->GetInt16Value(state, 3);
  5668. int8 r = lua_interface->GetInt8Value(state, 4);
  5669. int8 g = lua_interface->GetInt8Value(state, 5);
  5670. int8 b = lua_interface->GetInt8Value(state, 6);
  5671. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5672. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5673. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5674. lua_interface->ResetFunctionStack(state);
  5675. if (!spawn) {
  5676. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5677. return 0;
  5678. }
  5679. if (!spawn->IsEntity()) {
  5680. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5681. return 0;
  5682. }
  5683. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5684. spawn->vis_changed = true;
  5685. lua_interface->SetBooleanValue(state, true);
  5686. return 1;
  5687. }
  5688. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5689. if (!lua_interface)
  5690. return 0;
  5691. Spawn* player = lua_interface->GetSpawn(state);
  5692. int32 id = lua_interface->GetInt32Value(state, 2);
  5693. int8 count = lua_interface->GetInt8Value(state, 3);
  5694. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5695. lua_interface->ResetFunctionStack(state);
  5696. if (!player) {
  5697. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5698. return 0;
  5699. }
  5700. if (!player->IsPlayer()) {
  5701. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5702. return 0;
  5703. }
  5704. if (!count)
  5705. count = 1;
  5706. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5707. if (!item) {
  5708. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5709. return 0;
  5710. }
  5711. lua_interface->SetItemValue(state, item);
  5712. return 1;
  5713. }
  5714. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5715. if (!lua_interface)
  5716. return 0;
  5717. Spawn* spawn = lua_interface->GetSpawn(state);
  5718. int32 anim = lua_interface->GetInt32Value(state, 2);
  5719. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5720. int8 type = lua_interface->GetInt8Value(state, 4);
  5721. if (!spawn) {
  5722. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5723. return 0;
  5724. }
  5725. if (spawn2) {
  5726. if (spawn2->IsPlayer()) {
  5727. if (type != 1 && type != 2)
  5728. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5729. else
  5730. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5731. return 0;
  5732. }
  5733. else {
  5734. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5735. return 0;
  5736. }
  5737. }
  5738. else
  5739. spawn->GetZone()->PlayAnimation(spawn, anim);
  5740. return 0;
  5741. }
  5742. int EQ2Emu_lua_IsPet(lua_State* state) {
  5743. if (!lua_interface)
  5744. return 0;
  5745. Spawn* spawn = lua_interface->GetSpawn(state);
  5746. if (!spawn) {
  5747. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5748. return 0;
  5749. }
  5750. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5751. return 1;
  5752. }
  5753. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5754. if (!lua_interface)
  5755. return 0;
  5756. Spawn* spawn = lua_interface->GetSpawn(state);
  5757. if (!spawn) {
  5758. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5759. return 0;
  5760. }
  5761. if (!spawn->IsNPC()) {
  5762. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5763. return 0;
  5764. }
  5765. if (((NPC*)spawn)->GetOwner()) {
  5766. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5767. return 1;
  5768. }
  5769. return 0;
  5770. }
  5771. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5772. if (!lua_interface)
  5773. return 0;
  5774. Spawn* spawn = lua_interface->GetSpawn(state);
  5775. Spawn* target = lua_interface->GetSpawn(state, 2);
  5776. if (!spawn) {
  5777. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. if (!spawn) {
  5781. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5782. return 0;
  5783. }
  5784. spawn->SetTarget(target);
  5785. return 0;
  5786. }
  5787. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5788. if (!lua_interface)
  5789. return 0;
  5790. Spawn* spawn = lua_interface->GetSpawn(state);
  5791. bool val = lua_interface->GetBooleanValue(state, 2);
  5792. if (!spawn) {
  5793. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5794. return 0;
  5795. }
  5796. if (!spawn->IsEntity()) {
  5797. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5798. return 0;
  5799. }
  5800. ((Entity*)spawn)->InCombat(val);
  5801. if (val) {
  5802. spawn->ClearRunningLocations();
  5803. spawn->CalculateRunningLocation(true);
  5804. }
  5805. return 0;
  5806. }
  5807. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5808. if (!lua_interface)
  5809. return 0;
  5810. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5811. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5812. if (!spawn1) {
  5813. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5814. return 0;
  5815. }
  5816. if (!spawn2) {
  5817. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5821. return 1;
  5822. }
  5823. int EQ2Emu_lua_Runback(lua_State* state) {
  5824. if (!lua_interface)
  5825. return 0;
  5826. Spawn* spawn = lua_interface->GetSpawn(state);
  5827. if (!spawn) {
  5828. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5829. return 0;
  5830. }
  5831. if (!spawn->IsNPC()) {
  5832. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5833. return 0;
  5834. }
  5835. ((NPC*)spawn)->Runback();
  5836. return 0;
  5837. }
  5838. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5839. if (!lua_interface)
  5840. return 0;
  5841. Spawn* spawn = lua_interface->GetSpawn(state);
  5842. if (!spawn) {
  5843. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5844. return 0;
  5845. }
  5846. if (!spawn->IsNPC()) {
  5847. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5848. return 0;
  5849. }
  5850. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5851. return 1;
  5852. }
  5853. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5854. if (!lua_interface)
  5855. return 0;
  5856. Spawn* spawn = lua_interface->GetSpawn(state);
  5857. if (!spawn) {
  5858. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5859. return 0;
  5860. }
  5861. if (!spawn->IsEntity()) {
  5862. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5866. return 1;
  5867. }
  5868. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5869. if (!lua_interface)
  5870. return 0;
  5871. Spawn* spawn = lua_interface->GetSpawn(state);
  5872. if (!spawn) {
  5873. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5874. return 0;
  5875. }
  5876. if (!spawn->IsEntity()) {
  5877. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5878. return 0;
  5879. }
  5880. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5881. return 1;
  5882. }
  5883. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5884. if (!lua_interface)
  5885. return 0;
  5886. Spawn* spawn = lua_interface->GetSpawn(state);
  5887. if (!spawn) {
  5888. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5889. return 0;
  5890. }
  5891. if (!spawn->IsEntity()) {
  5892. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5893. return 0;
  5894. }
  5895. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5896. return 1;
  5897. }
  5898. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5899. if (!lua_interface)
  5900. return 0;
  5901. Spawn* spawn = lua_interface->GetSpawn(state);
  5902. if (!spawn) {
  5903. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5904. return 0;
  5905. }
  5906. if (!spawn->IsEntity()) {
  5907. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5908. return 0;
  5909. }
  5910. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5911. return 1;
  5912. }
  5913. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5914. if (!lua_interface)
  5915. return 0;
  5916. Spawn* spawn = lua_interface->GetSpawn(state);
  5917. Spawn* target = lua_interface->GetSpawn(state, 2);
  5918. float distance = lua_interface->GetFloatValue(state, 3);
  5919. if (!spawn) {
  5920. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5921. return 0;
  5922. }
  5923. if (!target) {
  5924. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5925. return 0;
  5926. }
  5927. if (!spawn->IsNPC()) {
  5928. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5929. return 0;
  5930. }
  5931. if (!target->IsEntity()) {
  5932. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5933. return 0;
  5934. }
  5935. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5936. return 1;
  5937. }
  5938. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5939. if (!lua_interface)
  5940. return 0;
  5941. Spawn* spawn = lua_interface->GetSpawn(state);
  5942. Spawn* target = lua_interface->GetSpawn(state, 2);
  5943. float distance = lua_interface->GetFloatValue(state, 3);
  5944. if (!spawn) {
  5945. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5946. return 0;
  5947. }
  5948. if (!target) {
  5949. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5950. return 0;
  5951. }
  5952. if (!spawn->IsNPC()) {
  5953. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5954. return 0;
  5955. }
  5956. if (!target->IsEntity()) {
  5957. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5958. return 0;
  5959. }
  5960. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5961. return 0;
  5962. }
  5963. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5964. if (!lua_interface)
  5965. return 0;
  5966. Spawn* spawn = lua_interface->GetSpawn(state);
  5967. if (!spawn) {
  5968. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5969. return 0;
  5970. }
  5971. if (!spawn->IsNPC()) {
  5972. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5973. return 0;
  5974. }
  5975. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5976. return 1;
  5977. }
  5978. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5979. if (!lua_interface)
  5980. return 0;
  5981. Spawn* spawn = lua_interface->GetSpawn(state);
  5982. if (!spawn) {
  5983. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5984. return 0;
  5985. }
  5986. if (!spawn->IsNPC()) {
  5987. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5988. return 0;
  5989. }
  5990. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5991. return 1;
  5992. }
  5993. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5994. if (!lua_interface)
  5995. return 0;
  5996. Spawn* spawn = lua_interface->GetSpawn(state);
  5997. if (!spawn) {
  5998. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. if (!spawn->IsNPC()) {
  6002. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6003. return 0;
  6004. }
  6005. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6006. if (hated) {
  6007. lua_interface->SetSpawnValue(state, hated);
  6008. return 1;
  6009. }
  6010. return 0;
  6011. }
  6012. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6013. if (!lua_interface)
  6014. return 0;
  6015. Spawn* spawn = lua_interface->GetSpawn(state);
  6016. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6017. if (!spawn) {
  6018. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6019. return 0;
  6020. }
  6021. if (!spawn->IsNPC()) {
  6022. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6023. return 0;
  6024. }
  6025. if (!hated) {
  6026. ((NPC*)spawn)->Brain()->ClearHate();
  6027. return 0;
  6028. }
  6029. else
  6030. {
  6031. if (!hated->IsEntity()) {
  6032. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6033. return 0;
  6034. }
  6035. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6036. return 0;
  6037. }
  6038. return 0;
  6039. }
  6040. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6041. if (!lua_interface)
  6042. return 0;
  6043. Spawn* spawn = lua_interface->GetSpawn(state);
  6044. if (!spawn) {
  6045. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6046. return 0;
  6047. }
  6048. if (!spawn->IsNPC()) {
  6049. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6050. return 0;
  6051. }
  6052. ((NPC*)spawn)->Brain()->ClearEncounter();
  6053. return 0;
  6054. }
  6055. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6056. if (!lua_interface)
  6057. return 0;
  6058. Spawn* spawn = lua_interface->GetSpawn(state);
  6059. if (!spawn) {
  6060. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6061. return 0;
  6062. }
  6063. if (!spawn->IsNPC()) {
  6064. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6065. return 0;
  6066. }
  6067. // Temp list to store hate list
  6068. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6069. if (encounterList->size() == 0) {
  6070. safe_delete(encounterList);
  6071. return 0;
  6072. }
  6073. lua_createtable(state, encounterList->size(), 0);
  6074. int newTable = lua_gettop(state);
  6075. for (int32 i = 0; i < encounterList->size(); i++) {
  6076. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6077. if (temp)
  6078. lua_interface->SetSpawnValue(state, temp);
  6079. lua_rawseti(state, newTable, i + 1);
  6080. }
  6081. safe_delete(encounterList);
  6082. return 1;
  6083. }
  6084. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6085. if (!lua_interface)
  6086. return 0;
  6087. Spawn* spawn = lua_interface->GetSpawn(state);
  6088. if (!spawn) {
  6089. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6090. return 0;
  6091. }
  6092. if (!spawn->IsNPC()) {
  6093. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6094. return 0;
  6095. }
  6096. // Temp list to store hate list
  6097. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6098. if (hateList->size() == 0) {
  6099. safe_delete(hateList);
  6100. return 0;
  6101. }
  6102. lua_createtable(state, hateList->size(), 0);
  6103. int newTable = lua_gettop(state);
  6104. for (int32 i = 0; i < hateList->size(); i++) {
  6105. lua_interface->SetSpawnValue(state, hateList->at(i));
  6106. lua_rawseti(state, newTable, i + 1);
  6107. }
  6108. safe_delete(hateList);
  6109. return 1;
  6110. }
  6111. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6112. if (!lua_interface)
  6113. return 0;
  6114. Spawn* spawn = lua_interface->GetSpawn(state);
  6115. if (!spawn) {
  6116. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6117. return 0;
  6118. }
  6119. if (spawn->IsPlayer()) {
  6120. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6121. lua_interface->SetBooleanValue(state, true);
  6122. else
  6123. lua_interface->SetBooleanValue(state, false);
  6124. return 1;
  6125. }
  6126. else {
  6127. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6128. return 1;
  6129. }
  6130. }
  6131. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6132. if (!lua_interface)
  6133. return 0;
  6134. Quest* quest = lua_interface->GetQuest(state);
  6135. if (!quest) {
  6136. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6137. return 0;
  6138. }
  6139. quest->SetCompletedFlag(true);
  6140. return 0;
  6141. }
  6142. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6143. if (!lua_interface)
  6144. return 0;
  6145. Spawn* spawn = lua_interface->GetSpawn(state);
  6146. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6147. int8 tier = lua_interface->GetInt8Value(state, 3);
  6148. if (!spawn) {
  6149. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6150. return 0;
  6151. }
  6152. if (!spawn->IsEntity()) {
  6153. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6154. return 0;
  6155. }
  6156. if (spellID == 0) {
  6157. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6158. return 0;
  6159. }
  6160. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6161. if (effect) {
  6162. if (tier > 0) {
  6163. // If a tier was passed chec to see if it is the same as the effect
  6164. if (tier == effect->tier)
  6165. lua_interface->SetBooleanValue(state, true);
  6166. else
  6167. lua_interface->SetBooleanValue(state, false);
  6168. return 1;
  6169. }
  6170. else {
  6171. // Have an effect but no tier was passed so return true
  6172. lua_interface->SetBooleanValue(state, true);
  6173. }
  6174. return 1;
  6175. }
  6176. // no effect so return false
  6177. lua_interface->SetBooleanValue(state, false);
  6178. return 1;
  6179. }
  6180. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6181. if (!lua_interface)
  6182. return 0;
  6183. Spawn* spawn = lua_interface->GetSpawn(state);
  6184. int32 id = lua_interface->GetInt32Value(state, 2);
  6185. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6186. Spawn* spawn2 = 0;
  6187. vector<Spawn*> list;
  6188. if (!spawn) {
  6189. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6190. return 0;
  6191. }
  6192. //If zone not provided, use spawn's zone
  6193. if (!zone)
  6194. zone = spawn->GetZone();
  6195. list = zone->GetSpawnsByID(id);
  6196. if (list.size() == 0) {
  6197. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6198. return 0;
  6199. }
  6200. vector<Spawn*>::iterator itr = list.begin();
  6201. for (int8 i = 0; i < list.size(); i++) {
  6202. spawn2 = itr[i];
  6203. if (spawn2)
  6204. spawn2->AddAllowAccessSpawn(spawn);
  6205. }
  6206. return 0;
  6207. }
  6208. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6209. if (!lua_interface)
  6210. return 0;
  6211. Spawn* spawn = lua_interface->GetSpawn(state);
  6212. int32 id = lua_interface->GetInt32Value(state, 2);
  6213. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6214. Spawn* spawn2 = 0;
  6215. if (!spawn) {
  6216. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6217. return 0;
  6218. }
  6219. //If zone not provided, use spawn's zone
  6220. if (!zone)
  6221. zone = spawn->GetZone();
  6222. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6223. vector<Spawn*>::iterator itr = list.begin();
  6224. if (list.size() == 0) {
  6225. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. for (int8 i = 0; i < list.size(); i++) {
  6229. spawn2 = itr[i];
  6230. if (spawn2)
  6231. spawn2->RemoveSpawnAccess(spawn);
  6232. }
  6233. return 0;
  6234. }
  6235. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6236. if (!lua_interface)
  6237. return 0;
  6238. Quest* quest = lua_interface->GetQuest(state);
  6239. if (!quest) {
  6240. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6241. return 0;
  6242. }
  6243. quest->SetYellowName(true);
  6244. return 0;
  6245. }
  6246. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6247. if (!lua_interface)
  6248. return 0;
  6249. Spawn* spawn = lua_interface->GetSpawn(state);
  6250. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6251. if (!spawn) {
  6252. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6253. return 0;
  6254. }
  6255. if (!spawn->IsPlayer()) {
  6256. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6257. return 0;
  6258. }
  6259. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6260. return 1;
  6261. }
  6262. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6263. if (!lua_interface)
  6264. return 0;
  6265. Spawn* spawn = lua_interface->GetSpawn(state);
  6266. if (!spawn) {
  6267. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6268. return 0;
  6269. }
  6270. if (!spawn->IsPlayer()) {
  6271. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6272. return 0;
  6273. }
  6274. ZoneServer* zone = spawn->GetZone();
  6275. if (!zone) {
  6276. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6277. return 0;
  6278. }
  6279. Instance_Type iType = zone->GetInstanceType();
  6280. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6281. iType == GROUP_LOCKOUT_INSTANCE ||
  6282. iType == RAID_LOCKOUT_INSTANCE ||
  6283. iType == SOLO_PERSIST_INSTANCE ||
  6284. iType == GROUP_PERSIST_INSTANCE ||
  6285. iType == RAID_PERSIST_INSTANCE) {
  6286. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6287. if (data) {
  6288. // Check to see if the timer has already been set, if it has return out.
  6289. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6290. return 0;
  6291. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6292. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6293. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6294. if (client) {
  6295. string time_msg = "";
  6296. int32 time = data->success_lockout_time;
  6297. int16 hour;
  6298. int8 min;
  6299. int8 sec;
  6300. hour = time / 3600;
  6301. time = time % 3600;
  6302. min = time / 60;
  6303. time = time % 60;
  6304. sec = time;
  6305. if (hour > 0) {
  6306. char temp[10];
  6307. sprintf(temp, " %i", hour);
  6308. time_msg.append(temp);
  6309. time_msg.append(" hour");
  6310. time_msg.append((hour > 1) ? "s" : "");
  6311. }
  6312. if (min > 0) {
  6313. char temp[5];
  6314. sprintf(temp, " %i", min);
  6315. time_msg.append(temp);
  6316. time_msg.append(" minute");
  6317. time_msg.append((min > 1) ? "s" : "");
  6318. }
  6319. // Only add seconds if minutes and hours are 0
  6320. if (hour == 0 && min == 0 && sec > 0) {
  6321. char temp[5];
  6322. sprintf(temp, " %i", sec);
  6323. time_msg.append(temp);
  6324. time_msg.append(" second");
  6325. time_msg.append((sec > 1) ? "s" : "");
  6326. }
  6327. 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());
  6328. }
  6329. }
  6330. else
  6331. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6332. }
  6333. else
  6334. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6335. return 0;
  6336. }
  6337. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6338. if (!lua_interface)
  6339. return 0;
  6340. Spawn* spawn = lua_interface->GetSpawn(state);
  6341. if (!spawn) {
  6342. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6343. return 0;
  6344. }
  6345. if (!spawn->IsPlayer()) {
  6346. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6347. return 0;
  6348. }
  6349. ZoneServer* zone = spawn->GetZone();
  6350. if (!zone) {
  6351. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6352. return 0;
  6353. }
  6354. Instance_Type iType = zone->GetInstanceType();
  6355. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6356. iType == GROUP_LOCKOUT_INSTANCE ||
  6357. iType == RAID_LOCKOUT_INSTANCE ||
  6358. iType == SOLO_PERSIST_INSTANCE ||
  6359. iType == GROUP_PERSIST_INSTANCE ||
  6360. iType == RAID_PERSIST_INSTANCE) {
  6361. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6362. if (data) {
  6363. // Check to see if the timer has already been set, if it has return out.
  6364. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6365. return 0;
  6366. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6367. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6368. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6369. if (client) {
  6370. string time_msg = "";
  6371. int32 time = data->failure_lockout_time;
  6372. int16 hour;
  6373. int8 min;
  6374. int8 sec;
  6375. hour = time / 3600;
  6376. time = time % 3600;
  6377. min = time / 60;
  6378. time = time % 60;
  6379. sec = time;
  6380. if (hour > 0) {
  6381. char temp[10];
  6382. sprintf(temp, " %i", hour);
  6383. time_msg.append(temp);
  6384. time_msg.append(" hour");
  6385. time_msg.append((hour > 1) ? "s" : "");
  6386. }
  6387. if (min > 0) {
  6388. char temp[5];
  6389. sprintf(temp, " %i", min);
  6390. time_msg.append(temp);
  6391. time_msg.append(" minute");
  6392. time_msg.append((min > 1) ? "s" : "");
  6393. }
  6394. // Only add seconds if minutes and hours are 0
  6395. if (hour == 0 && min == 0 && sec > 0) {
  6396. char temp[5];
  6397. sprintf(temp, " %i", sec);
  6398. time_msg.append(temp);
  6399. time_msg.append(" second");
  6400. time_msg.append((sec > 1) ? "s" : "");
  6401. }
  6402. 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());
  6403. }
  6404. }
  6405. else
  6406. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6407. }
  6408. else
  6409. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6410. return 0;
  6411. }
  6412. int EQ2Emu_lua_IsGroundSpawn(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 IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6418. return 0;
  6419. }
  6420. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6421. return 1;
  6422. }
  6423. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6424. if (!lua_interface)
  6425. return 0;
  6426. Spawn* player = lua_interface->GetSpawn(state);
  6427. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6428. if (!player) {
  6429. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6430. return 0;
  6431. }
  6432. if (!player->IsPlayer()) {
  6433. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6434. return 0;
  6435. }
  6436. if (!ground) {
  6437. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6438. return 0;
  6439. }
  6440. if (!ground->IsGroundSpawn()) {
  6441. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6442. return 0;
  6443. }
  6444. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6445. if (!groundspawn_entries) {
  6446. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6447. return 0;
  6448. }
  6449. Skill* skill = 0;
  6450. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6451. if (collection_skill == "Collecting")
  6452. skill = ((Player*)player)->GetSkillByName("Gathering");
  6453. else
  6454. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6455. if (!skill) {
  6456. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6457. return 0;
  6458. }
  6459. vector<GroundSpawnEntry*>::iterator itr;
  6460. GroundSpawnEntry* entry = 0;
  6461. bool can_harvest = false;
  6462. sint32 min_skill = -1;
  6463. int16 totalSkill = skill->current_val;
  6464. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6465. if(skillID != 0xFFFFFFFF)
  6466. {
  6467. ((Entity*)player)->MStats.lock();
  6468. totalSkill += ((Entity*)player)->stats[skillID];
  6469. ((Entity*)player)->MStats.unlock();
  6470. }
  6471. // first, iterate through groundspawn_entries, discard tables player cannot use
  6472. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6473. {
  6474. entry = *itr;
  6475. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6476. min_skill = entry->min_skill_level;
  6477. // if player lacks skill, skip table
  6478. if (entry->min_skill_level > totalSkill)
  6479. continue;
  6480. // if bonus, but player lacks level, skip table
  6481. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6482. continue;
  6483. can_harvest = true;
  6484. break;
  6485. }
  6486. lua_interface->SetBooleanValue(state, can_harvest);
  6487. // If false, send the message to the client
  6488. if (!can_harvest) {
  6489. Client* client = player->GetZone()->GetClientBySpawn(player);
  6490. if (client) {
  6491. string msg = "You do not have enough skill to ";
  6492. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6493. msg.append("gather");
  6494. else if (collection_skill == "Mining")
  6495. msg.append("mine");
  6496. else if (collection_skill == "Trapping")
  6497. msg.append("trap");
  6498. else if (collection_skill == "Foresting")
  6499. msg.append("forest");
  6500. else if (collection_skill == "Fishing")
  6501. msg.append("catch");
  6502. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6503. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6504. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6505. }
  6506. }
  6507. return 1;
  6508. }
  6509. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6510. if (!lua_interface)
  6511. return 0;
  6512. Spawn* player = lua_interface->GetSpawn(state);
  6513. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6514. if (!player) {
  6515. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6516. return 0;
  6517. }
  6518. if (!player->IsPlayer()) {
  6519. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6520. return 0;
  6521. }
  6522. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6523. lua_interface->SetBooleanValue(state, ret);
  6524. return 1;
  6525. }
  6526. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6527. // Check to see if we have a valid lua_interface
  6528. if (!lua_interface)
  6529. return 0;
  6530. // Get the spawn that is getting the pet
  6531. Spawn* spawn = lua_interface->GetSpawn(state);
  6532. Spawn* target = lua_interface->GetSpawn(state, 2);
  6533. // Get the DB ID of the pet
  6534. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6535. float x = lua_interface->GetFloatValue(state, 4);
  6536. float y = lua_interface->GetFloatValue(state, 5);
  6537. float z = lua_interface->GetFloatValue(state, 6);
  6538. // Get the spell that this command was called from
  6539. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6540. // Check to make sure the spawn pointer is valid
  6541. if (!spawn) {
  6542. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6543. return 0;
  6544. }
  6545. // Check to make sure the spawn is an entity
  6546. if (!spawn->IsEntity()) {
  6547. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6548. return 0;
  6549. }
  6550. if (!target) {
  6551. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6552. return 0;
  6553. }
  6554. if (!target->IsEntity()) {
  6555. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6556. return 0;
  6557. }
  6558. // Check to see if the DB ID for the pet is set
  6559. if (pet_id == 0) {
  6560. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6561. return 0;
  6562. }
  6563. // Check to see if the pointer to the spell is valid
  6564. if (!luaspell) {
  6565. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6566. return 0;
  6567. }
  6568. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6569. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6570. if (!pet) {
  6571. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6572. return 0;
  6573. }
  6574. // Check to make sure the pet is an npc
  6575. if (!pet->IsNPC()) {
  6576. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6577. return 0;
  6578. }
  6579. if (x == 0)
  6580. x = spawn->GetX();
  6581. if (y == 0)
  6582. y = spawn->GetY();
  6583. if (z == 0)
  6584. z = spawn->GetZ();
  6585. // Spawn the pet at the same location as the owner
  6586. pet->SetX(x);
  6587. pet->SetY(y);
  6588. pet->SetZ(z);
  6589. pet->SetLocation(spawn->GetLocation());
  6590. pet->SetHeading(spawn->GetHeading());
  6591. spawn->GetZone()->AddSpawn(pet);
  6592. /*
  6593. const char* spawn_script = world.GetSpawnScript(pet_id);
  6594. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6595. spawn->SetSpawnScript(string(spawn_script));
  6596. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6597. }*/
  6598. // Get a random pet name
  6599. string random_pet_name;
  6600. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6601. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6602. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6603. // Set the pets name
  6604. pet->SetName(random_pet_name.c_str());
  6605. // Set the level of the pet to the owners level
  6606. pet->SetLevel(spawn->GetLevel());
  6607. // Set the faction of the pet to the same faction as the owner
  6608. pet->SetFactionID(spawn->GetFactionID());
  6609. // Set the spawn as a pet
  6610. pet->SetPet(true);
  6611. // Give a pointer of the owner to the pet
  6612. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6613. // Set the pet type
  6614. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6615. // Set the spell id used to create this pet
  6616. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6617. // Set the spell tier used to create this pet
  6618. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6619. // Set the pets spawn type to 6
  6620. pet->SetSpawnType(6);
  6621. // Set the pets brain
  6622. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6623. // Check to see if the pet has a subtitle
  6624. if (strlen(pet->GetSubTitle()) > 0) {
  6625. // Add the players name to the front of the sub title
  6626. string pet_subtitle;
  6627. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6628. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6629. // Set the pets subtitle to the new one
  6630. pet->SetSubTitle(pet_subtitle.c_str());
  6631. }
  6632. // Set the pet as the return value for this function
  6633. lua_interface->SetSpawnValue(state, pet);
  6634. return 1;
  6635. }
  6636. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6637. if (!lua_interface)
  6638. return 0;
  6639. Spawn* spawn = lua_interface->GetSpawn(state);
  6640. Spawn* player = lua_interface->GetSpawn(state, 2);
  6641. float max_distance = lua_interface->GetFloatValue(state, 3);
  6642. string type = lua_interface->GetStringValue(state, 4);
  6643. if (!spawn || (spawn && spawn->IsPlayer())) {
  6644. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6645. return 0;
  6646. }
  6647. if (!player || (player && !player->IsPlayer())) {
  6648. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6649. return 0;
  6650. }
  6651. Client* client = 0;
  6652. if (player->GetZone())
  6653. client = player->GetZone()->GetClientBySpawn(player);
  6654. if (!client) {
  6655. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6656. return 0;
  6657. }
  6658. //Set max_distance to default if not set or not proper value
  6659. if (max_distance <= 0)
  6660. max_distance = 500;
  6661. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6662. if (packet) {
  6663. float unknown2_3 = 0;
  6664. int8 placement_mode = 0;
  6665. if (type == "wall") {
  6666. placement_mode = 2;
  6667. unknown2_3 = 150;
  6668. }
  6669. else if (type == "ceiling")
  6670. placement_mode = 1;
  6671. packet->setDataByName("placement_mode", placement_mode);
  6672. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6673. packet->setDataByName("model_type", spawn->GetModelType());
  6674. packet->setDataByName("unknown", 1); //size
  6675. packet->setDataByName("unknown2", 1); //size 2
  6676. packet->setDataByName("unknown2", .5, 1); //size 3
  6677. packet->setDataByName("unknown2", 3, 2);
  6678. packet->setDataByName("unknown2", unknown2_3, 3);
  6679. packet->setDataByName("max_distance", max_distance);
  6680. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6681. client->QueuePacket(packet->serialize());
  6682. safe_delete(packet);
  6683. }
  6684. return 0;
  6685. }
  6686. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6687. if (!lua_interface)
  6688. return 0;
  6689. Item* item = lua_interface->GetItem(state);
  6690. if (!item) {
  6691. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6692. return 0;
  6693. }
  6694. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6695. return 1;
  6696. }
  6697. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6698. if (!lua_interface)
  6699. return 0;
  6700. Spawn* spawn = lua_interface->GetSpawn(state);
  6701. if (!spawn) {
  6702. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6703. return 0;
  6704. }
  6705. if (spawn->GetZone())
  6706. spawn->GetZone()->AddTransportSpawn(spawn);
  6707. return 0;
  6708. }
  6709. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6710. if (!lua_interface)
  6711. return 0;
  6712. Skill* skill = lua_interface->GetSkill(state);
  6713. if (!skill) {
  6714. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6715. return 0;
  6716. }
  6717. lua_interface->SetInt32Value(state, skill->current_val);
  6718. return 1;
  6719. }
  6720. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6721. if (!lua_interface)
  6722. return 0;
  6723. Skill* skill = lua_interface->GetSkill(state);
  6724. if (!skill) {
  6725. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6726. return 0;
  6727. }
  6728. lua_interface->SetInt32Value(state, skill->max_val);
  6729. return 1;
  6730. }
  6731. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6732. if (!lua_interface)
  6733. return 0;
  6734. Skill* skill = lua_interface->GetSkill(state);
  6735. if (!skill) {
  6736. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6737. return 0;
  6738. }
  6739. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6740. return 1;
  6741. }
  6742. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6743. if (!lua_interface)
  6744. return 0;
  6745. Skill* skill = lua_interface->GetSkill(state);
  6746. int16 value = lua_interface->GetInt16Value(state, 2);
  6747. if (!skill) {
  6748. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6749. return 0;
  6750. }
  6751. skill->max_val = value;
  6752. if (skill->max_val < skill->current_val)
  6753. skill->current_val = skill->max_val;
  6754. return 0;
  6755. }
  6756. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6757. if (!lua_interface)
  6758. return 0;
  6759. Skill* skill = lua_interface->GetSkill(state);
  6760. int16 value = lua_interface->GetInt16Value(state, 2);
  6761. if (!skill) {
  6762. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6763. return 0;
  6764. }
  6765. if (value > skill->max_val)
  6766. skill->current_val = skill->max_val;
  6767. else
  6768. skill->current_val = value;
  6769. return 0;
  6770. }
  6771. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6772. if (!lua_interface)
  6773. return 0;
  6774. Spawn* player = lua_interface->GetSpawn(state);
  6775. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6776. if (skill_id > 0 && player && player->IsPlayer()) {
  6777. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6778. return 1;
  6779. }
  6780. return 0;
  6781. }
  6782. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6783. if (!lua_interface)
  6784. return 0;
  6785. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6786. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6787. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6788. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6789. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6790. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6791. if (player_spawn && player_spawn->IsPlayer()) {
  6792. Player* player = (Player*)player_spawn;
  6793. bool added = false;
  6794. if (!player->skill_list.HasSkill(skill_id)) {
  6795. player->AddSkill(skill_id, current_val, max_val, true);
  6796. added = true;
  6797. }
  6798. 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
  6799. Client* client = player->GetClient();
  6800. if (client) {
  6801. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6802. if (packet)
  6803. client->QueuePacket(packet);
  6804. }
  6805. }
  6806. if (added) {
  6807. lua_interface->SetBooleanValue(state, true);
  6808. return 1;
  6809. }
  6810. }
  6811. else {
  6812. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6813. }
  6814. }
  6815. else {
  6816. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6817. }
  6818. lua_interface->SetBooleanValue(state, false);
  6819. return 1;
  6820. }
  6821. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6822. if (!lua_interface)
  6823. return 0;
  6824. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6825. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6826. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6827. if (skill_id > 0) {
  6828. if (player_spawn && player_spawn->IsPlayer()) {
  6829. Player* player = (Player*)player_spawn;
  6830. if (player->skill_list.HasSkill(skill_id)) {
  6831. player->RemovePlayerSkill(skill_id);
  6832. if (!more_to_remove) {
  6833. Client* client = player->GetClient();
  6834. if (client) {
  6835. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6836. if (packet)
  6837. client->QueuePacket(packet);
  6838. }
  6839. }
  6840. }
  6841. }
  6842. else {
  6843. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6844. }
  6845. }
  6846. else {
  6847. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6848. }
  6849. return 0;
  6850. }
  6851. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6852. if (!lua_interface)
  6853. return 0;
  6854. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6855. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6856. int16 amount = lua_interface->GetInt8Value(state, 3);
  6857. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6858. if (amount > 0 && skill_type < 100) {
  6859. if (player_spawn && player_spawn->IsPlayer()) {
  6860. Player* player = (Player*)player_spawn;
  6861. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6862. if (!more_to_increase) {
  6863. Client* client = player->GetClient();
  6864. if (client) {
  6865. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6866. if (packet)
  6867. client->QueuePacket(packet);
  6868. }
  6869. }
  6870. }
  6871. else {
  6872. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6873. }
  6874. }
  6875. else {
  6876. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6877. }
  6878. return 0;
  6879. }
  6880. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6881. if (!lua_interface)
  6882. return 0;
  6883. Spawn* spawn = lua_interface->GetSpawn(state);
  6884. string name = lua_interface->GetStringValue(state, 2);
  6885. if (!spawn) {
  6886. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6887. return 0;
  6888. }
  6889. if (!spawn->IsEntity()) {
  6890. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6891. return 0;
  6892. }
  6893. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6894. if (skill) {
  6895. lua_interface->SetSkillValue(state, skill);
  6896. return 1;
  6897. }
  6898. return 0;
  6899. }
  6900. int EQ2Emu_lua_AddProc(lua_State* state) {
  6901. if (!lua_interface)
  6902. return 0;
  6903. Spawn* spawn = lua_interface->GetSpawn(state);
  6904. int8 type = lua_interface->GetInt8Value(state, 2);
  6905. float chance = lua_interface->GetFloatValue(state, 3);
  6906. Item* item = lua_interface->GetItem(state, 4);
  6907. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6908. LuaSpell* spell = 0;
  6909. if (!spawn && (!spell || !use_all_spelltargets)) {
  6910. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6911. return 0;
  6912. }
  6913. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6914. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6915. return 0;
  6916. }
  6917. if (!item)
  6918. spell = lua_interface->GetCurrentSpell(state);
  6919. if (!item && !spell) {
  6920. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6921. return 0;
  6922. }
  6923. if (spell && use_all_spelltargets) {
  6924. Spawn* target;
  6925. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6926. for (int8 i = 0; i < spell->targets.size(); i++) {
  6927. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6928. if (!target || !target->IsEntity())
  6929. continue;
  6930. ((Entity*)target)->AddProc(type, chance, item, spell);
  6931. }
  6932. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6933. }
  6934. else
  6935. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6936. return 0;
  6937. }
  6938. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6939. if (!lua_interface)
  6940. return 0;
  6941. Spawn* spawn = lua_interface->GetSpawn(state);
  6942. Item* item = lua_interface->GetItem(state, 2);
  6943. LuaSpell* spell = 0;
  6944. if (!spawn) {
  6945. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6946. return 0;
  6947. }
  6948. if (!spawn->IsEntity()) {
  6949. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6950. return 0;
  6951. }
  6952. if (!item)
  6953. spell = lua_interface->GetCurrentSpell(state);
  6954. if (!item && !spell) {
  6955. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6956. return 0;
  6957. }
  6958. if (spell) {
  6959. Spawn* target;
  6960. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6961. for (int8 i = 0; i < spell->targets.size(); i++) {
  6962. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6963. if (!target || !target->IsEntity())
  6964. continue;
  6965. ((Entity*)target)->RemoveProc(item, spell);
  6966. }
  6967. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6968. spell->caster->RemoveProc(item, spell);
  6969. }
  6970. else
  6971. ((Entity*)spawn)->RemoveProc(item, spell);
  6972. return 0;
  6973. }
  6974. int EQ2Emu_lua_Knockback(lua_State* state) {
  6975. if (!lua_interface)
  6976. return 0;
  6977. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6978. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6979. int32 duration = lua_interface->GetInt32Value(state, 3);
  6980. float vertical = lua_interface->GetFloatValue(state, 4);
  6981. float horizontal = lua_interface->GetFloatValue(state, 5);
  6982. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6983. if (!target_spawn) {
  6984. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6985. return 0;
  6986. }
  6987. if (!spawn) {
  6988. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6989. return 0;
  6990. }
  6991. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6992. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6993. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6994. if (packet) {
  6995. packet->setDataByName("target_x", target_spawn->GetX());
  6996. packet->setDataByName("target_y", target_spawn->GetY());
  6997. packet->setDataByName("target_z", target_spawn->GetZ());
  6998. packet->setDataByName("vertical_movement", vertical);
  6999. packet->setDataByName("horizontal_movement", horizontal);
  7000. if (use_heading)
  7001. packet->setDataByName("use_player_heading", 1);
  7002. client->QueuePacket(packet->serialize());
  7003. }
  7004. safe_delete(packet);
  7005. }
  7006. return 0;
  7007. }
  7008. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7009. if (!lua_interface)
  7010. return 0;
  7011. Spawn* spawn = lua_interface->GetSpawn(state);
  7012. if (!spawn) {
  7013. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7014. return 0;
  7015. }
  7016. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7017. return 1;
  7018. }
  7019. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7020. if (!lua_interface)
  7021. return 0;
  7022. Spawn* caster = lua_interface->GetSpawn(state);
  7023. Spawn* target = lua_interface->GetSpawn(state, 2);
  7024. string name = lua_interface->GetStringValue(state, 3);
  7025. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7026. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7027. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7028. string success_msg = lua_interface->GetStringValue(state, 7);
  7029. string effect_msg = lua_interface->GetStringValue(state, 8);
  7030. if (!caster) {
  7031. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7032. return 0;
  7033. }
  7034. if (!caster->IsEntity()) {
  7035. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7036. return 0;
  7037. }
  7038. if (!target) {
  7039. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7040. return 0;
  7041. }
  7042. if (!target->IsEntity()) {
  7043. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7044. return 0;
  7045. }
  7046. if (name.length() == 0) {
  7047. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7048. return 0;
  7049. }
  7050. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7051. return 0;
  7052. }
  7053. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7054. if (!lua_interface)
  7055. return 0;
  7056. string name = lua_interface->GetStringValue(state);
  7057. if (name.length() == 0) {
  7058. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7059. return 0;
  7060. }
  7061. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7062. if (!skill) {
  7063. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7064. return 0;
  7065. }
  7066. lua_interface->SetInt32Value(state, skill->skill_id);
  7067. return 1;
  7068. }
  7069. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7070. if (!lua_interface)
  7071. return 0;
  7072. Spawn* spawn = lua_interface->GetSpawn(state);
  7073. if (!spawn) {
  7074. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7075. return 0;
  7076. }
  7077. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7078. return 1;
  7079. }
  7080. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7081. if (!lua_interface)
  7082. return 0;
  7083. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7084. if (!luaspell) {
  7085. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7086. return 0;
  7087. }
  7088. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7089. return 1;
  7090. }
  7091. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7092. if (!lua_interface)
  7093. return 0;
  7094. Spawn* spawn = lua_interface->GetSpawn(state);
  7095. Spawn* target = lua_interface->GetSpawn(state, 2);
  7096. if (!spawn) {
  7097. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7098. return 0;
  7099. }
  7100. if (!spawn->IsEntity()) {
  7101. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7102. return 0;
  7103. }
  7104. if (!target) {
  7105. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7106. return 0;
  7107. }
  7108. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7109. return 1;
  7110. }
  7111. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7112. if (!lua_interface)
  7113. return 0;
  7114. Spawn* spawn = lua_interface->GetSpawn(state);
  7115. Spawn* target = lua_interface->GetSpawn(state, 2);
  7116. if (!spawn) {
  7117. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7118. return 0;
  7119. }
  7120. if (!spawn->IsEntity()) {
  7121. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7122. return 0;
  7123. }
  7124. if (!target) {
  7125. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7126. return 0;
  7127. }
  7128. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7129. return 1;
  7130. }
  7131. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7132. if (!lua_interface)
  7133. return 0;
  7134. Item* item = lua_interface->GetItem(state);
  7135. if (!item) {
  7136. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7137. return 0;
  7138. }
  7139. lua_interface->SetInt32Value(state, item->details.count);
  7140. return 1;
  7141. }
  7142. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7143. if (!lua_interface)
  7144. return 0;
  7145. Item* item = lua_interface->GetItem(state);
  7146. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7147. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7148. if (!item) {
  7149. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7150. return 0;
  7151. }
  7152. if (!owner) {
  7153. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7154. return 0;
  7155. }
  7156. if (!owner->IsPlayer()) {
  7157. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7158. return 0;
  7159. }
  7160. if (item->stack_count < new_count) {
  7161. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7162. return 0;
  7163. }
  7164. if (new_count > 0) {
  7165. item->details.count = new_count;
  7166. item->save_needed = true;
  7167. }
  7168. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7169. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7170. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7171. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7172. else
  7173. {
  7174. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7175. return 0;
  7176. }
  7177. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7178. if (!client)
  7179. return 0;
  7180. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7181. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7182. if (app)
  7183. client->QueuePacket(app);
  7184. return 0;
  7185. }
  7186. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7187. if (!lua_interface)
  7188. return 0;
  7189. int32 time = lua_interface->GetInt32Value(state);
  7190. string function = lua_interface->GetStringValue(state, 2);
  7191. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7192. Spawn* target = lua_interface->GetSpawn(state, 4);
  7193. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7194. if (time == 0) {
  7195. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7196. return 0;
  7197. }
  7198. if (function.length() == 0) {
  7199. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7200. return 0;
  7201. }
  7202. if (!spell) {
  7203. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7204. return 0;
  7205. }
  7206. SpellScriptTimer* timer = new SpellScriptTimer;
  7207. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7208. #ifdef WIN32
  7209. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7210. #else
  7211. bzero(timer, sizeof(SpellScriptTimer));
  7212. #endif*/
  7213. timer->caster = 0;
  7214. timer->deleteWhenDone = false;
  7215. timer->target = 0;
  7216. timer->time = Timer::GetCurrentTime2() + time;
  7217. timer->customFunction = function;
  7218. timer->spell = spell;
  7219. if (caster)
  7220. timer->caster = caster->GetID();
  7221. if (target)
  7222. timer->target = target->GetID();
  7223. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7224. return 0;
  7225. }
  7226. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7227. if (!lua_interface)
  7228. return 0;
  7229. float hp_perc = lua_interface->GetFloatValue(state);
  7230. float power_perc = lua_interface->GetFloatValue(state, 2);
  7231. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7232. Spawn* target = lua_interface->GetSpawn(state, 4);
  7233. string heal_name = lua_interface->GetStringValue(state, 5);
  7234. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7235. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7236. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7237. if (!spell) {
  7238. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7239. return 0;
  7240. }
  7241. Entity* caster = spell->caster;
  7242. if (!caster) {
  7243. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7244. return 0;
  7245. }
  7246. Client* client = 0;
  7247. PendingResurrection* rez = 0;
  7248. ZoneServer* zone = spell->caster->GetZone();
  7249. if (!target) {
  7250. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7251. if (spell->targets.size() > 0) {
  7252. vector<int32> spell_targets = spell->targets;
  7253. for (int8 i = 0; i < spell_targets.size(); i++) {
  7254. target = zone->GetSpawnByID(spell_targets.at(i));
  7255. if (!target)
  7256. continue;
  7257. if (!target->IsPlayer())
  7258. continue;
  7259. client = target->GetZone()->GetClientBySpawn(target);
  7260. if (!client)
  7261. continue;
  7262. rez = client->GetCurrentRez();
  7263. if (rez->active)
  7264. continue;
  7265. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7266. rez->active = true;
  7267. rez->caster = caster;
  7268. rez->expire_timer = new Timer;
  7269. int32 duration = spell->spell->GetSpellDuration();
  7270. rez->expire_timer->Start(duration * 100);
  7271. rez->hp_perc = hp_perc;
  7272. rez->mp_perc = power_perc;
  7273. rez->range = spell->spell->GetSpellData()->range;
  7274. rez->spell_name = spell->spell->GetName();
  7275. if (heal_name.length() > 0)
  7276. rez->heal_name = heal_name;
  7277. else
  7278. rez->heal_name = rez->spell_name;
  7279. rez->no_calcs = no_calcs;
  7280. rez->crit_mod = crit_mod;
  7281. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7282. if (send_window)
  7283. client->SendResurrectionWindow();
  7284. else {
  7285. target->GetZone()->ResurrectSpawn(target, client);
  7286. rez->should_delete = true;
  7287. }
  7288. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7289. }
  7290. }
  7291. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7292. }
  7293. else {
  7294. client = target->GetZone()->GetClientBySpawn(target);
  7295. if (!client)
  7296. return 0;
  7297. rez = client->GetCurrentRez();
  7298. if (rez->active)
  7299. return 0;
  7300. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7301. rez->active = true;
  7302. rez->caster = caster;
  7303. rez->expire_timer = new Timer;
  7304. int32 duration = spell->spell->GetSpellDuration();
  7305. rez->expire_timer->Start(duration * 100);
  7306. rez->hp_perc = hp_perc;
  7307. rez->mp_perc = power_perc;
  7308. rez->range = spell->spell->GetSpellData()->range;
  7309. rez->spell_name = spell->spell->GetName();
  7310. if (heal_name.length() > 0)
  7311. rez->heal_name = heal_name;
  7312. else
  7313. rez->heal_name = rez->spell_name;
  7314. rez->no_calcs = no_calcs;
  7315. rez->crit_mod = crit_mod;
  7316. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7317. if (send_window)
  7318. client->SendResurrectionWindow();
  7319. else {
  7320. target->GetZone()->ResurrectSpawn(target, client);
  7321. rez->should_delete = true;
  7322. }
  7323. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7324. }
  7325. return 0;
  7326. }
  7327. int EQ2Emu_lua_SetVision(lua_State* state) {
  7328. if (!lua_interface)
  7329. return 0;
  7330. Spawn* spawn = lua_interface->GetSpawn(state);
  7331. int8 vision = lua_interface->GetInt8Value(state, 2);
  7332. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7333. if (!spawn) {
  7334. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7335. return 0;
  7336. }
  7337. if (!spawn->IsEntity()) {
  7338. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7339. return 0;
  7340. }
  7341. if (spell && spell->targets.size() > 0) {
  7342. ZoneServer* zone = spell->caster->GetZone();
  7343. for (int8 i = 0; i < spell->targets.size(); i++) {
  7344. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7345. if (target && target->IsEntity()) {
  7346. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7347. if (target->IsPlayer())
  7348. ((Player*)target)->SetCharSheetChanged(true);
  7349. }
  7350. }
  7351. }
  7352. else {
  7353. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7354. if (spawn->IsPlayer())
  7355. ((Player*)spawn)->SetCharSheetChanged(true);
  7356. }
  7357. return 0;
  7358. }
  7359. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7360. if (!lua_interface)
  7361. return 0;
  7362. Spawn* spawn = lua_interface->GetSpawn(state);
  7363. float intensity = lua_interface->GetFloatValue(state, 2);
  7364. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7365. if (!spawn) {
  7366. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7367. return 0;
  7368. }
  7369. if (!spawn->IsEntity()) {
  7370. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7371. return 0;
  7372. }
  7373. if (spell && spell->targets.size() > 0) {
  7374. ZoneServer* zone = spell->caster->GetZone();
  7375. for (int8 i = 0; i < spell->targets.size(); i++) {
  7376. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7377. if (target && target->IsEntity()) {
  7378. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7379. if (target->IsPlayer())
  7380. ((Player*)target)->SetCharSheetChanged(true);
  7381. }
  7382. }
  7383. }
  7384. else {
  7385. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7386. if (spawn->IsPlayer())
  7387. ((Player*)spawn)->SetCharSheetChanged(true);
  7388. }
  7389. return 0;
  7390. }
  7391. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7392. if (!lua_interface)
  7393. return 0;
  7394. Spawn* spawn = lua_interface->GetSpawn(state);
  7395. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7396. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7397. if (!spawn) {
  7398. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7399. return 0;
  7400. }
  7401. if (!spawn->IsEntity()) {
  7402. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7403. return 0;
  7404. }
  7405. if (spell && spell->targets.size() > 0) {
  7406. ZoneServer* zone = spell->caster->GetZone();
  7407. for (int8 i = 0; i < spell->targets.size(); i++) {
  7408. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7409. if (target && target->IsEntity()) {
  7410. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7411. if (target->IsPlayer())
  7412. ((Player*)target)->SetCharSheetChanged(true);
  7413. }
  7414. }
  7415. }
  7416. else {
  7417. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7418. if (spawn->IsPlayer())
  7419. ((Player*)spawn)->SetCharSheetChanged(true);
  7420. }
  7421. return 0;
  7422. }
  7423. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7424. if (!lua_interface)
  7425. return 0;
  7426. Item* item = lua_interface->GetItem(state);
  7427. int8 type = lua_interface->GetInt32Value(state, 2);
  7428. if (!item) {
  7429. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7430. return 0;
  7431. }
  7432. if (type == 1)
  7433. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7434. else if (type == 2)
  7435. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7436. return 1;
  7437. }
  7438. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7439. if (!lua_interface)
  7440. return 0;
  7441. Spawn* target = lua_interface->GetSpawn(state);
  7442. float val = lua_interface->GetFloatValue(state, 2);
  7443. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7444. // Added from Gangrenous post
  7445. if (spell && spell->resisted)
  7446. return 0;
  7447. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7448. if (val > 1.0f)
  7449. val = 1.0f - (val / 100.0f);
  7450. if (spell && spell->spell && spell->targets.size() > 0) {
  7451. ZoneServer* zone = spell->caster->GetZone();
  7452. for (int32 i = 0; i != spell->targets.size(); i++) {
  7453. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7454. if (spawn && spawn->IsEntity()) {
  7455. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7456. if (spawn->IsPlayer())
  7457. ((Player*)spawn)->SetCharSheetChanged(true);
  7458. }
  7459. }
  7460. }
  7461. else {
  7462. if (target && target->IsEntity()) {
  7463. ((Entity*)target)->SetSpeedMultiplier(val);
  7464. if (target->IsPlayer())
  7465. ((Player*)target)->SetCharSheetChanged(true);
  7466. }
  7467. }
  7468. return 0;
  7469. }
  7470. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7471. if (!lua_interface)
  7472. return 0;
  7473. Spawn* spawn = lua_interface->GetSpawn(state);
  7474. int16 model = lua_interface->GetInt16Value(state, 2);
  7475. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7476. if (spell && spell->spell && spell->targets.size() > 0) {
  7477. ZoneServer* zone = spell->caster->GetZone();
  7478. for (int32 i = 0; i < spell->targets.size(); i++) {
  7479. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7480. if (target)
  7481. target->SetIllusionModel(model);
  7482. }
  7483. }
  7484. else {
  7485. if (!spawn) {
  7486. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. spawn->SetIllusionModel(model);
  7490. }
  7491. return 0;
  7492. }
  7493. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7494. if (!lua_interface)
  7495. return 0;
  7496. Spawn* spawn = lua_interface->GetSpawn(state);
  7497. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7498. if (spell && spell->spell && spell->targets.size() > 0) {
  7499. ZoneServer* zone = spell->caster->GetZone();
  7500. for (int32 i = 0; i < spell->targets.size(); i++) {
  7501. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7502. if (target)
  7503. target->SetIllusionModel(0);
  7504. }
  7505. }
  7506. else {
  7507. if (!spawn) {
  7508. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7509. return 0;
  7510. }
  7511. spawn->SetIllusionModel(0);
  7512. }
  7513. return 0;
  7514. }
  7515. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7516. if (!lua_interface)
  7517. return 0;
  7518. Spawn* caster = lua_interface->GetSpawn(state);
  7519. Spawn* target = lua_interface->GetSpawn(state, 2);
  7520. float chance = lua_interface->GetFloatValue(state, 3);
  7521. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7522. if (!caster) {
  7523. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7524. return 0;
  7525. }
  7526. if (!caster->IsEntity()) {
  7527. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7528. return 0;
  7529. }
  7530. if (!target) {
  7531. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7532. return 0;
  7533. }
  7534. if (!target->IsEntity()) {
  7535. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7536. return 0;
  7537. }
  7538. if (chance <= 0) {
  7539. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7540. return 0;
  7541. }
  7542. if (!spell) {
  7543. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7544. return 0;
  7545. }
  7546. if (((Entity*)caster)->GetThreatTransfer()) {
  7547. return 0;
  7548. }
  7549. ThreatTransfer* transfer = new ThreatTransfer;
  7550. transfer->Target = target->GetID();
  7551. transfer->Amount = chance;
  7552. transfer->Spell = spell;
  7553. ((Entity*)caster)->SetThreatTransfer(transfer);
  7554. return 0;
  7555. }
  7556. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7557. if (!lua_interface)
  7558. return 0;
  7559. Spawn* spawn = lua_interface->GetSpawn(state);
  7560. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7561. if (!spawn) {
  7562. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7563. return 0;
  7564. }
  7565. if (!spell) {
  7566. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7567. return 0;
  7568. }
  7569. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7570. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7571. ((Entity*)spawn)->SetThreatTransfer(0);
  7572. safe_delete(transfer);
  7573. }
  7574. return 0;
  7575. }
  7576. int EQ2Emu_lua_CureByType(lua_State* state) {
  7577. if (!lua_interface)
  7578. return 0;
  7579. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7580. if (!spell) {
  7581. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7582. return 0;
  7583. }
  7584. int8 cure_count = lua_interface->GetInt8Value(state);
  7585. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7586. string cure_name = lua_interface->GetStringValue(state, 3);
  7587. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7588. Spawn* target = lua_interface->GetSpawn(state, 5);
  7589. if (target) {
  7590. if (!target->IsEntity()) {
  7591. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7592. return 0;
  7593. }
  7594. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7595. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7596. }
  7597. else {
  7598. ZoneServer* zone = spell->caster->GetZone();
  7599. vector<int32> targets = spell->targets;
  7600. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7601. for (int8 i = 0; i < targets.size(); i++) {
  7602. target = zone->GetSpawnByID(targets.at(i));
  7603. if (!target || !target->IsEntity())
  7604. continue;
  7605. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7606. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7607. }
  7608. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7609. }
  7610. return 0;
  7611. }
  7612. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7613. if (!lua_interface)
  7614. return 0;
  7615. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7616. if (!spell) {
  7617. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7618. return 0;
  7619. }
  7620. int8 cure_count = lua_interface->GetInt8Value(state);
  7621. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7622. string cure_name = lua_interface->GetStringValue(state, 3);
  7623. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7624. Spawn* target = lua_interface->GetSpawn(state, 5);
  7625. if (target) {
  7626. if (!target->IsEntity()) {
  7627. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7628. return 0;
  7629. }
  7630. if (((Entity*)target)->GetDetCount() > 0)
  7631. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7632. }
  7633. else {
  7634. ZoneServer* zone = spell->caster->GetZone();
  7635. vector<int32> targets = spell->targets;
  7636. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7637. for (int8 i = 0; i < targets.size(); i++) {
  7638. target = zone->GetSpawnByID(targets.at(i));
  7639. if (!target || !target->IsEntity())
  7640. continue;
  7641. if (((Entity*)target)->GetDetCount() > 0)
  7642. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7643. }
  7644. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7645. }
  7646. return 0;
  7647. }
  7648. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7649. if (!lua_interface)
  7650. return 0;
  7651. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7652. if (!spell) {
  7653. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7654. return 0;
  7655. }
  7656. if (!spell->caster) {
  7657. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7658. return 0;
  7659. }
  7660. if (!spell->caster->GetZone()) {
  7661. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7662. return 0;
  7663. }
  7664. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7665. return 0;
  7666. }
  7667. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7668. if (!lua_interface)
  7669. return 0;
  7670. Spawn* spawn = lua_interface->GetSpawn(state);
  7671. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7672. if (!spell) {
  7673. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7674. return 0;
  7675. }
  7676. if (spawn && spawn->IsEntity())
  7677. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7678. else {
  7679. ZoneServer* zone = spell->caster->GetZone();
  7680. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7681. for (int32 i = 0; i < spell->targets.size(); i++) {
  7682. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7683. if (!spawn || !spawn->IsEntity())
  7684. continue;
  7685. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7686. }
  7687. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7688. }
  7689. return 0;
  7690. }
  7691. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7692. if (!lua_interface)
  7693. return 0;
  7694. Spawn* spawn = lua_interface->GetSpawn(state);
  7695. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7696. if (!spell) {
  7697. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7698. return 0;
  7699. }
  7700. if (spawn && spawn->IsEntity())
  7701. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7702. else {
  7703. ZoneServer* zone = spell->caster->GetZone();
  7704. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7705. for (int32 i = 0; i < spell->targets.size(); i++) {
  7706. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7707. if (!spawn || !spawn->IsEntity())
  7708. continue;
  7709. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7710. }
  7711. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7712. }
  7713. return 0;
  7714. }
  7715. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7716. if (!lua_interface)
  7717. return 0;
  7718. Spawn* caster = lua_interface->GetSpawn(state);
  7719. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7720. if (!caster) {
  7721. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7722. return 0;
  7723. }
  7724. if (!caster->IsPlayer()) {
  7725. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7726. return 0;
  7727. }
  7728. Spawn* target = caster->GetTarget();
  7729. if (!target) {
  7730. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7731. return 0;
  7732. }
  7733. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7734. if (!client) {
  7735. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7736. return 0;
  7737. }
  7738. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7739. if (ho) {
  7740. ho->SetTarget(target->GetID());
  7741. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7742. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7743. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7744. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7745. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7746. deque<GroupMemberInfo*>::iterator itr;
  7747. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7748. if (group)
  7749. {
  7750. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7751. deque<GroupMemberInfo*>* members = group->GetMembers();
  7752. for (itr = members->begin(); itr != members->end(); itr++) {
  7753. if ((*itr)->client)
  7754. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7755. }
  7756. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7757. }
  7758. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7759. }
  7760. else
  7761. safe_delete(ho);
  7762. }
  7763. else {
  7764. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7765. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7766. }
  7767. else
  7768. safe_delete(ho);
  7769. }
  7770. }
  7771. return 0;
  7772. }
  7773. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7774. if (!lua_interface)
  7775. return 0;
  7776. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7777. if (!spell) {
  7778. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7779. return 0;
  7780. }
  7781. int16 triggerCount = lua_interface->GetInt16Value(state);
  7782. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7783. if (!triggerCount) {
  7784. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7785. return 0;
  7786. }
  7787. spell->num_triggers = triggerCount;
  7788. spell->had_triggers = true;
  7789. spell->cancel_after_all_triggers = cancel_after_triggers;
  7790. return 0;
  7791. }
  7792. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7793. if (!lua_interface)
  7794. return 0;
  7795. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7796. if (!spell) {
  7797. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7798. return 0;
  7799. }
  7800. lua_interface->SetInt32Value(state, spell->num_triggers);
  7801. return 1;
  7802. }
  7803. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7804. if (!lua_interface)
  7805. return 0;
  7806. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7807. if (!spell) {
  7808. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7809. return 0;
  7810. }
  7811. int16 remove_count = lua_interface->GetInt16Value(state);
  7812. if (!remove_count)
  7813. remove_count = 1;
  7814. if (remove_count >= spell->num_triggers) {
  7815. spell->num_triggers = 0;
  7816. if (spell->cancel_after_all_triggers)
  7817. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7818. }
  7819. else {
  7820. spell->num_triggers -= remove_count;
  7821. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7822. }
  7823. return 0;
  7824. }
  7825. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7826. if (!lua_interface)
  7827. return 0;
  7828. Spawn* spawn = lua_interface->GetSpawn(state);
  7829. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7830. if (!spawn) {
  7831. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7832. return 0;
  7833. }
  7834. if (!copy_spawn) {
  7835. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7836. return 0;
  7837. }
  7838. spawn->CopySpawnAppearance(copy_spawn);
  7839. return 0;
  7840. }
  7841. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7842. Spawn* spawn = lua_interface->GetSpawn(state);
  7843. int8 type = lua_interface->GetInt8Value(state, 2);
  7844. if (!spawn) {
  7845. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7846. return 0;
  7847. }
  7848. else if (!spawn->IsEntity()) {
  7849. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7850. return 0;
  7851. }
  7852. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7853. return 1;
  7854. }
  7855. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7856. if (!lua_interface)
  7857. return 0;
  7858. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7859. int8 type = lua_interface->GetInt8Value(state);
  7860. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7861. if (!spell) {
  7862. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7863. return 0;
  7864. }
  7865. if (spawn) {
  7866. if (!spawn->IsEntity()) {
  7867. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7868. return 0;
  7869. }
  7870. Entity* entity = ((Entity*)spawn);
  7871. entity->AddImmunity(spell, type);
  7872. }
  7873. else {
  7874. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7875. for (int8 i = 0; i < spell->targets.size(); i++) {
  7876. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7877. if (!spawn || !spawn->IsEntity())
  7878. continue;
  7879. Entity* entity = ((Entity*)spawn);
  7880. entity->AddImmunity(spell, type);
  7881. }
  7882. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7883. }
  7884. return 0;
  7885. }
  7886. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7887. if (!lua_interface)
  7888. return 0;
  7889. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7890. int8 type = lua_interface->GetInt8Value(state);
  7891. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7892. if (!spell) {
  7893. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7894. return 0;
  7895. }
  7896. if (spawn) {
  7897. if (!spawn->IsEntity()) {
  7898. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7899. return 0;
  7900. }
  7901. Entity* entity = ((Entity*)spawn);
  7902. entity->RemoveImmunity(spell, type);
  7903. }
  7904. else {
  7905. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7906. for (int8 i = 0; i < spell->targets.size(); i++) {
  7907. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7908. if (!spawn || !spawn->IsEntity())
  7909. continue;
  7910. Entity* entity = ((Entity*)spawn);
  7911. entity->RemoveImmunity(spell, type);
  7912. }
  7913. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7914. }
  7915. return 0;
  7916. }
  7917. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7918. if (!lua_interface)
  7919. return 0;
  7920. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7921. if (!spell) {
  7922. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7923. return 0;
  7924. }
  7925. float snare = lua_interface->GetFloatValue(state);
  7926. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7927. // convert the val to the speed multipler value (100 - val)
  7928. float val = 100.0 - snare;
  7929. val /= 100.0;
  7930. if (spawn) {
  7931. if (!spawn->IsEntity()) {
  7932. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7933. return 0;
  7934. }
  7935. ((Entity*)spawn)->SetSnareValue(spell, val);
  7936. }
  7937. else {
  7938. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7939. for (int8 i = 0; i < spell->targets.size(); i++) {
  7940. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7941. if (!spawn || !spawn->IsEntity())
  7942. continue;
  7943. ((Entity*)spawn)->SetSnareValue(spell, val);
  7944. }
  7945. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7946. }
  7947. return 0;
  7948. }
  7949. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7950. if (!lua_interface)
  7951. return 0;
  7952. Spawn* spawn = lua_interface->GetSpawn(state);
  7953. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7954. if (!spawn) {
  7955. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7956. return 0;
  7957. }
  7958. if (race_id == 0) {
  7959. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7960. return 0;
  7961. }
  7962. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7963. return 1;
  7964. }
  7965. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7966. if (!lua_interface)
  7967. return 0;
  7968. Spawn* spawn = lua_interface->GetSpawn(state);
  7969. if (!spawn) {
  7970. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7971. return 0;
  7972. }
  7973. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7974. return 1;
  7975. }
  7976. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7977. if (!lua_interface)
  7978. return 0;
  7979. Spawn* spawn = lua_interface->GetSpawn(state);
  7980. if (!spawn) {
  7981. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7982. return 0;
  7983. }
  7984. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7985. return 1;
  7986. }
  7987. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7988. if (!lua_interface)
  7989. return 0;
  7990. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7991. if (!spell) {
  7992. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7993. return 0;
  7994. }
  7995. lua_interface->SetStringValue(state, spell->spell->GetName());
  7996. return 1;
  7997. }
  7998. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7999. if (!lua_interface)
  8000. return 0;
  8001. Quest* quest = lua_interface->GetQuest(state);
  8002. if (!quest) {
  8003. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8004. return 0;
  8005. }
  8006. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8007. return 1;
  8008. }
  8009. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8010. if (!lua_interface)
  8011. return 0;
  8012. Quest* quest = lua_interface->GetQuest(state);
  8013. int32 flags = lua_interface->GetInt32Value(state, 2);
  8014. if (!quest) {
  8015. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8016. return 0;
  8017. }
  8018. quest->SetQuestFlags(flags);
  8019. return 0;
  8020. }
  8021. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8022. if (!lua_interface)
  8023. return 0;
  8024. Quest* quest = lua_interface->GetQuest(state);
  8025. Spawn* player = lua_interface->GetSpawn(state, 2);
  8026. int32 step = lua_interface->GetInt32Value(state, 3);
  8027. int32 duration = lua_interface->GetInt32Value(state, 4);
  8028. string action = lua_interface->GetStringValue(state, 5);
  8029. if (!quest) {
  8030. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8031. return 0;
  8032. }
  8033. if (!player) {
  8034. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8035. return 0;
  8036. }
  8037. if (!player->IsPlayer()) {
  8038. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8039. return 0;
  8040. }
  8041. if (step == 0) {
  8042. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8043. return 0;
  8044. }
  8045. if (duration == 0) {
  8046. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8047. return 0;
  8048. }
  8049. if (action.length() == 0) {
  8050. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8051. return 0;
  8052. }
  8053. Client* client = player->GetZone()->GetClientBySpawn(player);
  8054. if (!client) {
  8055. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8056. return 0;
  8057. }
  8058. quest->SetTimerStep(step);
  8059. quest->AddFailedAction(step, action);
  8060. quest->SetStepTimer(duration);
  8061. client->AddQuestTimer(quest->GetQuestID());
  8062. return 0;
  8063. }
  8064. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8065. if (!lua_interface)
  8066. return 0;
  8067. Quest* quest = lua_interface->GetQuest(state);
  8068. Spawn* player = lua_interface->GetSpawn(state, 2);
  8069. if (!quest) {
  8070. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8071. return 0;
  8072. }
  8073. if (!player) {
  8074. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8075. return 0;
  8076. }
  8077. if (!player->IsPlayer()) {
  8078. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8079. return 0;
  8080. }
  8081. Client* client = player->GetZone()->GetClientBySpawn(player);
  8082. if (!client) {
  8083. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8084. return 0;
  8085. }
  8086. quest->SetTimerStep(0);
  8087. quest->SetStepTimer(0);
  8088. client->RemoveQuestTimer(quest->GetQuestID());
  8089. return 0;
  8090. }
  8091. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8092. if (!lua_interface)
  8093. return 0;
  8094. Spawn* player = lua_interface->GetSpawn(state);
  8095. Quest* quest = lua_interface->GetQuest(state, 2);
  8096. int32 step = lua_interface->GetInt32Value(state, 3);
  8097. if (!player) {
  8098. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8099. return 0;
  8100. }
  8101. if (!player->IsPlayer()) {
  8102. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8103. return 0;
  8104. }
  8105. if (!quest) {
  8106. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8107. return 0;
  8108. }
  8109. if (step == 0) {
  8110. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8111. return 0;
  8112. }
  8113. Client* client = player->GetZone()->GetClientBySpawn(player);
  8114. if (!client) {
  8115. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8116. return 0;
  8117. }
  8118. if (quest->RemoveQuestStep(step, client)) {
  8119. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8120. client->GetCurrentZone()->SendQuestUpdates(client);
  8121. }
  8122. else
  8123. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8124. return 0;
  8125. }
  8126. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8127. if (!lua_interface)
  8128. return 0;
  8129. Quest* quest = lua_interface->GetQuest(state, 1);
  8130. int32 step = lua_interface->GetInt32Value(state, 2);
  8131. string desc = lua_interface->GetStringValue(state, 3);
  8132. string task_group = lua_interface->GetStringValue(state, 4);
  8133. if (!quest) {
  8134. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8135. return 0;
  8136. }
  8137. if (step == 0) {
  8138. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8139. return 0;
  8140. }
  8141. QuestStep* quest_step = quest->GetQuestStep(step);
  8142. if (!quest_step) {
  8143. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8144. return 0;
  8145. }
  8146. quest_step->SetStepProgress(0);
  8147. quest_step->SetTaskGroup(task_group);
  8148. quest_step->SetDescription(desc);
  8149. return 0;
  8150. }
  8151. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8152. if (!lua_interface)
  8153. return 0;
  8154. Quest* quest = lua_interface->GetQuest(state);
  8155. int32 step = lua_interface->GetInt32Value(state, 2);
  8156. string action = lua_interface->GetStringValue(state, 3);
  8157. if (!quest) {
  8158. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8159. return 0;
  8160. }
  8161. if (step == 0) {
  8162. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8163. return 0;
  8164. }
  8165. if (action.length() == 0) {
  8166. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8167. return 0;
  8168. }
  8169. quest->AddFailedAction(step, action);
  8170. return 0;
  8171. }
  8172. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8173. if (!lua_interface)
  8174. return 0;
  8175. Spawn* player = lua_interface->GetSpawn(state);
  8176. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8177. int32 step = lua_interface->GetInt32Value(state, 3);
  8178. if (!player) {
  8179. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8180. return 0;
  8181. }
  8182. if (!player->IsPlayer()) {
  8183. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8184. return 0;
  8185. }
  8186. if (quest_id == 0) {
  8187. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8188. return 0;
  8189. }
  8190. if (step == 0) {
  8191. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8192. return 0;
  8193. }
  8194. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8195. if (!quest) {
  8196. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8197. return 0;
  8198. }
  8199. quest->StepFailed(step);
  8200. return 0;
  8201. }
  8202. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8203. if (!lua_interface)
  8204. return 0;
  8205. Spawn* player = lua_interface->GetSpawn(state);
  8206. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8207. if (!player) {
  8208. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8209. return 0;
  8210. }
  8211. if (!player->IsPlayer()) {
  8212. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8213. return 0;
  8214. }
  8215. if (quest_id == 0) {
  8216. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8217. return 0;
  8218. }
  8219. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8220. if (!quest) {
  8221. lua_interface->SetInt32Value(state, 0);
  8222. return 1;
  8223. }
  8224. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8225. return 1;
  8226. }
  8227. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8228. if (!lua_interface)
  8229. return 0;
  8230. string name = lua_interface->GetStringValue(state);
  8231. string value = lua_interface->GetStringValue(state, 2);
  8232. string comment = lua_interface->GetStringValue(state, 3);
  8233. if (name.length() == 0) {
  8234. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8235. return 0;
  8236. }
  8237. if (value.length() == 0) {
  8238. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8239. return 0;
  8240. }
  8241. string varname = string("lua_").append(name);
  8242. Variable* var = variables.FindVariable(varname);
  8243. if (var)
  8244. var->SetValue(value.c_str());
  8245. else {
  8246. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8247. variables.AddVariable(var);
  8248. }
  8249. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8250. return 0;
  8251. }
  8252. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8253. if (!lua_interface)
  8254. return 0;
  8255. string name = lua_interface->GetStringValue(state);
  8256. if (name.length() == 0) {
  8257. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8258. return 0;
  8259. }
  8260. string varname = string("lua_").append(name);
  8261. Variable* var = variables.FindVariable(varname);
  8262. if (var)
  8263. lua_interface->SetStringValue(state, var->GetValue());
  8264. else
  8265. lua_interface->SetStringValue(state, "NULL");
  8266. return 1;
  8267. }
  8268. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8269. if (!lua_interface)
  8270. return 0;
  8271. Spawn* player = lua_interface->GetSpawn(state);
  8272. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8273. if (!player) {
  8274. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8275. return 0;
  8276. }
  8277. if (!player->IsPlayer()) {
  8278. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8279. return 0;
  8280. }
  8281. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8282. return 1;
  8283. }
  8284. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8285. if (!lua_interface)
  8286. return 0;
  8287. Spawn* player = lua_interface->GetSpawn(state);
  8288. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8289. if (!player) {
  8290. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8291. return 0;
  8292. }
  8293. if (!player->IsPlayer()) {
  8294. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8295. return 0;
  8296. }
  8297. Language* language = master_languages_list.GetLanguage(language_id);
  8298. if (language)
  8299. {
  8300. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8301. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8302. }
  8303. return 0;
  8304. }
  8305. int EQ2Emu_lua_IsNight(lua_State* state) {
  8306. if (!lua_interface)
  8307. return 0;
  8308. ZoneServer* zone = lua_interface->GetZone(state);
  8309. if (!zone) {
  8310. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8311. return 0;
  8312. }
  8313. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8314. return 1;
  8315. }
  8316. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8317. if (!lua_interface)
  8318. return 0;
  8319. Spawn* spawn = lua_interface->GetSpawn(state);
  8320. if (!spawn) {
  8321. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (!spawn->IsWidget()) {
  8325. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. ((Widget*)spawn)->SetMultiFloorLift(true);
  8329. if (spawn->GetZone())
  8330. spawn->GetZone()->AddTransportSpawn(spawn);
  8331. return 0;
  8332. }
  8333. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8334. if (!lua_interface)
  8335. return 0;
  8336. Spawn* player = lua_interface->GetSpawn(state);
  8337. int32 path = lua_interface->GetInt32Value(state, 2);
  8338. if (!player) {
  8339. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8340. return 0;
  8341. }
  8342. if (!player->IsPlayer()) {
  8343. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8344. return 0;
  8345. }
  8346. if (path == 0) {
  8347. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8348. return 0;
  8349. }
  8350. Client* client = player->GetZone()->GetClientBySpawn(player);
  8351. if (!client) {
  8352. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8353. return 0;
  8354. }
  8355. client->SendFlightAutoMount(path);
  8356. return 0;
  8357. }
  8358. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8359. if (!lua_interface)
  8360. return 0;
  8361. Spawn* player = lua_interface->GetSpawn(state);
  8362. if (!player) {
  8363. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8364. return 0;
  8365. }
  8366. if (!player->IsPlayer()) {
  8367. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8368. return 0;
  8369. }
  8370. Client* client = player->GetZone()->GetClientBySpawn(player);
  8371. if (!client) {
  8372. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8373. return 0;
  8374. }
  8375. client->EndAutoMount();
  8376. return 0;
  8377. }
  8378. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8379. if (!lua_interface)
  8380. return 0;
  8381. Spawn* player = lua_interface->GetSpawn(state);
  8382. if (!player) {
  8383. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8384. return 0;
  8385. }
  8386. if (!player->IsPlayer()) {
  8387. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8388. return 0;
  8389. }
  8390. Client* client = player->GetZone()->GetClientBySpawn(player);
  8391. if (!client) {
  8392. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8393. return 0;
  8394. }
  8395. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8396. return 1;
  8397. }
  8398. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8399. if (!lua_interface)
  8400. return 0;
  8401. Spawn* player = lua_interface->GetSpawn(state);
  8402. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8403. int32 value = lua_interface->GetInt32Value(state, 3);
  8404. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8405. if (!player) {
  8406. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8407. return 0;
  8408. }
  8409. if (!player->IsPlayer()) {
  8410. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8411. return 0;
  8412. }
  8413. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8414. return 0;
  8415. }
  8416. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8417. if (!lua_interface)
  8418. return 0;
  8419. Spawn* player = lua_interface->GetSpawn(state);
  8420. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8421. if (!player) {
  8422. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. if (!player->IsPlayer()) {
  8426. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8427. return 0;
  8428. }
  8429. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8430. if (!hd)
  8431. return 0;
  8432. lua_interface->SetInt32Value(state, hd->Value);
  8433. lua_interface->SetInt32Value(state, hd->Value2);
  8434. return 2;
  8435. }
  8436. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8437. if (!lua_interface)
  8438. return 0;
  8439. Spawn* spawn = lua_interface->GetSpawn(state);
  8440. int32 grid = lua_interface->GetInt32Value(state, 2);
  8441. if (!spawn) {
  8442. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8443. return 0;
  8444. }
  8445. if (grid == 0) {
  8446. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8450. return 0;
  8451. }
  8452. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8453. if (!lua_interface)
  8454. return 0;
  8455. Spawn* spawn = lua_interface->GetSpawn(state);
  8456. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8457. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8458. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8459. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8460. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8461. if (!spawn) {
  8462. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8463. return 0;
  8464. }
  8465. //Add this quest to the list of required quests for this spawn
  8466. spawn->SetRequiredHistory(event_id, value1, value2);
  8467. //If private spawn value set
  8468. if (private_spawn) {
  8469. //Set the spawn to be private when not granted access via history
  8470. spawn->AddAllowAccessSpawn(spawn);
  8471. spawn->SetPrivateQuestSpawn(true);
  8472. }
  8473. //This value will override vis_flags in the vis packet
  8474. if (flag_override > 0)
  8475. spawn->SetQuestsRequiredOverride(flag_override);
  8476. return 0;
  8477. }
  8478. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8479. if (!lua_interface)
  8480. return 0;
  8481. Spawn* player = lua_interface->GetSpawn(state);
  8482. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8483. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8484. if (!player) {
  8485. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8486. return 0;
  8487. }
  8488. if (!player->IsPlayer()) {
  8489. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8490. return 0;
  8491. }
  8492. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8493. return 1;
  8494. }
  8495. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8496. if (!lua_interface)
  8497. return 0;
  8498. Spawn* player = lua_interface->GetSpawn(state);
  8499. int8 level = lua_interface->GetInt8Value(state, 2);
  8500. if (!player) {
  8501. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8502. return 0;
  8503. }
  8504. if (!player->IsPlayer()) {
  8505. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8506. return 0;
  8507. }
  8508. if (level == 0) {
  8509. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8510. return 0;
  8511. }
  8512. Client* client = player->GetZone()->GetClientBySpawn(player);
  8513. if (!client) {
  8514. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8515. return 0;
  8516. }
  8517. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8518. return 0;
  8519. }
  8520. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8521. if (!lua_interface)
  8522. return 0;
  8523. Spawn* player = lua_interface->GetSpawn(state);
  8524. int32 amount = lua_interface->GetInt32Value(state, 2);
  8525. if (!player) {
  8526. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8527. return 0;
  8528. }
  8529. if (!player->IsPlayer()) {
  8530. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8531. return 0;
  8532. }
  8533. if (amount == 0) {
  8534. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8535. return 0;
  8536. }
  8537. ((Player*)player)->AddCoins(amount);
  8538. return 0;
  8539. }
  8540. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8541. if (!lua_interface)
  8542. return 0;
  8543. Spawn* player = lua_interface->GetSpawn(state);
  8544. int32 amount = lua_interface->GetInt32Value(state, 2);
  8545. if (!player) {
  8546. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8547. return 0;
  8548. }
  8549. if (!player->IsPlayer()) {
  8550. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8551. return 0;
  8552. }
  8553. if (amount == 0) {
  8554. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8555. return 0;
  8556. }
  8557. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8558. return 1;
  8559. }
  8560. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8561. if (!lua_interface)
  8562. return 0;
  8563. ZoneServer* zone = lua_interface->GetZone(state);
  8564. if (!zone) {
  8565. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8566. return 0;
  8567. }
  8568. vector<Entity*> players = zone->GetPlayers();
  8569. if (players.size() == 0)
  8570. return 0;
  8571. lua_createtable(state, players.size(), 0);
  8572. int newTable = lua_gettop(state);
  8573. for (int32 i = 0; i < players.size(); i++) {
  8574. lua_interface->SetSpawnValue(state, players.at(i));
  8575. lua_rawseti(state, newTable, i + 1);
  8576. }
  8577. return 1;
  8578. }
  8579. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8580. if (!lua_interface)
  8581. return 0;
  8582. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8583. if (!zone) {
  8584. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8585. return 0;
  8586. }
  8587. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8588. //Map of <placement_id, location_id>
  8589. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8590. map<int32, int32>::iterator itr;
  8591. vector<Spawn*> group;
  8592. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8593. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8594. if (!location) {
  8595. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8596. return 0;
  8597. }
  8598. Spawn* spawn = 0;
  8599. if (location->entities[0]) {
  8600. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8601. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8602. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8603. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8604. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8605. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8606. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8607. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8608. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8609. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8610. if (spawn) {
  8611. const char* script = 0;
  8612. for (int x = 0; x < 3; x++) {
  8613. switch (x) {
  8614. case 0:
  8615. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8616. break;
  8617. case 1:
  8618. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8619. break;
  8620. case 2:
  8621. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8622. break;
  8623. }
  8624. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8625. spawn->SetSpawnScript(string(script));
  8626. break;
  8627. }
  8628. }
  8629. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8630. lua_interface->SetSpawnValue(state, spawn);
  8631. group.push_back(spawn);
  8632. }
  8633. else {
  8634. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8635. safe_delete(spawn);
  8636. }
  8637. }
  8638. }
  8639. if (!group.empty()) {
  8640. lua_createtable(state, group.size(), 0);
  8641. int newTable = lua_gettop(state);
  8642. for (int32 i = 0; i < group.size(); i++) {
  8643. lua_interface->SetSpawnValue(state, group[i]);
  8644. lua_rawseti(state, newTable, i + 1);
  8645. }
  8646. }
  8647. else
  8648. lua_pushnil(state);
  8649. return 1;
  8650. }
  8651. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8652. if (!lua_interface)
  8653. return 0;
  8654. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8655. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8656. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8657. if (!spawn) {
  8658. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8659. return 0;
  8660. }
  8661. if (anim_id == 0) {
  8662. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8663. return 0;
  8664. }
  8665. if (leeway == 0)
  8666. leeway = 5000;
  8667. spawn->SetSpawnAnim(anim_id);
  8668. spawn->SetSpawnAnimLeeway(leeway);
  8669. return 0;
  8670. }
  8671. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8672. if (!lua_interface)
  8673. return 0;
  8674. Spawn* player = lua_interface->GetSpawn(state);
  8675. if (!player) {
  8676. return 0;
  8677. }
  8678. Client* client = player->GetZone()->GetClientBySpawn(player);
  8679. if (!client) {
  8680. return 0;
  8681. }
  8682. lua_interface->SetInt32Value(state, client->GetVersion());
  8683. return 1;
  8684. }
  8685. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8686. if (!lua_interface)
  8687. return 0;
  8688. Item* item = lua_interface->GetItem(state);
  8689. if (!item) {
  8690. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8691. return 0;
  8692. }
  8693. lua_interface->SetInt32Value(state, item->details.item_id);
  8694. return 1;
  8695. }
  8696. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8697. if (!lua_interface)
  8698. return 0;
  8699. Spawn* spawn = lua_interface->GetSpawn(state);
  8700. if (!spawn) {
  8701. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8702. return 0;
  8703. }
  8704. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8705. return 1;
  8706. }
  8707. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8708. if (!lua_interface)
  8709. return 0;
  8710. Spawn* spawn = lua_interface->GetSpawn(state);
  8711. if (!spawn) {
  8712. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8713. return 0;
  8714. }
  8715. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8716. return 1;
  8717. }
  8718. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8719. if (!lua_interface)
  8720. return 0;
  8721. Spawn* spawn = lua_interface->GetSpawn(state);
  8722. if (!spawn) {
  8723. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8724. return 0;
  8725. }
  8726. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8727. return 1;
  8728. }
  8729. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8730. if (!lua_interface)
  8731. return 0;
  8732. Spawn* spawn = lua_interface->GetSpawn(state);
  8733. if (!spawn) {
  8734. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8735. return 0;
  8736. }
  8737. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8738. return 1;
  8739. }
  8740. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8741. if (!lua_interface)
  8742. return 0;
  8743. Spawn* spawn = lua_interface->GetSpawn(state);
  8744. float pct = lua_interface->GetFloatValue(state, 2);
  8745. if (!spawn) {
  8746. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8747. return 0;
  8748. }
  8749. if (pct == 0) {
  8750. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8751. return 0;
  8752. }
  8753. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8754. lua_interface->SetInt32Value(state, amount);
  8755. return 1;
  8756. }
  8757. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8758. if (!lua_interface)
  8759. return 0;
  8760. Spawn* spawn = lua_interface->GetSpawn(state);
  8761. float pct = lua_interface->GetFloatValue(state, 2);
  8762. if (!spawn) {
  8763. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8764. return 0;
  8765. }
  8766. if (pct == 0) {
  8767. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8768. return 0;
  8769. }
  8770. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8771. lua_interface->SetInt32Value(state, amount);
  8772. return 1;
  8773. }
  8774. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8775. if (!lua_interface)
  8776. return 0;
  8777. Spawn* spawn = lua_interface->GetSpawn(state);
  8778. if (!spawn) {
  8779. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8780. return 0;
  8781. }
  8782. if (!spawn->IsPlayer()) {
  8783. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8784. return 0;
  8785. }
  8786. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8787. return 1;
  8788. }
  8789. int EQ2Emu_lua_Evac(lua_State* state) {
  8790. if (!lua_interface)
  8791. return 0;
  8792. Spawn* target = lua_interface->GetSpawn(state);
  8793. if (target) {
  8794. float x = target->GetZone()->GetSafeX();
  8795. float y = target->GetZone()->GetSafeY();
  8796. float z = target->GetZone()->GetSafeZ();
  8797. float h = target->GetZone()->GetSafeHeading();
  8798. target->SetX(x);
  8799. target->SetY(y);
  8800. target->SetZ(z);
  8801. target->SetHeading(h);
  8802. target->SetSpawnOrigX(target->GetX());
  8803. target->SetSpawnOrigY(target->GetY());
  8804. target->SetSpawnOrigZ(target->GetZ());
  8805. target->SetSpawnOrigHeading(target->GetHeading());
  8806. if (target->IsPlayer()) {
  8807. Client* client = target->GetZone()->GetClientBySpawn(target);
  8808. if (client) {
  8809. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8810. if (packet)
  8811. {
  8812. packet->setDataByName("x", x);
  8813. packet->setDataByName("y", y);
  8814. packet->setDataByName("z", z);
  8815. client->QueuePacket(packet->serialize());
  8816. safe_delete(packet);
  8817. }
  8818. }
  8819. }
  8820. }
  8821. else {
  8822. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8823. ZoneServer* zone = spell->caster->GetZone();
  8824. float x = spell->caster->GetZone()->GetSafeX();
  8825. float y = spell->caster->GetZone()->GetSafeY();
  8826. float z = spell->caster->GetZone()->GetSafeZ();
  8827. float h = spell->caster->GetZone()->GetSafeHeading();
  8828. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8829. for (int32 i = 0; i < spell->targets.size(); i++) {
  8830. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8831. if (!target2)
  8832. continue;
  8833. target2->SetX(x);
  8834. target2->SetY(y);
  8835. target2->SetZ(z);
  8836. target2->SetHeading(h);
  8837. target2->SetSpawnOrigX(target2->GetX());
  8838. target2->SetSpawnOrigY(target2->GetY());
  8839. target2->SetSpawnOrigZ(target2->GetZ());
  8840. target2->SetSpawnOrigHeading(target2->GetHeading());
  8841. if (target2->IsPlayer()) {
  8842. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8843. if (client) {
  8844. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8845. if (packet)
  8846. {
  8847. client->SetReloadingZone(true);
  8848. packet->setDataByName("x", x);
  8849. packet->setDataByName("y", y);
  8850. packet->setDataByName("z", z);
  8851. client->QueuePacket(packet->serialize());
  8852. safe_delete(packet);
  8853. }
  8854. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8855. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8856. }
  8857. }
  8858. }
  8859. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8860. }
  8861. return 0;
  8862. }
  8863. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8864. if (!lua_interface)
  8865. return 0;
  8866. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8867. if (!luaspell) {
  8868. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8869. return 0;
  8870. }
  8871. int8 tier = luaspell->spell->GetSpellTier();
  8872. lua_interface->SetInt32Value(state, tier);
  8873. return 1;
  8874. }
  8875. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8876. if (!lua_interface)
  8877. return 0;
  8878. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8879. if (!luaspell) {
  8880. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8881. return 0;
  8882. }
  8883. int32 spell_id = luaspell->spell->GetSpellID();
  8884. lua_interface->SetInt32Value(state, spell_id);
  8885. return 1;
  8886. }
  8887. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8888. if (!lua_interface)
  8889. return 0;
  8890. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8891. if (!spawn) {
  8892. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8893. return 0;
  8894. }
  8895. if (!spawn->IsPlayer()) {
  8896. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8897. return 0;
  8898. }
  8899. ZoneServer* zone = spawn->GetZone();
  8900. if (!zone) {
  8901. return 0;
  8902. }
  8903. Client* client = zone->GetClientBySpawn(spawn);
  8904. if (!client) {
  8905. return 0;
  8906. }
  8907. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8908. return 0;
  8909. }
  8910. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8911. if (!lua_interface)
  8912. return 0;
  8913. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8914. if (!spawn) {
  8915. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8916. return 0;
  8917. }
  8918. if (!spawn->IsPlayer()) {
  8919. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8920. return 0;
  8921. }
  8922. ZoneServer* zone = spawn->GetZone();
  8923. if (!zone) {
  8924. return 0;
  8925. }
  8926. Client* client = zone->GetClientBySpawn(spawn);
  8927. if (!client) {
  8928. return 0;
  8929. }
  8930. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8931. return 0;
  8932. }
  8933. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8934. if (!lua_interface)
  8935. return 0;
  8936. Spawn* caster = lua_interface->GetSpawn(state);
  8937. Spawn* target = lua_interface->GetSpawn(state, 2);
  8938. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8939. string spell_name = lua_interface->GetStringValue(state, 4);
  8940. if (!caster) {
  8941. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8942. return 0;
  8943. }
  8944. if (!caster->IsEntity()) {
  8945. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8946. return 0;
  8947. }
  8948. if (!target) {
  8949. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8950. return 0;
  8951. }
  8952. if (!target->IsEntity()) {
  8953. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8954. return 0;
  8955. }
  8956. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8957. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8958. return 0;
  8959. }
  8960. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8961. if (!lua_interface)
  8962. return 0;
  8963. Spawn* player = lua_interface->GetSpawn(state);
  8964. int32 amount = lua_interface->GetInt32Value(state, 2);
  8965. if (player && player->IsPlayer() && amount > 0) {
  8966. ((Player*)player)->AddXP(amount);
  8967. ((Player*)player)->SetCharSheetChanged(true);
  8968. Client* client = player->GetZone()->GetClientBySpawn(player);
  8969. if (client) {
  8970. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8971. }
  8972. }
  8973. return 0;
  8974. }
  8975. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8976. if (!lua_interface)
  8977. return 0;
  8978. Spawn* player = lua_interface->GetSpawn(state);
  8979. int8 type = lua_interface->GetInt8Value(state, 2);
  8980. string text = lua_interface->GetStringValue(state, 3);
  8981. Client* client = 0;
  8982. if (player && player->IsPlayer())
  8983. client = player->GetZone()->GetClientBySpawn(player);
  8984. if (!client || text.length() == 0) {
  8985. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8986. return 0;
  8987. }
  8988. client->SimpleMessage(type, text.c_str());
  8989. return 0;
  8990. }
  8991. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8992. if (!lua_interface)
  8993. return 0;
  8994. Spawn* player = lua_interface->GetSpawn(state);
  8995. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8996. Client* client = 0;
  8997. if (player && player->IsPlayer())
  8998. client = player->GetZone()->GetClientBySpawn(player);
  8999. if (!client || !spawn) {
  9000. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9001. return 0;
  9002. }
  9003. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9004. if (!items) {
  9005. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9006. return 0;
  9007. }
  9008. client->Loot(spawn->GetLootCoins(), items, spawn);
  9009. return 0;
  9010. }
  9011. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9012. if (!lua_interface)
  9013. return 0;
  9014. Spawn* spawnref = lua_interface->GetSpawn(state);
  9015. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9016. if (spawn_id > 0 && spawnref) {
  9017. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9018. if (spawns.size() == 0) {
  9019. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9020. return 0;
  9021. }
  9022. Spawn* spawn = 0;
  9023. int16 index = MakeRandomInt(0, spawns.size());
  9024. if (index >= spawns.size() || index < 0)
  9025. index = 0;
  9026. spawn = spawns[index];
  9027. lua_interface->SetSpawnValue(state, spawn);
  9028. return 1;
  9029. }
  9030. else {
  9031. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9032. }
  9033. return 0;
  9034. }
  9035. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9036. Spawn* player = lua_interface->GetSpawn(state);
  9037. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9038. string name = lua_interface->GetStringValue(state, 3);
  9039. float distance = lua_interface->GetFloatValue(state, 4);
  9040. string command = lua_interface->GetStringValue(state, 5);
  9041. string error_text = lua_interface->GetStringValue(state, 6);
  9042. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9043. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9044. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9045. if (distance == 0)
  9046. distance = 10.0f;
  9047. if (command.length() == 0)
  9048. command = name;
  9049. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9050. if (spawns.size() == 0) {
  9051. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9052. return 0;
  9053. }
  9054. Spawn* spawn = 0;
  9055. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9056. spawn = *itr;
  9057. if (spawn) {
  9058. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9059. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9060. }
  9061. }
  9062. }
  9063. return 0;
  9064. }
  9065. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9066. if (!lua_interface)
  9067. return 0;
  9068. Client* client = 0;
  9069. Spawn* player = lua_interface->GetSpawn(state);
  9070. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9071. if (player && player->IsPlayer() && player->GetZone())
  9072. client = player->GetZone()->GetClientBySpawn(player);
  9073. else{
  9074. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9075. return 0;
  9076. }
  9077. if (client) {
  9078. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9079. if (packet) {
  9080. packet->setDataByName("goal_num", goal_num);
  9081. client->QueuePacket(packet->serialize());
  9082. safe_delete(packet);
  9083. }
  9084. }
  9085. return 0;
  9086. }
  9087. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9088. if (!lua_interface)
  9089. return 0;
  9090. Client* client = 0;
  9091. Spawn* player = lua_interface->GetSpawn(state);
  9092. if (player && player->IsPlayer() && player->GetZone())
  9093. client = player->GetZone()->GetClientBySpawn(player);
  9094. else {
  9095. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9096. return 0;
  9097. }
  9098. if (client) {
  9099. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9100. }
  9101. return 0;
  9102. }
  9103. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9104. if (!lua_interface)
  9105. return 0;
  9106. Client* client = 0;
  9107. Spawn* player = lua_interface->GetSpawn(state);
  9108. float duration = lua_interface->GetFloatValue(state, 2);
  9109. string text = lua_interface->GetStringValue(state, 3);
  9110. string voice = lua_interface->GetStringValue(state, 4);
  9111. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9112. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9113. string signal = lua_interface->GetStringValue(state, 7);
  9114. string goal1 = lua_interface->GetStringValue(state, 8);
  9115. string task1 = lua_interface->GetStringValue(state, 9);
  9116. string goal2 = lua_interface->GetStringValue(state, 10);
  9117. string task2 = lua_interface->GetStringValue(state, 11);
  9118. string goal3 = lua_interface->GetStringValue(state, 12);
  9119. string task3 = lua_interface->GetStringValue(state, 13);
  9120. string goal4 = lua_interface->GetStringValue(state, 14);
  9121. string task4 = lua_interface->GetStringValue(state, 15);
  9122. if (!player) {
  9123. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9124. return 0;
  9125. }
  9126. if (!player->IsPlayer()) {
  9127. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9128. return 0;
  9129. }
  9130. else
  9131. client = ((Player*)player)->GetClient();
  9132. if (!client) {
  9133. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9134. return 0;
  9135. }
  9136. if (text.length() == 0) {
  9137. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9138. return 0;
  9139. }
  9140. if (duration >= 0 && duration < 2)
  9141. duration = 2;
  9142. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9143. if (packet) {
  9144. packet->setDataByName("open_seconds_max", duration);
  9145. packet->setDataByName("text", text.c_str());
  9146. packet->setDataByName("voice", voice.c_str());
  9147. int8 num_goals = 1;
  9148. if (task2.length() > 0)
  9149. num_goals++;
  9150. if (task3.length() > 0)
  9151. num_goals++;
  9152. if (task4.length() > 0)
  9153. num_goals++;
  9154. packet->setArrayLengthByName("num_goals", num_goals);
  9155. for (int8 i = 0; i < num_goals; i++) {
  9156. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9157. }
  9158. if (goal1.length() > 0)
  9159. packet->setArrayDataByName("goal_text", goal1.c_str());
  9160. if (goal2.length() > 0)
  9161. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9162. if (goal3.length() > 0)
  9163. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9164. if (goal4.length() > 0)
  9165. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9166. packet->setSubArrayDataByName("task_text", task1.c_str());
  9167. if (task2.length() > 0)
  9168. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9169. if (task3.length() > 0)
  9170. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9171. if (task4.length() > 0)
  9172. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9173. packet->setDataByName("complete_sound", "click");
  9174. packet->setDataByName("signal", signal.c_str());
  9175. packet->setDataByName("voice_key1", voice_key1);
  9176. packet->setDataByName("voice_key2", voice_key2);
  9177. client->QueuePacket(packet->serialize());
  9178. safe_delete(packet);
  9179. }
  9180. return 0;
  9181. }
  9182. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9183. if (!lua_interface)
  9184. return 0;
  9185. Client* client = 0;
  9186. Spawn* player = lua_interface->GetSpawn(state);
  9187. string window = lua_interface->GetStringValue(state, 2);
  9188. int8 show = lua_interface->GetInt8Value(state, 3);
  9189. if (!player) {
  9190. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9191. return 0;
  9192. }
  9193. if (!player->IsPlayer()) {
  9194. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9195. return 0;
  9196. }
  9197. else
  9198. client = ((Player*)player)->GetClient();
  9199. if (!client) {
  9200. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9201. return 0;
  9202. }
  9203. if (window.length() == 0) {
  9204. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9205. return 0;
  9206. }
  9207. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9208. if (packet) {
  9209. packet->setDataByName("window", window.c_str());
  9210. packet->setDataByName("show", show);
  9211. client->QueuePacket(packet->serialize());
  9212. safe_delete(packet);
  9213. }
  9214. return 0;
  9215. }
  9216. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9217. //See GameEvents.txt for options that can be used for this function
  9218. if (!lua_interface)
  9219. return 0;
  9220. Client* client = 0;
  9221. Spawn* player = lua_interface->GetSpawn(state);
  9222. string event_name = lua_interface->GetStringValue(state, 2);
  9223. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9224. if (!player || !player->IsPlayer()) {
  9225. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9226. return 0;
  9227. }
  9228. if (player->GetZone())
  9229. client = player->GetZone()->GetClientBySpawn(player);
  9230. if (!client) {
  9231. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9232. return 0;
  9233. }
  9234. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9235. if (packet) {
  9236. packet->setDataByName("event_name", event_name.c_str());
  9237. packet->setDataByName("enabled", enabled);
  9238. client->QueuePacket(packet->serialize());
  9239. safe_delete(packet);
  9240. }
  9241. return 0;
  9242. }
  9243. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9244. if (!lua_interface)
  9245. return 0;
  9246. Spawn* player = lua_interface->GetSpawn(state);
  9247. if (player && player->IsPlayer()) {
  9248. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9249. return 1;
  9250. }
  9251. return 0;
  9252. }
  9253. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9254. if (!lua_interface)
  9255. return 0;
  9256. Spawn* player = lua_interface->GetSpawn(state);
  9257. int8 step = lua_interface->GetInt8Value(state, 2);
  9258. if (player && player->IsPlayer() && step > 0) {
  9259. ((Player*)player)->SetTutorialStep(step);
  9260. }
  9261. return 0;
  9262. }
  9263. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9264. if (!lua_interface)
  9265. return 0;
  9266. Client* client = 0;
  9267. Spawn* player = lua_interface->GetSpawn(state);
  9268. string window = lua_interface->GetStringValue(state, 2);
  9269. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9270. if (!player) {
  9271. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9272. return 0;
  9273. }
  9274. if (!player->IsPlayer()) {
  9275. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9276. return 0;
  9277. }
  9278. else
  9279. client = ((Player*)player)->GetClient();
  9280. if (!client) {
  9281. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9282. return 0;
  9283. }
  9284. if (window.length() == 0) {
  9285. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9286. return 0;
  9287. }
  9288. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9289. if (packet) {
  9290. packet->setDataByName("window", window.c_str());
  9291. packet->setDataByName("flash_seconds", flash_seconds);
  9292. client->QueuePacket(packet->serialize());
  9293. safe_delete(packet);
  9294. }
  9295. return 0;
  9296. }
  9297. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9298. if (!lua_interface)
  9299. return 0;
  9300. Spawn* spawn = lua_interface->GetSpawn(state);
  9301. Spawn* target = lua_interface->GetSpawn(state, 2);
  9302. if (spawn && target)
  9303. return spawn->CheckLoS(target);
  9304. return 0;
  9305. }
  9306. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9307. if (!lua_interface)
  9308. return 0;
  9309. Spawn* spawn = lua_interface->GetSpawn(state);
  9310. float x = lua_interface->GetFloatValue(state, 2);
  9311. float y = lua_interface->GetFloatValue(state, 3);
  9312. float z = lua_interface->GetFloatValue(state, 4);
  9313. if (spawn)
  9314. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9315. return 0;
  9316. }
  9317. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9318. if (!lua_interface)
  9319. return 0;
  9320. ZoneServer* zone = lua_interface->GetZone(state);
  9321. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9322. if (zone)
  9323. zone->SetExpansionFlag(xpackFlag);
  9324. return 0;
  9325. }
  9326. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9327. if (!lua_interface)
  9328. return 0;
  9329. ZoneServer* zone = lua_interface->GetZone(state);
  9330. if (zone) {
  9331. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9332. return 1;
  9333. }
  9334. return 0;
  9335. }
  9336. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9337. if (!lua_interface)
  9338. return 0;
  9339. ZoneServer* zone = lua_interface->GetZone(state);
  9340. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9341. if (zone)
  9342. zone->SetHolidayFlag(holidayFlag);
  9343. return 0;
  9344. }
  9345. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9346. if (!lua_interface)
  9347. return 0;
  9348. ZoneServer* zone = lua_interface->GetZone(state);
  9349. if (zone) {
  9350. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9351. return 1;
  9352. }
  9353. return 0;
  9354. }
  9355. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9356. if (!lua_interface)
  9357. return 0;
  9358. Spawn* spawn = lua_interface->GetSpawn(state);
  9359. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9360. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9361. float distance = lua_interface->GetFloatValue(state, 4);
  9362. string in_range_function = lua_interface->GetStringValue(state, 5);
  9363. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9364. if (spawn && distance > 0 && in_range_function.length() > 0)
  9365. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9366. return 0;
  9367. }
  9368. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9369. if (!lua_interface)
  9370. return 0;
  9371. Spawn* spawn = lua_interface->GetSpawn(state);
  9372. Spawn* target = lua_interface->GetSpawn(state, 2);
  9373. if (spawn && target)
  9374. {
  9375. if (spawn->IsPlayer() && target->IsEntity())
  9376. {
  9377. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9378. return 1;
  9379. }
  9380. else if (spawn->IsEntity() && target->IsEntity())
  9381. {
  9382. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9383. return 1;
  9384. }
  9385. }
  9386. return 0;
  9387. }
  9388. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9389. if (!lua_interface)
  9390. return 0;
  9391. Spawn* spawn = lua_interface->GetSpawn(state);
  9392. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9393. if (spawn && spawn->IsEntity())
  9394. {
  9395. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9396. if (spawn->IsPlayer())
  9397. {
  9398. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9399. if (client)
  9400. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9401. }
  9402. }
  9403. return 0;
  9404. }
  9405. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9406. if (!lua_interface)
  9407. return 0;
  9408. Spawn* spawn = lua_interface->GetSpawn(state);
  9409. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9410. if (spawn && spawn->IsEntity())
  9411. {
  9412. ((Entity*)spawn)->SetSeeHideSpell(val);
  9413. if (spawn->IsPlayer())
  9414. {
  9415. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9416. if (client)
  9417. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9418. }
  9419. }
  9420. return 0;
  9421. }
  9422. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9423. {
  9424. if (!lua_interface)
  9425. return 0;
  9426. Spawn* player = lua_interface->GetSpawn(state);
  9427. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9428. string command = lua_interface->GetStringValue(state, 3);
  9429. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9430. lua_interface->ResetFunctionStack(state);
  9431. if (spawn && player && player->IsPlayer())
  9432. {
  9433. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9434. bool res = false;
  9435. if (cmd)
  9436. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9437. lua_interface->SetBooleanValue(state, res);
  9438. return 1;
  9439. }
  9440. return 0;
  9441. }
  9442. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9443. {
  9444. if (!lua_interface)
  9445. return 0;
  9446. Spawn* spawn = lua_interface->GetSpawn(state);
  9447. int32 charID = lua_interface->GetInt32Value(state, 2);
  9448. string command = lua_interface->GetStringValue(state, 3);
  9449. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9450. lua_interface->ResetFunctionStack(state);
  9451. if (spawn && charID)
  9452. {
  9453. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9454. bool res = false;
  9455. if (cmd)
  9456. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9457. lua_interface->SetBooleanValue(state, res);
  9458. return 1;
  9459. }
  9460. return 0;
  9461. }
  9462. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9463. {
  9464. if (!lua_interface)
  9465. return 0;
  9466. Spawn* spawn = lua_interface->GetSpawn(state);
  9467. string command = lua_interface->GetStringValue(state, 2);
  9468. lua_interface->ResetFunctionStack(state);
  9469. if (spawn && command.length() > 0)
  9470. spawn->RemovePrimaryEntityCommand(command.c_str());
  9471. return 0;
  9472. }
  9473. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9474. if (!lua_interface)
  9475. return 0;
  9476. Spawn* spawn = lua_interface->GetSpawn(state);
  9477. float distance = lua_interface->GetFloatValue(state, 2);
  9478. string command = lua_interface->GetStringValue(state, 3);
  9479. Spawn* player = lua_interface->GetSpawn(state, 4);
  9480. lua_interface->ResetFunctionStack(state);
  9481. if (spawn) {
  9482. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9483. }
  9484. return 0;
  9485. }
  9486. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9487. if (!lua_interface)
  9488. return 0;
  9489. Spawn* spawn = lua_interface->GetSpawn(state);
  9490. Spawn* player = lua_interface->GetSpawn(state, 2);
  9491. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9492. lua_interface->ResetFunctionStack(state);
  9493. if (spawn && player && transport_id && player->IsPlayer()) {
  9494. Client* client = 0;
  9495. if (player && player->IsPlayer())
  9496. client = player->GetZone()->GetClientBySpawn(player);
  9497. if (!client)
  9498. return 0;
  9499. vector<TransportDestination*> destinations;
  9500. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9501. if (destinations.size())
  9502. {
  9503. client->SetTemporaryTransportID(transport_id);
  9504. client->ProcessTeleport(spawn, &destinations, transport_id);
  9505. }
  9506. else
  9507. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9508. }
  9509. return 0;
  9510. }
  9511. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9512. if (!lua_interface)
  9513. return 0;
  9514. Spawn* player = lua_interface->GetSpawn(state);
  9515. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9516. lua_interface->ResetFunctionStack(state);
  9517. if (player && player->IsPlayer()) {
  9518. Client* client = 0;
  9519. if (player && player->IsPlayer())
  9520. client = player->GetZone()->GetClientBySpawn(player);
  9521. if (!client)
  9522. return 0;
  9523. client->SetTemporaryTransportID(transport_id);
  9524. }
  9525. return 0;
  9526. }
  9527. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9528. if (!lua_interface)
  9529. return 0;
  9530. Spawn* player = lua_interface->GetSpawn(state);
  9531. lua_interface->ResetFunctionStack(state);
  9532. if (player && player->IsPlayer()) {
  9533. Client* client = 0;
  9534. if (player && player->IsPlayer())
  9535. client = player->GetZone()->GetClientBySpawn(player);
  9536. if (!client)
  9537. return 0;
  9538. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9539. return 1;
  9540. }
  9541. return 0;
  9542. }
  9543. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9544. if (!lua_interface)
  9545. return 0;
  9546. Spawn* spawn = lua_interface->GetSpawn(state);
  9547. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9548. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9549. if (!spawn) {
  9550. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9551. return 0;
  9552. }
  9553. if (!spawn->IsEntity()) {
  9554. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9555. return 0;
  9556. }
  9557. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9558. {
  9559. 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);
  9560. return 0;
  9561. }
  9562. lua_interface->ResetFunctionStack(state);
  9563. if (spell && spell->targets.size() > 0) {
  9564. ZoneServer* zone = spell->caster->GetZone();
  9565. for (int8 i = 0; i < spell->targets.size(); i++) {
  9566. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9567. if (target && target->IsEntity()) {
  9568. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9569. if (target->IsPlayer())
  9570. ((Player*)target)->SetCharSheetChanged(true);
  9571. }
  9572. }
  9573. }
  9574. else {
  9575. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9576. if (spawn->IsPlayer())
  9577. ((Player*)spawn)->SetCharSheetChanged(true);
  9578. }
  9579. return 0;
  9580. }
  9581. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9582. if (!lua_interface)
  9583. return 0;
  9584. Spawn* spawn = lua_interface->GetSpawn(state);
  9585. lua_interface->ResetFunctionStack(state);
  9586. if (!spawn) {
  9587. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9588. return 0;
  9589. }
  9590. if (!spawn->IsEntity()) {
  9591. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9592. return 0;
  9593. }
  9594. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9595. return 1;
  9596. }
  9597. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9598. if (!lua_interface)
  9599. return 0;
  9600. int32 spell_id = lua_interface->GetInt32Value(state);
  9601. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9602. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9603. if (spell_id > 0) {
  9604. if (spell_tier == 0)
  9605. spell_tier = 1;
  9606. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9607. LuaSpell* lua_spell = 0;
  9608. if(custom_lua_script.size() > 0)
  9609. {
  9610. // attempt to load the custom script since it isn't already loaded
  9611. // we will re-obtain the lua_spell further below
  9612. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9613. {
  9614. 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());
  9615. lua_interface->LoadLuaSpell(custom_lua_script);
  9616. }
  9617. }
  9618. else
  9619. custom_lua_script = spell->GetSpellData()->lua_script;
  9620. if (!lua_spell && lua_interface)
  9621. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9622. if (!lua_spell)
  9623. {
  9624. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9625. return 0;
  9626. }
  9627. lua_spell->spell = new Spell(spell);
  9628. lua_interface->AddCustomSpell(lua_spell);
  9629. lua_interface->SetSpellValue(state, lua_spell);
  9630. return 1;
  9631. }
  9632. return 0;
  9633. }
  9634. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9635. if (!lua_interface)
  9636. return 0;
  9637. LuaSpell* spell = lua_interface->GetSpell(state);
  9638. string field = lua_interface->GetStringValue(state, 2);
  9639. if (!spell) {
  9640. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9641. return 0;
  9642. }
  9643. if (!spell->spell || !spell->spell->GetSpellData()) {
  9644. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9645. return 0;
  9646. }
  9647. boost::to_lower(field);
  9648. return spell->spell->GetSpellData(state, field);
  9649. }
  9650. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9651. if (!lua_interface)
  9652. return 0;
  9653. LuaSpell* spell = lua_interface->GetSpell(state);
  9654. string field = lua_interface->GetStringValue(state, 2);
  9655. int8 fieldArg = 3; // field value after the initial set
  9656. if (!spell) {
  9657. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9658. return 0;
  9659. }
  9660. if (!spell->spell || !spell->spell->GetSpellData()) {
  9661. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9662. return 0;
  9663. }
  9664. boost::to_lower(field);
  9665. bool valSet = false;
  9666. spell->spell->SetSpellData(state, field, fieldArg);
  9667. return valSet;
  9668. }
  9669. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9670. if (!lua_interface)
  9671. return 0;
  9672. LuaSpell* spell = lua_interface->GetSpell(state);
  9673. int8 idx = lua_interface->GetInt32Value(state, 2);
  9674. if (!spell) {
  9675. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9676. return 0;
  9677. }
  9678. if (!spell->spell || !spell->spell->GetSpellData()) {
  9679. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9680. return 0;
  9681. }
  9682. if (spell->spell->lua_data.size() <= idx)
  9683. {
  9684. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9685. return 0;
  9686. }
  9687. bool setVal = true;
  9688. LUAData* data = spell->spell->lua_data[idx];
  9689. switch (data->type)
  9690. {
  9691. case 0:
  9692. {
  9693. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9694. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9695. data->int_value = value;
  9696. data->int_value2 = value2;
  9697. break;
  9698. }
  9699. case 1:
  9700. {
  9701. float value = lua_interface->GetFloatValue(state, 3);
  9702. float value2 = lua_interface->GetFloatValue(state, 4);
  9703. data->float_value = value;
  9704. data->float_value2 = value2;
  9705. break;
  9706. }
  9707. case 2:
  9708. {
  9709. bool value = lua_interface->GetBooleanValue(state, 3);
  9710. data->bool_value = value;
  9711. break;
  9712. }
  9713. case 3:
  9714. {
  9715. string value = lua_interface->GetStringValue(state, 3);
  9716. string value2 = lua_interface->GetStringValue(state, 4);
  9717. data->string_value = value;
  9718. data->string_value2 = value2;
  9719. break;
  9720. }
  9721. default:
  9722. setVal = false;
  9723. }
  9724. return setVal;
  9725. }
  9726. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9727. if (!lua_interface)
  9728. return 0;
  9729. LuaSpell* spell = lua_interface->GetSpell(state);
  9730. int8 idx = lua_interface->GetInt32Value(state, 2);
  9731. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9732. if (!spell) {
  9733. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9734. return 0;
  9735. }
  9736. if (!spell->spell || !spell->spell->GetSpellData()) {
  9737. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9738. return 0;
  9739. }
  9740. if (spell->spell->lua_data.size() <= idx)
  9741. {
  9742. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9743. return 0;
  9744. }
  9745. bool setVal = true;
  9746. LUAData* data = spell->spell->lua_data[idx];
  9747. switch (data->type)
  9748. {
  9749. case 0:
  9750. {
  9751. if(!secondfield)
  9752. lua_interface->SetSInt32Value(state, data->int_value);
  9753. else
  9754. lua_interface->SetSInt32Value(state, data->int_value2);
  9755. break;
  9756. }
  9757. case 1:
  9758. {
  9759. if (!secondfield)
  9760. lua_interface->SetFloatValue(state, data->float_value);
  9761. else
  9762. lua_interface->SetFloatValue(state, data->float_value2);
  9763. break;
  9764. }
  9765. case 2:
  9766. {
  9767. lua_interface->SetBooleanValue(state, data->bool_value);
  9768. break;
  9769. }
  9770. case 3:
  9771. {
  9772. if (!secondfield)
  9773. lua_interface->SetStringValue(state, data->string_value.c_str());
  9774. else
  9775. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9776. break;
  9777. }
  9778. default:
  9779. setVal = false;
  9780. }
  9781. return setVal;
  9782. }
  9783. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9784. if (!lua_interface)
  9785. return 0;
  9786. LuaSpell* spell = lua_interface->GetSpell(state);
  9787. int8 idx = lua_interface->GetInt32Value(state, 2);
  9788. string field = lua_interface->GetStringValue(state, 3);
  9789. boost::to_lower(field);
  9790. if (!spell) {
  9791. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9792. return 0;
  9793. }
  9794. if (!spell->spell || !spell->spell->GetSpellData()) {
  9795. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9796. return 0;
  9797. }
  9798. if (spell->spell->effects.size() <= idx)
  9799. {
  9800. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9801. return 0;
  9802. }
  9803. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9804. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9805. if (field == "description")
  9806. effect->description = string(lua_interface->GetStringValue(state, 4));
  9807. else if (field == "bullet")
  9808. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9809. else if (field == "percentage")
  9810. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9811. else // no match
  9812. return 0;
  9813. return 1;
  9814. }
  9815. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9816. if (!lua_interface)
  9817. return 0;
  9818. LuaSpell* spell = lua_interface->GetSpell(state);
  9819. int8 idx = lua_interface->GetInt32Value(state, 2);
  9820. string field = lua_interface->GetStringValue(state, 3);
  9821. boost::to_lower(field);
  9822. if (!spell) {
  9823. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9824. return 0;
  9825. }
  9826. if (!spell->spell || !spell->spell->GetSpellData()) {
  9827. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9828. return 0;
  9829. }
  9830. if (spell->spell->effects.size() <= idx)
  9831. {
  9832. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9833. return 0;
  9834. }
  9835. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9836. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9837. if (field == "description")
  9838. lua_interface->SetStringValue(state, effect->description.c_str());
  9839. else if (field == "bullet")
  9840. lua_interface->SetInt32Value(state, effect->subbullet);
  9841. else if (field == "percentage")
  9842. lua_interface->SetInt32Value(state, effect->percentage);
  9843. else // no match
  9844. return 0;
  9845. return 1;
  9846. }
  9847. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9848. if (!lua_interface)
  9849. return 0;
  9850. LuaSpell* spell = lua_interface->GetSpell(state);
  9851. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9852. Spawn* target = lua_interface->GetSpawn(state, 3);
  9853. if (!target) {
  9854. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9855. return 0;
  9856. }
  9857. if (!target->IsEntity()) {
  9858. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9859. return 0;
  9860. }
  9861. if (!spell) {
  9862. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9863. return 0;
  9864. }
  9865. if (caster && !caster->IsEntity()) {
  9866. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9867. return 0;
  9868. }
  9869. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9870. return 0;
  9871. }
  9872. int EQ2Emu_lua_InWater(lua_State* state) {
  9873. if (!lua_interface)
  9874. return 0;
  9875. Spawn* spawn = lua_interface->GetSpawn(state);
  9876. lua_interface->ResetFunctionStack(state);
  9877. if (spawn) {
  9878. lua_interface->SetBooleanValue(state, spawn->InWater());
  9879. return 1;
  9880. }
  9881. return 0;
  9882. }
  9883. int EQ2Emu_lua_InLava(lua_State* state) {
  9884. if (!lua_interface)
  9885. return 0;
  9886. Spawn* spawn = lua_interface->GetSpawn(state);
  9887. lua_interface->ResetFunctionStack(state);
  9888. if (spawn) {
  9889. lua_interface->SetBooleanValue(state, spawn->InLava());
  9890. return 1;
  9891. }
  9892. return 0;
  9893. }
  9894. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9895. if (!lua_interface)
  9896. return 0;
  9897. Spawn* attacker = lua_interface->GetSpawn(state);
  9898. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9899. int8 type = lua_interface->GetInt8Value(state, 3);
  9900. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9901. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9902. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9903. string spell_name = lua_interface->GetStringValue(state, 7);
  9904. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9905. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9906. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9907. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9908. lua_interface->ResetFunctionStack(state);
  9909. if (!attacker) {
  9910. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9911. return 0;
  9912. }
  9913. if (!attacker->IsEntity()) {
  9914. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9915. return 0;
  9916. }
  9917. if (!victim) {
  9918. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9919. return 0;
  9920. }
  9921. if (!victim->IsEntity()) {
  9922. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9923. return 0;
  9924. }
  9925. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9926. return 0;
  9927. }
  9928. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9929. if (!lua_interface)
  9930. return 0;
  9931. Spawn* spawn = lua_interface->GetSpawn(state);
  9932. lua_interface->ResetFunctionStack(state);
  9933. if (spawn) {
  9934. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9935. return 1;
  9936. }
  9937. return 0;
  9938. }
  9939. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9940. if (!lua_interface)
  9941. return 0;
  9942. Spawn* spawn = lua_interface->GetSpawn(state);
  9943. bool invul = lua_interface->GetBooleanValue(state, 2);
  9944. lua_interface->ResetFunctionStack(state);
  9945. if (spawn) {
  9946. spawn->SetInvulnerable(invul);
  9947. }
  9948. return 0;
  9949. }
  9950. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  9951. if (!lua_interface)
  9952. return 0;
  9953. string category = lua_interface->GetStringValue(state);
  9954. string name = lua_interface->GetStringValue(state, 2);
  9955. lua_interface->ResetFunctionStack(state);
  9956. Rule *ret = 0;
  9957. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9958. lua_interface->SetBooleanValue(state, ret->GetBool());
  9959. return 1;
  9960. }
  9961. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9962. return 0;
  9963. }
  9964. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9965. if (!lua_interface)
  9966. return 0;
  9967. string category = lua_interface->GetStringValue(state);
  9968. string name = lua_interface->GetStringValue(state, 2);
  9969. lua_interface->ResetFunctionStack(state);
  9970. Rule *ret = 0;
  9971. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9972. lua_interface->SetInt32Value(state, ret->GetInt32());
  9973. return 1;
  9974. }
  9975. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9976. return 0;
  9977. }
  9978. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  9979. if (!lua_interface)
  9980. return 0;
  9981. string category = lua_interface->GetStringValue(state);
  9982. string name = lua_interface->GetStringValue(state, 2);
  9983. lua_interface->ResetFunctionStack(state);
  9984. Rule *ret = 0;
  9985. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9986. lua_interface->SetFloatValue(state, ret->GetFloat());
  9987. return 1;
  9988. }
  9989. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9990. return 0;
  9991. }
  9992. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  9993. if (!lua_interface)
  9994. return 0;
  9995. Spawn* spawn = lua_interface->GetSpawn(state);
  9996. string type = lua_interface->GetStringValue(state, 2);
  9997. lua_interface->ResetFunctionStack(state);
  9998. if (spawn) {
  9999. int res = 1;
  10000. boost::to_lower(type);
  10001. if(type == "assigned_aa")
  10002. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10003. else if ( type == "unassigned_aa")
  10004. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10005. else if ( type == "assigned_tradeskill_aa")
  10006. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10007. else if ( type == "unassigned_tradeskill_aa")
  10008. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10009. else if ( type == "assigned_prestige_aa")
  10010. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10011. else if ( type == "unassigned_prestige_aa")
  10012. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10013. else if ( type == "assigned_tradeskill_prestige_aa")
  10014. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10015. else if ( type == "unassigned_tradeskill_prestige_aa")
  10016. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10017. else
  10018. res = 0;
  10019. return res;
  10020. }
  10021. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10022. return 0;
  10023. }
  10024. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10025. if (!lua_interface)
  10026. return 0;
  10027. Spawn* spawn = lua_interface->GetSpawn(state);
  10028. string type = lua_interface->GetStringValue(state, 2);
  10029. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10030. lua_interface->ResetFunctionStack(state);
  10031. if (spawn) {
  10032. boost::to_lower(type);
  10033. if(type == "assigned_aa")
  10034. spawn->SetAssignedAA((sint16)value);
  10035. else if ( type == "unassigned_aa")
  10036. spawn->SetUnassignedAA((sint16)value);
  10037. else if ( type == "assigned_tradeskill_aa")
  10038. spawn->SetTradeskillAA((sint16)value);
  10039. else if ( type == "unassigned_tradeskill_aa")
  10040. spawn->SetUnassignedTradeskillAA((sint16)value);
  10041. else if ( type == "assigned_prestige_aa")
  10042. spawn->SetPrestigeAA((sint16)value);
  10043. else if ( type == "unassigned_prestige_aa")
  10044. spawn->SetUnassignedPrestigeAA((sint16)value);
  10045. else if ( type == "assigned_tradeskill_prestige_aa")
  10046. spawn->SetTradeskillPrestigeAA((sint16)value);
  10047. else if ( type == "unassigned_tradeskill_prestige_aa")
  10048. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10049. if(spawn->IsPlayer())
  10050. ((Player*)spawn)->SetCharSheetChanged(true);
  10051. }
  10052. return 0;
  10053. }
  10054. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10055. if (!lua_interface)
  10056. return 0;
  10057. string titleName = lua_interface->GetStringValue(state);
  10058. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10059. lua_interface->ResetFunctionStack(state);
  10060. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10061. lua_interface->SetSInt32Value(state, index);
  10062. return 1;
  10063. }
  10064. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10065. if (!lua_interface)
  10066. return 0;
  10067. Spawn* spawn = lua_interface->GetSpawn(state);
  10068. string titleName = lua_interface->GetStringValue(state, 2);
  10069. lua_interface->ResetFunctionStack(state);
  10070. if(!spawn->IsPlayer())
  10071. {
  10072. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10073. lua_interface->SetSInt32Value(state, -1);
  10074. return 1;
  10075. }
  10076. Player* player = (Player*)spawn;
  10077. // check if player already has the title, don't need to add twice
  10078. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10079. if ( playerHasTitle)
  10080. {
  10081. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10082. return 1;
  10083. }
  10084. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10085. if(!title)
  10086. {
  10087. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10088. lua_interface->SetSInt32Value(state, -1);
  10089. return 1;
  10090. }
  10091. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10092. if(returnIdx < 0)
  10093. {
  10094. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10095. }
  10096. lua_interface->SetSInt32Value(state, returnIdx);
  10097. player->GetClient()->SendTitleUpdate();
  10098. return 1;
  10099. }
  10100. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10101. if (!lua_interface)
  10102. return 0;
  10103. Spawn* spawn = lua_interface->GetSpawn(state);
  10104. string titleName = lua_interface->GetStringValue(state, 2);
  10105. lua_interface->ResetFunctionStack(state);
  10106. if(!spawn->IsPlayer())
  10107. {
  10108. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10109. return 0;
  10110. }
  10111. Player* player = (Player*)spawn;
  10112. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10113. if(!title)
  10114. {
  10115. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10116. return 0;
  10117. }
  10118. if(title->GetPrefix())
  10119. {
  10120. 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());
  10121. return 0;
  10122. }
  10123. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10124. player->GetClient()->SendTitleUpdate();
  10125. return 1;
  10126. }
  10127. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10128. if (!lua_interface)
  10129. return 0;
  10130. Spawn* spawn = lua_interface->GetSpawn(state);
  10131. string titleName = lua_interface->GetStringValue(state, 2);
  10132. lua_interface->ResetFunctionStack(state);
  10133. if(!spawn->IsPlayer())
  10134. {
  10135. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10136. return 0;
  10137. }
  10138. Player* player = (Player*)spawn;
  10139. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10140. if(!title)
  10141. {
  10142. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10143. return 0;
  10144. }
  10145. if(!title->GetPrefix())
  10146. {
  10147. 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());
  10148. return 0;
  10149. }
  10150. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10151. player->GetClient()->SendTitleUpdate();
  10152. return 1;
  10153. }
  10154. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10155. if (!lua_interface)
  10156. return 0;
  10157. Spawn* spawn = lua_interface->GetSpawn(state);
  10158. lua_interface->ResetFunctionStack(state);
  10159. if(!spawn->IsPlayer())
  10160. {
  10161. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10162. return 0;
  10163. }
  10164. Player* player = (Player*)spawn;
  10165. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10166. player->GetClient()->SendTitleUpdate();
  10167. return 1;
  10168. }
  10169. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10170. if (!lua_interface)
  10171. return 0;
  10172. Spawn* spawn = lua_interface->GetSpawn(state);
  10173. lua_interface->ResetFunctionStack(state);
  10174. if(!spawn->IsPlayer())
  10175. {
  10176. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10177. return 0;
  10178. }
  10179. Player* player = (Player*)spawn;
  10180. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10181. player->GetClient()->SendTitleUpdate();
  10182. return 1;
  10183. }
  10184. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10185. if (!lua_interface)
  10186. return 0;
  10187. Spawn* spawn = lua_interface->GetSpawn(state);
  10188. string field = lua_interface->GetStringValue(state, 2);
  10189. lua_interface->ResetFunctionStack(state);
  10190. if(!spawn || !spawn->IsEntity())
  10191. {
  10192. 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));
  10193. return 0;
  10194. }
  10195. Entity* ent = (Entity*)spawn;
  10196. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10197. return 1;
  10198. }
  10199. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10200. if (!lua_interface)
  10201. return 0;
  10202. Spawn* spawn = lua_interface->GetSpawn(state);
  10203. string field = lua_interface->GetStringValue(state, 2);
  10204. lua_interface->ResetFunctionStack(state);
  10205. if(!spawn || !spawn->IsEntity())
  10206. {
  10207. 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));
  10208. return 0;
  10209. }
  10210. Entity* ent = (Entity*)spawn;
  10211. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10212. return 1;
  10213. }
  10214. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10215. if (!lua_interface)
  10216. return 0;
  10217. Spawn* spawn = lua_interface->GetSpawn(state);
  10218. string field = lua_interface->GetStringValue(state, 2);
  10219. lua_interface->ResetFunctionStack(state);
  10220. if(!spawn || !spawn->IsEntity())
  10221. {
  10222. 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));
  10223. return 0;
  10224. }
  10225. Entity* ent = (Entity*)spawn;
  10226. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10227. return 1;
  10228. }
  10229. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10230. if (!lua_interface)
  10231. return 0;
  10232. Spawn* spawn = lua_interface->GetSpawn(state);
  10233. string field = lua_interface->GetStringValue(state, 2);
  10234. lua_interface->ResetFunctionStack(state);
  10235. if(!spawn || !spawn->IsEntity())
  10236. {
  10237. 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));
  10238. return 0;
  10239. }
  10240. Entity* ent = (Entity*)spawn;
  10241. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10242. return 1;
  10243. }
  10244. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10245. if (!lua_interface)
  10246. return 0;
  10247. Spawn* spawn = lua_interface->GetSpawn(state);
  10248. string field = lua_interface->GetStringValue(state, 2);
  10249. string value = lua_interface->GetStringValue(state, 3);
  10250. lua_interface->ResetFunctionStack(state);
  10251. if(!spawn || !spawn->IsEntity())
  10252. {
  10253. 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));
  10254. return 0;
  10255. }
  10256. Entity* ent = (Entity*)spawn;
  10257. bool set_ = ent->SetInfoStructString(field, value);
  10258. lua_interface->SetBooleanValue(state, set_);
  10259. return 1;
  10260. }
  10261. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10262. if (!lua_interface)
  10263. return 0;
  10264. Spawn* spawn = lua_interface->GetSpawn(state);
  10265. string field = lua_interface->GetStringValue(state, 2);
  10266. int64 value = lua_interface->GetInt64Value(state, 3);
  10267. lua_interface->ResetFunctionStack(state);
  10268. if(!spawn || !spawn->IsEntity())
  10269. {
  10270. 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));
  10271. return 0;
  10272. }
  10273. Entity* ent = (Entity*)spawn;
  10274. bool set_ = ent->SetInfoStructUInt(field, value);
  10275. lua_interface->SetBooleanValue(state, set_);
  10276. return 1;
  10277. }
  10278. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10279. if (!lua_interface)
  10280. return 0;
  10281. Spawn* spawn = lua_interface->GetSpawn(state);
  10282. string field = lua_interface->GetStringValue(state, 2);
  10283. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10284. lua_interface->ResetFunctionStack(state);
  10285. if(!spawn || !spawn->IsEntity())
  10286. {
  10287. 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));
  10288. return 0;
  10289. }
  10290. Entity* ent = (Entity*)spawn;
  10291. bool set_ = ent->SetInfoStructSInt(field, value);
  10292. lua_interface->SetBooleanValue(state, set_);
  10293. return 1;
  10294. }
  10295. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10296. if (!lua_interface)
  10297. return 0;
  10298. Spawn* spawn = lua_interface->GetSpawn(state);
  10299. string field = lua_interface->GetStringValue(state, 2);
  10300. float value = lua_interface->GetFloatValue(state, 3);
  10301. lua_interface->ResetFunctionStack(state);
  10302. if(!spawn || !spawn->IsEntity())
  10303. {
  10304. 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));
  10305. return 0;
  10306. }
  10307. Entity* ent = (Entity*)spawn;
  10308. bool set_ = ent->SetInfoStructFloat(field, value);
  10309. lua_interface->SetBooleanValue(state, set_);
  10310. return 1;
  10311. }
  10312. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10313. if (!lua_interface)
  10314. return 0;
  10315. Spawn* spawn = lua_interface->GetSpawn(state);
  10316. bool value = lua_interface->GetBooleanValue(state, 2);
  10317. lua_interface->ResetFunctionStack(state);
  10318. if(!spawn || !spawn->IsPlayer())
  10319. {
  10320. 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));
  10321. return 0;
  10322. }
  10323. ((Player*)spawn)->SetCharSheetChanged(value);
  10324. return 0;
  10325. }
  10326. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10327. if (!lua_interface)
  10328. return 0;
  10329. Spawn* spawn = lua_interface->GetSpawn(state);
  10330. std::string fromName = lua_interface->GetStringValue(state, 2);
  10331. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10332. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10333. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10334. int32 copper = lua_interface->GetInt32Value(state, 6);
  10335. int32 silver = lua_interface->GetInt32Value(state, 7);
  10336. int32 gold = lua_interface->GetInt32Value(state, 8);
  10337. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10338. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10339. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10340. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10341. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10342. lua_interface->ResetFunctionStack(state);
  10343. if(!spawn || !spawn->IsPlayer())
  10344. {
  10345. 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));
  10346. lua_interface->SetBooleanValue(state, false);
  10347. return 1;
  10348. }
  10349. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10350. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10351. lua_interface->SetBooleanValue(state, true);
  10352. return 1;
  10353. }
  10354. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10355. if (!lua_interface)
  10356. return 0;
  10357. int32 char_id = lua_interface->GetInt32Value(state);
  10358. std::string fromName = lua_interface->GetStringValue(state, 2);
  10359. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10360. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10361. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10362. int32 copper = lua_interface->GetInt32Value(state, 6);
  10363. int32 silver = lua_interface->GetInt32Value(state, 7);
  10364. int32 gold = lua_interface->GetInt32Value(state, 8);
  10365. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10366. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10367. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10368. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10369. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10370. lua_interface->ResetFunctionStack(state);
  10371. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10372. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10373. lua_interface->SetBooleanValue(state, true);
  10374. return 1;
  10375. }
  10376. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10377. Spawn* widget;
  10378. if (lua_interface) {
  10379. widget = lua_interface->GetSpawn(state);
  10380. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10381. lua_interface->ResetFunctionStack(state);
  10382. if (widget && widget->IsWidget())
  10383. {
  10384. ((Widget*)widget)->OpenDoor();
  10385. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10386. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10387. }
  10388. else
  10389. 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));
  10390. }
  10391. return 0;
  10392. }
  10393. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10394. Spawn* widget;
  10395. if (lua_interface) {
  10396. widget = lua_interface->GetSpawn(state);
  10397. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10398. lua_interface->ResetFunctionStack(state);
  10399. if (widget && widget->IsWidget())
  10400. {
  10401. ((Widget*)widget)->CloseDoor();
  10402. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10403. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10404. }
  10405. else
  10406. 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));
  10407. }
  10408. return 0;
  10409. }
  10410. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10411. if (!lua_interface)
  10412. return 0;
  10413. Spawn* widget = lua_interface->GetSpawn(state);
  10414. lua_interface->ResetFunctionStack(state);
  10415. if (widget && widget->IsWidget())
  10416. {
  10417. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10418. return 1;
  10419. }
  10420. return 0;
  10421. }
  10422. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10423. if (!lua_interface)
  10424. return 0;
  10425. sint32 min = lua_interface->GetSInt32Value(state);
  10426. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10427. lua_interface->ResetFunctionStack(state);
  10428. sint32 result = MakeRandomInt(min, max);
  10429. lua_interface->SetSInt32Value(state, result);
  10430. return 1;
  10431. }
  10432. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10433. if (!lua_interface)
  10434. return 0;
  10435. float min = lua_interface->GetFloatValue(state);
  10436. float max = lua_interface->GetFloatValue(state, 2);
  10437. lua_interface->ResetFunctionStack(state);
  10438. float result = MakeRandomFloat(min, max);
  10439. lua_interface->SetFloatValue(state, result);
  10440. return 1;
  10441. }
  10442. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10443. if (!lua_interface)
  10444. return 0;
  10445. Spawn* spawn = lua_interface->GetSpawn(state);
  10446. int32 value = lua_interface->GetInt32Value(state, 2);
  10447. lua_interface->ResetFunctionStack(state);
  10448. if(!spawn)
  10449. {
  10450. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10451. lua_interface->SetBooleanValue(state, false);
  10452. return 1;
  10453. }
  10454. spawn->AddIconValue(value);
  10455. lua_interface->SetBooleanValue(state, true);
  10456. return 1;
  10457. }
  10458. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10459. if (!lua_interface)
  10460. return 0;
  10461. Spawn* spawn = lua_interface->GetSpawn(state);
  10462. int32 value = lua_interface->GetInt32Value(state, 2);
  10463. lua_interface->ResetFunctionStack(state);
  10464. if(!spawn)
  10465. {
  10466. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10467. lua_interface->SetBooleanValue(state, false);
  10468. return 1;
  10469. }
  10470. spawn->RemoveIconValue(value);
  10471. lua_interface->SetBooleanValue(state, true);
  10472. return 1;
  10473. }
  10474. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10475. Spawn* npc = lua_interface->GetSpawn(state);
  10476. lua_interface->ResetFunctionStack(state);
  10477. if (npc && npc->IsNPC()) {
  10478. NPC* shard = (NPC*)npc;
  10479. int32 shardid = shard->GetShardID();
  10480. lua_interface->SetInt32Value(state, shardid);
  10481. return 1;
  10482. }
  10483. lua_interface->SetInt32Value(state, 0);
  10484. return 1;
  10485. }
  10486. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10487. Spawn* npc = lua_interface->GetSpawn(state);
  10488. lua_interface->ResetFunctionStack(state);
  10489. if (npc && npc->IsNPC()) {
  10490. NPC* shard = (NPC*)npc;
  10491. int32 charid = shard->GetShardCharID();
  10492. lua_interface->SetInt32Value(state, charid);
  10493. return 1;
  10494. }
  10495. lua_interface->SetInt32Value(state, 0);
  10496. return 1;
  10497. }
  10498. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10499. Spawn* npc = lua_interface->GetSpawn(state);
  10500. lua_interface->ResetFunctionStack(state);
  10501. if (npc && npc->IsNPC()) {
  10502. NPC* shard = (NPC*)npc;
  10503. int64 timestamp = shard->GetShardCreatedTimestamp();
  10504. lua_interface->SetSInt64Value(state, timestamp);
  10505. return 1;
  10506. }
  10507. lua_interface->SetSInt64Value(state, 0);
  10508. return 1;
  10509. }
  10510. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10511. if (!lua_interface)
  10512. return 0;
  10513. int32 shardid = lua_interface->GetInt32Value(state);
  10514. lua_interface->ResetFunctionStack(state);
  10515. if(shardid < 1)
  10516. lua_interface->SetBooleanValue(state, false);
  10517. else
  10518. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10519. return 1;
  10520. }
  10521. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10522. if (!lua_interface)
  10523. return 0;
  10524. Spawn* spawn = lua_interface->GetSpawn(state);
  10525. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10526. if (spawn) {
  10527. spawn->PauseMovement(delay_in_ms);
  10528. }
  10529. lua_interface->ResetFunctionStack(state);
  10530. return 0;
  10531. }
  10532. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10533. if (!lua_interface)
  10534. return 0;
  10535. Spawn* spawn = lua_interface->GetSpawn(state);
  10536. if (spawn) {
  10537. spawn->StopMovement();
  10538. }
  10539. lua_interface->ResetFunctionStack(state);
  10540. return 0;
  10541. }
  10542. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10543. Player* player = (Player*)lua_interface->GetSpawn(state);
  10544. int8 level = lua_interface->GetInt8Value(state, 2);
  10545. lua_interface->ResetFunctionStack(state);
  10546. if (player && player->IsPlayer() && level > 0) {
  10547. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10548. return 1;
  10549. }
  10550. return 0;
  10551. }
  10552. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10553. Player* player = (Player*)lua_interface->GetSpawn(state);
  10554. int8 level = lua_interface->GetInt8Value(state, 2);
  10555. lua_interface->ResetFunctionStack(state);
  10556. if (player && player->IsPlayer() && level > 0) {
  10557. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10558. return 1;
  10559. }
  10560. return 0;
  10561. }