LuaFunctions.cpp 370 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135
  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()->SendStateCommand(spawn, 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. spawn->LootItem(item_id);
  724. }
  725. return 0;
  726. }
  727. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  728. if (!lua_interface)
  729. return 0;
  730. Spawn* spawn = lua_interface->GetSpawn(state);
  731. if (spawn) {
  732. int32 val = lua_interface->GetInt32Value(state, 2);
  733. spawn->AddLootCoins(val);
  734. }
  735. return 0;
  736. }
  737. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  738. if (!lua_interface)
  739. return 0;
  740. Spawn* entity = lua_interface->GetSpawn(state);
  741. Spawn* player = lua_interface->GetSpawn(state, 2);
  742. if (entity && player && player->IsPlayer()) {
  743. int32 coins = lua_interface->GetInt32Value(state, 3);
  744. vector<Item*>* items = 0;
  745. int i = 0;
  746. int32 item_id = 0;
  747. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  748. if (items == 0)
  749. items = new vector<Item*>;
  750. if (master_item_list.GetItem(item_id))
  751. items->push_back(master_item_list.GetItem(item_id));
  752. i++;
  753. }
  754. Client* client = 0;
  755. client = player->GetZone()->GetClientBySpawn(player);
  756. if (client)
  757. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  758. if(coins > 0)
  759. entity->AddLootCoins(coins);
  760. safe_delete(items);
  761. }
  762. return 0;
  763. }
  764. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  765. if (!lua_interface)
  766. return 0;
  767. Spawn* entity = lua_interface->GetSpawn(state);
  768. Spawn* player = lua_interface->GetSpawn(state, 2);
  769. int32 item_id = lua_interface->GetInt32Value(state, 3);
  770. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  771. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  772. return 1;
  773. }
  774. return 0;
  775. }
  776. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  777. if (!lua_interface)
  778. return 0;
  779. Spawn* entity = lua_interface->GetSpawn(state);
  780. Spawn* player = lua_interface->GetSpawn(state, 2);
  781. if (entity && player && player->IsPlayer()) {
  782. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  783. return 1;
  784. }
  785. return 0;
  786. }
  787. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  788. if (!lua_interface)
  789. return 0;
  790. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  791. safe_delete(conversation);
  792. conversation = new vector<ConversationOption>();
  793. lua_interface->SetConversationValue(state, conversation);
  794. return 1;
  795. }
  796. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  800. if (conversation) {
  801. ConversationOption conv_option;
  802. conv_option.option = lua_interface->GetStringValue(state, 2);
  803. conv_option.function = lua_interface->GetStringValue(state, 3);
  804. if (conv_option.option.length() > 0)
  805. conversation->push_back(conv_option);
  806. }
  807. return 0;
  808. }
  809. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. Spawn* npc = lua_interface->GetSpawn(state);
  813. Spawn* player = lua_interface->GetSpawn(state, 2);
  814. if (npc && player && player->IsPlayer() && player->GetZone()) {
  815. Client* client = player->GetZone()->GetClientBySpawn(player);
  816. if (client) {
  817. int32 conversation_id = client->GetConversationID(npc, 0);
  818. client->CloseDialog(conversation_id);
  819. }
  820. }
  821. return 0;
  822. }
  823. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  824. if (!lua_interface)
  825. return 0;
  826. Item* item = lua_interface->GetItem(state);
  827. Spawn* player = lua_interface->GetSpawn(state, 2);
  828. if (item && player && player->IsPlayer() && player->GetZone()) {
  829. Client* client = player->GetZone()->GetClientBySpawn(player);
  830. if (client) {
  831. int32 conversation_id = client->GetConversationID(0, item);
  832. client->CloseDialog(conversation_id);
  833. }
  834. }
  835. return 0;
  836. }
  837. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  838. if (!lua_interface)
  839. return 0;
  840. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  841. Spawn* spawn = 0;
  842. Item* item = 0;
  843. int8 type = lua_interface->GetInt8Value(state, 2);
  844. if (type == 1 || type == 3)
  845. spawn = lua_interface->GetSpawn(state, 3);
  846. else if (type == 2 || type == 4)
  847. item = lua_interface->GetItem(state, 3);
  848. Spawn* player = lua_interface->GetSpawn(state, 4);
  849. string text = lua_interface->GetStringValue(state, 5);
  850. string mp3 = lua_interface->GetStringValue(state, 6);
  851. int32 key1 = lua_interface->GetInt32Value(state, 7);
  852. int32 key2 = lua_interface->GetInt32Value(state, 8);
  853. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  854. Client* client = player->GetZone()->GetClientBySpawn(player);
  855. if (client) {
  856. if (spawn) {
  857. // Need to do this so the function works the same as it did before
  858. if (type == 1)
  859. type++;
  860. if (mp3.length() > 0)
  861. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  862. else
  863. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  864. }
  865. else {
  866. if (mp3.length() > 0)
  867. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  868. else
  869. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  870. }
  871. }
  872. }
  873. safe_delete(conversation);
  874. lua_interface->SetConversationValue(state, NULL);
  875. return 0;
  876. }
  877. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  878. if(!lua_interface)
  879. return 0;
  880. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  881. Item* item = lua_interface->GetItem(state, 2);
  882. Spawn* player = lua_interface->GetSpawn(state, 3);
  883. string text = lua_interface->GetStringValue(state, 4);
  884. string mp3 = lua_interface->GetStringValue(state, 5);
  885. int32 key1 = lua_interface->GetInt32Value(state, 6);
  886. int32 key2 = lua_interface->GetInt32Value(state, 7);
  887. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  888. Client* client = player->GetZone()->GetClientBySpawn(player);
  889. if(client){
  890. if(mp3.length() > 0)
  891. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  892. else
  893. client->DisplayConversation(item, conversation, (char*)text.c_str());
  894. }
  895. safe_delete(conversation);
  896. }
  897. return 0;
  898. }*/
  899. int EQ2Emu_lua_StartConversation(lua_State* state) {
  900. if (!lua_interface)
  901. return 0;
  902. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  903. Spawn* source = lua_interface->GetSpawn(state, 2);
  904. Spawn* player = lua_interface->GetSpawn(state, 3);
  905. string text = lua_interface->GetStringValue(state, 4);
  906. string mp3 = lua_interface->GetStringValue(state, 5);
  907. int32 key1 = lua_interface->GetInt32Value(state, 6);
  908. int32 key2 = lua_interface->GetInt32Value(state, 7);
  909. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  910. Client* client = source->GetZone()->GetClientBySpawn(player);
  911. if (mp3.length() > 0)
  912. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  913. else
  914. client->DisplayConversation(source, 1, conversation, text.c_str());
  915. safe_delete(conversation);
  916. lua_interface->SetConversationValue(state, NULL);
  917. }
  918. else
  919. 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);
  920. return 0;
  921. }
  922. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  923. if (!lua_interface)
  924. return 0;
  925. Spawn* spawn = lua_interface->GetSpawn(state);
  926. float distance = lua_interface->GetFloatValue(state, 2);
  927. string in_range_function = lua_interface->GetStringValue(state, 3);
  928. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  929. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  930. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  931. return 0;
  932. }
  933. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  934. ZoneServer* zone = lua_interface->GetZone(state);
  935. float x = lua_interface->GetFloatValue(state, 2);
  936. float y = lua_interface->GetFloatValue(state, 3);
  937. float z = lua_interface->GetFloatValue(state, 4);
  938. float max_variation = lua_interface->GetFloatValue(state, 5);
  939. string in_range_function = lua_interface->GetStringValue(state, 6);
  940. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  941. if (zone && in_range_function.length() > 0)
  942. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  943. return 0;
  944. }
  945. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  946. if (!lua_interface)
  947. return 0;
  948. Spawn* spawn = lua_interface->GetSpawn(state);
  949. if (spawn && spawn->IsEntity()) {
  950. int32 val = lua_interface->GetInt32Value(state, 2);
  951. ((Entity*)spawn)->SetLootCoins(val);
  952. }
  953. return 0;
  954. }
  955. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  956. if (!lua_interface)
  957. return 0;
  958. Spawn* spawn = lua_interface->GetSpawn(state);
  959. if (spawn && spawn->IsEntity()) {
  960. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  961. return 1;
  962. }
  963. return 0;
  964. }
  965. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  966. if (!lua_interface)
  967. return 0;
  968. Spawn* spawn = lua_interface->GetSpawn(state);
  969. float x = lua_interface->GetFloatValue(state, 2);
  970. float y = lua_interface->GetFloatValue(state, 3);
  971. float z = lua_interface->GetFloatValue(state, 4);
  972. float speed = lua_interface->GetFloatValue(state, 5);
  973. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  974. string function = lua_interface->GetStringValue(state, 7);
  975. if (spawn) {
  976. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  977. spawn->GetZone()->AddMovementNPC(spawn);
  978. }
  979. lua_interface->ResetFunctionStack(state);
  980. return 0;
  981. }
  982. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  983. if (!lua_interface)
  984. return 0;
  985. Spawn* spawn = lua_interface->GetSpawn(state);
  986. if (spawn) {
  987. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  988. return 1;
  989. }
  990. return 0;
  991. }
  992. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  993. if (!lua_interface)
  994. return 0;
  995. Spawn* spawn = lua_interface->GetSpawn(state);
  996. if (spawn && spawn->IsPlayer()) {
  997. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  998. return 1;
  999. }
  1000. lua_interface->SetInt32Value(state, 0);
  1001. return 1;
  1002. }
  1003. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1004. if (!lua_interface)
  1005. return 0;
  1006. Spawn* spawn = lua_interface->GetSpawn(state);
  1007. Spawn* target = lua_interface->GetSpawn(state, 2);
  1008. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1009. bool reset_action_state = true;
  1010. if(num_args > 2)
  1011. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1012. if (spawn && target) {
  1013. if (spawn->IsEntity())
  1014. // ((Entity*)spawn)->FaceTarget(target);
  1015. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1016. }
  1017. lua_interface->ResetFunctionStack(state);
  1018. return 0;
  1019. }
  1020. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1021. if (!lua_interface)
  1022. return 0;
  1023. Spawn* spawn = lua_interface->GetSpawn(state);
  1024. float x = lua_interface->GetFloatValue(state, 2);
  1025. float y = lua_interface->GetFloatValue(state, 3);
  1026. float z = lua_interface->GetFloatValue(state, 4);
  1027. float speed = lua_interface->GetFloatValue(state, 5);
  1028. string lua_function = lua_interface->GetStringValue(state, 6);
  1029. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1030. if (spawn) {
  1031. if (speed == 0)
  1032. speed = spawn->GetSpeed();
  1033. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1034. }
  1035. lua_interface->ResetFunctionStack(state);
  1036. return 0;
  1037. }
  1038. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1039. if (!lua_interface)
  1040. return 0;
  1041. Spawn* spawn = lua_interface->GetSpawn(state);
  1042. if (spawn) {
  1043. spawn->ClearRunningLocations();
  1044. }
  1045. return 0;
  1046. }
  1047. int EQ2Emu_lua_Say(lua_State* state) {
  1048. if (!lua_interface)
  1049. return 0;
  1050. Spawn* spawn = lua_interface->GetSpawn(state);
  1051. string message = lua_interface->GetStringValue(state, 2);
  1052. Spawn* player = lua_interface->GetSpawn(state, 3);
  1053. int32 language = lua_interface->GetInt32Value(state, 4);
  1054. if (spawn && message.length() > 0) {
  1055. Client* client = 0;
  1056. if (player && player->IsPlayer())
  1057. client = spawn->GetZone()->GetClientBySpawn(player);
  1058. if (client)
  1059. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1060. else
  1061. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1062. }
  1063. lua_interface->ResetFunctionStack(state);
  1064. return 0;
  1065. }
  1066. int EQ2Emu_lua_Shout(lua_State* state) {
  1067. if (!lua_interface)
  1068. return 0;
  1069. Spawn* spawn = lua_interface->GetSpawn(state);
  1070. string message = lua_interface->GetStringValue(state, 2);
  1071. Spawn* player = lua_interface->GetSpawn(state, 3);
  1072. if (spawn && message.length() > 0) {
  1073. Client* client = 0;
  1074. if (player && player->IsPlayer())
  1075. client = spawn->GetZone()->GetClientBySpawn(player);
  1076. if (client)
  1077. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1078. else
  1079. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1080. }
  1081. lua_interface->ResetFunctionStack(state);
  1082. return 0;
  1083. }
  1084. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1085. if (!lua_interface)
  1086. return 0;
  1087. Spawn* spawn = lua_interface->GetSpawn(state);
  1088. string message = lua_interface->GetStringValue(state, 2);
  1089. Spawn* player = lua_interface->GetSpawn(state, 3);
  1090. if (spawn && message.length() > 0) {
  1091. Client* client = 0;
  1092. if (player && player->IsPlayer())
  1093. client = spawn->GetZone()->GetClientBySpawn(player);
  1094. if (client)
  1095. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1096. else
  1097. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1098. }
  1099. lua_interface->ResetFunctionStack(state);
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_Emote(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. string message = lua_interface->GetStringValue(state, 2);
  1107. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1108. Spawn* player = lua_interface->GetSpawn(state, 4);
  1109. char* to = 0;
  1110. if (spawn2)
  1111. to = spawn2->GetName();
  1112. if (spawn && message.length() > 0) {
  1113. Client* client = 0;
  1114. if (player && player->IsPlayer())
  1115. client = spawn->GetZone()->GetClientBySpawn(player);
  1116. if (client)
  1117. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1118. else
  1119. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1120. }
  1121. lua_interface->ResetFunctionStack(state);
  1122. return 0;
  1123. }
  1124. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1125. if (!lua_interface)
  1126. return 0;
  1127. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1128. if (!luaspell)
  1129. return 0;
  1130. Spawn* caster = luaspell->caster;
  1131. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1132. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1133. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1134. Spawn* target = lua_interface->GetSpawn(state, 4);
  1135. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1136. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1137. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1138. lua_interface->ResetFunctionStack(state);
  1139. boost::to_lower(heal_type);
  1140. if (caster && caster->IsEntity()) {
  1141. bool success = false;
  1142. luaspell->resisted = false;
  1143. if (target) {
  1144. float distance = caster->GetDistance(target, true);
  1145. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1146. success = true;
  1147. }
  1148. if (luaspell->targets.size() > 0) {
  1149. Spawn* target = 0;
  1150. ZoneServer* zone = luaspell->caster->GetZone();
  1151. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1152. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1153. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1154. float distance = caster->GetDistance(target, true);
  1155. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1156. }
  1157. }
  1158. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1159. success = true;
  1160. }
  1161. if (success) {
  1162. if (caster->GetZone())
  1163. caster->GetZone()->TriggerCharSheetTimer();
  1164. }
  1165. }
  1166. return 0;
  1167. }
  1168. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1169. if (!lua_interface)
  1170. return 0;
  1171. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1172. if (!luaspell)
  1173. return 0;
  1174. Spawn* caster = luaspell->caster;
  1175. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1176. float percentage = lua_interface->GetFloatValue(state, 2);
  1177. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1178. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1179. Spawn* target = lua_interface->GetSpawn(state, 5);
  1180. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1181. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1182. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1183. lua_interface->ResetFunctionStack(state);
  1184. boost::to_lower(heal_type);
  1185. int32 min_heal = 0, max_heal = 0;
  1186. if (caster && caster->IsEntity() && target) {
  1187. if(percentage <= 0.0f)
  1188. {
  1189. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1190. return 0;
  1191. }
  1192. if(heal_type == "power")
  1193. {
  1194. if(current_value)
  1195. {
  1196. if(caster_value)
  1197. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1198. else
  1199. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1200. }
  1201. else
  1202. {
  1203. if(caster_value)
  1204. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1205. else
  1206. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1207. }
  1208. }
  1209. else
  1210. {
  1211. if(current_value)
  1212. {
  1213. if(caster_value)
  1214. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1215. else
  1216. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1217. }
  1218. else
  1219. {
  1220. if(caster_value)
  1221. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1222. else
  1223. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1224. }
  1225. }
  1226. bool success = false;
  1227. luaspell->resisted = false;
  1228. if (target) {
  1229. float distance = caster->GetDistance(target, true);
  1230. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1231. success = true;
  1232. }
  1233. if (luaspell->targets.size() > 0) {
  1234. Spawn* target = 0;
  1235. ZoneServer* zone = luaspell->caster->GetZone();
  1236. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1237. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1238. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1239. float distance = caster->GetDistance(target, true);
  1240. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1241. }
  1242. }
  1243. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1244. success = true;
  1245. }
  1246. if (success) {
  1247. if (caster->GetZone())
  1248. caster->GetZone()->TriggerCharSheetTimer();
  1249. }
  1250. }
  1251. return 0;
  1252. }
  1253. int EQ2Emu_lua_AddItem(lua_State* state) {
  1254. if (!lua_interface)
  1255. return 0;
  1256. Spawn* spawn = lua_interface->GetSpawn(state);
  1257. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1258. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1259. // default of 1 quantity to add
  1260. if (quantity == 0)
  1261. quantity = 1;
  1262. if (spawn && spawn->IsPlayer()) {
  1263. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1264. if (client && item_id > 0) {
  1265. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1266. return 1;
  1267. }
  1268. }
  1269. lua_interface->SetBooleanValue(state, false);
  1270. return 1;
  1271. }
  1272. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1273. if (!lua_interface)
  1274. return 0;
  1275. Spawn* spawn = lua_interface->GetSpawn(state);
  1276. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1277. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1278. string location = lua_interface->GetStringValue(state, 4);
  1279. if (spawn && spawn->IsPlayer()) {
  1280. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1281. if (client && item_id > 0) {
  1282. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1283. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1284. else
  1285. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1286. if (send_messages) {
  1287. Item* item = master_item_list.GetItem(item_id);
  1288. if (item) {
  1289. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1290. string popup_text = "You receive " + item->name;
  1291. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1292. }
  1293. }
  1294. return 1;
  1295. }
  1296. }
  1297. lua_interface->SetBooleanValue(state, false);
  1298. return 1;
  1299. }
  1300. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1301. Spawn* spawn = lua_interface->GetSpawn(state);
  1302. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1303. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1304. // default of 1 to remove
  1305. if (quantity == 0)
  1306. quantity = 1;
  1307. Client* client;
  1308. Item* item;
  1309. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1310. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1311. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1312. if (client->RemoveItem(item, quantity)) {
  1313. lua_interface->SetBooleanValue(state, true);
  1314. return 1;
  1315. }
  1316. }
  1317. }
  1318. }
  1319. lua_interface->SetBooleanValue(state, false);
  1320. return 1;
  1321. }
  1322. int EQ2Emu_lua_HasItem(lua_State* state) {
  1323. Spawn* player = lua_interface->GetSpawn(state);
  1324. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1325. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1326. if (player && player->IsPlayer()) {
  1327. bool hasItem = false;
  1328. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1329. if (!hasItem)
  1330. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1331. lua_interface->SetBooleanValue(state, hasItem);
  1332. return 1;
  1333. }
  1334. lua_interface->SetBooleanValue(state, false);
  1335. return 1;
  1336. }
  1337. int EQ2Emu_lua_Spawn(lua_State* state) {
  1338. if (!lua_interface)
  1339. return 0;
  1340. ZoneServer* zone = lua_interface->GetZone(state);
  1341. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1342. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1343. float x = lua_interface->GetFloatValue(state, 4);
  1344. float y = lua_interface->GetFloatValue(state, 5);
  1345. float z = lua_interface->GetFloatValue(state, 6);
  1346. float heading = lua_interface->GetFloatValue(state, 7);
  1347. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1348. Spawn* spawn = zone->GetSpawn(spawn_id);
  1349. if (!spawn)
  1350. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1351. else {
  1352. spawn->SetX(x);
  1353. spawn->SetZ(z);
  1354. spawn->SetY(y,true,true);
  1355. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1356. spawn->SetHeading(heading);
  1357. if (restricted_npc)
  1358. spawn->AddAllowAccessSpawn(spawn);
  1359. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1360. bool scriptActive = false;
  1361. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1362. scriptActive = true;
  1363. spawn->SetSpawnScript(string(spawn_script));
  1364. }
  1365. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1366. zone->AddSpawn(spawn);
  1367. if (scriptActive) {
  1368. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1369. }
  1370. lua_interface->SetSpawnValue(state, spawn);
  1371. return 1;
  1372. }
  1373. }
  1374. else {
  1375. string output = "Invalid paramaters to LUA Spawn command: \n";
  1376. if (!zone)
  1377. output = output.append("\t").append("Missing zone reference. \n");
  1378. if (spawn_id == 0)
  1379. output = output.append("\t").append("Missing spawn_id.");
  1380. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1381. }
  1382. return 0;
  1383. }
  1384. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1385. if (!lua_interface)
  1386. return 0;
  1387. ZoneServer* zone = lua_interface->GetZone(state);
  1388. if (zone) {
  1389. lua_interface->SetStringValue(state, zone->GetZoneName());
  1390. return 1;
  1391. }
  1392. return 0;
  1393. }
  1394. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. ZoneServer* zone = lua_interface->GetZone(state);
  1398. if (zone) {
  1399. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1400. return 1;
  1401. }
  1402. return 0;
  1403. }
  1404. int EQ2Emu_lua_GetZone(lua_State* state) {
  1405. if (!lua_interface)
  1406. return 0;
  1407. int32 zone_id = lua_interface->GetInt32Value(state);
  1408. ZoneServer* zone = 0;
  1409. if (zone_id > 0)
  1410. zone = zone_list.Get(zone_id);
  1411. else {
  1412. string zone_name = lua_interface->GetStringValue(state);
  1413. if (zone_name.length() > 0) {
  1414. zone = zone_list.Get(zone_name.c_str());
  1415. }
  1416. else {
  1417. Spawn* spawn = lua_interface->GetSpawn(state);
  1418. if (spawn)
  1419. zone = spawn->GetZone();
  1420. }
  1421. }
  1422. if (zone) {
  1423. lua_interface->SetZoneValue(state, zone);
  1424. return 1;
  1425. }
  1426. return 0;
  1427. }
  1428. int EQ2Emu_lua_AddHate(lua_State* state) {
  1429. Spawn* entity = lua_interface->GetSpawn(state);
  1430. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1431. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1432. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1433. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1434. if (entity && entity->IsEntity() && amount != 0) {
  1435. if (luaspell) {
  1436. ZoneServer* zone = luaspell->caster->GetZone();
  1437. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1438. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1439. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1440. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1441. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1442. if (send_packet)
  1443. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1444. }
  1445. }
  1446. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1447. }
  1448. else if (npc && npc->IsNPC() && npc->GetZone())
  1449. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1450. }
  1451. return 0;
  1452. }
  1453. int EQ2Emu_lua_Zone(lua_State* state) {
  1454. if (!lua_interface)
  1455. return 0;
  1456. ZoneServer* zone = lua_interface->GetZone(state);
  1457. Spawn* player = lua_interface->GetSpawn(state, 2);
  1458. Client* client = 0;
  1459. if (player && player->IsPlayer())
  1460. client = player->GetZone()->GetClientBySpawn(player);
  1461. float x = lua_interface->GetFloatValue(state, 3);
  1462. float y = lua_interface->GetFloatValue(state, 4);
  1463. float z = lua_interface->GetFloatValue(state, 5);
  1464. float heading = lua_interface->GetFloatValue(state, 6);
  1465. if (zone && client) {
  1466. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1467. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1468. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1469. {
  1470. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1471. return 0;
  1472. }
  1473. if (x != 0 || y != 0 || z != 0) {
  1474. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1475. player->SetX(x);
  1476. player->SetY(y);
  1477. player->SetZ(z);
  1478. player->SetHeading(heading);
  1479. client->Zone(zone->GetZoneName(), false);
  1480. }
  1481. else
  1482. client->Zone(zone->GetZoneName());
  1483. }
  1484. else
  1485. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1486. return 0;
  1487. }
  1488. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1489. if (!lua_interface)
  1490. return 0;
  1491. Spawn* spawn = lua_interface->GetSpawn(state);
  1492. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1493. if (spawn && spawn2)
  1494. spawn->AddAllowAccessSpawn(spawn2);
  1495. return 0;
  1496. }
  1497. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1498. if (!lua_interface)
  1499. return 0;
  1500. Spawn* target = lua_interface->GetSpawn(state);
  1501. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1502. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1503. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1504. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1505. if (!target) {
  1506. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1507. return 0;
  1508. }
  1509. if (!target->IsEntity()) {
  1510. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1511. return 0;
  1512. }
  1513. if (spell_id <= 0) {
  1514. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1515. return 0;
  1516. }
  1517. if (caster && !caster->IsEntity()) {
  1518. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1519. return 0;
  1520. }
  1521. if (spell_tier == 0)
  1522. spell_tier = 1;
  1523. if (!caster)
  1524. caster = target;
  1525. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1526. return 0;
  1527. }
  1528. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1529. if (!lua_interface)
  1530. return 0;
  1531. Spawn* target = lua_interface->GetSpawn(state);
  1532. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1533. if (!luaspell)
  1534. return 0;
  1535. Spawn* caster = luaspell->caster;
  1536. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1537. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1538. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1539. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1540. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1541. //lua_interface->ResetFunctionStack(state);
  1542. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1543. vector<int16> faction_req;
  1544. vector<int16> race_req;
  1545. int32 class_req = 0;
  1546. int32 i = 0;
  1547. int8 f = 0;
  1548. int8 r = 0;
  1549. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1550. if (class_id < 100) {
  1551. class_req += pow(2.0, double(class_id - 1));
  1552. }
  1553. else if (class_id > 100 && class_id < 1000) {
  1554. race_req.push_back(class_id);
  1555. r++;
  1556. }
  1557. else {
  1558. faction_req.push_back(class_id);
  1559. f++;
  1560. }
  1561. i++;
  1562. }
  1563. if (caster && caster->IsEntity()) {
  1564. bool race_match = false;
  1565. bool success = false;
  1566. luaspell->resisted = false;
  1567. if (luaspell->targets.size() > 0) {
  1568. ZoneServer* zone = luaspell->caster->GetZone();
  1569. Spawn* target = 0;
  1570. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1571. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1572. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1573. if (race_req.size() > 0) {
  1574. for (int8 i = 0; i < race_req.size(); i++) {
  1575. if (target->GetLuaRaceId() == race_req[i]) {
  1576. race_match = true;
  1577. }
  1578. }
  1579. }
  1580. else
  1581. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1582. if (race_match == true) {
  1583. float distance = caster->GetDistance(target, true);
  1584. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1585. }
  1586. }
  1587. }
  1588. success = true;
  1589. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1590. }
  1591. else if (target) {
  1592. //check class and race/faction here
  1593. if (race_req.size() > 0) {
  1594. for (int8 i = 0; i < race_req.size(); i++) {
  1595. if (target->GetLuaRaceId() == race_req[i]) {
  1596. race_match = true;
  1597. }
  1598. }
  1599. }
  1600. else
  1601. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1602. if (race_match == true) {
  1603. float distance = caster->GetDistance(target, true);
  1604. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1605. success = true;
  1606. }
  1607. }
  1608. if (success) {
  1609. Spell* spell = luaspell->spell;
  1610. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1611. ((Player*)caster)->InCombat(true);
  1612. if (caster->GetZone())
  1613. caster->GetZone()->TriggerCharSheetTimer();
  1614. }
  1615. }
  1616. }
  1617. return 0;
  1618. }
  1619. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1620. if (!lua_interface)
  1621. return 0;
  1622. Spawn* spawn = lua_interface->GetSpawn(state);
  1623. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1624. lua_interface->ResetFunctionStack(state);
  1625. if (spawn && value != 0) {
  1626. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1627. spawn->SetPower(spawn->GetTotalPower());
  1628. else
  1629. spawn->SetPower(spawn->GetPower() + value);
  1630. }
  1631. return 0;
  1632. }
  1633. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1634. if (!lua_interface)
  1635. return 0;
  1636. Spawn* spawn = lua_interface->GetSpawn(state);
  1637. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1638. lua_interface->ResetFunctionStack(state);
  1639. if (spawn && value != 0) {
  1640. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1641. spawn->SetHP(spawn->GetTotalHP());
  1642. else
  1643. spawn->SetHP(spawn->GetHP() + value);
  1644. }
  1645. return 0;
  1646. }
  1647. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1648. if (!lua_interface)
  1649. return 0;
  1650. Spawn* spawn = lua_interface->GetSpawn(state);
  1651. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1652. lua_interface->ResetFunctionStack(state);
  1653. if (spawn && value != 0) {
  1654. spawn->SetPower(spawn->GetPower() + value);
  1655. if (value > spawn->GetTotalHPBase())
  1656. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1657. }
  1658. return 0;
  1659. }
  1660. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1661. if (!lua_interface)
  1662. return 0;
  1663. Spawn* spawn = lua_interface->GetSpawn(state);
  1664. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1665. lua_interface->ResetFunctionStack(state);
  1666. if (spawn && value != 0) {
  1667. spawn->SetHP(spawn->GetHP() + value);
  1668. if (value > spawn->GetTotalHPBase())
  1669. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1670. }
  1671. return 0;
  1672. }
  1673. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1674. if (!lua_interface)
  1675. return 0;
  1676. Spawn* spawn = lua_interface->GetSpawn(state);
  1677. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1678. lua_interface->ResetFunctionStack(state);
  1679. if (spawn) {
  1680. spawn->SetHP(value);
  1681. if (value > spawn->GetTotalHPBase())
  1682. spawn->SetTotalHP(value);
  1683. }
  1684. return 0;
  1685. }
  1686. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1687. if (!lua_interface)
  1688. return 0;
  1689. Spawn* spawn = lua_interface->GetSpawn(state);
  1690. float value = lua_interface->GetFloatValue(state, 2);
  1691. lua_interface->ResetFunctionStack(state);
  1692. if (spawn && spawn->IsEntity() && value > 0)
  1693. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1694. if (spawn->IsPlayer())
  1695. ((Player*)spawn)->SetCharSheetChanged(true);
  1696. return 0;
  1697. }
  1698. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1699. if (!lua_interface)
  1700. return 0;
  1701. Spawn* spawn = lua_interface->GetSpawn(state);
  1702. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1703. lua_interface->ResetFunctionStack(state);
  1704. if (spawn && spawn->IsEntity() && value > 0)
  1705. ((Entity*)spawn)->SetTotalHPBase(value);
  1706. return 0;
  1707. }
  1708. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1709. if (!lua_interface)
  1710. return 0;
  1711. Spawn* spawn = lua_interface->GetSpawn(state);
  1712. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1713. lua_interface->ResetFunctionStack(state);
  1714. if (spawn && value > 0) {
  1715. spawn->SetPower(value);
  1716. if (value > spawn->GetTotalPowerBase())
  1717. spawn->SetTotalPower(value);
  1718. }
  1719. return 0;
  1720. }
  1721. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1722. if (!lua_interface)
  1723. return 0;
  1724. Spawn* spawn = lua_interface->GetSpawn(state);
  1725. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1726. lua_interface->ResetFunctionStack(state);
  1727. if (spawn && spawn->IsEntity() && value > 0)
  1728. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1729. return 0;
  1730. }
  1731. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1732. if (!lua_interface)
  1733. return 0;
  1734. Spawn* spawn = lua_interface->GetSpawn(state);
  1735. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1736. lua_interface->ResetFunctionStack(state);
  1737. if (spawn && spawn->IsEntity() && value > 0)
  1738. ((Entity*)spawn)->SetTotalPowerBase(value);
  1739. return 0;
  1740. }
  1741. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1742. if (!lua_interface)
  1743. return 0;
  1744. Spawn* spawn = lua_interface->GetSpawn(state);
  1745. float x = lua_interface->GetFloatValue(state, 2);
  1746. float y = lua_interface->GetFloatValue(state, 3);
  1747. float z = lua_interface->GetFloatValue(state, 4);
  1748. float heading = lua_interface->GetFloatValue(state, 5);
  1749. lua_interface->ResetFunctionStack(state);
  1750. if (spawn) {
  1751. spawn->SetX(x);
  1752. spawn->SetY(y);
  1753. spawn->SetZ(z);
  1754. if (heading != 0)
  1755. spawn->SetHeading(heading);
  1756. spawn->SetSpawnOrigX(spawn->GetX());
  1757. spawn->SetSpawnOrigY(spawn->GetY());
  1758. spawn->SetSpawnOrigZ(spawn->GetZ());
  1759. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1760. if (spawn->IsPlayer()) {
  1761. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1762. if (client) {
  1763. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1764. client->QueuePacket(packet);
  1765. }
  1766. }
  1767. }
  1768. return 0;
  1769. }
  1770. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1771. if (!lua_interface)
  1772. return 0;
  1773. Spawn* spawn = lua_interface->GetSpawn(state);
  1774. float value = lua_interface->GetFloatValue(state, 2);
  1775. lua_interface->ResetFunctionStack(state);
  1776. if (spawn) {
  1777. spawn->SetHeading(value);
  1778. if (spawn->IsPlayer()) {
  1779. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1780. if (client) {
  1781. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1782. client->QueuePacket(packet);
  1783. }
  1784. }
  1785. }
  1786. return 0;
  1787. }
  1788. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1789. if (!lua_interface)
  1790. return 0;
  1791. Spawn* spawn = lua_interface->GetSpawn(state);
  1792. int16 value = lua_interface->GetInt16Value(state, 2);
  1793. lua_interface->ResetFunctionStack(state);
  1794. if (spawn)
  1795. spawn->SetModelType(value);
  1796. return 0;
  1797. }
  1798. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1799. if (!lua_interface)
  1800. return 0;
  1801. Spawn* spawn = lua_interface->GetSpawn(state);
  1802. int8 value = lua_interface->GetInt8Value(state, 2);
  1803. lua_interface->ResetFunctionStack(state);
  1804. if (spawn) {
  1805. if (spawn->IsPlayer())
  1806. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1807. else
  1808. spawn->SetAdventureClass(value);
  1809. }
  1810. return 0;
  1811. }
  1812. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1813. if (!lua_interface)
  1814. return 0;
  1815. Spawn* spawn = lua_interface->GetSpawn(state);
  1816. int8 value = lua_interface->GetInt8Value(state, 2);
  1817. lua_interface->ResetFunctionStack(state);
  1818. if (spawn) {
  1819. spawn->SetTradeskillClass(value);
  1820. if (spawn->IsEntity()) {
  1821. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1822. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1823. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1824. }
  1825. if (spawn->IsPlayer())
  1826. ((Player*)spawn)->SetCharSheetChanged(true);
  1827. }
  1828. return 0;
  1829. }
  1830. int EQ2Emu_lua_SetMount(lua_State* state) {
  1831. if (!lua_interface)
  1832. return 0;
  1833. Spawn* spawn = lua_interface->GetSpawn(state);
  1834. int16 value = lua_interface->GetInt16Value(state, 2);
  1835. if (spawn && spawn->IsEntity()) {
  1836. ((Entity*)spawn)->SetMount(value);
  1837. EQ2_Color color;
  1838. color.red = 255;
  1839. color.green = 255;
  1840. color.blue = 255;
  1841. ((Entity*)spawn)->SetMountColor(&color);
  1842. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1843. }
  1844. return 0;
  1845. }
  1846. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1847. if (!lua_interface)
  1848. return 0;
  1849. Spawn* spawn = lua_interface->GetSpawn(state);
  1850. EQ2_Color mount_color;
  1851. EQ2_Color saddle_color;
  1852. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1853. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1854. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1855. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1856. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1857. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1858. if (spawn && spawn->IsEntity()) {
  1859. ((Entity*)spawn)->SetMountColor(&mount_color);
  1860. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1861. }
  1862. return 0;
  1863. }
  1864. int EQ2Emu_lua_GetMount(lua_State* state) {
  1865. if (!lua_interface)
  1866. return 0;
  1867. Spawn* spawn = lua_interface->GetSpawn(state);
  1868. if (spawn && spawn->IsEntity()) {
  1869. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1870. return 1;
  1871. }
  1872. return 0;
  1873. }
  1874. int EQ2Emu_lua_GetRace(lua_State* state) {
  1875. if (!lua_interface)
  1876. return 0;
  1877. Spawn* spawn = lua_interface->GetSpawn(state);
  1878. if (spawn)
  1879. {
  1880. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1881. lua_interface->SetInt32Value(state, spawn->GetRace());
  1882. return 1;
  1883. }
  1884. return 0;
  1885. }
  1886. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1887. if (!lua_interface)
  1888. return 0;
  1889. Spawn* spawn = lua_interface->GetSpawn(state);
  1890. if (spawn) {
  1891. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1892. return 1;
  1893. }
  1894. return 0;
  1895. }
  1896. int EQ2Emu_lua_GetClass(lua_State* state) {
  1897. Spawn* spawn = lua_interface->GetSpawn(state);
  1898. if (spawn) {
  1899. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1900. return 1;
  1901. }
  1902. return 0;
  1903. }
  1904. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1905. Spawn* spawn = lua_interface->GetSpawn(state);
  1906. if (spawn) {
  1907. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1908. return 1;
  1909. }
  1910. return 0;
  1911. }
  1912. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1913. if (!lua_interface)
  1914. return 0;
  1915. Spawn* spawn = lua_interface->GetSpawn(state);
  1916. float value = lua_interface->GetFloatValue(state, 2);
  1917. lua_interface->ResetFunctionStack(state);
  1918. if (spawn) {
  1919. spawn->SetSpeed(value);
  1920. ((Entity*)spawn)->SetSpeed(value);
  1921. if (spawn->IsPlayer()) {
  1922. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1923. if (client) {
  1924. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1925. if (packet) {
  1926. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1927. packet->setDataByName("speed", value);
  1928. packet->setDataByName("size", 0.51);
  1929. EQ2Packet* app = packet->serialize();
  1930. client->QueuePacket(app);
  1931. safe_delete(packet);
  1932. }
  1933. }
  1934. }
  1935. }
  1936. return 0;
  1937. }
  1938. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1939. if (!lua_interface)
  1940. return 0;
  1941. Spawn* spawn = lua_interface->GetSpawn(state);
  1942. const int16 type = lua_interface->GetInt16Value(state, 2);
  1943. const float value = lua_interface->GetFloatValue(state, 3);
  1944. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1945. int64 class_req = 0;
  1946. int32 class_id = 0;
  1947. vector<int16> faction_req;
  1948. vector<int16> race_req;
  1949. int32 i = 0;
  1950. int8 f = 0;
  1951. int8 r = 0;
  1952. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1953. if (class_id < 100) {
  1954. class_req += pow(2.0, double(class_id - 1));
  1955. }
  1956. else if (class_id > 100 && class_id < 1000) {
  1957. race_req.push_back(class_id);
  1958. r++;
  1959. }
  1960. else {
  1961. faction_req.push_back(class_id);
  1962. f++;
  1963. }
  1964. i++;
  1965. }
  1966. if (value != 0 && type >= 0) {
  1967. if (luaspell && luaspell->spell && luaspell->caster) {
  1968. ZoneServer* zone = luaspell->caster->GetZone();
  1969. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1970. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1971. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1972. if (target) {
  1973. if (target->IsPlayer()) {
  1974. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1975. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1976. if (((Player*)target)->GetGroupMemberInfo())
  1977. ((Player*)target)->UpdateGroupMemberInfo();
  1978. ((Player*)target)->SetCharSheetChanged(true);
  1979. }
  1980. else if (target->IsNPC())
  1981. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1982. else
  1983. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1984. }
  1985. }
  1986. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1987. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1988. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1989. }
  1990. else if (spawn && spawn->IsEntity()) {
  1991. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1992. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1993. if (spawn->IsPlayer())
  1994. ((Player*)spawn)->SetCharSheetChanged(true);
  1995. }
  1996. else
  1997. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1998. }
  1999. else
  2000. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2001. return 0;
  2002. }
  2003. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2004. if (!lua_interface)
  2005. return 0;
  2006. Spawn* spawn = lua_interface->GetSpawn(state);
  2007. int16 type = lua_interface->GetInt16Value(state, 2);
  2008. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2009. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2010. if (!spawn) {
  2011. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2012. return 0;
  2013. }
  2014. if (!spawn->IsEntity()) {
  2015. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2016. return 0;
  2017. }
  2018. if (value == 0) {
  2019. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2020. return 0;
  2021. }
  2022. if (!luaspell || !luaspell->spell) {
  2023. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2024. return 0;
  2025. }
  2026. int32 class_req = 0;
  2027. vector<int16> faction_req;
  2028. vector<int16> race_req;
  2029. int32 class_id = 0;
  2030. int32 i = 0;
  2031. int8 f = 0;
  2032. int8 r = 0;
  2033. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2034. if (class_id < 100) {
  2035. class_req += pow(2.0, double(class_id - 1));
  2036. }
  2037. else if (class_id > 100 && class_id < 1000) {
  2038. race_req.push_back(class_id);
  2039. r++;
  2040. }
  2041. else {
  2042. faction_req.push_back(class_id);
  2043. f++;
  2044. }
  2045. i++;
  2046. }
  2047. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2048. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2049. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2050. if (spawn->IsPlayer())
  2051. ((Player*)spawn)->SetCharSheetChanged(true);
  2052. return 0;
  2053. }
  2054. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2055. if (!lua_interface)
  2056. return 0;
  2057. Spawn* spawn = lua_interface->GetSpawn(state);
  2058. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2059. if (!spawn) {
  2060. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2061. return 0;
  2062. }
  2063. if (!spawn->IsEntity()) {
  2064. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2065. return 0;
  2066. }
  2067. if (!luaspell || !luaspell->spell) {
  2068. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2069. return 0;
  2070. }
  2071. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2072. if (spawn->IsPlayer())
  2073. ((Player*)spawn)->SetCharSheetChanged(true);
  2074. return 0;
  2075. }
  2076. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2077. if (!lua_interface)
  2078. return 0;
  2079. Spawn* spawn = lua_interface->GetSpawn(state);
  2080. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2081. if (luaspell && luaspell->spell) {
  2082. ZoneServer* zone = luaspell->caster->GetZone();
  2083. Spawn* target = 0;
  2084. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2085. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2086. target = zone->GetSpawnByID(luaspell->targets[i]);
  2087. if (target && target->IsEntity()) {
  2088. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2089. if (target->IsPlayer())
  2090. ((Player*)target)->SetCharSheetChanged(true);
  2091. }
  2092. }
  2093. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2094. }
  2095. else if (spawn && spawn->IsEntity()) {
  2096. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2097. if (spawn->IsPlayer())
  2098. ((Player*)spawn)->SetCharSheetChanged(true);
  2099. }
  2100. return 0;
  2101. }
  2102. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2103. if (!lua_interface)
  2104. return 0;
  2105. Spawn* spawn = lua_interface->GetSpawn(state);
  2106. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2107. float value = lua_interface->GetFloatValue(state, 3);
  2108. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2109. if (value != 0) {
  2110. int32 spell_id = 0;
  2111. if (luaspell && luaspell->spell && luaspell->caster) {
  2112. spell_id = luaspell->spell->GetSpellID();
  2113. ZoneServer* zone = luaspell->caster->GetZone();
  2114. Spawn* target = 0;
  2115. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2116. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2117. target = zone->GetSpawnByID(luaspell->targets[i]);
  2118. if (target && target->Alive()) {
  2119. if (target->IsPlayer()) {
  2120. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2121. Client* client = target->GetZone()->GetClientBySpawn(target);
  2122. if (client) {
  2123. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2124. if (packet)
  2125. client->QueuePacket(packet);
  2126. }
  2127. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2128. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2129. }
  2130. else if (target->IsNPC()) {
  2131. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2132. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2133. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2134. }
  2135. else
  2136. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2137. }
  2138. }
  2139. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2140. }
  2141. else if (spawn) {
  2142. if (spawn->IsPlayer()) {
  2143. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2144. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2145. if (client) {
  2146. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2147. if (packet)
  2148. client->QueuePacket(packet);
  2149. }
  2150. }
  2151. else if (spawn->IsNPC())
  2152. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2153. else
  2154. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2155. }
  2156. }
  2157. else
  2158. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2159. return 0;
  2160. }
  2161. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2162. if (!lua_interface)
  2163. return 0;
  2164. Spawn* spawn = lua_interface->GetSpawn(state);
  2165. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2166. if (spawn && spawn->IsPlayer()) {
  2167. int32 spell_id = 0;
  2168. if (luaspell && luaspell->spell) {
  2169. spell_id = luaspell->spell->GetSpellID();
  2170. ZoneServer* zone = luaspell->caster->GetZone();
  2171. Spawn* target = 0;
  2172. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2173. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2174. target = zone->GetSpawnByID(luaspell->targets[i]);
  2175. if (target) {
  2176. if (target->IsPlayer()) {
  2177. ((Player*)target)->RemoveSkillBonus(spell_id);
  2178. Client* client = target->GetZone()->GetClientBySpawn(target);
  2179. if (client) {
  2180. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2181. if (packet)
  2182. client->QueuePacket(packet);
  2183. }
  2184. }
  2185. else if (target->IsNPC())
  2186. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2187. else
  2188. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2189. }
  2190. }
  2191. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2192. }
  2193. else if (spawn) {
  2194. if (spawn->IsPlayer()) {
  2195. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2196. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2197. if (client) {
  2198. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2199. if (packet)
  2200. client->QueuePacket(packet);
  2201. }
  2202. }
  2203. else if (spawn->IsNPC())
  2204. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2205. else
  2206. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2207. }
  2208. }
  2209. return 0;
  2210. }
  2211. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2212. if (!lua_interface)
  2213. return 0;
  2214. Spawn* spawn = lua_interface->GetSpawn(state);
  2215. int8 type = lua_interface->GetInt32Value(state, 2);
  2216. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2217. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2218. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2219. ZoneServer* zone = luaspell->caster->GetZone();
  2220. Spawn* target = 0;
  2221. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2222. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2223. target = zone->GetSpawnByID(luaspell->targets[i]);
  2224. if (target && target->IsEntity()) {
  2225. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2226. ((Entity*)target)->AddMezSpell(luaspell);
  2227. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2228. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2229. if (target->IsNPC())
  2230. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2231. }
  2232. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2233. ((Entity*)target)->AddStifleSpell(luaspell);
  2234. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2235. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2236. if (target->IsNPC())
  2237. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2238. }
  2239. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2240. ((Entity*)target)->AddDazeSpell(luaspell);
  2241. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2242. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2243. if (target->IsNPC())
  2244. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2245. }
  2246. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2247. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2248. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2249. ((Entity*)target)->AddStunSpell(luaspell);
  2250. if (target->IsNPC())
  2251. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2252. }
  2253. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2254. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2255. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2256. ((Entity*)target)->AddRootSpell(luaspell);
  2257. if (target->IsNPC())
  2258. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2259. }
  2260. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2261. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2262. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2263. ((Entity*)target)->AddFearSpell(luaspell);
  2264. if (target->IsNPC())
  2265. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2266. }
  2267. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2268. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2269. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2270. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2271. }
  2272. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2273. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2274. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2275. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2276. }
  2277. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2278. ((Entity*)target)->AddSnareSpell(luaspell);
  2279. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2280. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2281. if (target->IsNPC())
  2282. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2283. }
  2284. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2285. ((Entity*)target)->AddFlightSpell(luaspell);
  2286. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2287. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2288. }
  2289. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2290. ((Entity*)target)->AddGlideSpell(luaspell);
  2291. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2292. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2293. }
  2294. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2295. ((Entity*)target)->AddSafefallSpell(luaspell);
  2296. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2297. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2298. }
  2299. else
  2300. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2301. }
  2302. else
  2303. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2304. }
  2305. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2306. }
  2307. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2308. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2309. ((Entity*)spawn)->AddMezSpell(luaspell);
  2310. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2311. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2312. }
  2313. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2314. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2315. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2316. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2317. }
  2318. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2319. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2320. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2321. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2322. }
  2323. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2324. ((Entity*)spawn)->AddStunSpell(luaspell);
  2325. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2326. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2327. }
  2328. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2329. ((Entity*)spawn)->AddRootSpell(luaspell);
  2330. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2331. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2332. }
  2333. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2334. ((Entity*)spawn)->AddFearSpell(luaspell);
  2335. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2336. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2337. }
  2338. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2339. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2340. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2341. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2342. }
  2343. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2344. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2345. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2346. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2347. }
  2348. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2349. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2350. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2351. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2352. }
  2353. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2354. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2355. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2356. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2357. }
  2358. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2359. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2360. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2361. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2362. }
  2363. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2364. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2365. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2366. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2367. }
  2368. else
  2369. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2370. }
  2371. else
  2372. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2373. return 0;
  2374. }
  2375. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2376. if (!lua_interface)
  2377. return 0;
  2378. Spawn* spawn = lua_interface->GetSpawn(state);
  2379. int8 type = lua_interface->GetInt8Value(state, 2);
  2380. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2381. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2382. if (spawn && spawn->IsEntity()) {
  2383. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2384. ZoneServer* zone = luaspell->caster->GetZone();
  2385. Spawn* target = 0;
  2386. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2387. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2388. target = zone->GetSpawnByID(luaspell->targets[i]);
  2389. if (target) {
  2390. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2391. ((Entity*)target)->RemoveMezSpell(luaspell);
  2392. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2393. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2394. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2395. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2396. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2397. ((Entity*)target)->RemoveStunSpell(luaspell);
  2398. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2399. ((Entity*)target)->RemoveRootSpell(luaspell);
  2400. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2401. ((Entity*)target)->RemoveFearSpell(luaspell);
  2402. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2403. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2404. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2405. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2406. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2407. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2408. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2409. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2410. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2411. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2412. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2413. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2414. else
  2415. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2416. }
  2417. }
  2418. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2419. }
  2420. else if (only_remove_spawn) {
  2421. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2422. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2423. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2424. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2425. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2426. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2427. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2428. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2429. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2430. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2431. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2432. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2433. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2434. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2435. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2436. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2437. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2438. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2439. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2440. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2441. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2442. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2443. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2444. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2445. else
  2446. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2447. }
  2448. }
  2449. return 0;
  2450. }
  2451. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2452. if (!lua_interface)
  2453. return 0;
  2454. Spawn* spawn = lua_interface->GetSpawn(state);
  2455. int8 type = lua_interface->GetInt8Value(state, 2);
  2456. bool hasEffect = false;
  2457. if (!spawn)
  2458. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2459. else if (!spawn->IsEntity())
  2460. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2461. else if (type < CONTROL_MAX_EFFECTS)
  2462. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2463. else
  2464. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2465. lua_interface->SetBooleanValue(state, hasEffect);
  2466. return 1;
  2467. }
  2468. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2469. if (!lua_interface)
  2470. return 0;
  2471. Spawn* spawn = lua_interface->GetSpawn(state);
  2472. float distance = 0.0f;
  2473. if (!spawn)
  2474. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2475. else if (!spawn->IsNPC())
  2476. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2477. else
  2478. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2479. lua_interface->SetFloatValue(state, distance);
  2480. return 1;
  2481. }
  2482. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2483. if (!lua_interface)
  2484. return 0;
  2485. Spawn* spawn = lua_interface->GetSpawn(state);
  2486. float distance = 0.0f;
  2487. if (!spawn)
  2488. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2489. else if (!spawn->IsNPC())
  2490. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2491. else
  2492. distance = ((NPC*)spawn)->GetAggroRadius();
  2493. lua_interface->SetFloatValue(state, distance);
  2494. return 1;
  2495. }
  2496. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2497. if (!lua_interface)
  2498. return 0;
  2499. Spawn* spawn = lua_interface->GetSpawn(state);
  2500. float distance = lua_interface->GetFloatValue(state, 2);
  2501. bool override = lua_interface->GetBooleanValue(state, 3);
  2502. bool result = false;
  2503. lua_interface->ResetFunctionStack(state);
  2504. if (!spawn)
  2505. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2506. else if (!spawn->IsNPC())
  2507. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2508. else
  2509. {
  2510. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2511. result = true;
  2512. }
  2513. lua_interface->SetBooleanValue(state, result);
  2514. return 1;
  2515. }
  2516. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2517. if (!lua_interface)
  2518. return 0;
  2519. Spawn* spawn = lua_interface->GetSpawn(state);
  2520. int16 value = lua_interface->GetInt16Value(state, 2);
  2521. if (spawn && spawn->IsEntity()) {
  2522. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2523. if (spawn->IsPlayer())
  2524. ((Player*)spawn)->SetCharSheetChanged(true);
  2525. }
  2526. return 0;
  2527. }
  2528. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2529. if (!lua_interface)
  2530. return 0;
  2531. Spawn* spawn = lua_interface->GetSpawn(state);
  2532. int16 value = lua_interface->GetInt16Value(state, 2);
  2533. if (spawn && spawn->IsEntity()) {
  2534. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2535. if (spawn->IsPlayer())
  2536. ((Player*)spawn)->SetCharSheetChanged(true);
  2537. }
  2538. return 0;
  2539. }
  2540. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2541. if (!lua_interface)
  2542. return 0;
  2543. Spawn* spawn = lua_interface->GetSpawn(state);
  2544. int16 value = lua_interface->GetInt16Value(state, 2);
  2545. if (spawn && spawn->IsEntity()) {
  2546. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2547. if (spawn->IsPlayer())
  2548. ((Player*)spawn)->SetCharSheetChanged(true);
  2549. }
  2550. return 0;
  2551. }
  2552. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2553. if (!lua_interface)
  2554. return 0;
  2555. Spawn* spawn = lua_interface->GetSpawn(state);
  2556. int16 value = lua_interface->GetInt16Value(state, 2);
  2557. if (spawn && spawn->IsEntity()) {
  2558. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2559. if (spawn->IsPlayer())
  2560. ((Player*)spawn)->SetCharSheetChanged(true);
  2561. }
  2562. return 0;
  2563. }
  2564. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2565. if (!lua_interface)
  2566. return 0;
  2567. Spawn* spawn = lua_interface->GetSpawn(state);
  2568. int16 value = lua_interface->GetInt16Value(state, 2);
  2569. if (spawn && spawn->IsEntity()) {
  2570. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2571. if (spawn->IsPlayer())
  2572. ((Player*)spawn)->SetCharSheetChanged(true);
  2573. }
  2574. return 0;
  2575. }
  2576. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2577. if (!lua_interface)
  2578. return 0;
  2579. Spawn* spawn = lua_interface->GetSpawn(state);
  2580. int8 value = lua_interface->GetInt8Value(state, 2);
  2581. if (spawn && spawn->IsEntity()) {
  2582. ((Entity*)spawn)->SetDeity(value);
  2583. if (spawn->IsPlayer())
  2584. ((Player*)spawn)->SetCharSheetChanged(true);
  2585. }
  2586. lua_interface->ResetFunctionStack(state);
  2587. return 0;
  2588. }
  2589. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2590. if (!lua_interface)
  2591. return 0;
  2592. Spawn* spawn = lua_interface->GetSpawn(state);
  2593. if (spawn && spawn->IsEntity()) {
  2594. int8 deity = ((Entity*)spawn)->GetDeity();
  2595. lua_interface->SetInt32Value(state, deity);
  2596. return 1;
  2597. }
  2598. return 0;
  2599. }
  2600. int EQ2Emu_lua_SetInt(lua_State* state) {
  2601. if (!lua_interface)
  2602. return 0;
  2603. Spawn* spawn = lua_interface->GetSpawn(state);
  2604. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2605. if (spawn && spawn->IsEntity()) {
  2606. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2607. if (spawn->IsPlayer())
  2608. ((Player*)spawn)->SetCharSheetChanged(true);
  2609. }
  2610. return 0;
  2611. }
  2612. int EQ2Emu_lua_SetWis(lua_State* state) {
  2613. if (!lua_interface)
  2614. return 0;
  2615. Spawn* spawn = lua_interface->GetSpawn(state);
  2616. float value = lua_interface->GetFloatValue(state, 2);
  2617. if (spawn && spawn->IsEntity()) {
  2618. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2619. if (spawn->IsPlayer())
  2620. ((Player*)spawn)->SetCharSheetChanged(true);
  2621. }
  2622. return 0;
  2623. }
  2624. int EQ2Emu_lua_SetSta(lua_State* state) {
  2625. if (!lua_interface)
  2626. return 0;
  2627. Spawn* spawn = lua_interface->GetSpawn(state);
  2628. float value = lua_interface->GetFloatValue(state, 2);
  2629. if (spawn && spawn->IsEntity()) {
  2630. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2631. if (spawn->IsPlayer())
  2632. ((Player*)spawn)->SetCharSheetChanged(true);
  2633. }
  2634. return 0;
  2635. }
  2636. int EQ2Emu_lua_SetStr(lua_State* state) {
  2637. if (!lua_interface)
  2638. return 0;
  2639. Spawn* spawn = lua_interface->GetSpawn(state);
  2640. float value = lua_interface->GetFloatValue(state, 2);
  2641. if (spawn && spawn->IsEntity()) {
  2642. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2643. if (spawn->IsPlayer())
  2644. ((Player*)spawn)->SetCharSheetChanged(true);
  2645. }
  2646. return 0;
  2647. }
  2648. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2649. if (!lua_interface)
  2650. return 0;
  2651. Spawn* spawn = lua_interface->GetSpawn(state);
  2652. float value = lua_interface->GetFloatValue(state, 2);
  2653. if (spawn && spawn->IsEntity()) {
  2654. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2655. if (spawn->IsPlayer())
  2656. ((Player*)spawn)->SetCharSheetChanged(true);
  2657. }
  2658. return 0;
  2659. }
  2660. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2661. if (!lua_interface)
  2662. return 0;
  2663. Spawn* spawn = lua_interface->GetSpawn(state);
  2664. if (spawn) {
  2665. lua_interface->SetInt32Value(state, spawn->GetHP());
  2666. return 1;
  2667. }
  2668. return 0;
  2669. }
  2670. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2671. if (!lua_interface)
  2672. return 0;
  2673. Spawn* spawn = lua_interface->GetSpawn(state);
  2674. if (spawn) {
  2675. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2676. return 1;
  2677. }
  2678. return 0;
  2679. }
  2680. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2681. if (!lua_interface)
  2682. return 0;
  2683. Spawn* spawn = lua_interface->GetSpawn(state);
  2684. if (spawn) {
  2685. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2686. return 1;
  2687. }
  2688. return 0;
  2689. }
  2690. int EQ2Emu_lua_GetName(lua_State* state) {
  2691. if (!lua_interface)
  2692. return 0;
  2693. Spawn* spawn = lua_interface->GetSpawn(state);
  2694. if (spawn) {
  2695. lua_interface->SetStringValue(state, spawn->GetName());
  2696. return 1;
  2697. }
  2698. return 0;
  2699. }
  2700. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2701. Spawn* spawn = lua_interface->GetSpawn(state);
  2702. if (spawn) {
  2703. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2704. return 1;
  2705. }
  2706. return 0;
  2707. }
  2708. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2709. if (!lua_interface)
  2710. return 0;
  2711. Spawn* spawn = lua_interface->GetSpawn(state);
  2712. if (spawn) {
  2713. lua_interface->SetInt32Value(state, spawn->GetPower());
  2714. return 1;
  2715. }
  2716. return 0;
  2717. }
  2718. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2719. if (!lua_interface)
  2720. return 0;
  2721. Spawn* spawn = lua_interface->GetSpawn(state);
  2722. if (spawn) {
  2723. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2724. return 1;
  2725. }
  2726. return 0;
  2727. }
  2728. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2729. if (!lua_interface)
  2730. return 0;
  2731. Spawn* spawn = lua_interface->GetSpawn(state);
  2732. if (spawn) {
  2733. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2734. return 1;
  2735. }
  2736. return 0;
  2737. }
  2738. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2739. if (!lua_interface)
  2740. return 0;
  2741. Spawn* spawn = lua_interface->GetSpawn(state);
  2742. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2743. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2744. if (spawn && spawn2) {
  2745. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2746. lua_interface->SetFloatValue(state, distance);
  2747. return 1;
  2748. }
  2749. return 0;
  2750. }
  2751. int EQ2Emu_lua_GetX(lua_State* state) {
  2752. if (!lua_interface)
  2753. return 0;
  2754. Spawn* spawn = lua_interface->GetSpawn(state);
  2755. if (spawn) {
  2756. lua_interface->SetFloatValue(state, spawn->GetX());
  2757. return 1;
  2758. }
  2759. return 0;
  2760. }
  2761. int EQ2Emu_lua_GetY(lua_State* state) {
  2762. if (!lua_interface)
  2763. return 0;
  2764. Spawn* spawn = lua_interface->GetSpawn(state);
  2765. if (spawn) {
  2766. lua_interface->SetFloatValue(state, spawn->GetY());
  2767. return 1;
  2768. }
  2769. return 0;
  2770. }
  2771. int EQ2Emu_lua_GetZ(lua_State* state) {
  2772. if (!lua_interface)
  2773. return 0;
  2774. Spawn* spawn = lua_interface->GetSpawn(state);
  2775. if (spawn) {
  2776. lua_interface->SetFloatValue(state, spawn->GetZ());
  2777. return 1;
  2778. }
  2779. return 0;
  2780. }
  2781. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2782. if (!lua_interface)
  2783. return 0;
  2784. Spawn* spawn = lua_interface->GetSpawn(state);
  2785. if (spawn) {
  2786. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2787. return 1;
  2788. }
  2789. return 0;
  2790. }
  2791. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2792. if (!lua_interface)
  2793. return 0;
  2794. Spawn* spawn = lua_interface->GetSpawn(state);
  2795. if (spawn) {
  2796. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2797. return 1;
  2798. }
  2799. return 0;
  2800. }
  2801. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2802. if (!lua_interface)
  2803. return 0;
  2804. Spawn* spawn = lua_interface->GetSpawn(state);
  2805. if (spawn) {
  2806. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2807. return 1;
  2808. }
  2809. return 0;
  2810. }
  2811. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2812. if (!lua_interface)
  2813. return 0;
  2814. Spawn* spawn = lua_interface->GetSpawn(state);
  2815. if (spawn && spawn->IsEntity()) {
  2816. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2817. return 1;
  2818. }
  2819. return 0;
  2820. }
  2821. int EQ2Emu_lua_GetInt(lua_State* state) {
  2822. if (!lua_interface)
  2823. return 0;
  2824. Spawn* spawn = lua_interface->GetSpawn(state);
  2825. if (spawn && spawn->IsEntity()) {
  2826. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2827. return 1;
  2828. }
  2829. return 0;
  2830. }
  2831. int EQ2Emu_lua_GetWis(lua_State* state) {
  2832. if (!lua_interface)
  2833. return 0;
  2834. Spawn* spawn = lua_interface->GetSpawn(state);
  2835. if (spawn && spawn->IsEntity()) {
  2836. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2837. return 1;
  2838. }
  2839. return 0;
  2840. }
  2841. int EQ2Emu_lua_GetSta(lua_State* state) {
  2842. if (!lua_interface)
  2843. return 0;
  2844. Spawn* spawn = lua_interface->GetSpawn(state);
  2845. if (spawn && spawn->IsEntity()) {
  2846. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2847. return 1;
  2848. }
  2849. return 0;
  2850. }
  2851. int EQ2Emu_lua_GetStr(lua_State* state) {
  2852. if (!lua_interface)
  2853. return 0;
  2854. Spawn* spawn = lua_interface->GetSpawn(state);
  2855. if (spawn && spawn->IsEntity()) {
  2856. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2857. return 1;
  2858. }
  2859. return 0;
  2860. }
  2861. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2862. if (!lua_interface)
  2863. return 0;
  2864. Spawn* spawn = lua_interface->GetSpawn(state);
  2865. if (spawn && spawn->IsEntity()) {
  2866. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2867. return 1;
  2868. }
  2869. return 0;
  2870. }
  2871. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2872. if (!lua_interface)
  2873. return 0;
  2874. Spawn* spawn = lua_interface->GetSpawn(state);
  2875. if (spawn && spawn->IsEntity()) {
  2876. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2877. return 1;
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Spawn* spawn = lua_interface->GetSpawn(state);
  2885. if (spawn && spawn->IsEntity()) {
  2886. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2887. return 1;
  2888. }
  2889. return 0;
  2890. }
  2891. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2892. if (!lua_interface)
  2893. return 0;
  2894. Spawn* spawn = lua_interface->GetSpawn(state);
  2895. if (spawn && spawn->IsEntity()) {
  2896. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2897. return 1;
  2898. }
  2899. return 0;
  2900. }
  2901. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2902. if (!lua_interface)
  2903. return 0;
  2904. Spawn* spawn = lua_interface->GetSpawn(state);
  2905. if (spawn && spawn->IsEntity()) {
  2906. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2907. return 1;
  2908. }
  2909. return 0;
  2910. }
  2911. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2912. if (!lua_interface)
  2913. return 0;
  2914. Spawn* spawn = lua_interface->GetSpawn(state);
  2915. if (spawn && spawn->IsEntity()) {
  2916. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2917. return 1;
  2918. }
  2919. return 0;
  2920. }
  2921. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2922. if (!lua_interface)
  2923. return 0;
  2924. Spawn* player = lua_interface->GetSpawn(state);
  2925. if (!player || !player->IsPlayer()) {
  2926. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2927. return 0;
  2928. }
  2929. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2930. if (quest_id <= 0) {
  2931. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2932. return 0;
  2933. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2934. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2935. return 0;
  2936. }
  2937. int32 step = lua_interface->GetInt32Value(state, 3);
  2938. if (step > 0) {
  2939. Client* client = player->GetZone()->GetClientBySpawn(player);
  2940. if (client)
  2941. client->AddPendingQuestUpdate(quest_id, step);
  2942. } else {
  2943. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2944. }
  2945. return 0;
  2946. }
  2947. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2948. Spawn* player = lua_interface->GetSpawn(state);
  2949. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2950. int32 step = lua_interface->GetInt32Value(state, 3);
  2951. int32 progress = lua_interface->GetInt32Value(state, 4);
  2952. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2953. Client* client = player->GetZone()->GetClientBySpawn(player);
  2954. if (client)
  2955. client->AddPendingQuestUpdate(quest_id, step, progress);
  2956. }
  2957. return 0;
  2958. }
  2959. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2960. if (!lua_interface)
  2961. return 0;
  2962. Spawn* player = lua_interface->GetSpawn(state);
  2963. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2964. if (player && player->IsPlayer() && quest_id > 0) {
  2965. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2966. return 1;
  2967. }
  2968. return 0;
  2969. }
  2970. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2971. if (!lua_interface)
  2972. return 0;
  2973. Spawn* player = lua_interface->GetSpawn(state);
  2974. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2975. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2976. if (player && player->IsPlayer() && quest_id > 0) {
  2977. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* player = lua_interface->GetSpawn(state);
  2986. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2987. if (player && player->IsPlayer() && quest_id > 0) {
  2988. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2989. return 1;
  2990. }
  2991. return 0;
  2992. }
  2993. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2994. if (!lua_interface)
  2995. return 0;
  2996. Quest* quest = lua_interface->GetQuest(state);
  2997. string name = lua_interface->GetStringValue(state, 2);
  2998. string type = lua_interface->GetStringValue(state, 3);
  2999. string zone = lua_interface->GetStringValue(state, 4);
  3000. int16 level = lua_interface->GetInt16Value(state, 5);
  3001. string description = lua_interface->GetStringValue(state, 6);
  3002. bool load = true;
  3003. if (!quest) {
  3004. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3005. load = false;
  3006. }
  3007. if (load && name.length() == 0) {
  3008. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3009. load = false;
  3010. }
  3011. if (load && type.length() == 0) {
  3012. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3013. load = false;
  3014. }
  3015. if (load && zone.length() == 0) {
  3016. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3017. load = false;
  3018. }
  3019. if (load && description.length() == 0) {
  3020. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3021. load = false;
  3022. }
  3023. if (load && level == 0) {
  3024. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3025. load = false;
  3026. }
  3027. if (load)
  3028. quest->RegisterQuest(name, type, zone, level, description);
  3029. return 0;
  3030. }
  3031. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3032. if (!lua_interface)
  3033. return 0;
  3034. Quest* quest = lua_interface->GetQuest(state);
  3035. if (quest) {
  3036. int8 level = lua_interface->GetInt16Value(state, 2);
  3037. quest->SetPrereqLevel(level);
  3038. }
  3039. return 0;
  3040. }
  3041. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3042. if (!lua_interface)
  3043. return 0;
  3044. Quest* quest = lua_interface->GetQuest(state);
  3045. if (quest) {
  3046. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3047. quest->AddPrereqQuest(quest_id);
  3048. }
  3049. return 0;
  3050. }
  3051. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3052. if (!lua_interface)
  3053. return 0;
  3054. Quest* quest = lua_interface->GetQuest(state);
  3055. if (quest) {
  3056. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3057. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3058. if (quantity == 0)
  3059. quantity = 1;
  3060. Item* master_item = master_item_list.GetItem(item_id);
  3061. if (master_item) {
  3062. Item* item = new Item(master_item);
  3063. item->details.count = quantity;
  3064. quest->AddPrereqItem(item);
  3065. }
  3066. }
  3067. return 0;
  3068. }
  3069. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3070. if (!lua_interface)
  3071. return 0;
  3072. Spawn* player = lua_interface->GetSpawn(state);
  3073. if(!player || !player->IsPlayer()) {
  3074. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3075. return 0;
  3076. }
  3077. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3078. if (quest_id > 0) {
  3079. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3080. return 1;
  3081. } else {
  3082. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3083. }
  3084. return 0;
  3085. }
  3086. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3087. if (!lua_interface)
  3088. return 0;
  3089. Quest* quest = lua_interface->GetQuest(state);
  3090. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3091. if (quest && spawn_id > 0)
  3092. quest->SetQuestReturnNPC(spawn_id);
  3093. return 0;
  3094. }
  3095. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3096. if (!lua_interface)
  3097. return 0;
  3098. Spawn* spawn = lua_interface->GetSpawn(state);
  3099. if (!spawn) {
  3100. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3101. return 0;
  3102. }
  3103. int32 time = lua_interface->GetInt32Value(state, 2);
  3104. if (time <= 0) {
  3105. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3106. return 0;
  3107. }
  3108. string function = lua_interface->GetStringValue(state, 3);
  3109. if (function.length() == 0) {
  3110. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3111. return 0;
  3112. }
  3113. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3114. Spawn* player = lua_interface->GetSpawn(state, 5);
  3115. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3116. timer->timer = Timer::GetCurrentTime2() + time;
  3117. timer->function = function;
  3118. timer->spawn = spawn->GetID();
  3119. timer->player = player ? player->GetID() : 0;
  3120. if (max_count == 0)
  3121. max_count = 1;
  3122. timer->max_count = max_count;
  3123. timer->current_count = 0;
  3124. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3125. return 0;
  3126. }
  3127. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3128. if (!lua_interface)
  3129. return 0;
  3130. Spawn* player = lua_interface->GetSpawn(state);
  3131. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3132. if (player && player->IsPlayer() && quest_id > 0) {
  3133. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3134. return 1;
  3135. }
  3136. return 0;
  3137. }
  3138. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3139. if (!lua_interface)
  3140. return 0;
  3141. Spawn* player = lua_interface->GetSpawn(state);
  3142. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3143. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3144. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3145. if (quest)
  3146. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3147. return 1;
  3148. }
  3149. return 0;
  3150. }
  3151. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3152. if (!lua_interface)
  3153. return 0;
  3154. Spawn* player = lua_interface->GetSpawn(state);
  3155. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3156. if (player && player->IsPlayer() && quest_id > 0) {
  3157. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3158. return 1;
  3159. }
  3160. return 0;
  3161. }
  3162. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3163. if (!lua_interface)
  3164. return 0;
  3165. Spawn* npc = lua_interface->GetSpawn(state);
  3166. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3167. if (npc && !npc->IsPlayer() && quest_id > 0)
  3168. npc->AddProvidedQuest(quest_id);
  3169. return 0;
  3170. }
  3171. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3172. if (!lua_interface)
  3173. return 0;
  3174. Spawn* npc = lua_interface->GetSpawn(state);
  3175. Spawn* player = lua_interface->GetSpawn(state, 2);
  3176. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3177. bool forced = lua_interface->GetBooleanValue(state, 4);
  3178. /* NPC is allowed to be null */
  3179. if (player && player->IsPlayer() && quest_id > 0) {
  3180. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3181. if (master_quest) {
  3182. Client* client = player->GetZone()->GetClientBySpawn(player);
  3183. if (!client) {
  3184. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3185. }
  3186. Quest* quest = new Quest(master_quest);
  3187. if (!quest) {
  3188. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3189. }
  3190. if (client && quest) {
  3191. if (npc)
  3192. quest->SetQuestGiver(npc->GetDatabaseID());
  3193. else
  3194. quest->SetQuestGiver(0);
  3195. client->AddPendingQuest(quest, forced);
  3196. }
  3197. }
  3198. else {
  3199. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3200. }
  3201. }
  3202. else {
  3203. 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);
  3204. }
  3205. return 0;
  3206. }
  3207. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3208. if (!lua_interface)
  3209. return 0;
  3210. Quest* quest = lua_interface->GetQuest(state);
  3211. if (quest) {
  3212. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3213. quest->AddPrereqClass(class_id);
  3214. }
  3215. return 0;
  3216. }
  3217. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3218. if (!lua_interface)
  3219. return 0;
  3220. Quest* quest = lua_interface->GetQuest(state);
  3221. if (quest) {
  3222. int8 race = lua_interface->GetInt8Value(state, 2);
  3223. quest->AddPrereqRace(race);
  3224. }
  3225. return 0;
  3226. }
  3227. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3228. if (!lua_interface)
  3229. return 0;
  3230. Quest* quest = lua_interface->GetQuest(state);
  3231. if (quest) {
  3232. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3233. quest->AddPrereqModelType(model_type);
  3234. }
  3235. return 0;
  3236. }
  3237. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3238. if (!lua_interface)
  3239. return 0;
  3240. Quest* quest = lua_interface->GetQuest(state);
  3241. if (!quest) {
  3242. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3243. return 0;
  3244. }
  3245. int8 level = lua_interface->GetInt8Value(state, 2);
  3246. quest->SetPrereqTSLevel(level);
  3247. return 0;
  3248. }
  3249. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3250. if (!lua_interface)
  3251. return 0;
  3252. Quest* quest = lua_interface->GetQuest(state);
  3253. if (!quest) {
  3254. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3255. return 0;
  3256. }
  3257. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3258. quest->AddPrereqTradeskillClass(class_id);
  3259. return 0;
  3260. }
  3261. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3262. if (!lua_interface)
  3263. return 0;
  3264. Quest* quest = lua_interface->GetQuest(state);
  3265. if (quest) {
  3266. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3267. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3268. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3269. quest->AddPrereqFaction(faction_id, min, max);
  3270. }
  3271. return 0;
  3272. }
  3273. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3274. if (!lua_interface)
  3275. return 0;
  3276. Quest* quest = lua_interface->GetQuest(state);
  3277. if (quest) {
  3278. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3279. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3280. if (quantity == 0)
  3281. quantity = 1;
  3282. Item* master_item = master_item_list.GetItem(item_id);
  3283. if (master_item) {
  3284. Item* item = new Item(master_item);
  3285. item->details.count = quantity;
  3286. quest->AddSelectableRewardItem(item);
  3287. }
  3288. }
  3289. return 0;
  3290. }
  3291. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3292. if (!lua_interface)
  3293. return 0;
  3294. Quest* quest = lua_interface->GetQuest(state);
  3295. if (quest) {
  3296. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3297. vector<Item*>* items = quest->GetRewardItems();
  3298. if (items) {
  3299. vector<Item*>::iterator itr;
  3300. for (itr = items->begin(); itr != items->end(); itr++) {
  3301. if (*itr && (*itr)->details.item_id == item_id) {
  3302. lua_interface->SetBooleanValue(state, true);
  3303. return 1;
  3304. }
  3305. }
  3306. }
  3307. }
  3308. lua_interface->SetBooleanValue(state, false);
  3309. return 1;
  3310. }
  3311. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3312. if (!lua_interface)
  3313. return 0;
  3314. Quest* quest = lua_interface->GetQuest(state);
  3315. if (quest) {
  3316. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3317. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3318. if (quantity == 0)
  3319. quantity = 1;
  3320. Item* master_item = master_item_list.GetItem(item_id);
  3321. if (master_item) {
  3322. Item* item = new Item(master_item);
  3323. item->details.count = quantity;
  3324. quest->AddRewardItem(item);
  3325. }
  3326. }
  3327. return 0;
  3328. }
  3329. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3330. if (!lua_interface)
  3331. return 0;
  3332. Quest* quest = lua_interface->GetQuest(state);
  3333. if (quest) {
  3334. int32 copper = lua_interface->GetInt32Value(state, 2);
  3335. int32 silver = lua_interface->GetInt32Value(state, 3);
  3336. int32 gold = lua_interface->GetInt32Value(state, 4);
  3337. int32 plat = lua_interface->GetInt32Value(state, 5);
  3338. quest->AddRewardCoins(copper, silver, gold, plat);
  3339. }
  3340. return 0;
  3341. }
  3342. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3343. if (!lua_interface)
  3344. return 0;
  3345. Quest* quest = lua_interface->GetQuest(state);
  3346. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3347. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3348. if (quest && faction_id > 0 && amount != 0)
  3349. quest->AddRewardFaction(faction_id, amount);
  3350. return 0;
  3351. }
  3352. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3353. if (!lua_interface)
  3354. return 0;
  3355. Quest* quest = lua_interface->GetQuest(state);
  3356. if (quest) {
  3357. int32 status = lua_interface->GetInt32Value(state, 2);
  3358. quest->SetRewardStatus(status);
  3359. }
  3360. return 0;
  3361. }
  3362. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3363. if (!lua_interface)
  3364. return 0;
  3365. Quest* quest = lua_interface->GetQuest(state);
  3366. if (quest) {
  3367. int32 status = lua_interface->GetInt32Value(state, 2);
  3368. quest->SetStatusTmpReward(status);
  3369. }
  3370. return 0;
  3371. }
  3372. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3373. if (!lua_interface)
  3374. return 0;
  3375. Quest* quest = lua_interface->GetQuest(state);
  3376. if (quest) {
  3377. int64 coins = lua_interface->GetInt64Value(state, 2);
  3378. quest->SetCoinTmpReward(coins);
  3379. }
  3380. return 0;
  3381. }
  3382. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3383. if (!lua_interface)
  3384. return 0;
  3385. Quest* quest = lua_interface->GetQuest(state);
  3386. if (quest) {
  3387. string comment = lua_interface->GetStringValue(state, 2);
  3388. quest->SetRewardComment(comment);
  3389. }
  3390. return 0;
  3391. }
  3392. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3393. if (!lua_interface)
  3394. return 0;
  3395. Quest* quest = lua_interface->GetQuest(state);
  3396. if (quest) {
  3397. int32 exp = lua_interface->GetInt32Value(state, 2);
  3398. quest->SetRewardXP(exp);
  3399. }
  3400. return 0;
  3401. }
  3402. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3403. Quest* quest = lua_interface->GetQuest(state);
  3404. if (quest) {
  3405. int32 step = lua_interface->GetInt32Value(state, 2);
  3406. string description = lua_interface->GetStringValue(state, 3);
  3407. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3408. float percentage = lua_interface->GetFloatValue(state, 5);
  3409. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3410. int16 icon = lua_interface->GetInt16Value(state, 7);
  3411. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3412. const char* taskgroup = 0;
  3413. if (str_taskgroup.length() > 0)
  3414. taskgroup = str_taskgroup.c_str();
  3415. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3416. if (quest_step && icon && quantity > 0)
  3417. quest_step->SetIcon(icon);
  3418. }
  3419. return 0;
  3420. }
  3421. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3422. if (!lua_interface)
  3423. return 0;
  3424. Quest* quest = lua_interface->GetQuest(state);
  3425. if (quest) {
  3426. int32 step = lua_interface->GetInt32Value(state, 2);
  3427. string description = lua_interface->GetStringValue(state, 3);
  3428. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3429. float percentage = lua_interface->GetFloatValue(state, 5);
  3430. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3431. int16 icon = lua_interface->GetInt16Value(state, 7);
  3432. const char* taskgroup = 0;
  3433. if (str_taskgroup.length() > 0)
  3434. taskgroup = str_taskgroup.c_str();
  3435. int32 npc_id = 0;
  3436. vector<int32>* ids = 0;
  3437. int i = 0;
  3438. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3439. if (ids == 0)
  3440. ids = new vector<int32>;
  3441. ids->push_back(npc_id);
  3442. i++;
  3443. }
  3444. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3445. if (quest_step && icon > 0 && quantity > 0)
  3446. quest_step->SetIcon(icon);
  3447. if (quest->GetPlayer()) {
  3448. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3449. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3450. }
  3451. safe_delete(ids);
  3452. }
  3453. return 0;
  3454. }
  3455. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3456. if (!lua_interface)
  3457. return 0;
  3458. Quest* quest = lua_interface->GetQuest(state);
  3459. if (quest) {
  3460. int32 step = lua_interface->GetInt32Value(state, 2);
  3461. string description = lua_interface->GetStringValue(state, 3);
  3462. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3463. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3464. int16 icon = lua_interface->GetInt16Value(state, 6);
  3465. const char* taskgroup = 0;
  3466. if (str_taskgroup.length() > 0)
  3467. taskgroup = str_taskgroup.c_str();
  3468. int32 npc_id = 0;
  3469. vector<int32>* ids = 0;
  3470. int i = 0;
  3471. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3472. if (ids == 0)
  3473. ids = new vector<int32>;
  3474. ids->push_back(npc_id);
  3475. i++;
  3476. }
  3477. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3478. if (quest_step && icon > 0)
  3479. quest_step->SetIcon(icon);
  3480. if (quest->GetPlayer()) {
  3481. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3482. if(client)
  3483. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3484. }
  3485. safe_delete(ids);
  3486. }
  3487. return 0;
  3488. }
  3489. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3490. if (!lua_interface)
  3491. return 0;
  3492. Quest* quest = lua_interface->GetQuest(state);
  3493. if (quest) {
  3494. int32 step = lua_interface->GetInt32Value(state, 2);
  3495. string description = lua_interface->GetStringValue(state, 3);
  3496. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3497. float percentage = lua_interface->GetFloatValue(state, 5);
  3498. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3499. int16 icon = lua_interface->GetInt16Value(state, 7);
  3500. const char* taskgroup = 0;
  3501. if (str_taskgroup.length() > 0)
  3502. taskgroup = str_taskgroup.c_str();
  3503. int32 item_id = 0;
  3504. vector<int32>* ids = 0;
  3505. int i = 0;
  3506. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3507. if (ids == 0)
  3508. ids = new vector<int32>;
  3509. ids->push_back(item_id);
  3510. i++;
  3511. }
  3512. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3513. if (quest_step && icon > 0 && quantity > 0)
  3514. quest_step->SetIcon(icon);
  3515. if (quest->GetPlayer()) {
  3516. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3517. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3518. }
  3519. safe_delete(ids);
  3520. }
  3521. return 0;
  3522. }
  3523. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3524. if (!lua_interface)
  3525. return 0;
  3526. Quest* quest = lua_interface->GetQuest(state);
  3527. if (quest) {
  3528. int32 step = lua_interface->GetInt32Value(state, 2);
  3529. string description = lua_interface->GetStringValue(state, 3);
  3530. float max_variation = lua_interface->GetFloatValue(state, 4);
  3531. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3532. int16 icon = lua_interface->GetInt16Value(state, 6);
  3533. const char* taskgroup = 0;
  3534. if (str_taskgroup.length() > 0)
  3535. taskgroup = str_taskgroup.c_str();
  3536. vector<Location>* locations = 0;
  3537. int i = 7;
  3538. while (true) {
  3539. Location loc;
  3540. loc.x = lua_interface->GetFloatValue(state, i);
  3541. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3542. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3543. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3544. break;
  3545. if (locations == 0)
  3546. locations = new vector<Location>;
  3547. locations->push_back(loc);
  3548. i += 3;
  3549. }
  3550. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3551. if (quest_step && icon > 0)
  3552. quest_step->SetIcon(icon);
  3553. if (quest->GetPlayer()) {
  3554. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3555. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3556. }
  3557. }
  3558. return 0;
  3559. }
  3560. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3561. if (!lua_interface)
  3562. return 0;
  3563. Quest* quest = lua_interface->GetQuest(state);
  3564. if (quest) {
  3565. int32 step = lua_interface->GetInt32Value(state, 2);
  3566. string description = lua_interface->GetStringValue(state, 3);
  3567. float max_variation = lua_interface->GetFloatValue(state, 4);
  3568. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3569. int16 icon = lua_interface->GetInt16Value(state, 6);
  3570. const char* taskgroup = 0;
  3571. if (str_taskgroup.length() > 0)
  3572. taskgroup = str_taskgroup.c_str();
  3573. vector<Location>* locations = 0;
  3574. int i = 7;
  3575. while (true) {
  3576. Location loc;
  3577. loc.x = lua_interface->GetFloatValue(state, i);
  3578. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3579. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3580. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3581. break;
  3582. if (locations == 0)
  3583. locations = new vector<Location>;
  3584. locations->push_back(loc);
  3585. i += 3;
  3586. }
  3587. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3588. if (quest_step && icon > 0)
  3589. quest_step->SetIcon(icon);
  3590. if (quest->GetPlayer()) {
  3591. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3592. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3593. }
  3594. }
  3595. return 0;
  3596. }
  3597. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3598. Quest* quest = lua_interface->GetQuest(state);
  3599. if (quest) {
  3600. int32 step = lua_interface->GetInt32Value(state, 2);
  3601. string description = lua_interface->GetStringValue(state, 3);
  3602. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3603. float percentage = lua_interface->GetFloatValue(state, 5);
  3604. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3605. int16 icon = lua_interface->GetInt16Value(state, 7);
  3606. const char* taskgroup = 0;
  3607. if (str_taskgroup.length() > 0)
  3608. taskgroup = str_taskgroup.c_str();
  3609. int32 spell_id = 0;
  3610. vector<int32>* ids = 0;
  3611. int i = 0;
  3612. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3613. if (ids == 0)
  3614. ids = new vector<int32>;
  3615. ids->push_back(spell_id);
  3616. i++;
  3617. }
  3618. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3619. if (quest_step && icon > 0 && quantity > 0)
  3620. quest_step->SetIcon(icon);
  3621. if (quest->GetPlayer()) {
  3622. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3623. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3624. }
  3625. safe_delete(ids);
  3626. }
  3627. return 0;
  3628. }
  3629. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3630. if (!lua_interface)
  3631. return 0;
  3632. Quest* quest = lua_interface->GetQuest(state);
  3633. if (quest) {
  3634. int32 step = lua_interface->GetInt32Value(state, 2);
  3635. string description = lua_interface->GetStringValue(state, 3);
  3636. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3637. float percentage = lua_interface->GetFloatValue(state, 5);
  3638. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3639. int16 icon = lua_interface->GetInt16Value(state, 7);
  3640. const char* taskgroup = 0;
  3641. if (str_taskgroup.length() > 0)
  3642. taskgroup = str_taskgroup.c_str();
  3643. int32 item_id = 0;
  3644. vector<int32>* ids = 0;
  3645. int i = 0;
  3646. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3647. if (ids == 0)
  3648. ids = new vector<int32>;
  3649. ids->push_back(item_id);
  3650. i++;
  3651. }
  3652. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3653. if (quest_step && icon > 0 && quantity > 0)
  3654. quest_step->SetIcon(icon);
  3655. if (quest->GetPlayer()) {
  3656. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3657. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3658. }
  3659. safe_delete(ids);
  3660. }
  3661. return 0;
  3662. }
  3663. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3664. if (!lua_interface)
  3665. return 0;
  3666. Quest* quest = lua_interface->GetQuest(state);
  3667. if (quest) {
  3668. int32 step = lua_interface->GetInt32Value(state, 2);
  3669. string description = lua_interface->GetStringValue(state, 3);
  3670. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3671. float percentage = lua_interface->GetFloatValue(state, 5);
  3672. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3673. int16 icon = lua_interface->GetInt16Value(state, 7);
  3674. const char* taskgroup = 0;
  3675. if (str_taskgroup.length() > 0)
  3676. taskgroup = str_taskgroup.c_str();
  3677. int32 item_id = 0;
  3678. vector<int32>* ids = 0;
  3679. int i = 0;
  3680. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3681. if (ids == 0)
  3682. ids = new vector<int32>;
  3683. ids->push_back(item_id);
  3684. i++;
  3685. }
  3686. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3687. if (quest_step && icon > 0 && quantity > 0)
  3688. quest_step->SetIcon(icon);
  3689. if (quest->GetPlayer()) {
  3690. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3691. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3692. }
  3693. safe_delete(ids);
  3694. }
  3695. return 0;
  3696. }
  3697. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3698. if (!lua_interface)
  3699. return 0;
  3700. Quest* quest = lua_interface->GetQuest(state);
  3701. if (quest) {
  3702. string action = lua_interface->GetStringValue(state, 2);
  3703. if (action.length() > 0)
  3704. quest->SetCompleteAction(action);
  3705. }
  3706. return 0;
  3707. }
  3708. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3709. if (!lua_interface)
  3710. return 0;
  3711. Quest* quest = lua_interface->GetQuest(state);
  3712. if (quest) {
  3713. int32 step = lua_interface->GetInt32Value(state, 2);
  3714. string action = lua_interface->GetStringValue(state, 3);
  3715. if (step > 0 && action.length() > 0)
  3716. quest->AddCompleteAction(step, action);
  3717. }
  3718. return 0;
  3719. }
  3720. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3721. if (!lua_interface)
  3722. return 0;
  3723. Quest* quest = lua_interface->GetQuest(state);
  3724. if (quest) {
  3725. int32 step = lua_interface->GetInt32Value(state, 2);
  3726. string action = lua_interface->GetStringValue(state, 3);
  3727. if (step > 0 && action.length() > 0)
  3728. quest->AddProgressAction(step, action);
  3729. }
  3730. return 0;
  3731. }
  3732. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3733. if (!lua_interface)
  3734. return 0;
  3735. Quest* quest = lua_interface->GetQuest(state);
  3736. string description = lua_interface->GetStringValue(state, 2);
  3737. if (quest && description.length() > 0)
  3738. quest->SetDescription(description);
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3742. if (!lua_interface)
  3743. return 0;
  3744. Quest* quest = lua_interface->GetQuest(state);
  3745. string description = lua_interface->GetStringValue(state, 2);
  3746. if (quest && description.length() > 0)
  3747. quest->SetCompletedDescription(description);
  3748. return 0;
  3749. }
  3750. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3751. if (!lua_interface)
  3752. return 0;
  3753. Quest* quest = lua_interface->GetQuest(state);
  3754. int32 step = lua_interface->GetInt32Value(state, 2);
  3755. string description = lua_interface->GetStringValue(state, 3);
  3756. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3757. if (quest && step > 0 && description.length() > 0) {
  3758. quest->SetTaskGroupDescription(step, description, display_bullets);
  3759. /* if (quest->GetPlayer()) {
  3760. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3761. if (client)
  3762. client->SendQuestUpdateStep(quest, step, false);
  3763. }*/
  3764. }
  3765. return 0;
  3766. }
  3767. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3768. if (!lua_interface)
  3769. return 0;
  3770. Quest* quest = lua_interface->GetQuest(state);
  3771. int32 step = lua_interface->GetInt32Value(state, 2);
  3772. string description = lua_interface->GetStringValue(state, 3);
  3773. if (quest && step > 0 && description.length() > 0) {
  3774. quest->SetStepDescription(step, description);
  3775. /*if (quest->GetPlayer()) {
  3776. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3777. if (client)
  3778. client->SendQuestUpdateStepImmediately(quest, step);
  3779. }*/
  3780. }
  3781. return 0;
  3782. }
  3783. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3784. Quest* quest = lua_interface->GetQuest(state);
  3785. string zone = lua_interface->GetStringValue(state, 2);
  3786. if (quest && zone.length() > 0)
  3787. quest->SetZone(zone);
  3788. return 0;
  3789. }
  3790. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3791. if (!lua_interface)
  3792. return 0;
  3793. Quest* quest = lua_interface->GetQuest(state);
  3794. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3795. lua_interface->ResetFunctionStack(state);
  3796. if (quest && spawn) {
  3797. if (spawn->IsPlayer()) {
  3798. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3799. if (client)
  3800. {
  3801. client->AddPendingQuestAcceptReward(quest);
  3802. client->AddPendingQuestReward(quest);
  3803. }
  3804. }
  3805. }
  3806. return 0;
  3807. }
  3808. int EQ2Emu_lua_Harvest(lua_State* state) {
  3809. if (!lua_interface)
  3810. return 0;
  3811. Spawn* player = lua_interface->GetSpawn(state);
  3812. Spawn* node = lua_interface->GetSpawn(state, 2);
  3813. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3814. Client* client = player->GetZone()->GetClientBySpawn(player);
  3815. if (client) {
  3816. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3817. ((GroundSpawn*)node)->ProcessHarvest(client);
  3818. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3819. player->GetZone()->RemoveSpawn(node, true);
  3820. }
  3821. }
  3822. else if (player && player->IsPlayer()) {
  3823. Client* client = player->GetZone()->GetClientBySpawn(player);
  3824. if (client)
  3825. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3826. }
  3827. return 0;
  3828. }
  3829. int EQ2Emu_lua_Bind(lua_State* state) {
  3830. if (!lua_interface)
  3831. return 0;
  3832. Spawn* spawn = lua_interface->GetSpawn(state);
  3833. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3834. float x = lua_interface->GetFloatValue(state, 3);
  3835. float y = lua_interface->GetFloatValue(state, 4);
  3836. float z = lua_interface->GetFloatValue(state, 5);
  3837. float h = lua_interface->GetFloatValue(state, 6);
  3838. if (!spawn) {
  3839. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3840. return 0;
  3841. }
  3842. if (!spawn->IsPlayer()) {
  3843. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3844. return 0;
  3845. }
  3846. if (zone_id == 0) {
  3847. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3848. if (!client) {
  3849. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3850. return 0;
  3851. }
  3852. if (!client->Bind())
  3853. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3854. }
  3855. else {
  3856. Player* player = (Player*)spawn;
  3857. player->GetPlayerInfo()->SetBindZone(zone_id);
  3858. player->GetPlayerInfo()->SetBindX(x);
  3859. player->GetPlayerInfo()->SetBindY(y);
  3860. player->GetPlayerInfo()->SetBindZ(z);
  3861. player->GetPlayerInfo()->SetBindHeading(h);
  3862. }
  3863. return 0;
  3864. }
  3865. int EQ2Emu_lua_Gate(lua_State* state) {
  3866. if (!lua_interface)
  3867. return 0;
  3868. Spawn* spawn = lua_interface->GetSpawn(state);
  3869. if (spawn) {
  3870. if (spawn->IsPlayer()) {
  3871. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3872. if (client) {
  3873. if (!client->Gate())
  3874. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3875. }
  3876. }
  3877. }
  3878. return 0;
  3879. }
  3880. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3881. if (!lua_interface)
  3882. return 0;
  3883. bool ret = false;
  3884. Spawn* spawn = lua_interface->GetSpawn(state);
  3885. if (spawn) {
  3886. if (spawn->IsPlayer()) {
  3887. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3888. if (client)
  3889. ret = client->BindAllowed();
  3890. }
  3891. }
  3892. lua_interface->SetBooleanValue(state, ret);
  3893. return 1;
  3894. }
  3895. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3896. if (!lua_interface)
  3897. return 0;
  3898. bool ret = false;
  3899. Spawn* spawn = lua_interface->GetSpawn(state);
  3900. if (spawn) {
  3901. if (spawn->IsPlayer()) {
  3902. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3903. if (client)
  3904. ret = client->GateAllowed();
  3905. }
  3906. }
  3907. lua_interface->SetBooleanValue(state, ret);
  3908. return 1;
  3909. }
  3910. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3911. Spawn* spawn = lua_interface->GetSpawn(state);
  3912. if (spawn) {
  3913. lua_interface->SetBooleanValue(state, spawn->Alive());
  3914. return 1;
  3915. }
  3916. return 0;
  3917. }
  3918. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3919. if (!lua_interface)
  3920. return 0;
  3921. Spawn* spawn = lua_interface->GetSpawn(state);
  3922. if (spawn && spawn->IsEntity()) {
  3923. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3924. return 1;
  3925. }
  3926. return 0;
  3927. }
  3928. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3929. Spawn* spawn = lua_interface->GetSpawn(state);
  3930. string message = lua_interface->GetStringValue(state, 2);
  3931. string color_str = lua_interface->GetStringValue(state, 3);
  3932. int8 color = CHANNEL_NARRATIVE;
  3933. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3934. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3935. if (client) {
  3936. if (color_str.length() > 0) {
  3937. // leave for backwards compat, but all future should just use the number
  3938. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3939. color = CHANNEL_COLOR_RED;
  3940. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3941. color = CHANNEL_COLOR_YELLOW;
  3942. else
  3943. {
  3944. // use a number to specify the channel as per Commands/Commands.h defines
  3945. color = (int8)atoul(color_str.c_str());
  3946. }
  3947. }
  3948. client->SimpleMessage(color, message.c_str());
  3949. }
  3950. }
  3951. return 0;
  3952. }
  3953. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3954. Spawn* spawn = lua_interface->GetSpawn(state);
  3955. string message = lua_interface->GetStringValue(state, 2);
  3956. int8 red = lua_interface->GetInt8Value(state, 3);
  3957. int8 green = lua_interface->GetInt8Value(state, 4);
  3958. int8 blue = lua_interface->GetInt8Value(state, 5);
  3959. if (!spawn) {
  3960. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3961. return 0;
  3962. }
  3963. int32 words = ::CountWordsInString(message.c_str());
  3964. if (words < 5)
  3965. words = 5;
  3966. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3967. if (client)
  3968. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3969. return 0;
  3970. }
  3971. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3972. Spawn* spawn = lua_interface->GetSpawn(state);
  3973. int8 param = lua_interface->GetInt8Value(state, 2);
  3974. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3975. int8 value = lua_interface->GetInt8Value(state, 4);
  3976. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3977. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3978. if (client) {
  3979. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3980. switch (param) {
  3981. case 1: {
  3982. packet->setDataByName("parameter1", param_value);
  3983. break;
  3984. }
  3985. case 2: {
  3986. packet->setDataByName("parameter2", param_value);
  3987. break;
  3988. }
  3989. case 3: {
  3990. packet->setDataByName("parameter3", param_value);
  3991. break;
  3992. }
  3993. case 4: {
  3994. packet->setDataByName("parameter4", param_value);
  3995. break;
  3996. }
  3997. case 5: {
  3998. packet->setDataByName("parameter5", param_value);
  3999. break;
  4000. }
  4001. }
  4002. packet->setDataByName("value", value);
  4003. client->QueuePacket(packet->serialize());
  4004. safe_delete(packet);
  4005. }
  4006. }
  4007. return 0;
  4008. }
  4009. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4010. Spawn* spawn = lua_interface->GetSpawn(state);
  4011. if (spawn && spawn->IsPlayer()) {
  4012. if (((Player*)spawn)->GetIsTracking())
  4013. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4014. else
  4015. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4016. }
  4017. return 0;
  4018. }
  4019. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4020. Spawn* player = lua_interface->GetSpawn(state);
  4021. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4022. string name = lua_interface->GetStringValue(state, 3);
  4023. float distance = lua_interface->GetFloatValue(state, 4);
  4024. string command = lua_interface->GetStringValue(state, 5);
  4025. string error_text = lua_interface->GetStringValue(state, 6);
  4026. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4027. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4028. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4029. if (spawn) {
  4030. if (distance == 0)
  4031. distance = 10.0f;
  4032. if (command.length() == 0)
  4033. command = name;
  4034. if (command.length() < 1 && name.length() < 1)
  4035. {
  4036. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4037. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4038. spawn->RemovePrimaryCommands();
  4039. }
  4040. else
  4041. {
  4042. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4043. }
  4044. }
  4045. return 0;
  4046. }
  4047. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4048. if (!lua_interface)
  4049. return 0;
  4050. Spawn* player = lua_interface->GetSpawn(state);
  4051. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4052. int16 tier = lua_interface->GetInt16Value(state, 3);
  4053. if (player && player->IsPlayer()) {
  4054. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4055. return 1;
  4056. }
  4057. return 0;
  4058. }
  4059. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4060. if (!lua_interface)
  4061. return 0;
  4062. Spawn* player = lua_interface->GetSpawn(state);
  4063. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4064. int16 tier = lua_interface->GetInt16Value(state, 3);
  4065. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4066. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4067. bool add_to_hotbar = true;
  4068. if (num_args > 4) {
  4069. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4070. }
  4071. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4072. if (player && spell && player->IsPlayer()) {
  4073. Client* client = player->GetClient();
  4074. if (client) {
  4075. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4076. {
  4077. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4078. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4079. client->GetPlayer()->UnlockSpell(spell);
  4080. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4081. }
  4082. else
  4083. {
  4084. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4085. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4086. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4087. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4088. client->GetPlayer()->UnlockSpell(spell);
  4089. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4090. }
  4091. //if (client ) {
  4092. // ((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);
  4093. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4094. if (outapp)
  4095. client->QueuePacket(outapp);
  4096. }
  4097. }
  4098. return 0;
  4099. }
  4100. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4101. if (!lua_interface)
  4102. return 0;
  4103. Spawn* player = lua_interface->GetSpawn(state);
  4104. if (player && player->IsPlayer()) {
  4105. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4106. return 1;
  4107. }
  4108. return 0;
  4109. }
  4110. int EQ2Emu_lua_Attack(lua_State* state) {
  4111. if (lua_interface) {
  4112. Spawn* npc = lua_interface->GetSpawn(state);
  4113. Spawn* player = lua_interface->GetSpawn(state, 2);
  4114. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4115. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4116. }
  4117. return 0;
  4118. }
  4119. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4120. if (lua_interface) {
  4121. Spawn* target = lua_interface->GetSpawn(state);
  4122. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4123. if (target && target->GetZone())
  4124. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4125. }
  4126. return 0;
  4127. }
  4128. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4129. Spawn* player;
  4130. if (lua_interface) {
  4131. player = lua_interface->GetSpawn(state);
  4132. if (player && player->IsPlayer()) {
  4133. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4134. return 1;
  4135. }
  4136. }
  4137. return 0;
  4138. }
  4139. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4140. Spawn* player;
  4141. Client* client;
  4142. if (lua_interface) {
  4143. player = lua_interface->GetSpawn(state);
  4144. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4145. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4146. client->HandInCollections();
  4147. }
  4148. return 0;
  4149. }
  4150. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4151. Spawn* widget;
  4152. if (lua_interface) {
  4153. widget = lua_interface->GetSpawn(state);
  4154. if (widget && widget->IsWidget())
  4155. ((Widget*)widget)->HandleUse(nullptr, "");
  4156. }
  4157. return 0;
  4158. }
  4159. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4160. Spawn* spawn = 0;
  4161. int32 primary_list = 0;
  4162. int32 secondary_list = 0;
  4163. if (lua_interface) {
  4164. spawn = lua_interface->GetSpawn(state);
  4165. primary_list = lua_interface->GetInt32Value(state, 2);
  4166. secondary_list = lua_interface->GetInt32Value(state, 3);
  4167. if (!spawn->IsNPC()) {
  4168. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4169. return 0;
  4170. }
  4171. NPC* npc = (NPC*)spawn;
  4172. npc->SetPrimarySpellList(primary_list);
  4173. npc->SetSecondarySpellList(secondary_list);
  4174. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4175. }
  4176. return 0;
  4177. }
  4178. int EQ2Emu_lua_GetPet(lua_State* state) {
  4179. if (!lua_interface)
  4180. return 0;
  4181. Spawn* spawn = lua_interface->GetSpawn(state);
  4182. if (spawn) {
  4183. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4184. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4185. return 1;
  4186. }
  4187. }
  4188. return 0;
  4189. }
  4190. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4191. if (!lua_interface)
  4192. return 0;
  4193. Spawn* spawn = lua_interface->GetSpawn(state);
  4194. if (spawn) {
  4195. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4196. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4197. return 1;
  4198. }
  4199. }
  4200. return 0;
  4201. }
  4202. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4203. if (!lua_interface)
  4204. return 0;
  4205. Spawn* spawn = lua_interface->GetSpawn(state);
  4206. if (spawn) {
  4207. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4208. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4209. return 1;
  4210. }
  4211. }
  4212. return 0;
  4213. }
  4214. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4215. if (!lua_interface)
  4216. return 0;
  4217. Spawn* spawn = lua_interface->GetSpawn(state);
  4218. if (spawn) {
  4219. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4220. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4221. return 1;
  4222. }
  4223. }
  4224. return 0;
  4225. }
  4226. int EQ2Emu_lua_Charm(lua_State* state) {
  4227. if (!lua_interface)
  4228. return 0;
  4229. Spawn* owner = lua_interface->GetSpawn(state);
  4230. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4231. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4232. if (!luaspell) {
  4233. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4234. return 0;
  4235. }
  4236. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4237. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4238. pet->SetPet(true);
  4239. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4240. ((NPC*)pet)->SetOwner((Entity*)owner);
  4241. // If owner is player and player does not have a summoned pet set the players charsheet
  4242. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4243. Player* player = (Player*)owner;
  4244. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4245. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4246. player->GetInfoStruct()->set_pet_movement(2);
  4247. player->GetInfoStruct()->set_pet_behavior(3);
  4248. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4249. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4250. // Make sure the values get sent to the client
  4251. player->SetCharSheetChanged(true);
  4252. }
  4253. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4254. pet->SetSpawnScript("");
  4255. // Set faction to the same as the owner
  4256. pet->SetFactionID(owner->GetFactionID());
  4257. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4258. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4259. // Clear hate list
  4260. ((NPC*)pet)->Brain()->ClearHate();
  4261. // Set the brain to a pet brain
  4262. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4263. }
  4264. return 0;
  4265. }
  4266. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4267. if (!lua_interface)
  4268. return 0;
  4269. Spawn* spawn = lua_interface->GetSpawn(state);
  4270. if (!spawn) {
  4271. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4272. return 0;
  4273. }
  4274. vector<Spawn*> groupMembers;
  4275. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4276. groupMembers = *spawn->GetSpawnGroup();
  4277. }
  4278. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4279. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4280. deque<GroupMemberInfo*>::iterator itr;
  4281. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4282. if (group)
  4283. {
  4284. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4285. deque<GroupMemberInfo*>* members = group->GetMembers();
  4286. GroupMemberInfo* info = 0;
  4287. for (itr = members->begin(); itr != members->end(); itr++) {
  4288. info = *itr;
  4289. if (info->client)
  4290. groupMembers.push_back(info->client->GetPlayer());
  4291. }
  4292. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4293. }
  4294. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4295. }
  4296. else
  4297. return 0;
  4298. lua_createtable(state, groupMembers.size(), 0);
  4299. int newTable = lua_gettop(state);
  4300. for (int32 i = 0; i < groupMembers.size(); i++) {
  4301. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4302. lua_rawseti(state, newTable, i + 1);
  4303. }
  4304. return 1;
  4305. }
  4306. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4307. if (!lua_interface)
  4308. return 0;
  4309. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4310. lua_interface->SetOptionWindowValue(state, option_window);
  4311. return 1;
  4312. }
  4313. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4314. if (!lua_interface)
  4315. return 0;
  4316. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4317. if (option_window) {
  4318. OptionWindowOption option_window_option;
  4319. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4320. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4321. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4322. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4323. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4324. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4325. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4326. option_window->push_back(option_window_option);
  4327. }
  4328. return 0;
  4329. }
  4330. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4331. if (!lua_interface)
  4332. return 0;
  4333. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4334. Spawn* player = lua_interface->GetSpawn(state, 2);
  4335. string window_title = lua_interface->GetStringValue(state, 3);
  4336. string cancel_command = lua_interface->GetStringValue(state, 4);
  4337. Client* client = player->GetZone()->GetClientBySpawn(player);
  4338. if (option_window && window_title.length() > 0 && client) {
  4339. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4340. if (!packet)
  4341. return 0;
  4342. packet->setDataByName("title_text", window_title.c_str());
  4343. if (cancel_command.length() > 0)
  4344. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4345. packet->setArrayLengthByName("num_selections", option_window->size());
  4346. vector<OptionWindowOption>::iterator itr;
  4347. int8 i = 0;
  4348. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4349. OptionWindowOption opt = *itr;
  4350. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4351. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4352. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4353. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4354. if (opt.optionCommand.length() > 0)
  4355. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4356. if (opt.optionConfirmTitle.length() > 0)
  4357. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4358. i++;
  4359. }
  4360. client->QueuePacket(packet->serialize());
  4361. safe_delete(option_window);
  4362. safe_delete(packet);
  4363. }
  4364. return 0;
  4365. }
  4366. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4367. if (!lua_interface)
  4368. return 0;
  4369. Spawn* spawn = lua_interface->GetSpawn(state);
  4370. if (spawn) {
  4371. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4372. return 1;
  4373. }
  4374. else
  4375. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4376. return 0;
  4377. }
  4378. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4379. if (!lua_interface)
  4380. return 0;
  4381. Spawn* spawn = lua_interface->GetSpawn(state);
  4382. if (spawn) {
  4383. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4384. return 1;
  4385. }
  4386. else
  4387. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4388. return 0;
  4389. }
  4390. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4391. if (!lua_interface)
  4392. return 0;
  4393. Spawn* spawn = lua_interface->GetSpawn(state);
  4394. if (spawn) {
  4395. int8 class_id = spawn->GetTradeskillClass();
  4396. // Need to add 42 for the offset in the array
  4397. class_id += 44;
  4398. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4399. return 1;
  4400. }
  4401. else
  4402. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4403. return 0;
  4404. }
  4405. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4406. if (!lua_interface)
  4407. return 0;
  4408. Spawn* spawn = lua_interface->GetSpawn(state);
  4409. int16 level = lua_interface->GetInt8Value(state, 2);
  4410. if (spawn) {
  4411. if (spawn->IsPlayer())
  4412. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4413. else
  4414. spawn->SetTSLevel(level);
  4415. }
  4416. else
  4417. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4418. return 0;
  4419. }
  4420. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4421. if (!lua_interface)
  4422. return 0;
  4423. Spawn* spawn = lua_interface->GetSpawn(state);
  4424. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4425. if (spawn) {
  4426. spawn->SetAttackable(attackable);
  4427. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4428. }
  4429. return 0;
  4430. }
  4431. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4432. // Check to see if we have a valid lua_interface
  4433. if (!lua_interface)
  4434. return 0;
  4435. // Get the spawn that is getting the pet
  4436. Spawn* spawn = lua_interface->GetSpawn(state);
  4437. // Get the DB ID of the pet
  4438. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4439. // The max level the pet can gain
  4440. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4441. // Get the spell that this command was called from
  4442. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4443. // Check to make sure the spawn pointer is valid
  4444. if (!spawn) {
  4445. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4446. return 0;
  4447. }
  4448. // Check to make sure the spawn is an entity
  4449. if (!spawn->IsEntity()) {
  4450. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4451. return 0;
  4452. }
  4453. // Check to make sure the spawn doesn't already have a pet of this type
  4454. if (((Entity*)spawn)->GetPet()) {
  4455. if (spawn->IsPlayer()) {
  4456. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4457. if (client)
  4458. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4459. }
  4460. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4461. return 0;
  4462. }
  4463. // Check to see if the DB ID for the pet is set
  4464. if (pet_id == 0) {
  4465. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4466. return 0;
  4467. }
  4468. // Check to see if the pointer to the spell is valid
  4469. if (!luaspell) {
  4470. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4471. return 0;
  4472. }
  4473. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4474. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4475. if (!pet) {
  4476. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4477. return 0;
  4478. }
  4479. // Check to make sure the pet is an npc
  4480. if (!pet->IsNPC()) {
  4481. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4482. return 0;
  4483. }
  4484. // Spawn the pet at the same location as the owner
  4485. pet->SetX(spawn->GetX());
  4486. pet->SetY(spawn->GetY());
  4487. pet->SetZ(spawn->GetZ());
  4488. pet->SetLocation(spawn->GetLocation());
  4489. pet->SetHeading(spawn->GetHeading());
  4490. spawn->GetZone()->AddSpawn(pet);
  4491. /*
  4492. const char* spawn_script = world.GetSpawnScript(pet_id);
  4493. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4494. spawn->SetSpawnScript(string(spawn_script));
  4495. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4496. }*/
  4497. // Get a random pet name
  4498. string random_pet_name;
  4499. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4500. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4501. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4502. // If player set various values for the char sheet (pet window)
  4503. if (spawn->IsPlayer()) {
  4504. Player* player = (Player*)spawn;
  4505. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4506. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4507. player->GetInfoStruct()->set_pet_movement(2);
  4508. player->GetInfoStruct()->set_pet_behavior(3);
  4509. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4510. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4511. // Make sure the values get sent to the client
  4512. player->SetCharSheetChanged(true);
  4513. }
  4514. // Set the pets name
  4515. pet->SetName(random_pet_name.c_str());
  4516. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4517. if (max_level > 0)
  4518. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4519. else
  4520. pet->SetLevel(spawn->GetLevel());
  4521. // Set the max level this pet can reach
  4522. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4523. // Set the faction of the pet to the same faction as the owner
  4524. pet->SetFactionID(spawn->GetFactionID());
  4525. // Set the spawn as a pet
  4526. pet->SetPet(true);
  4527. // Give a pointer of the owner to the pet
  4528. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4529. // Give a pointer of the pet to the owner
  4530. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4531. // Set the pet type
  4532. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4533. // Set the spell id used to create this pet
  4534. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4535. // Set the spell tier used to create this pet
  4536. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4537. // Set the pets spawn type to 6
  4538. pet->SetSpawnType(6);
  4539. // Set the pets brain
  4540. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4541. // Check to see if the pet has a subtitle
  4542. if (strlen(pet->GetSubTitle()) > 0) {
  4543. // Add the players name to the front of the sub title
  4544. string pet_subtitle;
  4545. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4546. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4547. // Set the pets subtitle to the new one
  4548. pet->SetSubTitle(pet_subtitle.c_str());
  4549. }
  4550. // Add the "Pet Options" entity command to the pet
  4551. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4552. // Set the pet as the return value for this function
  4553. lua_interface->SetSpawnValue(state, pet);
  4554. return 1;
  4555. }
  4556. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4557. if (!lua_interface)
  4558. return 0;
  4559. Spawn* spawn = lua_interface->GetSpawn(state);
  4560. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4561. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4562. if (!spawn) {
  4563. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4564. return 0;
  4565. }
  4566. if (!spawn->IsEntity()) {
  4567. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4568. return 0;
  4569. }
  4570. if (((Entity*)spawn)->GetDeityPet()) {
  4571. if (spawn->IsPlayer()) {
  4572. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4573. if (client)
  4574. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4575. }
  4576. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4577. return 0;
  4578. }
  4579. if (pet_id == 0) {
  4580. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4581. return 0;
  4582. }
  4583. if (!luaspell) {
  4584. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4585. return 0;
  4586. }
  4587. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4588. if (!pet) {
  4589. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4590. return 0;
  4591. }
  4592. if (!pet->IsNPC()) {
  4593. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4594. return 0;
  4595. }
  4596. pet->SetX(spawn->GetX());
  4597. pet->SetY(spawn->GetY());
  4598. pet->SetZ(spawn->GetZ());
  4599. pet->SetLocation(spawn->GetLocation());
  4600. pet->SetHeading(spawn->GetHeading());
  4601. spawn->GetZone()->AddSpawn(pet);
  4602. string random_pet_name;
  4603. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4604. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4605. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4606. pet->SetName(random_pet_name.c_str());
  4607. pet->SetLevel(spawn->GetLevel());
  4608. pet->SetFactionID(spawn->GetFactionID());
  4609. pet->SetPet(true);
  4610. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4611. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4612. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4613. pet->SetSpawnType(6);
  4614. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4615. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4616. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4617. if (strlen(pet->GetSubTitle()) > 0) {
  4618. string pet_subtitle;
  4619. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4620. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4621. pet->SetSubTitle(pet_subtitle.c_str());
  4622. }
  4623. // deity and cosmetic pets are not attackable
  4624. pet->SetAttackable(false);
  4625. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4626. lua_interface->SetSpawnValue(state, pet);
  4627. return 1;
  4628. }
  4629. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4630. if (!lua_interface)
  4631. return 0;
  4632. Spawn* spawn = lua_interface->GetSpawn(state);
  4633. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4634. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4635. if (!spawn) {
  4636. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4637. return 0;
  4638. }
  4639. if (!spawn->IsEntity()) {
  4640. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4641. return 0;
  4642. }
  4643. if (((Entity*)spawn)->GetCosmeticPet()) {
  4644. if (spawn->IsPlayer()) {
  4645. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4646. if (client)
  4647. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4648. }
  4649. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4650. return 0;
  4651. }
  4652. if (pet_id == 0) {
  4653. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4654. return 0;
  4655. }
  4656. if (!luaspell) {
  4657. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4658. return 0;
  4659. }
  4660. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4661. if (!pet) {
  4662. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4663. return 0;
  4664. }
  4665. if (!pet->IsNPC()) {
  4666. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4667. return 0;
  4668. }
  4669. pet->SetX(spawn->GetX());
  4670. pet->SetY(spawn->GetY());
  4671. pet->SetZ(spawn->GetZ());
  4672. pet->SetLocation(spawn->GetLocation());
  4673. pet->SetHeading(spawn->GetHeading());
  4674. spawn->GetZone()->AddSpawn(pet);
  4675. string random_pet_name;
  4676. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4677. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4678. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4679. pet->SetName(random_pet_name.c_str());
  4680. pet->SetLevel(spawn->GetLevel());
  4681. pet->SetFactionID(spawn->GetFactionID());
  4682. pet->SetPet(true);
  4683. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4684. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4685. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4686. pet->SetSpawnType(6);
  4687. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4688. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4689. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4690. if (strlen(pet->GetSubTitle()) > 0) {
  4691. string pet_subtitle;
  4692. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4693. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4694. pet->SetSubTitle(pet_subtitle.c_str());
  4695. }
  4696. pet->SetAttackable(false);
  4697. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4698. lua_interface->SetSpawnValue(state, pet);
  4699. return 1;
  4700. }
  4701. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4702. if (!lua_interface)
  4703. return 0;
  4704. Spawn* spawn = lua_interface->GetSpawn(state);
  4705. if (!spawn) {
  4706. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4707. return 0;
  4708. }
  4709. if (!spawn->IsPet()) {
  4710. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4711. return 0;
  4712. }
  4713. if (!((NPC*)spawn)->IsDismissing())
  4714. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4715. return 0;
  4716. }
  4717. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4718. if (!lua_interface)
  4719. return 0;
  4720. Quest* quest = lua_interface->GetQuest(state);
  4721. if (!quest) {
  4722. 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));
  4723. return 0;
  4724. }
  4725. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4726. if (feather_color > 0)
  4727. quest->SetFeatherColor(feather_color);
  4728. return 0;
  4729. }
  4730. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4731. if (!lua_interface)
  4732. return 0;
  4733. Spawn* spawn = lua_interface->GetSpawn(state);
  4734. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4735. if (!spawn) {
  4736. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4737. return 0;
  4738. }
  4739. if (!spawn2) {
  4740. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4741. return 0;
  4742. }
  4743. spawn->RemoveSpawnAccess(spawn2);
  4744. return 0;
  4745. }
  4746. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4747. if (!lua_interface)
  4748. return 0;
  4749. ZoneServer* zone = lua_interface->GetZone(state);
  4750. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4751. if (!zone) {
  4752. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4753. return 0;
  4754. }
  4755. if (location_id == 0) {
  4756. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4757. return 0;
  4758. }
  4759. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4760. if (!location) {
  4761. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4762. return 0;
  4763. }
  4764. Spawn* spawn = 0;
  4765. if (location->entities[0]) {
  4766. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4767. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4768. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4769. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4770. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4771. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4772. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4773. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4774. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4775. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4776. if (spawn) {
  4777. const char* script = 0;
  4778. for (int x = 0; x < 3; x++) {
  4779. switch (x) {
  4780. case 0:
  4781. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4782. break;
  4783. case 1:
  4784. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4785. break;
  4786. case 2:
  4787. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4788. break;
  4789. }
  4790. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4791. spawn->SetSpawnScript(string(script));
  4792. break;
  4793. }
  4794. }
  4795. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4796. lua_interface->SetSpawnValue(state, spawn);
  4797. return 1;
  4798. }
  4799. else {
  4800. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4801. safe_delete(spawn);
  4802. }
  4803. }
  4804. return 0;
  4805. }
  4806. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4807. if (!lua_interface)
  4808. return 0;
  4809. Spawn* caster = lua_interface->GetSpawn(state);
  4810. Spawn* target = lua_interface->GetSpawn(state, 2);
  4811. int32 id = lua_interface->GetInt32Value(state, 3);
  4812. string command = lua_interface->GetStringValue(state, 4);
  4813. if (!caster) {
  4814. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4815. return 0;
  4816. }
  4817. if (!target) {
  4818. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4819. return 0;
  4820. }
  4821. if (!caster->IsPlayer()) {
  4822. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4823. return 0;
  4824. }
  4825. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4826. if (!entity_command) {
  4827. 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());
  4828. return 0;
  4829. }
  4830. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4831. if (!client) {
  4832. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4833. return 0;
  4834. }
  4835. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4836. return 0;
  4837. }
  4838. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4839. if (!lua_interface)
  4840. return 0;
  4841. Spawn* spawn = lua_interface->GetSpawn(state);
  4842. if (!spawn) {
  4843. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4844. return 0;
  4845. }
  4846. if (!spawn->IsNPC()) {
  4847. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4848. return 0;
  4849. }
  4850. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4851. return 0;
  4852. }
  4853. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4854. if (!lua_interface)
  4855. return 0;
  4856. Spawn* spawn = lua_interface->GetSpawn(state);
  4857. int16 tick = lua_interface->GetInt16Value(state, 2);
  4858. if (!spawn) {
  4859. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4860. return 0;
  4861. }
  4862. if (!spawn->IsNPC()) {
  4863. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4864. return 0;
  4865. }
  4866. if (tick < 20) {
  4867. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4868. return 0;
  4869. }
  4870. ((NPC*)spawn)->Brain()->SetTick(tick);
  4871. return 0;
  4872. }
  4873. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4874. if (!lua_interface)
  4875. return 0;
  4876. Spawn* spawn = lua_interface->GetSpawn(state);
  4877. Spawn* target = lua_interface->GetSpawn(state, 2);
  4878. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4879. if (!spawn) {
  4880. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4881. return 0;
  4882. }
  4883. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4884. spawn->SetFollowTarget(target, follow_distance);
  4885. return 0;
  4886. }
  4887. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4888. if (!lua_interface)
  4889. return 0;
  4890. Spawn* spawn = lua_interface->GetSpawn(state);
  4891. if (!spawn) {
  4892. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4893. return 0;
  4894. }
  4895. Spawn* target = spawn->GetFollowTarget();
  4896. if (target) {
  4897. lua_interface->SetSpawnValue(state, target);
  4898. return 1;
  4899. }
  4900. return 0;
  4901. }
  4902. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4903. if (!lua_interface)
  4904. return 0;
  4905. Spawn* spawn = lua_interface->GetSpawn(state);
  4906. if (!spawn) {
  4907. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4908. return 0;
  4909. }
  4910. if (spawn->following)
  4911. spawn->following = false;
  4912. else
  4913. spawn->following = true;
  4914. return 0;
  4915. }
  4916. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4917. if (!lua_interface)
  4918. return 0;
  4919. Spawn* spawn = lua_interface->GetSpawn(state);
  4920. if (!spawn) {
  4921. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4922. return 0;
  4923. }
  4924. lua_interface->SetBooleanValue(state, spawn->following);
  4925. return 1;
  4926. }
  4927. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4928. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4929. // I will attempt to explain how this function works for future refrence
  4930. // Fist lets make sure lua_interface is valid, if not return out
  4931. if (!lua_interface)
  4932. return 0;
  4933. // Next we grab the first 2 params same as we usually would
  4934. Spawn* spawn = lua_interface->GetSpawn(state);
  4935. string var = lua_interface->GetStringValue(state, 2);
  4936. // 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
  4937. // 1 = Spawn
  4938. // 2 = Zone
  4939. // 3 = Item
  4940. // 4 = Quest
  4941. // 5 = String
  4942. // 6 = nil (null)
  4943. int8 dataType = 0;
  4944. // Define pointers for each potential type
  4945. Spawn* spawnVal = 0;
  4946. ZoneServer* zone = 0;
  4947. Item* item = 0;
  4948. Quest* quest = 0;
  4949. string val;
  4950. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4951. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4952. // options window are also light user data be we do not handle those.
  4953. // We check with lua_islightuserdata(lua_State*, index)
  4954. if (lua_islightuserdata(state, 3)) {
  4955. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4956. // and convert it to LUAUserData*
  4957. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4958. // Check to make sure the data we got is valid, if not give an error
  4959. if (!data || !data->IsCorrectlyInitialized()) {
  4960. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4961. }
  4962. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4963. else if (data->IsSpawn()) {
  4964. spawnVal = data->spawn;
  4965. dataType = 1;
  4966. }
  4967. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4968. else if (data->IsZone()) {
  4969. zone = data->zone;
  4970. dataType = 2;
  4971. }
  4972. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4973. else if (data->IsItem()) {
  4974. item = data->item;
  4975. dataType = 3;
  4976. }
  4977. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4978. else if (data->IsQuest()) {
  4979. quest = data->quest;
  4980. dataType = 4;
  4981. }
  4982. }
  4983. // Wasn't light user data, check if it is nil(null)
  4984. else if (lua_isnil(state, 3)) {
  4985. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4986. dataType = 6;
  4987. }
  4988. // Wasn't light user data or nil (null), must be a string
  4989. else {
  4990. // Set the string and dataType variable
  4991. val = lua_interface->GetStringValue(state, 3);
  4992. dataType = 5;
  4993. }
  4994. // We now have all the params, lets check to make sure they are valid
  4995. if (!spawn) {
  4996. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4997. return 0;
  4998. }
  4999. if (var.length() == 0) {
  5000. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5001. return 0;
  5002. }
  5003. if (dataType == 0) {
  5004. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5005. return 0;
  5006. }
  5007. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5008. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5009. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5010. switch (dataType) {
  5011. case 1:
  5012. // 1 = Spawn
  5013. spawn->AddTempVariable(var, spawnVal);
  5014. break;
  5015. case 2:
  5016. // 2 = Zone
  5017. spawn->AddTempVariable(var, zone);
  5018. break;
  5019. case 3:
  5020. // 3 = Item
  5021. spawn->AddTempVariable(var, item);
  5022. break;
  5023. case 4:
  5024. // 4 = Quest
  5025. spawn->AddTempVariable(var, quest);
  5026. break;
  5027. case 5:
  5028. // 5 = String
  5029. spawn->AddTempVariable(var, val);
  5030. break;
  5031. case 6:
  5032. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5033. spawn->DeleteTempVariable(var);
  5034. break;
  5035. }
  5036. // And we are done so return out
  5037. return 0;
  5038. }
  5039. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5040. if (!lua_interface)
  5041. return 0;
  5042. Spawn* spawn = lua_interface->GetSpawn(state);
  5043. string var = lua_interface->GetStringValue(state, 2);
  5044. if (!spawn) {
  5045. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5046. return 0;
  5047. }
  5048. if (var.length() == 0) {
  5049. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5050. return 0;
  5051. }
  5052. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5053. int8 type = spawn->GetTempVariableType(var);
  5054. Spawn* spawn2 = 0;
  5055. ZoneServer* zone = 0;
  5056. Item* item = 0;
  5057. Quest* quest = 0;
  5058. // Set the lua function return value based on the type of data the variable contains
  5059. switch (type) {
  5060. case 1:
  5061. spawn2 = spawn->GetTempVariableSpawn(var);
  5062. if (!spawn2)
  5063. return 0;
  5064. lua_interface->SetSpawnValue(state, spawn2);
  5065. break;
  5066. case 2:
  5067. zone = spawn->GetTempVariableZone(var);
  5068. if (!zone)
  5069. return 0;
  5070. lua_interface->SetZoneValue(state, zone);
  5071. break;
  5072. case 3:
  5073. item = spawn->GetTempVariableItem(var);
  5074. if (!item)
  5075. return 0;
  5076. lua_interface->SetItemValue(state, item);
  5077. break;
  5078. case 4:
  5079. quest = spawn->GetTempVariableQuest(var);
  5080. if (!quest)
  5081. return 0;
  5082. lua_interface->SetQuestValue(state, quest);
  5083. break;
  5084. case 5:
  5085. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5086. break;
  5087. default:
  5088. // Not a valid type then the variable was not set so return out
  5089. return 0;
  5090. }
  5091. // Return value was set so return out
  5092. return 1;
  5093. }
  5094. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5095. {
  5096. if (!lua_interface)
  5097. return 0;
  5098. Quest* quest = lua_interface->GetQuest(state);
  5099. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5100. string description = lua_interface->GetStringValue(state, 3);
  5101. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5102. if (!quest) {
  5103. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5104. lua_interface->SetBooleanValue(state, false);
  5105. return 1;
  5106. }
  5107. if (!spawn) {
  5108. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5109. lua_interface->SetBooleanValue(state, false);
  5110. return 1;
  5111. }
  5112. if (!spawn->IsPlayer()) {
  5113. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5114. lua_interface->SetBooleanValue(state, false);
  5115. return 1;
  5116. }
  5117. if (item_id == 0) {
  5118. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5119. lua_interface->SetBooleanValue(state, false);
  5120. return 1;
  5121. }
  5122. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5123. if (!client) {
  5124. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5125. lua_interface->SetBooleanValue(state, false);
  5126. return 1;
  5127. }
  5128. Item* item = master_item_list.GetItem(item_id);
  5129. if (!item) {
  5130. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5131. lua_interface->SetBooleanValue(state, false);
  5132. return 1;
  5133. }
  5134. Item* firstItem = new Item(item);
  5135. quest->AddTmpRewardItem(firstItem);
  5136. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5137. bool itemsAddedSuccessfully = true;
  5138. if(num_args > 4)
  5139. {
  5140. for(int8 n=5;n<num_args+1;n++)
  5141. {
  5142. int32 new_item = lua_interface->GetInt32Value(state, n);
  5143. Item* tmpItem = master_item_list.GetItem(new_item);
  5144. if(tmpItem)
  5145. {
  5146. Item* newTmpItem = new Item(tmpItem);
  5147. quest->AddTmpRewardItem(newTmpItem);
  5148. }
  5149. else
  5150. itemsAddedSuccessfully = false;
  5151. }
  5152. }
  5153. client->AddPendingQuestAcceptReward(quest);
  5154. client->DisplayQuestComplete(quest, true, description);
  5155. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5156. return 1;
  5157. }
  5158. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5159. if (!lua_interface)
  5160. return 0;
  5161. Quest* quest = lua_interface->GetQuest(state);
  5162. if (!quest) {
  5163. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5164. return 0;
  5165. }
  5166. quest->SetRepeatable(true);
  5167. return 0;
  5168. }
  5169. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5170. if (!lua_interface)
  5171. return 0;
  5172. Spawn* spawn = lua_interface->GetSpawn(state);
  5173. if (!spawn) {
  5174. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5175. return 0;
  5176. }
  5177. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5178. string ret = classes.GetClassNameCase(base_class);
  5179. if (ret.length() > 0) {
  5180. lua_interface->SetStringValue(state, ret.c_str());
  5181. return 1;
  5182. }
  5183. return 0;
  5184. }
  5185. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5186. if (!lua_interface)
  5187. return 0;
  5188. Spawn* player = lua_interface->GetSpawn(state);
  5189. if (player && player->IsPlayer()) {
  5190. Client* client = player->GetClient();
  5191. if (client)
  5192. client->SendWaypoints();
  5193. }
  5194. return 0;
  5195. }
  5196. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5197. if (!lua_interface)
  5198. return 0;
  5199. Spawn* player = lua_interface->GetSpawn(state);
  5200. string name = lua_interface->GetStringValue(state, 2);
  5201. int32 type = lua_interface->GetInt32Value(state, 3);
  5202. if (type == 0)
  5203. type = 2;
  5204. if (name.length() > 0) {
  5205. if (player && player->IsPlayer()) {
  5206. Client* client = player->GetClient();
  5207. if (client)
  5208. client->AddWaypoint(name, type);
  5209. }
  5210. }
  5211. return 0;
  5212. }
  5213. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5214. if (!lua_interface)
  5215. return 0;
  5216. Spawn* player = lua_interface->GetSpawn(state);
  5217. string name = lua_interface->GetStringValue(state, 2);
  5218. if (name.length() > 0) {
  5219. if (player && player->IsPlayer()) {
  5220. Client* client = player->GetClient();
  5221. if (client)
  5222. client->RemoveWaypoint(name);
  5223. }
  5224. }
  5225. return 0;
  5226. }
  5227. int EQ2Emu_lua_AddWard(lua_State* state) {
  5228. if (!lua_interface)
  5229. return 0;
  5230. int32 damage = lua_interface->GetInt32Value(state);
  5231. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5232. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5233. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5234. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5235. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5236. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5237. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5238. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5239. bool ward_was_added = false;
  5240. ZoneServer* zone = spell->caster->GetZone();
  5241. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5242. for (int32 i = 0; i < spell->targets.size(); i++) {
  5243. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5244. if (!target)
  5245. continue;
  5246. if (target->IsEntity()) {
  5247. // If the ward is already active remove it
  5248. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5249. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5250. // Create new ward info
  5251. WardInfo* ward = new WardInfo;
  5252. ward->Spell = spell;
  5253. ward->BaseDamage = damage;
  5254. ward->DamageLeft = damage;
  5255. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5256. ward->keepWard = keepWard;
  5257. ward->WardType = wardType;
  5258. if (damageAbsorptionPercent > 100)
  5259. damageAbsorptionPercent = 100;
  5260. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5261. if (damageAbsorptionMaxHealthPercent > 100)
  5262. damageAbsorptionMaxHealthPercent = 100;
  5263. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5264. ward->RedirectDamagePercent = redirectDamagePercent;
  5265. ward->LastRedirectDamage = 0;
  5266. ward->LastAbsorbedDamage = 0;
  5267. ward->HitCount = 0;
  5268. spell->num_triggers = maxHitCount;
  5269. spell->had_triggers = true;
  5270. spell->cancel_after_all_triggers = false;
  5271. ward->MaxHitCount = maxHitCount;
  5272. if (wardType == WARD_TYPE_MAGICAL)
  5273. ward->DamageType = damageTypes;
  5274. // Add the ward to the entity
  5275. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5276. ward_was_added = true;
  5277. }
  5278. }
  5279. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5280. if (ward_was_added && spell->caster->IsPlayer()) {
  5281. spell->had_dmg_remaining = true;
  5282. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5283. }
  5284. return 0;
  5285. }
  5286. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5287. if (!lua_interface)
  5288. return 0;
  5289. int32 amount = lua_interface->GetInt32Value(state);
  5290. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5291. WardInfo* ward = 0;
  5292. ZoneServer* zone = spell->caster->GetZone();
  5293. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5294. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5295. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5296. ward = target->GetWard(spell->spell->GetSpellID());
  5297. if (target && ward) {
  5298. ward->DamageLeft += amount;
  5299. if (ward->DamageLeft > ward->BaseDamage)
  5300. ward->DamageLeft = ward->BaseDamage;
  5301. for (int32 i = 0; i < spell->targets.size(); i++) {
  5302. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5303. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5304. }
  5305. }
  5306. }
  5307. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5308. if (ward && spell->caster->IsPlayer())
  5309. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5310. return 0;
  5311. }
  5312. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5313. if (!lua_interface)
  5314. return 0;
  5315. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5316. if (!spell) {
  5317. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5318. return 0;
  5319. }
  5320. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5321. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5322. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5323. if (ward) {
  5324. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5325. return 1;
  5326. }
  5327. }
  5328. return 0;
  5329. }
  5330. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5331. if (!lua_interface)
  5332. return 0;
  5333. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5334. if (!spell) {
  5335. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5336. return 0;
  5337. }
  5338. string type = lua_interface->GetStringValue(state, 2);
  5339. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5340. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5341. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5342. if (ward) {
  5343. if (boost::iequals(type, "damageleft"))
  5344. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5345. else if (boost::iequals(type, "basedamage"))
  5346. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5347. else if (boost::iequals(type, "keepward"))
  5348. lua_interface->SetBooleanValue(state, ward->keepWard);
  5349. else if (boost::iequals(type, "wardtype"))
  5350. lua_interface->SetInt32Value(state, ward->WardType);
  5351. else if (boost::iequals(type, "dmgabsorptionpct"))
  5352. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5353. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5354. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5355. else if (boost::iequals(type, "redirectdamagepercent"))
  5356. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5357. else if (boost::iequals(type, "lastredirectdamage"))
  5358. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5359. else if (boost::iequals(type, "lastabsorbeddamage"))
  5360. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5361. else if (boost::iequals(type, "hitcount"))
  5362. lua_interface->SetInt32Value(state, ward->HitCount);
  5363. else if (boost::iequals(type, "maxhitcount"))
  5364. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5365. else
  5366. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5367. return 1;
  5368. }
  5369. }
  5370. return 0;
  5371. }
  5372. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5373. if (!lua_interface)
  5374. return 0;
  5375. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5376. ZoneServer* zone = spell->caster->GetZone();
  5377. Spawn* target = 0;
  5378. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5379. for (int32 i = 0; i < spell->targets.size(); i++) {
  5380. target = zone->GetSpawnByID(spell->targets.at(i));
  5381. if (target && target->IsEntity()) {
  5382. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5383. }
  5384. }
  5385. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5386. return 0;
  5387. }
  5388. int EQ2Emu_lua_Interrupt(lua_State* state)
  5389. {
  5390. if (!lua_interface)
  5391. return 0;
  5392. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5393. Spawn* target = lua_interface->GetSpawn(state, 2);
  5394. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5395. if (!caster)
  5396. {
  5397. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5398. return 0;
  5399. }
  5400. if (!target)
  5401. {
  5402. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5403. return 0;
  5404. }
  5405. if (!spell) {
  5406. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5407. return 0;
  5408. }
  5409. if (!target->IsEntity() && !spell)
  5410. {
  5411. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5412. return 0;
  5413. }
  5414. if (!target && spell) {
  5415. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5416. for (int8 i = 0; i < spell->targets.size(); i++) {
  5417. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5418. if (!target || !target->IsEntity())
  5419. continue;
  5420. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5421. }
  5422. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5423. }
  5424. else
  5425. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5426. return 0;
  5427. }
  5428. int EQ2Emu_lua_Stealth(lua_State* state) {
  5429. if (!lua_interface)
  5430. return 0;
  5431. int8 type = lua_interface->GetInt8Value(state);
  5432. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5433. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5434. if (!spell) {
  5435. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5436. return 0;
  5437. }
  5438. ZoneServer* zone = spell->caster->GetZone();
  5439. if (spawn) {
  5440. if (spawn->IsEntity()) {
  5441. if (type == 1) {
  5442. ((Entity*)spawn)->AddStealthSpell(spell);
  5443. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5444. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5445. }
  5446. else if (type == 2) {
  5447. ((Entity*)spawn)->AddInvisSpell(spell);
  5448. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5449. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5450. }
  5451. return 0;
  5452. }
  5453. else {
  5454. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5455. return 0;
  5456. }
  5457. }
  5458. else {
  5459. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5460. for (int32 i = 0; i < spell->targets.size(); i++) {
  5461. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5462. if (!spawn || !spawn->IsEntity())
  5463. continue;
  5464. if (type == 1) {
  5465. ((Entity*)spawn)->AddStealthSpell(spell);
  5466. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5467. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5468. }
  5469. else if (type == 2) {
  5470. ((Entity*)spawn)->AddInvisSpell(spell);
  5471. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5472. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5473. }
  5474. else {
  5475. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5476. break;
  5477. }
  5478. }
  5479. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5480. }
  5481. return 0;
  5482. }
  5483. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5484. if (!lua_interface)
  5485. return 0;
  5486. Spawn* spawn = lua_interface->GetSpawn(state);
  5487. if (!spawn) {
  5488. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. if (spawn->IsEntity()) {
  5492. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5493. return 1;
  5494. }
  5495. else
  5496. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5497. return 0;
  5498. }
  5499. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5500. if (!lua_interface)
  5501. return 0;
  5502. Spawn* spawn = lua_interface->GetSpawn(state);
  5503. if (!spawn) {
  5504. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5505. return 0;
  5506. }
  5507. if (spawn->IsEntity()) {
  5508. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5509. return 1;
  5510. }
  5511. else
  5512. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5513. return 0;
  5514. }
  5515. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5516. if (!lua_interface)
  5517. return 0;
  5518. Spawn* player = lua_interface->GetSpawn(state);
  5519. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5520. lua_interface->ResetFunctionStack(state);
  5521. if (!player->IsPlayer()) {
  5522. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5523. return 0;
  5524. }
  5525. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5526. return 1;
  5527. }
  5528. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5529. if (!lua_interface)
  5530. return 0;
  5531. Spawn* player = lua_interface->GetSpawn(state);
  5532. int8 slot = lua_interface->GetInt8Value(state, 2);
  5533. lua_interface->ResetFunctionStack(state);
  5534. if (!player) {
  5535. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5536. return 0;
  5537. }
  5538. if (!player->IsPlayer()) {
  5539. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5540. return 0;
  5541. }
  5542. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5543. if (!item) {
  5544. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5545. return 0;
  5546. }
  5547. lua_interface->SetItemValue(state, item);
  5548. return 1;
  5549. }
  5550. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5551. if (!lua_interface)
  5552. return 0;
  5553. Spawn* player = lua_interface->GetSpawn(state);
  5554. int32 id = lua_interface->GetInt32Value(state, 2);
  5555. lua_interface->ResetFunctionStack(state);
  5556. if (!player) {
  5557. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5558. return 0;
  5559. }
  5560. if (!player->IsPlayer()) {
  5561. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5562. return 0;
  5563. }
  5564. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5565. if (!item) {
  5566. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5567. return 0;
  5568. }
  5569. lua_interface->SetItemValue(state, item);
  5570. return 1;
  5571. }
  5572. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5573. if (!lua_interface)
  5574. return 0;
  5575. Spawn* spawn = lua_interface->GetSpawn(state);
  5576. int8 slot = lua_interface->GetInt8Value(state, 2);
  5577. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5578. lua_interface->ResetFunctionStack(state);
  5579. if (!spawn) {
  5580. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5581. return 0;
  5582. }
  5583. if (!spawn->IsEntity()) {
  5584. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5585. return 0;
  5586. }
  5587. Item* item = master_item_list.GetItem(item_id);
  5588. if (!item) {
  5589. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5590. return 0;
  5591. }
  5592. Item* copy = new Item(item);
  5593. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5594. if(result)
  5595. {
  5596. ((Entity*)spawn)->SetEquipment(copy, slot);
  5597. spawn->vis_changed = true;
  5598. if(spawn->IsPlayer())
  5599. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5600. }
  5601. else
  5602. {
  5603. safe_delete(copy);
  5604. }
  5605. lua_interface->SetBooleanValue(state, result);
  5606. return 1;
  5607. }
  5608. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5609. if (!lua_interface)
  5610. return 0;
  5611. Spawn* spawn = lua_interface->GetSpawn(state);
  5612. int8 slot = lua_interface->GetInt8Value(state, 2);
  5613. Item* item = lua_interface->GetItem(state, 3);
  5614. lua_interface->ResetFunctionStack(state);
  5615. if (!spawn) {
  5616. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5617. return 0;
  5618. }
  5619. if (!spawn->IsEntity()) {
  5620. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5621. return 0;
  5622. }
  5623. if (!item) {
  5624. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5625. return 0;
  5626. }
  5627. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5628. if(result)
  5629. {
  5630. ((Entity*)spawn)->SetEquipment(item, slot);
  5631. spawn->vis_changed = true;
  5632. if(spawn->IsPlayer())
  5633. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5634. }
  5635. lua_interface->SetBooleanValue(state, result);
  5636. return 1;
  5637. }
  5638. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5639. if (!lua_interface)
  5640. return 0;
  5641. Spawn* spawn = lua_interface->GetSpawn(state);
  5642. int8 slot = lua_interface->GetInt8Value(state, 2);
  5643. 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
  5644. lua_interface->ResetFunctionStack(state);
  5645. if (!spawn) {
  5646. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5647. return 0;
  5648. }
  5649. if (!spawn->IsEntity()) {
  5650. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5651. return 0;
  5652. }
  5653. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5654. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5655. spawn->vis_changed = true;
  5656. if(spawn->IsPlayer())
  5657. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5658. lua_interface->SetBooleanValue(state, true);
  5659. return 1;
  5660. }
  5661. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5662. if (!lua_interface)
  5663. return 0;
  5664. Spawn* spawn = lua_interface->GetSpawn(state);
  5665. int8 slot = lua_interface->GetInt8Value(state, 2);
  5666. int16 type = lua_interface->GetInt16Value(state, 3);
  5667. int8 r = lua_interface->GetInt8Value(state, 4);
  5668. int8 g = lua_interface->GetInt8Value(state, 5);
  5669. int8 b = lua_interface->GetInt8Value(state, 6);
  5670. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5671. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5672. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5673. lua_interface->ResetFunctionStack(state);
  5674. if (!spawn) {
  5675. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5676. return 0;
  5677. }
  5678. if (!spawn->IsEntity()) {
  5679. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5680. return 0;
  5681. }
  5682. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5683. spawn->vis_changed = true;
  5684. lua_interface->SetBooleanValue(state, true);
  5685. return 1;
  5686. }
  5687. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5688. if (!lua_interface)
  5689. return 0;
  5690. Spawn* player = lua_interface->GetSpawn(state);
  5691. int32 id = lua_interface->GetInt32Value(state, 2);
  5692. int8 count = lua_interface->GetInt8Value(state, 3);
  5693. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5694. lua_interface->ResetFunctionStack(state);
  5695. if (!player) {
  5696. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5697. return 0;
  5698. }
  5699. if (!player->IsPlayer()) {
  5700. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5701. return 0;
  5702. }
  5703. if (!count)
  5704. count = 1;
  5705. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5706. if (!item) {
  5707. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5708. return 0;
  5709. }
  5710. lua_interface->SetItemValue(state, item);
  5711. return 1;
  5712. }
  5713. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5714. if (!lua_interface)
  5715. return 0;
  5716. Spawn* spawn = lua_interface->GetSpawn(state);
  5717. int32 anim = lua_interface->GetInt32Value(state, 2);
  5718. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5719. int8 type = lua_interface->GetInt8Value(state, 4);
  5720. if (!spawn) {
  5721. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5722. return 0;
  5723. }
  5724. if (spawn2) {
  5725. if (spawn2->IsPlayer()) {
  5726. if (type != 1 && type != 2)
  5727. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5728. else
  5729. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5730. return 0;
  5731. }
  5732. else {
  5733. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5734. return 0;
  5735. }
  5736. }
  5737. else
  5738. spawn->GetZone()->PlayAnimation(spawn, anim);
  5739. return 0;
  5740. }
  5741. int EQ2Emu_lua_IsPet(lua_State* state) {
  5742. if (!lua_interface)
  5743. return 0;
  5744. Spawn* spawn = lua_interface->GetSpawn(state);
  5745. if (!spawn) {
  5746. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5747. return 0;
  5748. }
  5749. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5750. return 1;
  5751. }
  5752. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5753. if (!lua_interface)
  5754. return 0;
  5755. Spawn* spawn = lua_interface->GetSpawn(state);
  5756. if (!spawn) {
  5757. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5758. return 0;
  5759. }
  5760. if (!spawn->IsNPC()) {
  5761. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5762. return 0;
  5763. }
  5764. if (((NPC*)spawn)->GetOwner()) {
  5765. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5766. return 1;
  5767. }
  5768. return 0;
  5769. }
  5770. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5771. if (!lua_interface)
  5772. return 0;
  5773. Spawn* spawn = lua_interface->GetSpawn(state);
  5774. Spawn* target = lua_interface->GetSpawn(state, 2);
  5775. if (!spawn) {
  5776. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5777. return 0;
  5778. }
  5779. if (!spawn) {
  5780. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5781. return 0;
  5782. }
  5783. spawn->SetTarget(target);
  5784. return 0;
  5785. }
  5786. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5787. if (!lua_interface)
  5788. return 0;
  5789. Spawn* spawn = lua_interface->GetSpawn(state);
  5790. bool val = lua_interface->GetBooleanValue(state, 2);
  5791. if (!spawn) {
  5792. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5793. return 0;
  5794. }
  5795. if (!spawn->IsEntity()) {
  5796. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5797. return 0;
  5798. }
  5799. ((Entity*)spawn)->InCombat(val);
  5800. if (val) {
  5801. spawn->ClearRunningLocations();
  5802. spawn->CalculateRunningLocation(true);
  5803. }
  5804. return 0;
  5805. }
  5806. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5807. if (!lua_interface)
  5808. return 0;
  5809. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5810. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5811. if (!spawn1) {
  5812. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5813. return 0;
  5814. }
  5815. if (!spawn2) {
  5816. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5817. return 0;
  5818. }
  5819. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5820. return 1;
  5821. }
  5822. int EQ2Emu_lua_Runback(lua_State* state) {
  5823. if (!lua_interface)
  5824. return 0;
  5825. Spawn* spawn = lua_interface->GetSpawn(state);
  5826. if (!spawn) {
  5827. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5828. return 0;
  5829. }
  5830. if (!spawn->IsNPC()) {
  5831. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5832. return 0;
  5833. }
  5834. ((NPC*)spawn)->Runback();
  5835. return 0;
  5836. }
  5837. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5838. if (!lua_interface)
  5839. return 0;
  5840. Spawn* spawn = lua_interface->GetSpawn(state);
  5841. if (!spawn) {
  5842. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5843. return 0;
  5844. }
  5845. if (!spawn->IsNPC()) {
  5846. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5847. return 0;
  5848. }
  5849. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5850. return 1;
  5851. }
  5852. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5853. if (!lua_interface)
  5854. return 0;
  5855. Spawn* spawn = lua_interface->GetSpawn(state);
  5856. if (!spawn) {
  5857. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5858. return 0;
  5859. }
  5860. if (!spawn->IsEntity()) {
  5861. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5862. return 0;
  5863. }
  5864. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5865. return 1;
  5866. }
  5867. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5868. if (!lua_interface)
  5869. return 0;
  5870. Spawn* spawn = lua_interface->GetSpawn(state);
  5871. if (!spawn) {
  5872. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5873. return 0;
  5874. }
  5875. if (!spawn->IsEntity()) {
  5876. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5877. return 0;
  5878. }
  5879. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5880. return 1;
  5881. }
  5882. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5883. if (!lua_interface)
  5884. return 0;
  5885. Spawn* spawn = lua_interface->GetSpawn(state);
  5886. if (!spawn) {
  5887. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5888. return 0;
  5889. }
  5890. if (!spawn->IsEntity()) {
  5891. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5892. return 0;
  5893. }
  5894. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5895. return 1;
  5896. }
  5897. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5898. if (!lua_interface)
  5899. return 0;
  5900. Spawn* spawn = lua_interface->GetSpawn(state);
  5901. if (!spawn) {
  5902. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5903. return 0;
  5904. }
  5905. if (!spawn->IsEntity()) {
  5906. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5907. return 0;
  5908. }
  5909. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5910. return 1;
  5911. }
  5912. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5913. if (!lua_interface)
  5914. return 0;
  5915. Spawn* spawn = lua_interface->GetSpawn(state);
  5916. Spawn* target = lua_interface->GetSpawn(state, 2);
  5917. float distance = lua_interface->GetFloatValue(state, 3);
  5918. if (!spawn) {
  5919. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5920. return 0;
  5921. }
  5922. if (!target) {
  5923. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5924. return 0;
  5925. }
  5926. if (!spawn->IsNPC()) {
  5927. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5928. return 0;
  5929. }
  5930. if (!target->IsEntity()) {
  5931. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5932. return 0;
  5933. }
  5934. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5935. return 1;
  5936. }
  5937. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5938. if (!lua_interface)
  5939. return 0;
  5940. Spawn* spawn = lua_interface->GetSpawn(state);
  5941. Spawn* target = lua_interface->GetSpawn(state, 2);
  5942. float distance = lua_interface->GetFloatValue(state, 3);
  5943. if (!spawn) {
  5944. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5945. return 0;
  5946. }
  5947. if (!target) {
  5948. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. if (!spawn->IsNPC()) {
  5952. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5953. return 0;
  5954. }
  5955. if (!target->IsEntity()) {
  5956. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5957. return 0;
  5958. }
  5959. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5960. return 0;
  5961. }
  5962. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5963. if (!lua_interface)
  5964. return 0;
  5965. Spawn* spawn = lua_interface->GetSpawn(state);
  5966. if (!spawn) {
  5967. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5968. return 0;
  5969. }
  5970. if (!spawn->IsNPC()) {
  5971. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5972. return 0;
  5973. }
  5974. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5975. return 1;
  5976. }
  5977. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5978. if (!lua_interface)
  5979. return 0;
  5980. Spawn* spawn = lua_interface->GetSpawn(state);
  5981. if (!spawn) {
  5982. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5983. return 0;
  5984. }
  5985. if (!spawn->IsNPC()) {
  5986. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5987. return 0;
  5988. }
  5989. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5990. return 1;
  5991. }
  5992. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5993. if (!lua_interface)
  5994. return 0;
  5995. Spawn* spawn = lua_interface->GetSpawn(state);
  5996. if (!spawn) {
  5997. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5998. return 0;
  5999. }
  6000. if (!spawn->IsNPC()) {
  6001. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6002. return 0;
  6003. }
  6004. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6005. if (hated) {
  6006. lua_interface->SetSpawnValue(state, hated);
  6007. return 1;
  6008. }
  6009. return 0;
  6010. }
  6011. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6012. if (!lua_interface)
  6013. return 0;
  6014. Spawn* spawn = lua_interface->GetSpawn(state);
  6015. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6016. if (!spawn) {
  6017. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6018. return 0;
  6019. }
  6020. if (!spawn->IsNPC()) {
  6021. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6022. return 0;
  6023. }
  6024. if (!hated) {
  6025. ((NPC*)spawn)->Brain()->ClearHate();
  6026. return 0;
  6027. }
  6028. else
  6029. {
  6030. if (!hated->IsEntity()) {
  6031. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6032. return 0;
  6033. }
  6034. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6035. return 0;
  6036. }
  6037. return 0;
  6038. }
  6039. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6040. if (!lua_interface)
  6041. return 0;
  6042. Spawn* spawn = lua_interface->GetSpawn(state);
  6043. if (!spawn) {
  6044. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6045. return 0;
  6046. }
  6047. if (!spawn->IsNPC()) {
  6048. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6049. return 0;
  6050. }
  6051. ((NPC*)spawn)->Brain()->ClearEncounter();
  6052. return 0;
  6053. }
  6054. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6055. if (!lua_interface)
  6056. return 0;
  6057. Spawn* spawn = lua_interface->GetSpawn(state);
  6058. if (!spawn) {
  6059. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6060. return 0;
  6061. }
  6062. if (!spawn->IsNPC()) {
  6063. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6064. return 0;
  6065. }
  6066. // Temp list to store hate list
  6067. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6068. if (encounterList->size() == 0) {
  6069. safe_delete(encounterList);
  6070. return 0;
  6071. }
  6072. lua_createtable(state, encounterList->size(), 0);
  6073. int newTable = lua_gettop(state);
  6074. for (int32 i = 0; i < encounterList->size(); i++) {
  6075. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6076. if (temp)
  6077. lua_interface->SetSpawnValue(state, temp);
  6078. lua_rawseti(state, newTable, i + 1);
  6079. }
  6080. safe_delete(encounterList);
  6081. return 1;
  6082. }
  6083. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6084. if (!lua_interface)
  6085. return 0;
  6086. Spawn* spawn = lua_interface->GetSpawn(state);
  6087. if (!spawn) {
  6088. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6089. return 0;
  6090. }
  6091. if (!spawn->IsNPC()) {
  6092. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6093. return 0;
  6094. }
  6095. // Temp list to store hate list
  6096. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6097. if (hateList->size() == 0) {
  6098. safe_delete(hateList);
  6099. return 0;
  6100. }
  6101. lua_createtable(state, hateList->size(), 0);
  6102. int newTable = lua_gettop(state);
  6103. for (int32 i = 0; i < hateList->size(); i++) {
  6104. lua_interface->SetSpawnValue(state, hateList->at(i));
  6105. lua_rawseti(state, newTable, i + 1);
  6106. }
  6107. safe_delete(hateList);
  6108. return 1;
  6109. }
  6110. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6111. if (!lua_interface)
  6112. return 0;
  6113. Spawn* spawn = lua_interface->GetSpawn(state);
  6114. if (!spawn) {
  6115. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6116. return 0;
  6117. }
  6118. if (spawn->IsPlayer()) {
  6119. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6120. lua_interface->SetBooleanValue(state, true);
  6121. else
  6122. lua_interface->SetBooleanValue(state, false);
  6123. return 1;
  6124. }
  6125. else {
  6126. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6127. return 1;
  6128. }
  6129. }
  6130. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6131. if (!lua_interface)
  6132. return 0;
  6133. Quest* quest = lua_interface->GetQuest(state);
  6134. if (!quest) {
  6135. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. quest->SetCompletedFlag(true);
  6139. return 0;
  6140. }
  6141. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6142. if (!lua_interface)
  6143. return 0;
  6144. Spawn* spawn = lua_interface->GetSpawn(state);
  6145. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6146. int8 tier = lua_interface->GetInt8Value(state, 3);
  6147. if (!spawn) {
  6148. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6149. return 0;
  6150. }
  6151. if (!spawn->IsEntity()) {
  6152. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6153. return 0;
  6154. }
  6155. if (spellID == 0) {
  6156. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6157. return 0;
  6158. }
  6159. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6160. if (effect) {
  6161. if (tier > 0) {
  6162. // If a tier was passed chec to see if it is the same as the effect
  6163. if (tier == effect->tier)
  6164. lua_interface->SetBooleanValue(state, true);
  6165. else
  6166. lua_interface->SetBooleanValue(state, false);
  6167. return 1;
  6168. }
  6169. else {
  6170. // Have an effect but no tier was passed so return true
  6171. lua_interface->SetBooleanValue(state, true);
  6172. }
  6173. return 1;
  6174. }
  6175. // no effect so return false
  6176. lua_interface->SetBooleanValue(state, false);
  6177. return 1;
  6178. }
  6179. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6180. if (!lua_interface)
  6181. return 0;
  6182. Spawn* spawn = lua_interface->GetSpawn(state);
  6183. int32 id = lua_interface->GetInt32Value(state, 2);
  6184. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6185. Spawn* spawn2 = 0;
  6186. vector<Spawn*> list;
  6187. if (!spawn) {
  6188. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6189. return 0;
  6190. }
  6191. //If zone not provided, use spawn's zone
  6192. if (!zone)
  6193. zone = spawn->GetZone();
  6194. list = zone->GetSpawnsByID(id);
  6195. if (list.size() == 0) {
  6196. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6197. return 0;
  6198. }
  6199. vector<Spawn*>::iterator itr = list.begin();
  6200. for (int8 i = 0; i < list.size(); i++) {
  6201. spawn2 = itr[i];
  6202. if (spawn2)
  6203. spawn2->AddAllowAccessSpawn(spawn);
  6204. }
  6205. return 0;
  6206. }
  6207. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6208. if (!lua_interface)
  6209. return 0;
  6210. Spawn* spawn = lua_interface->GetSpawn(state);
  6211. int32 id = lua_interface->GetInt32Value(state, 2);
  6212. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6213. Spawn* spawn2 = 0;
  6214. if (!spawn) {
  6215. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6216. return 0;
  6217. }
  6218. //If zone not provided, use spawn's zone
  6219. if (!zone)
  6220. zone = spawn->GetZone();
  6221. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6222. vector<Spawn*>::iterator itr = list.begin();
  6223. if (list.size() == 0) {
  6224. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6225. return 0;
  6226. }
  6227. for (int8 i = 0; i < list.size(); i++) {
  6228. spawn2 = itr[i];
  6229. if (spawn2)
  6230. spawn2->RemoveSpawnAccess(spawn);
  6231. }
  6232. return 0;
  6233. }
  6234. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6235. if (!lua_interface)
  6236. return 0;
  6237. Quest* quest = lua_interface->GetQuest(state);
  6238. if (!quest) {
  6239. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. quest->SetYellowName(true);
  6243. return 0;
  6244. }
  6245. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6246. if (!lua_interface)
  6247. return 0;
  6248. Spawn* spawn = lua_interface->GetSpawn(state);
  6249. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6250. if (!spawn) {
  6251. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6252. return 0;
  6253. }
  6254. if (!spawn->IsPlayer()) {
  6255. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6256. return 0;
  6257. }
  6258. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6259. return 1;
  6260. }
  6261. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6262. if (!lua_interface)
  6263. return 0;
  6264. Spawn* spawn = lua_interface->GetSpawn(state);
  6265. if (!spawn) {
  6266. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6267. return 0;
  6268. }
  6269. if (!spawn->IsPlayer()) {
  6270. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6271. return 0;
  6272. }
  6273. ZoneServer* zone = spawn->GetZone();
  6274. if (!zone) {
  6275. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6276. return 0;
  6277. }
  6278. Instance_Type iType = zone->GetInstanceType();
  6279. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6280. iType == GROUP_LOCKOUT_INSTANCE ||
  6281. iType == RAID_LOCKOUT_INSTANCE ||
  6282. iType == SOLO_PERSIST_INSTANCE ||
  6283. iType == GROUP_PERSIST_INSTANCE ||
  6284. iType == RAID_PERSIST_INSTANCE) {
  6285. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6286. if (data) {
  6287. // Check to see if the timer has already been set, if it has return out.
  6288. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6289. return 0;
  6290. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6291. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6292. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6293. if (client) {
  6294. string time_msg = "";
  6295. int32 time = data->success_lockout_time;
  6296. int16 hour;
  6297. int8 min;
  6298. int8 sec;
  6299. hour = time / 3600;
  6300. time = time % 3600;
  6301. min = time / 60;
  6302. time = time % 60;
  6303. sec = time;
  6304. if (hour > 0) {
  6305. char temp[10];
  6306. sprintf(temp, " %i", hour);
  6307. time_msg.append(temp);
  6308. time_msg.append(" hour");
  6309. time_msg.append((hour > 1) ? "s" : "");
  6310. }
  6311. if (min > 0) {
  6312. char temp[5];
  6313. sprintf(temp, " %i", min);
  6314. time_msg.append(temp);
  6315. time_msg.append(" minute");
  6316. time_msg.append((min > 1) ? "s" : "");
  6317. }
  6318. // Only add seconds if minutes and hours are 0
  6319. if (hour == 0 && min == 0 && sec > 0) {
  6320. char temp[5];
  6321. sprintf(temp, " %i", sec);
  6322. time_msg.append(temp);
  6323. time_msg.append(" second");
  6324. time_msg.append((sec > 1) ? "s" : "");
  6325. }
  6326. 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());
  6327. }
  6328. }
  6329. else
  6330. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6331. }
  6332. else
  6333. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6334. return 0;
  6335. }
  6336. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6337. if (!lua_interface)
  6338. return 0;
  6339. Spawn* spawn = lua_interface->GetSpawn(state);
  6340. if (!spawn) {
  6341. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6342. return 0;
  6343. }
  6344. if (!spawn->IsPlayer()) {
  6345. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6346. return 0;
  6347. }
  6348. ZoneServer* zone = spawn->GetZone();
  6349. if (!zone) {
  6350. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6351. return 0;
  6352. }
  6353. Instance_Type iType = zone->GetInstanceType();
  6354. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6355. iType == GROUP_LOCKOUT_INSTANCE ||
  6356. iType == RAID_LOCKOUT_INSTANCE ||
  6357. iType == SOLO_PERSIST_INSTANCE ||
  6358. iType == GROUP_PERSIST_INSTANCE ||
  6359. iType == RAID_PERSIST_INSTANCE) {
  6360. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6361. if (data) {
  6362. // Check to see if the timer has already been set, if it has return out.
  6363. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6364. return 0;
  6365. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6366. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6367. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6368. if (client) {
  6369. string time_msg = "";
  6370. int32 time = data->failure_lockout_time;
  6371. int16 hour;
  6372. int8 min;
  6373. int8 sec;
  6374. hour = time / 3600;
  6375. time = time % 3600;
  6376. min = time / 60;
  6377. time = time % 60;
  6378. sec = time;
  6379. if (hour > 0) {
  6380. char temp[10];
  6381. sprintf(temp, " %i", hour);
  6382. time_msg.append(temp);
  6383. time_msg.append(" hour");
  6384. time_msg.append((hour > 1) ? "s" : "");
  6385. }
  6386. if (min > 0) {
  6387. char temp[5];
  6388. sprintf(temp, " %i", min);
  6389. time_msg.append(temp);
  6390. time_msg.append(" minute");
  6391. time_msg.append((min > 1) ? "s" : "");
  6392. }
  6393. // Only add seconds if minutes and hours are 0
  6394. if (hour == 0 && min == 0 && sec > 0) {
  6395. char temp[5];
  6396. sprintf(temp, " %i", sec);
  6397. time_msg.append(temp);
  6398. time_msg.append(" second");
  6399. time_msg.append((sec > 1) ? "s" : "");
  6400. }
  6401. 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());
  6402. }
  6403. }
  6404. else
  6405. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6406. }
  6407. else
  6408. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6409. return 0;
  6410. }
  6411. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6412. if (!lua_interface)
  6413. return 0;
  6414. Spawn* spawn = lua_interface->GetSpawn(state);
  6415. if (!spawn) {
  6416. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6417. return 0;
  6418. }
  6419. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6420. return 1;
  6421. }
  6422. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6423. if (!lua_interface)
  6424. return 0;
  6425. Spawn* player = lua_interface->GetSpawn(state);
  6426. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6427. if (!player) {
  6428. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6429. return 0;
  6430. }
  6431. if (!player->IsPlayer()) {
  6432. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6433. return 0;
  6434. }
  6435. if (!ground) {
  6436. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6437. return 0;
  6438. }
  6439. if (!ground->IsGroundSpawn()) {
  6440. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6441. return 0;
  6442. }
  6443. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6444. if (!groundspawn_entries) {
  6445. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6446. return 0;
  6447. }
  6448. Skill* skill = 0;
  6449. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6450. if (collection_skill == "Collecting")
  6451. skill = ((Player*)player)->GetSkillByName("Gathering");
  6452. else
  6453. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6454. if (!skill) {
  6455. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6456. return 0;
  6457. }
  6458. vector<GroundSpawnEntry*>::iterator itr;
  6459. GroundSpawnEntry* entry = 0;
  6460. bool can_harvest = false;
  6461. sint32 min_skill = -1;
  6462. int16 totalSkill = skill->current_val;
  6463. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6464. if(skillID != 0xFFFFFFFF)
  6465. {
  6466. ((Entity*)player)->MStats.lock();
  6467. totalSkill += ((Entity*)player)->stats[skillID];
  6468. ((Entity*)player)->MStats.unlock();
  6469. }
  6470. // first, iterate through groundspawn_entries, discard tables player cannot use
  6471. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6472. {
  6473. entry = *itr;
  6474. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6475. min_skill = entry->min_skill_level;
  6476. // if player lacks skill, skip table
  6477. if (entry->min_skill_level > totalSkill)
  6478. continue;
  6479. // if bonus, but player lacks level, skip table
  6480. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6481. continue;
  6482. can_harvest = true;
  6483. break;
  6484. }
  6485. lua_interface->SetBooleanValue(state, can_harvest);
  6486. // If false, send the message to the client
  6487. if (!can_harvest) {
  6488. Client* client = player->GetZone()->GetClientBySpawn(player);
  6489. if (client) {
  6490. string msg = "You do not have enough skill to ";
  6491. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6492. msg.append("gather");
  6493. else if (collection_skill == "Mining")
  6494. msg.append("mine");
  6495. else if (collection_skill == "Trapping")
  6496. msg.append("trap");
  6497. else if (collection_skill == "Foresting")
  6498. msg.append("forest");
  6499. else if (collection_skill == "Fishing")
  6500. msg.append("catch");
  6501. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6502. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6503. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6504. }
  6505. }
  6506. return 1;
  6507. }
  6508. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6509. if (!lua_interface)
  6510. return 0;
  6511. Spawn* player = lua_interface->GetSpawn(state);
  6512. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6513. if (!player) {
  6514. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6515. return 0;
  6516. }
  6517. if (!player->IsPlayer()) {
  6518. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6519. return 0;
  6520. }
  6521. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6522. lua_interface->SetBooleanValue(state, ret);
  6523. return 1;
  6524. }
  6525. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6526. // Check to see if we have a valid lua_interface
  6527. if (!lua_interface)
  6528. return 0;
  6529. // Get the spawn that is getting the pet
  6530. Spawn* spawn = lua_interface->GetSpawn(state);
  6531. Spawn* target = lua_interface->GetSpawn(state, 2);
  6532. // Get the DB ID of the pet
  6533. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6534. float x = lua_interface->GetFloatValue(state, 4);
  6535. float y = lua_interface->GetFloatValue(state, 5);
  6536. float z = lua_interface->GetFloatValue(state, 6);
  6537. // Get the spell that this command was called from
  6538. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6539. // Check to make sure the spawn pointer is valid
  6540. if (!spawn) {
  6541. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6542. return 0;
  6543. }
  6544. // Check to make sure the spawn is an entity
  6545. if (!spawn->IsEntity()) {
  6546. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6547. return 0;
  6548. }
  6549. if (!target) {
  6550. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6551. return 0;
  6552. }
  6553. if (!target->IsEntity()) {
  6554. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6555. return 0;
  6556. }
  6557. // Check to see if the DB ID for the pet is set
  6558. if (pet_id == 0) {
  6559. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6560. return 0;
  6561. }
  6562. // Check to see if the pointer to the spell is valid
  6563. if (!luaspell) {
  6564. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6565. return 0;
  6566. }
  6567. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6568. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6569. if (!pet) {
  6570. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6571. return 0;
  6572. }
  6573. // Check to make sure the pet is an npc
  6574. if (!pet->IsNPC()) {
  6575. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6576. return 0;
  6577. }
  6578. if (x == 0)
  6579. x = spawn->GetX();
  6580. if (y == 0)
  6581. y = spawn->GetY();
  6582. if (z == 0)
  6583. z = spawn->GetZ();
  6584. // Spawn the pet at the same location as the owner
  6585. pet->SetX(x);
  6586. pet->SetY(y);
  6587. pet->SetZ(z);
  6588. pet->SetLocation(spawn->GetLocation());
  6589. pet->SetHeading(spawn->GetHeading());
  6590. spawn->GetZone()->AddSpawn(pet);
  6591. /*
  6592. const char* spawn_script = world.GetSpawnScript(pet_id);
  6593. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6594. spawn->SetSpawnScript(string(spawn_script));
  6595. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6596. }*/
  6597. // Get a random pet name
  6598. string random_pet_name;
  6599. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6600. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6601. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6602. // Set the pets name
  6603. pet->SetName(random_pet_name.c_str());
  6604. // Set the level of the pet to the owners level
  6605. pet->SetLevel(spawn->GetLevel());
  6606. // Set the faction of the pet to the same faction as the owner
  6607. pet->SetFactionID(spawn->GetFactionID());
  6608. // Set the spawn as a pet
  6609. pet->SetPet(true);
  6610. // Give a pointer of the owner to the pet
  6611. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6612. // Set the pet type
  6613. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6614. // Set the spell id used to create this pet
  6615. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6616. // Set the spell tier used to create this pet
  6617. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6618. // Set the pets spawn type to 6
  6619. pet->SetSpawnType(6);
  6620. // Set the pets brain
  6621. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6622. // Check to see if the pet has a subtitle
  6623. if (strlen(pet->GetSubTitle()) > 0) {
  6624. // Add the players name to the front of the sub title
  6625. string pet_subtitle;
  6626. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6627. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6628. // Set the pets subtitle to the new one
  6629. pet->SetSubTitle(pet_subtitle.c_str());
  6630. }
  6631. // Set the pet as the return value for this function
  6632. lua_interface->SetSpawnValue(state, pet);
  6633. return 1;
  6634. }
  6635. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6636. if (!lua_interface)
  6637. return 0;
  6638. Spawn* spawn = lua_interface->GetSpawn(state);
  6639. Spawn* player = lua_interface->GetSpawn(state, 2);
  6640. float max_distance = lua_interface->GetFloatValue(state, 3);
  6641. string type = lua_interface->GetStringValue(state, 4);
  6642. if (!spawn || (spawn && spawn->IsPlayer())) {
  6643. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6644. return 0;
  6645. }
  6646. if (!player || (player && !player->IsPlayer())) {
  6647. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6648. return 0;
  6649. }
  6650. Client* client = 0;
  6651. if (player->GetZone())
  6652. client = player->GetZone()->GetClientBySpawn(player);
  6653. if (!client) {
  6654. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6655. return 0;
  6656. }
  6657. //Set max_distance to default if not set or not proper value
  6658. if (max_distance <= 0)
  6659. max_distance = 500;
  6660. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6661. if (packet) {
  6662. float unknown2_3 = 0;
  6663. int8 placement_mode = 0;
  6664. if (type == "wall") {
  6665. placement_mode = 2;
  6666. unknown2_3 = 150;
  6667. }
  6668. else if (type == "ceiling")
  6669. placement_mode = 1;
  6670. packet->setDataByName("placement_mode", placement_mode);
  6671. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6672. packet->setDataByName("model_type", spawn->GetModelType());
  6673. packet->setDataByName("unknown", 1); //size
  6674. packet->setDataByName("unknown2", 1); //size 2
  6675. packet->setDataByName("unknown2", .5, 1); //size 3
  6676. packet->setDataByName("unknown2", 3, 2);
  6677. packet->setDataByName("unknown2", unknown2_3, 3);
  6678. packet->setDataByName("max_distance", max_distance);
  6679. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6680. client->QueuePacket(packet->serialize());
  6681. safe_delete(packet);
  6682. }
  6683. return 0;
  6684. }
  6685. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6686. if (!lua_interface)
  6687. return 0;
  6688. Item* item = lua_interface->GetItem(state);
  6689. if (!item) {
  6690. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6691. return 0;
  6692. }
  6693. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6694. return 1;
  6695. }
  6696. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6697. if (!lua_interface)
  6698. return 0;
  6699. Spawn* spawn = lua_interface->GetSpawn(state);
  6700. if (!spawn) {
  6701. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6702. return 0;
  6703. }
  6704. if (spawn->GetZone())
  6705. spawn->GetZone()->AddTransportSpawn(spawn);
  6706. return 0;
  6707. }
  6708. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6709. if (!lua_interface)
  6710. return 0;
  6711. Skill* skill = lua_interface->GetSkill(state);
  6712. if (!skill) {
  6713. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6714. return 0;
  6715. }
  6716. lua_interface->SetInt32Value(state, skill->current_val);
  6717. return 1;
  6718. }
  6719. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6720. if (!lua_interface)
  6721. return 0;
  6722. Skill* skill = lua_interface->GetSkill(state);
  6723. if (!skill) {
  6724. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6725. return 0;
  6726. }
  6727. lua_interface->SetInt32Value(state, skill->max_val);
  6728. return 1;
  6729. }
  6730. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6731. if (!lua_interface)
  6732. return 0;
  6733. Skill* skill = lua_interface->GetSkill(state);
  6734. if (!skill) {
  6735. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6736. return 0;
  6737. }
  6738. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6739. return 1;
  6740. }
  6741. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6742. if (!lua_interface)
  6743. return 0;
  6744. Skill* skill = lua_interface->GetSkill(state);
  6745. int16 value = lua_interface->GetInt16Value(state, 2);
  6746. if (!skill) {
  6747. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6748. return 0;
  6749. }
  6750. skill->max_val = value;
  6751. if (skill->max_val < skill->current_val)
  6752. skill->current_val = skill->max_val;
  6753. return 0;
  6754. }
  6755. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6756. if (!lua_interface)
  6757. return 0;
  6758. Skill* skill = lua_interface->GetSkill(state);
  6759. int16 value = lua_interface->GetInt16Value(state, 2);
  6760. if (!skill) {
  6761. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6762. return 0;
  6763. }
  6764. if (value > skill->max_val)
  6765. skill->current_val = skill->max_val;
  6766. else
  6767. skill->current_val = value;
  6768. return 0;
  6769. }
  6770. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6771. if (!lua_interface)
  6772. return 0;
  6773. Spawn* player = lua_interface->GetSpawn(state);
  6774. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6775. if (skill_id > 0 && player && player->IsPlayer()) {
  6776. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6777. return 1;
  6778. }
  6779. return 0;
  6780. }
  6781. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6782. if (!lua_interface)
  6783. return 0;
  6784. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6785. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6786. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6787. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6788. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6789. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6790. if (player_spawn && player_spawn->IsPlayer()) {
  6791. Player* player = (Player*)player_spawn;
  6792. bool added = false;
  6793. if (!player->skill_list.HasSkill(skill_id)) {
  6794. player->AddSkill(skill_id, current_val, max_val, true);
  6795. added = true;
  6796. }
  6797. 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
  6798. Client* client = player->GetClient();
  6799. if (client) {
  6800. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6801. if (packet)
  6802. client->QueuePacket(packet);
  6803. }
  6804. }
  6805. if (added) {
  6806. lua_interface->SetBooleanValue(state, true);
  6807. return 1;
  6808. }
  6809. }
  6810. else {
  6811. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6812. }
  6813. }
  6814. else {
  6815. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6816. }
  6817. lua_interface->SetBooleanValue(state, false);
  6818. return 1;
  6819. }
  6820. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6821. if (!lua_interface)
  6822. return 0;
  6823. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6824. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6825. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6826. if (skill_id > 0) {
  6827. if (player_spawn && player_spawn->IsPlayer()) {
  6828. Player* player = (Player*)player_spawn;
  6829. if (player->skill_list.HasSkill(skill_id)) {
  6830. player->RemovePlayerSkill(skill_id);
  6831. if (!more_to_remove) {
  6832. Client* client = player->GetClient();
  6833. if (client) {
  6834. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6835. if (packet)
  6836. client->QueuePacket(packet);
  6837. }
  6838. }
  6839. }
  6840. }
  6841. else {
  6842. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6843. }
  6844. }
  6845. else {
  6846. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6847. }
  6848. return 0;
  6849. }
  6850. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6851. if (!lua_interface)
  6852. return 0;
  6853. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6854. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6855. int16 amount = lua_interface->GetInt8Value(state, 3);
  6856. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6857. if (amount > 0 && skill_type < 100) {
  6858. if (player_spawn && player_spawn->IsPlayer()) {
  6859. Player* player = (Player*)player_spawn;
  6860. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6861. if (!more_to_increase) {
  6862. Client* client = player->GetClient();
  6863. if (client) {
  6864. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6865. if (packet)
  6866. client->QueuePacket(packet);
  6867. }
  6868. }
  6869. }
  6870. else {
  6871. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6872. }
  6873. }
  6874. else {
  6875. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6876. }
  6877. return 0;
  6878. }
  6879. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6880. if (!lua_interface)
  6881. return 0;
  6882. Spawn* spawn = lua_interface->GetSpawn(state);
  6883. string name = lua_interface->GetStringValue(state, 2);
  6884. if (!spawn) {
  6885. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6886. return 0;
  6887. }
  6888. if (!spawn->IsEntity()) {
  6889. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6890. return 0;
  6891. }
  6892. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6893. if (skill) {
  6894. lua_interface->SetSkillValue(state, skill);
  6895. return 1;
  6896. }
  6897. return 0;
  6898. }
  6899. int EQ2Emu_lua_AddProc(lua_State* state) {
  6900. if (!lua_interface)
  6901. return 0;
  6902. Spawn* spawn = lua_interface->GetSpawn(state);
  6903. int8 type = lua_interface->GetInt8Value(state, 2);
  6904. float chance = lua_interface->GetFloatValue(state, 3);
  6905. Item* item = lua_interface->GetItem(state, 4);
  6906. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6907. LuaSpell* spell = 0;
  6908. if (!spawn && (!spell || !use_all_spelltargets)) {
  6909. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6910. return 0;
  6911. }
  6912. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6913. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6914. return 0;
  6915. }
  6916. if (!item)
  6917. spell = lua_interface->GetCurrentSpell(state);
  6918. if (!item && !spell) {
  6919. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6920. return 0;
  6921. }
  6922. if (spell && use_all_spelltargets) {
  6923. Spawn* target;
  6924. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6925. for (int8 i = 0; i < spell->targets.size(); i++) {
  6926. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6927. if (!target || !target->IsEntity())
  6928. continue;
  6929. ((Entity*)target)->AddProc(type, chance, item, spell);
  6930. }
  6931. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6932. }
  6933. else
  6934. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6935. return 0;
  6936. }
  6937. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6938. if (!lua_interface)
  6939. return 0;
  6940. Spawn* spawn = lua_interface->GetSpawn(state);
  6941. Item* item = lua_interface->GetItem(state, 2);
  6942. LuaSpell* spell = 0;
  6943. if (!spawn) {
  6944. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6945. return 0;
  6946. }
  6947. if (!spawn->IsEntity()) {
  6948. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6949. return 0;
  6950. }
  6951. if (!item)
  6952. spell = lua_interface->GetCurrentSpell(state);
  6953. if (!item && !spell) {
  6954. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6955. return 0;
  6956. }
  6957. if (spell) {
  6958. Spawn* target;
  6959. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6960. for (int8 i = 0; i < spell->targets.size(); i++) {
  6961. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6962. if (!target || !target->IsEntity())
  6963. continue;
  6964. ((Entity*)target)->RemoveProc(item, spell);
  6965. }
  6966. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6967. spell->caster->RemoveProc(item, spell);
  6968. }
  6969. else
  6970. ((Entity*)spawn)->RemoveProc(item, spell);
  6971. return 0;
  6972. }
  6973. int EQ2Emu_lua_Knockback(lua_State* state) {
  6974. if (!lua_interface)
  6975. return 0;
  6976. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6977. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6978. int32 duration = lua_interface->GetInt32Value(state, 3);
  6979. float vertical = lua_interface->GetFloatValue(state, 4);
  6980. float horizontal = lua_interface->GetFloatValue(state, 5);
  6981. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6982. if (!target_spawn) {
  6983. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6984. return 0;
  6985. }
  6986. if (!spawn) {
  6987. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6988. return 0;
  6989. }
  6990. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6991. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6992. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6993. if (packet) {
  6994. packet->setDataByName("target_x", target_spawn->GetX());
  6995. packet->setDataByName("target_y", target_spawn->GetY());
  6996. packet->setDataByName("target_z", target_spawn->GetZ());
  6997. packet->setDataByName("vertical_movement", vertical);
  6998. packet->setDataByName("horizontal_movement", horizontal);
  6999. if (use_heading)
  7000. packet->setDataByName("use_player_heading", 1);
  7001. client->QueuePacket(packet->serialize());
  7002. }
  7003. safe_delete(packet);
  7004. }
  7005. return 0;
  7006. }
  7007. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7008. if (!lua_interface)
  7009. return 0;
  7010. Spawn* spawn = lua_interface->GetSpawn(state);
  7011. if (!spawn) {
  7012. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7013. return 0;
  7014. }
  7015. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7016. return 1;
  7017. }
  7018. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7019. if (!lua_interface)
  7020. return 0;
  7021. Spawn* caster = lua_interface->GetSpawn(state);
  7022. Spawn* target = lua_interface->GetSpawn(state, 2);
  7023. string name = lua_interface->GetStringValue(state, 3);
  7024. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7025. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7026. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7027. string success_msg = lua_interface->GetStringValue(state, 7);
  7028. string effect_msg = lua_interface->GetStringValue(state, 8);
  7029. if (!caster) {
  7030. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7031. return 0;
  7032. }
  7033. if (!caster->IsEntity()) {
  7034. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7035. return 0;
  7036. }
  7037. if (!target) {
  7038. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7039. return 0;
  7040. }
  7041. if (!target->IsEntity()) {
  7042. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7043. return 0;
  7044. }
  7045. if (name.length() == 0) {
  7046. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7047. return 0;
  7048. }
  7049. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7050. return 0;
  7051. }
  7052. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7053. if (!lua_interface)
  7054. return 0;
  7055. string name = lua_interface->GetStringValue(state);
  7056. if (name.length() == 0) {
  7057. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7058. return 0;
  7059. }
  7060. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7061. if (!skill) {
  7062. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7063. return 0;
  7064. }
  7065. lua_interface->SetInt32Value(state, skill->skill_id);
  7066. return 1;
  7067. }
  7068. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7069. if (!lua_interface)
  7070. return 0;
  7071. Spawn* spawn = lua_interface->GetSpawn(state);
  7072. if (!spawn) {
  7073. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7074. return 0;
  7075. }
  7076. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7077. return 1;
  7078. }
  7079. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7080. if (!lua_interface)
  7081. return 0;
  7082. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7083. if (!luaspell) {
  7084. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7085. return 0;
  7086. }
  7087. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7088. return 1;
  7089. }
  7090. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7091. if (!lua_interface)
  7092. return 0;
  7093. Spawn* spawn = lua_interface->GetSpawn(state);
  7094. Spawn* target = lua_interface->GetSpawn(state, 2);
  7095. if (!spawn) {
  7096. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7097. return 0;
  7098. }
  7099. if (!spawn->IsEntity()) {
  7100. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7101. return 0;
  7102. }
  7103. if (!target) {
  7104. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7105. return 0;
  7106. }
  7107. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7108. return 1;
  7109. }
  7110. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7111. if (!lua_interface)
  7112. return 0;
  7113. Spawn* spawn = lua_interface->GetSpawn(state);
  7114. Spawn* target = lua_interface->GetSpawn(state, 2);
  7115. if (!spawn) {
  7116. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7117. return 0;
  7118. }
  7119. if (!spawn->IsEntity()) {
  7120. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7121. return 0;
  7122. }
  7123. if (!target) {
  7124. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7125. return 0;
  7126. }
  7127. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7128. return 1;
  7129. }
  7130. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7131. if (!lua_interface)
  7132. return 0;
  7133. Item* item = lua_interface->GetItem(state);
  7134. if (!item) {
  7135. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7136. return 0;
  7137. }
  7138. lua_interface->SetInt32Value(state, item->details.count);
  7139. return 1;
  7140. }
  7141. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7142. if (!lua_interface)
  7143. return 0;
  7144. Item* item = lua_interface->GetItem(state);
  7145. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7146. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7147. if (!item) {
  7148. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7149. return 0;
  7150. }
  7151. if (!owner) {
  7152. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7153. return 0;
  7154. }
  7155. if (!owner->IsPlayer()) {
  7156. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7157. return 0;
  7158. }
  7159. if (item->stack_count < new_count) {
  7160. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7161. return 0;
  7162. }
  7163. if (new_count > 0) {
  7164. item->details.count = new_count;
  7165. item->save_needed = true;
  7166. }
  7167. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7168. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7169. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7170. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7171. else
  7172. {
  7173. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7174. return 0;
  7175. }
  7176. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7177. if (!client)
  7178. return 0;
  7179. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7180. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7181. if (app)
  7182. client->QueuePacket(app);
  7183. return 0;
  7184. }
  7185. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7186. if (!lua_interface)
  7187. return 0;
  7188. int32 time = lua_interface->GetInt32Value(state);
  7189. string function = lua_interface->GetStringValue(state, 2);
  7190. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7191. Spawn* target = lua_interface->GetSpawn(state, 4);
  7192. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7193. if (time == 0) {
  7194. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7195. return 0;
  7196. }
  7197. if (function.length() == 0) {
  7198. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7199. return 0;
  7200. }
  7201. if (!spell) {
  7202. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. SpellScriptTimer* timer = new SpellScriptTimer;
  7206. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7207. #ifdef WIN32
  7208. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7209. #else
  7210. bzero(timer, sizeof(SpellScriptTimer));
  7211. #endif*/
  7212. timer->caster = 0;
  7213. timer->deleteWhenDone = false;
  7214. timer->target = 0;
  7215. timer->time = Timer::GetCurrentTime2() + time;
  7216. timer->customFunction = function;
  7217. timer->spell = spell;
  7218. if (caster)
  7219. timer->caster = caster->GetID();
  7220. if (target)
  7221. timer->target = target->GetID();
  7222. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7223. return 0;
  7224. }
  7225. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7226. if (!lua_interface)
  7227. return 0;
  7228. float hp_perc = lua_interface->GetFloatValue(state);
  7229. float power_perc = lua_interface->GetFloatValue(state, 2);
  7230. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7231. Spawn* target = lua_interface->GetSpawn(state, 4);
  7232. string heal_name = lua_interface->GetStringValue(state, 5);
  7233. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7234. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7235. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7236. if (!spell) {
  7237. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7238. return 0;
  7239. }
  7240. Entity* caster = spell->caster;
  7241. if (!caster) {
  7242. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7243. return 0;
  7244. }
  7245. Client* client = 0;
  7246. PendingResurrection* rez = 0;
  7247. ZoneServer* zone = spell->caster->GetZone();
  7248. if (!target) {
  7249. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7250. if (spell->targets.size() > 0) {
  7251. vector<int32> spell_targets = spell->targets;
  7252. for (int8 i = 0; i < spell_targets.size(); i++) {
  7253. target = zone->GetSpawnByID(spell_targets.at(i));
  7254. if (!target)
  7255. continue;
  7256. if (!target->IsPlayer())
  7257. continue;
  7258. client = target->GetZone()->GetClientBySpawn(target);
  7259. if (!client)
  7260. continue;
  7261. rez = client->GetCurrentRez();
  7262. if (rez->active)
  7263. continue;
  7264. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7265. rez->active = true;
  7266. rez->caster = caster;
  7267. rez->expire_timer = new Timer;
  7268. int32 duration = spell->spell->GetSpellDuration();
  7269. rez->expire_timer->Start(duration * 100);
  7270. rez->hp_perc = hp_perc;
  7271. rez->mp_perc = power_perc;
  7272. rez->range = spell->spell->GetSpellData()->range;
  7273. rez->spell_name = spell->spell->GetName();
  7274. if (heal_name.length() > 0)
  7275. rez->heal_name = heal_name;
  7276. else
  7277. rez->heal_name = rez->spell_name;
  7278. rez->no_calcs = no_calcs;
  7279. rez->crit_mod = crit_mod;
  7280. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7281. if (send_window)
  7282. client->SendResurrectionWindow();
  7283. else {
  7284. target->GetZone()->ResurrectSpawn(target, client);
  7285. rez->should_delete = true;
  7286. }
  7287. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7288. }
  7289. }
  7290. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7291. }
  7292. else {
  7293. client = target->GetZone()->GetClientBySpawn(target);
  7294. if (!client)
  7295. return 0;
  7296. rez = client->GetCurrentRez();
  7297. if (rez->active)
  7298. return 0;
  7299. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7300. rez->active = true;
  7301. rez->caster = caster;
  7302. rez->expire_timer = new Timer;
  7303. int32 duration = spell->spell->GetSpellDuration();
  7304. rez->expire_timer->Start(duration * 100);
  7305. rez->hp_perc = hp_perc;
  7306. rez->mp_perc = power_perc;
  7307. rez->range = spell->spell->GetSpellData()->range;
  7308. rez->spell_name = spell->spell->GetName();
  7309. if (heal_name.length() > 0)
  7310. rez->heal_name = heal_name;
  7311. else
  7312. rez->heal_name = rez->spell_name;
  7313. rez->no_calcs = no_calcs;
  7314. rez->crit_mod = crit_mod;
  7315. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7316. if (send_window)
  7317. client->SendResurrectionWindow();
  7318. else {
  7319. target->GetZone()->ResurrectSpawn(target, client);
  7320. rez->should_delete = true;
  7321. }
  7322. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7323. }
  7324. return 0;
  7325. }
  7326. int EQ2Emu_lua_SetVision(lua_State* state) {
  7327. if (!lua_interface)
  7328. return 0;
  7329. Spawn* spawn = lua_interface->GetSpawn(state);
  7330. int8 vision = lua_interface->GetInt8Value(state, 2);
  7331. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7332. if (!spawn) {
  7333. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7334. return 0;
  7335. }
  7336. if (!spawn->IsEntity()) {
  7337. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7338. return 0;
  7339. }
  7340. if (spell && spell->targets.size() > 0) {
  7341. ZoneServer* zone = spell->caster->GetZone();
  7342. for (int8 i = 0; i < spell->targets.size(); i++) {
  7343. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7344. if (target && target->IsEntity()) {
  7345. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7346. if (target->IsPlayer())
  7347. ((Player*)target)->SetCharSheetChanged(true);
  7348. }
  7349. }
  7350. }
  7351. else {
  7352. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7353. if (spawn->IsPlayer())
  7354. ((Player*)spawn)->SetCharSheetChanged(true);
  7355. }
  7356. return 0;
  7357. }
  7358. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7359. if (!lua_interface)
  7360. return 0;
  7361. Spawn* spawn = lua_interface->GetSpawn(state);
  7362. float intensity = lua_interface->GetFloatValue(state, 2);
  7363. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7364. if (!spawn) {
  7365. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7366. return 0;
  7367. }
  7368. if (!spawn->IsEntity()) {
  7369. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7370. return 0;
  7371. }
  7372. if (spell && spell->targets.size() > 0) {
  7373. ZoneServer* zone = spell->caster->GetZone();
  7374. for (int8 i = 0; i < spell->targets.size(); i++) {
  7375. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7376. if (target && target->IsEntity()) {
  7377. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7378. if (target->IsPlayer())
  7379. ((Player*)target)->SetCharSheetChanged(true);
  7380. }
  7381. }
  7382. }
  7383. else {
  7384. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7385. if (spawn->IsPlayer())
  7386. ((Player*)spawn)->SetCharSheetChanged(true);
  7387. }
  7388. return 0;
  7389. }
  7390. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7391. if (!lua_interface)
  7392. return 0;
  7393. Spawn* spawn = lua_interface->GetSpawn(state);
  7394. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7395. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7396. if (!spawn) {
  7397. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7398. return 0;
  7399. }
  7400. if (!spawn->IsEntity()) {
  7401. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7402. return 0;
  7403. }
  7404. if (spell && spell->targets.size() > 0) {
  7405. ZoneServer* zone = spell->caster->GetZone();
  7406. for (int8 i = 0; i < spell->targets.size(); i++) {
  7407. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7408. if (target && target->IsEntity()) {
  7409. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7410. if (target->IsPlayer())
  7411. ((Player*)target)->SetCharSheetChanged(true);
  7412. }
  7413. }
  7414. }
  7415. else {
  7416. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7417. if (spawn->IsPlayer())
  7418. ((Player*)spawn)->SetCharSheetChanged(true);
  7419. }
  7420. return 0;
  7421. }
  7422. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7423. if (!lua_interface)
  7424. return 0;
  7425. Item* item = lua_interface->GetItem(state);
  7426. int8 type = lua_interface->GetInt32Value(state, 2);
  7427. if (!item) {
  7428. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7429. return 0;
  7430. }
  7431. if (type == 1)
  7432. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7433. else if (type == 2)
  7434. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7435. return 1;
  7436. }
  7437. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7438. if (!lua_interface)
  7439. return 0;
  7440. Spawn* target = lua_interface->GetSpawn(state);
  7441. float val = lua_interface->GetFloatValue(state, 2);
  7442. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7443. // Added from Gangrenous post
  7444. if (spell && spell->resisted)
  7445. return 0;
  7446. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7447. if (val > 1.0f)
  7448. val = 1.0f - (val / 100.0f);
  7449. if (spell && spell->spell && spell->targets.size() > 0) {
  7450. ZoneServer* zone = spell->caster->GetZone();
  7451. for (int32 i = 0; i != spell->targets.size(); i++) {
  7452. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7453. if (spawn && spawn->IsEntity()) {
  7454. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7455. if (spawn->IsPlayer())
  7456. ((Player*)spawn)->SetCharSheetChanged(true);
  7457. }
  7458. }
  7459. }
  7460. else {
  7461. if (target && target->IsEntity()) {
  7462. ((Entity*)target)->SetSpeedMultiplier(val);
  7463. if (target->IsPlayer())
  7464. ((Player*)target)->SetCharSheetChanged(true);
  7465. }
  7466. }
  7467. return 0;
  7468. }
  7469. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7470. if (!lua_interface)
  7471. return 0;
  7472. Spawn* spawn = lua_interface->GetSpawn(state);
  7473. int16 model = lua_interface->GetInt16Value(state, 2);
  7474. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7475. if (spell && spell->spell && spell->targets.size() > 0) {
  7476. ZoneServer* zone = spell->caster->GetZone();
  7477. for (int32 i = 0; i < spell->targets.size(); i++) {
  7478. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7479. if (target)
  7480. target->SetIllusionModel(model);
  7481. }
  7482. }
  7483. else {
  7484. if (!spawn) {
  7485. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7486. return 0;
  7487. }
  7488. spawn->SetIllusionModel(model);
  7489. }
  7490. return 0;
  7491. }
  7492. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7493. if (!lua_interface)
  7494. return 0;
  7495. Spawn* spawn = lua_interface->GetSpawn(state);
  7496. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7497. if (spell && spell->spell && spell->targets.size() > 0) {
  7498. ZoneServer* zone = spell->caster->GetZone();
  7499. for (int32 i = 0; i < spell->targets.size(); i++) {
  7500. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7501. if (target)
  7502. target->SetIllusionModel(0);
  7503. }
  7504. }
  7505. else {
  7506. if (!spawn) {
  7507. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7508. return 0;
  7509. }
  7510. spawn->SetIllusionModel(0);
  7511. }
  7512. return 0;
  7513. }
  7514. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7515. if (!lua_interface)
  7516. return 0;
  7517. Spawn* caster = lua_interface->GetSpawn(state);
  7518. Spawn* target = lua_interface->GetSpawn(state, 2);
  7519. float chance = lua_interface->GetFloatValue(state, 3);
  7520. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7521. if (!caster) {
  7522. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7523. return 0;
  7524. }
  7525. if (!caster->IsEntity()) {
  7526. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7527. return 0;
  7528. }
  7529. if (!target) {
  7530. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7531. return 0;
  7532. }
  7533. if (!target->IsEntity()) {
  7534. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7535. return 0;
  7536. }
  7537. if (chance <= 0) {
  7538. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7539. return 0;
  7540. }
  7541. if (!spell) {
  7542. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7543. return 0;
  7544. }
  7545. if (((Entity*)caster)->GetThreatTransfer()) {
  7546. return 0;
  7547. }
  7548. ThreatTransfer* transfer = new ThreatTransfer;
  7549. transfer->Target = target->GetID();
  7550. transfer->Amount = chance;
  7551. transfer->Spell = spell;
  7552. ((Entity*)caster)->SetThreatTransfer(transfer);
  7553. return 0;
  7554. }
  7555. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7556. if (!lua_interface)
  7557. return 0;
  7558. Spawn* spawn = lua_interface->GetSpawn(state);
  7559. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7560. if (!spawn) {
  7561. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7562. return 0;
  7563. }
  7564. if (!spell) {
  7565. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7566. return 0;
  7567. }
  7568. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7569. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7570. ((Entity*)spawn)->SetThreatTransfer(0);
  7571. safe_delete(transfer);
  7572. }
  7573. return 0;
  7574. }
  7575. int EQ2Emu_lua_CureByType(lua_State* state) {
  7576. if (!lua_interface)
  7577. return 0;
  7578. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7579. if (!spell) {
  7580. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7581. return 0;
  7582. }
  7583. int8 cure_count = lua_interface->GetInt8Value(state);
  7584. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7585. string cure_name = lua_interface->GetStringValue(state, 3);
  7586. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7587. Spawn* target = lua_interface->GetSpawn(state, 5);
  7588. if (target) {
  7589. if (!target->IsEntity()) {
  7590. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7591. return 0;
  7592. }
  7593. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7594. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7595. }
  7596. else {
  7597. ZoneServer* zone = spell->caster->GetZone();
  7598. vector<int32> targets = spell->targets;
  7599. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7600. for (int8 i = 0; i < targets.size(); i++) {
  7601. target = zone->GetSpawnByID(targets.at(i));
  7602. if (!target || !target->IsEntity())
  7603. continue;
  7604. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7605. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7606. }
  7607. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7608. }
  7609. return 0;
  7610. }
  7611. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7612. if (!lua_interface)
  7613. return 0;
  7614. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7615. if (!spell) {
  7616. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7617. return 0;
  7618. }
  7619. int8 cure_count = lua_interface->GetInt8Value(state);
  7620. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7621. string cure_name = lua_interface->GetStringValue(state, 3);
  7622. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7623. Spawn* target = lua_interface->GetSpawn(state, 5);
  7624. if (target) {
  7625. if (!target->IsEntity()) {
  7626. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7627. return 0;
  7628. }
  7629. if (((Entity*)target)->GetDetCount() > 0)
  7630. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7631. }
  7632. else {
  7633. ZoneServer* zone = spell->caster->GetZone();
  7634. vector<int32> targets = spell->targets;
  7635. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7636. for (int8 i = 0; i < targets.size(); i++) {
  7637. target = zone->GetSpawnByID(targets.at(i));
  7638. if (!target || !target->IsEntity())
  7639. continue;
  7640. if (((Entity*)target)->GetDetCount() > 0)
  7641. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7642. }
  7643. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7644. }
  7645. return 0;
  7646. }
  7647. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7648. if (!lua_interface)
  7649. return 0;
  7650. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7651. if (!spell) {
  7652. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7653. return 0;
  7654. }
  7655. if (!spell->caster) {
  7656. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7657. return 0;
  7658. }
  7659. if (!spell->caster->GetZone()) {
  7660. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7661. return 0;
  7662. }
  7663. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7664. return 0;
  7665. }
  7666. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7667. if (!lua_interface)
  7668. return 0;
  7669. Spawn* spawn = lua_interface->GetSpawn(state);
  7670. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7671. if (!spell) {
  7672. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7673. return 0;
  7674. }
  7675. if (spawn && spawn->IsEntity())
  7676. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7677. else {
  7678. ZoneServer* zone = spell->caster->GetZone();
  7679. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7680. for (int32 i = 0; i < spell->targets.size(); i++) {
  7681. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7682. if (!spawn || !spawn->IsEntity())
  7683. continue;
  7684. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7685. }
  7686. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7687. }
  7688. return 0;
  7689. }
  7690. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7691. if (!lua_interface)
  7692. return 0;
  7693. Spawn* spawn = lua_interface->GetSpawn(state);
  7694. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7695. if (!spell) {
  7696. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7697. return 0;
  7698. }
  7699. if (spawn && spawn->IsEntity())
  7700. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7701. else {
  7702. ZoneServer* zone = spell->caster->GetZone();
  7703. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7704. for (int32 i = 0; i < spell->targets.size(); i++) {
  7705. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7706. if (!spawn || !spawn->IsEntity())
  7707. continue;
  7708. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7709. }
  7710. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7711. }
  7712. return 0;
  7713. }
  7714. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7715. if (!lua_interface)
  7716. return 0;
  7717. Spawn* caster = lua_interface->GetSpawn(state);
  7718. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7719. if (!caster) {
  7720. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7721. return 0;
  7722. }
  7723. if (!caster->IsPlayer()) {
  7724. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7725. return 0;
  7726. }
  7727. Spawn* target = caster->GetTarget();
  7728. if (!target) {
  7729. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7730. return 0;
  7731. }
  7732. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7733. if (!client) {
  7734. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7735. return 0;
  7736. }
  7737. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7738. if (ho) {
  7739. ho->SetTarget(target->GetID());
  7740. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7741. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7742. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7743. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7744. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7745. deque<GroupMemberInfo*>::iterator itr;
  7746. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7747. if (group)
  7748. {
  7749. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7750. deque<GroupMemberInfo*>* members = group->GetMembers();
  7751. for (itr = members->begin(); itr != members->end(); itr++) {
  7752. if ((*itr)->client)
  7753. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7754. }
  7755. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7756. }
  7757. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7758. }
  7759. else
  7760. safe_delete(ho);
  7761. }
  7762. else {
  7763. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7764. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7765. }
  7766. else
  7767. safe_delete(ho);
  7768. }
  7769. }
  7770. return 0;
  7771. }
  7772. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7773. if (!lua_interface)
  7774. return 0;
  7775. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7776. if (!spell) {
  7777. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7778. return 0;
  7779. }
  7780. int16 triggerCount = lua_interface->GetInt16Value(state);
  7781. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7782. if (!triggerCount) {
  7783. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7784. return 0;
  7785. }
  7786. spell->num_triggers = triggerCount;
  7787. spell->had_triggers = true;
  7788. spell->cancel_after_all_triggers = cancel_after_triggers;
  7789. return 0;
  7790. }
  7791. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7792. if (!lua_interface)
  7793. return 0;
  7794. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7795. if (!spell) {
  7796. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. lua_interface->SetInt32Value(state, spell->num_triggers);
  7800. return 1;
  7801. }
  7802. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7803. if (!lua_interface)
  7804. return 0;
  7805. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7806. if (!spell) {
  7807. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7808. return 0;
  7809. }
  7810. int16 remove_count = lua_interface->GetInt16Value(state);
  7811. if (!remove_count)
  7812. remove_count = 1;
  7813. if (remove_count >= spell->num_triggers) {
  7814. spell->num_triggers = 0;
  7815. if (spell->cancel_after_all_triggers)
  7816. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7817. }
  7818. else {
  7819. spell->num_triggers -= remove_count;
  7820. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7821. }
  7822. return 0;
  7823. }
  7824. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7825. if (!lua_interface)
  7826. return 0;
  7827. Spawn* spawn = lua_interface->GetSpawn(state);
  7828. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7829. if (!spawn) {
  7830. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7831. return 0;
  7832. }
  7833. if (!copy_spawn) {
  7834. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7835. return 0;
  7836. }
  7837. spawn->CopySpawnAppearance(copy_spawn);
  7838. return 0;
  7839. }
  7840. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7841. Spawn* spawn = lua_interface->GetSpawn(state);
  7842. int8 type = lua_interface->GetInt8Value(state, 2);
  7843. if (!spawn) {
  7844. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7845. return 0;
  7846. }
  7847. else if (!spawn->IsEntity()) {
  7848. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7849. return 0;
  7850. }
  7851. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7852. return 1;
  7853. }
  7854. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7855. if (!lua_interface)
  7856. return 0;
  7857. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7858. int8 type = lua_interface->GetInt8Value(state);
  7859. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7860. if (!spell) {
  7861. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7862. return 0;
  7863. }
  7864. if (spawn) {
  7865. if (!spawn->IsEntity()) {
  7866. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7867. return 0;
  7868. }
  7869. Entity* entity = ((Entity*)spawn);
  7870. entity->AddImmunity(spell, type);
  7871. }
  7872. else {
  7873. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7874. for (int8 i = 0; i < spell->targets.size(); i++) {
  7875. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7876. if (!spawn || !spawn->IsEntity())
  7877. continue;
  7878. Entity* entity = ((Entity*)spawn);
  7879. entity->AddImmunity(spell, type);
  7880. }
  7881. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7882. }
  7883. return 0;
  7884. }
  7885. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7886. if (!lua_interface)
  7887. return 0;
  7888. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7889. int8 type = lua_interface->GetInt8Value(state);
  7890. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7891. if (!spell) {
  7892. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7893. return 0;
  7894. }
  7895. if (spawn) {
  7896. if (!spawn->IsEntity()) {
  7897. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7898. return 0;
  7899. }
  7900. Entity* entity = ((Entity*)spawn);
  7901. entity->RemoveImmunity(spell, type);
  7902. }
  7903. else {
  7904. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7905. for (int8 i = 0; i < spell->targets.size(); i++) {
  7906. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7907. if (!spawn || !spawn->IsEntity())
  7908. continue;
  7909. Entity* entity = ((Entity*)spawn);
  7910. entity->RemoveImmunity(spell, type);
  7911. }
  7912. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7913. }
  7914. return 0;
  7915. }
  7916. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7917. if (!lua_interface)
  7918. return 0;
  7919. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7920. if (!spell) {
  7921. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7922. return 0;
  7923. }
  7924. float snare = lua_interface->GetFloatValue(state);
  7925. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7926. // convert the val to the speed multipler value (100 - val)
  7927. float val = 100.0 - snare;
  7928. val /= 100.0;
  7929. if (spawn) {
  7930. if (!spawn->IsEntity()) {
  7931. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7932. return 0;
  7933. }
  7934. ((Entity*)spawn)->SetSnareValue(spell, val);
  7935. }
  7936. else {
  7937. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7938. for (int8 i = 0; i < spell->targets.size(); i++) {
  7939. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7940. if (!spawn || !spawn->IsEntity())
  7941. continue;
  7942. ((Entity*)spawn)->SetSnareValue(spell, val);
  7943. }
  7944. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7945. }
  7946. return 0;
  7947. }
  7948. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7949. if (!lua_interface)
  7950. return 0;
  7951. Spawn* spawn = lua_interface->GetSpawn(state);
  7952. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7953. if (!spawn) {
  7954. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7955. return 0;
  7956. }
  7957. if (race_id == 0) {
  7958. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7959. return 0;
  7960. }
  7961. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7962. return 1;
  7963. }
  7964. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7965. if (!lua_interface)
  7966. return 0;
  7967. Spawn* spawn = lua_interface->GetSpawn(state);
  7968. if (!spawn) {
  7969. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7970. return 0;
  7971. }
  7972. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7973. return 1;
  7974. }
  7975. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7976. if (!lua_interface)
  7977. return 0;
  7978. Spawn* spawn = lua_interface->GetSpawn(state);
  7979. if (!spawn) {
  7980. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7981. return 0;
  7982. }
  7983. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7984. return 1;
  7985. }
  7986. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7987. if (!lua_interface)
  7988. return 0;
  7989. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7990. if (!spell) {
  7991. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7992. return 0;
  7993. }
  7994. lua_interface->SetStringValue(state, spell->spell->GetName());
  7995. return 1;
  7996. }
  7997. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7998. if (!lua_interface)
  7999. return 0;
  8000. Quest* quest = lua_interface->GetQuest(state);
  8001. if (!quest) {
  8002. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8003. return 0;
  8004. }
  8005. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8006. return 1;
  8007. }
  8008. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8009. if (!lua_interface)
  8010. return 0;
  8011. Quest* quest = lua_interface->GetQuest(state);
  8012. int32 flags = lua_interface->GetInt32Value(state, 2);
  8013. if (!quest) {
  8014. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8015. return 0;
  8016. }
  8017. quest->SetQuestFlags(flags);
  8018. return 0;
  8019. }
  8020. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8021. if (!lua_interface)
  8022. return 0;
  8023. Quest* quest = lua_interface->GetQuest(state);
  8024. Spawn* player = lua_interface->GetSpawn(state, 2);
  8025. int32 step = lua_interface->GetInt32Value(state, 3);
  8026. int32 duration = lua_interface->GetInt32Value(state, 4);
  8027. string action = lua_interface->GetStringValue(state, 5);
  8028. if (!quest) {
  8029. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8030. return 0;
  8031. }
  8032. if (!player) {
  8033. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8034. return 0;
  8035. }
  8036. if (!player->IsPlayer()) {
  8037. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8038. return 0;
  8039. }
  8040. if (step == 0) {
  8041. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8042. return 0;
  8043. }
  8044. if (duration == 0) {
  8045. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8046. return 0;
  8047. }
  8048. if (action.length() == 0) {
  8049. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8050. return 0;
  8051. }
  8052. Client* client = player->GetZone()->GetClientBySpawn(player);
  8053. if (!client) {
  8054. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8055. return 0;
  8056. }
  8057. quest->SetTimerStep(step);
  8058. quest->AddFailedAction(step, action);
  8059. quest->SetStepTimer(duration);
  8060. client->AddQuestTimer(quest->GetQuestID());
  8061. return 0;
  8062. }
  8063. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8064. if (!lua_interface)
  8065. return 0;
  8066. Quest* quest = lua_interface->GetQuest(state);
  8067. Spawn* player = lua_interface->GetSpawn(state, 2);
  8068. if (!quest) {
  8069. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8070. return 0;
  8071. }
  8072. if (!player) {
  8073. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8074. return 0;
  8075. }
  8076. if (!player->IsPlayer()) {
  8077. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8078. return 0;
  8079. }
  8080. Client* client = player->GetZone()->GetClientBySpawn(player);
  8081. if (!client) {
  8082. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8083. return 0;
  8084. }
  8085. quest->SetTimerStep(0);
  8086. quest->SetStepTimer(0);
  8087. client->RemoveQuestTimer(quest->GetQuestID());
  8088. return 0;
  8089. }
  8090. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8091. if (!lua_interface)
  8092. return 0;
  8093. Spawn* player = lua_interface->GetSpawn(state);
  8094. Quest* quest = lua_interface->GetQuest(state, 2);
  8095. int32 step = lua_interface->GetInt32Value(state, 3);
  8096. if (!player) {
  8097. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8098. return 0;
  8099. }
  8100. if (!player->IsPlayer()) {
  8101. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8102. return 0;
  8103. }
  8104. if (!quest) {
  8105. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8106. return 0;
  8107. }
  8108. if (step == 0) {
  8109. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8110. return 0;
  8111. }
  8112. Client* client = player->GetZone()->GetClientBySpawn(player);
  8113. if (!client) {
  8114. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8115. return 0;
  8116. }
  8117. if (quest->RemoveQuestStep(step, client)) {
  8118. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8119. client->GetCurrentZone()->SendQuestUpdates(client);
  8120. }
  8121. else
  8122. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8123. return 0;
  8124. }
  8125. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8126. if (!lua_interface)
  8127. return 0;
  8128. Quest* quest = lua_interface->GetQuest(state, 1);
  8129. int32 step = lua_interface->GetInt32Value(state, 2);
  8130. string desc = lua_interface->GetStringValue(state, 3);
  8131. string task_group = lua_interface->GetStringValue(state, 4);
  8132. if (!quest) {
  8133. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8134. return 0;
  8135. }
  8136. if (step == 0) {
  8137. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8138. return 0;
  8139. }
  8140. QuestStep* quest_step = quest->GetQuestStep(step);
  8141. if (!quest_step) {
  8142. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8143. return 0;
  8144. }
  8145. quest_step->SetStepProgress(0);
  8146. quest_step->SetTaskGroup(task_group);
  8147. quest_step->SetDescription(desc);
  8148. return 0;
  8149. }
  8150. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8151. if (!lua_interface)
  8152. return 0;
  8153. Quest* quest = lua_interface->GetQuest(state);
  8154. int32 step = lua_interface->GetInt32Value(state, 2);
  8155. string action = lua_interface->GetStringValue(state, 3);
  8156. if (!quest) {
  8157. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8158. return 0;
  8159. }
  8160. if (step == 0) {
  8161. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8162. return 0;
  8163. }
  8164. if (action.length() == 0) {
  8165. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8166. return 0;
  8167. }
  8168. quest->AddFailedAction(step, action);
  8169. return 0;
  8170. }
  8171. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8172. if (!lua_interface)
  8173. return 0;
  8174. Spawn* player = lua_interface->GetSpawn(state);
  8175. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8176. int32 step = lua_interface->GetInt32Value(state, 3);
  8177. if (!player) {
  8178. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8179. return 0;
  8180. }
  8181. if (!player->IsPlayer()) {
  8182. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8183. return 0;
  8184. }
  8185. if (quest_id == 0) {
  8186. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8187. return 0;
  8188. }
  8189. if (step == 0) {
  8190. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8191. return 0;
  8192. }
  8193. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8194. if (!quest) {
  8195. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8196. return 0;
  8197. }
  8198. quest->StepFailed(step);
  8199. return 0;
  8200. }
  8201. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8202. if (!lua_interface)
  8203. return 0;
  8204. Spawn* player = lua_interface->GetSpawn(state);
  8205. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8206. if (!player) {
  8207. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8208. return 0;
  8209. }
  8210. if (!player->IsPlayer()) {
  8211. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8212. return 0;
  8213. }
  8214. if (quest_id == 0) {
  8215. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8216. return 0;
  8217. }
  8218. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8219. if (!quest) {
  8220. lua_interface->SetInt32Value(state, 0);
  8221. return 1;
  8222. }
  8223. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8224. return 1;
  8225. }
  8226. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8227. if (!lua_interface)
  8228. return 0;
  8229. string name = lua_interface->GetStringValue(state);
  8230. string value = lua_interface->GetStringValue(state, 2);
  8231. string comment = lua_interface->GetStringValue(state, 3);
  8232. if (name.length() == 0) {
  8233. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8234. return 0;
  8235. }
  8236. if (value.length() == 0) {
  8237. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8238. return 0;
  8239. }
  8240. string varname = string("lua_").append(name);
  8241. Variable* var = variables.FindVariable(varname);
  8242. if (var)
  8243. var->SetValue(value.c_str());
  8244. else {
  8245. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8246. variables.AddVariable(var);
  8247. }
  8248. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8249. return 0;
  8250. }
  8251. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8252. if (!lua_interface)
  8253. return 0;
  8254. string name = lua_interface->GetStringValue(state);
  8255. if (name.length() == 0) {
  8256. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8257. return 0;
  8258. }
  8259. string varname = string("lua_").append(name);
  8260. Variable* var = variables.FindVariable(varname);
  8261. if (var)
  8262. lua_interface->SetStringValue(state, var->GetValue());
  8263. else
  8264. lua_interface->SetStringValue(state, "NULL");
  8265. return 1;
  8266. }
  8267. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8268. if (!lua_interface)
  8269. return 0;
  8270. Spawn* player = lua_interface->GetSpawn(state);
  8271. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8272. if (!player) {
  8273. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8274. return 0;
  8275. }
  8276. if (!player->IsPlayer()) {
  8277. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8278. return 0;
  8279. }
  8280. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8281. return 1;
  8282. }
  8283. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8284. if (!lua_interface)
  8285. return 0;
  8286. Spawn* player = lua_interface->GetSpawn(state);
  8287. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8288. if (!player) {
  8289. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8290. return 0;
  8291. }
  8292. if (!player->IsPlayer()) {
  8293. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8294. return 0;
  8295. }
  8296. Language* language = master_languages_list.GetLanguage(language_id);
  8297. if (language)
  8298. {
  8299. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8300. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8301. }
  8302. return 0;
  8303. }
  8304. int EQ2Emu_lua_IsNight(lua_State* state) {
  8305. if (!lua_interface)
  8306. return 0;
  8307. ZoneServer* zone = lua_interface->GetZone(state);
  8308. if (!zone) {
  8309. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8310. return 0;
  8311. }
  8312. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8313. return 1;
  8314. }
  8315. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8316. if (!lua_interface)
  8317. return 0;
  8318. Spawn* spawn = lua_interface->GetSpawn(state);
  8319. if (!spawn) {
  8320. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8321. return 0;
  8322. }
  8323. if (!spawn->IsWidget()) {
  8324. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. ((Widget*)spawn)->SetMultiFloorLift(true);
  8328. if (spawn->GetZone())
  8329. spawn->GetZone()->AddTransportSpawn(spawn);
  8330. return 0;
  8331. }
  8332. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8333. if (!lua_interface)
  8334. return 0;
  8335. Spawn* player = lua_interface->GetSpawn(state);
  8336. int32 path = lua_interface->GetInt32Value(state, 2);
  8337. if (!player) {
  8338. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8339. return 0;
  8340. }
  8341. if (!player->IsPlayer()) {
  8342. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8343. return 0;
  8344. }
  8345. if (path == 0) {
  8346. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8347. return 0;
  8348. }
  8349. Client* client = player->GetZone()->GetClientBySpawn(player);
  8350. if (!client) {
  8351. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8352. return 0;
  8353. }
  8354. client->SendFlightAutoMount(path);
  8355. return 0;
  8356. }
  8357. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8358. if (!lua_interface)
  8359. return 0;
  8360. Spawn* player = lua_interface->GetSpawn(state);
  8361. if (!player) {
  8362. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8363. return 0;
  8364. }
  8365. if (!player->IsPlayer()) {
  8366. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8367. return 0;
  8368. }
  8369. Client* client = player->GetZone()->GetClientBySpawn(player);
  8370. if (!client) {
  8371. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8372. return 0;
  8373. }
  8374. client->EndAutoMount();
  8375. return 0;
  8376. }
  8377. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8378. if (!lua_interface)
  8379. return 0;
  8380. Spawn* player = lua_interface->GetSpawn(state);
  8381. if (!player) {
  8382. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8383. return 0;
  8384. }
  8385. if (!player->IsPlayer()) {
  8386. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8387. return 0;
  8388. }
  8389. Client* client = player->GetZone()->GetClientBySpawn(player);
  8390. if (!client) {
  8391. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8392. return 0;
  8393. }
  8394. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8395. return 1;
  8396. }
  8397. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8398. if (!lua_interface)
  8399. return 0;
  8400. Spawn* player = lua_interface->GetSpawn(state);
  8401. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8402. int32 value = lua_interface->GetInt32Value(state, 3);
  8403. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8404. if (!player) {
  8405. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8406. return 0;
  8407. }
  8408. if (!player->IsPlayer()) {
  8409. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8410. return 0;
  8411. }
  8412. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8413. return 0;
  8414. }
  8415. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8416. if (!lua_interface)
  8417. return 0;
  8418. Spawn* player = lua_interface->GetSpawn(state);
  8419. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8420. if (!player) {
  8421. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8422. return 0;
  8423. }
  8424. if (!player->IsPlayer()) {
  8425. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8426. return 0;
  8427. }
  8428. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8429. if (!hd)
  8430. return 0;
  8431. lua_interface->SetInt32Value(state, hd->Value);
  8432. lua_interface->SetInt32Value(state, hd->Value2);
  8433. return 2;
  8434. }
  8435. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8436. if (!lua_interface)
  8437. return 0;
  8438. Spawn* spawn = lua_interface->GetSpawn(state);
  8439. int32 grid = lua_interface->GetInt32Value(state, 2);
  8440. if (!spawn) {
  8441. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8442. return 0;
  8443. }
  8444. if (grid == 0) {
  8445. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8446. return 0;
  8447. }
  8448. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8449. return 0;
  8450. }
  8451. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8452. if (!lua_interface)
  8453. return 0;
  8454. Spawn* spawn = lua_interface->GetSpawn(state);
  8455. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8456. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8457. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8458. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8459. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8460. if (!spawn) {
  8461. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8462. return 0;
  8463. }
  8464. //Add this quest to the list of required quests for this spawn
  8465. spawn->SetRequiredHistory(event_id, value1, value2);
  8466. //If private spawn value set
  8467. if (private_spawn) {
  8468. //Set the spawn to be private when not granted access via history
  8469. spawn->AddAllowAccessSpawn(spawn);
  8470. spawn->SetPrivateQuestSpawn(true);
  8471. }
  8472. //This value will override vis_flags in the vis packet
  8473. if (flag_override > 0)
  8474. spawn->SetQuestsRequiredOverride(flag_override);
  8475. return 0;
  8476. }
  8477. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8478. if (!lua_interface)
  8479. return 0;
  8480. Spawn* player = lua_interface->GetSpawn(state);
  8481. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8482. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8483. if (!player) {
  8484. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8485. return 0;
  8486. }
  8487. if (!player->IsPlayer()) {
  8488. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8489. return 0;
  8490. }
  8491. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8492. return 1;
  8493. }
  8494. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8495. if (!lua_interface)
  8496. return 0;
  8497. Spawn* player = lua_interface->GetSpawn(state);
  8498. int8 level = lua_interface->GetInt8Value(state, 2);
  8499. if (!player) {
  8500. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8501. return 0;
  8502. }
  8503. if (!player->IsPlayer()) {
  8504. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8505. return 0;
  8506. }
  8507. if (level == 0) {
  8508. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8509. return 0;
  8510. }
  8511. Client* client = player->GetZone()->GetClientBySpawn(player);
  8512. if (!client) {
  8513. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8514. return 0;
  8515. }
  8516. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8517. return 0;
  8518. }
  8519. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8520. if (!lua_interface)
  8521. return 0;
  8522. Spawn* player = lua_interface->GetSpawn(state);
  8523. int32 amount = lua_interface->GetInt32Value(state, 2);
  8524. if (!player) {
  8525. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8526. return 0;
  8527. }
  8528. if (!player->IsPlayer()) {
  8529. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8530. return 0;
  8531. }
  8532. if (amount == 0) {
  8533. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8534. return 0;
  8535. }
  8536. ((Player*)player)->AddCoins(amount);
  8537. return 0;
  8538. }
  8539. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8540. if (!lua_interface)
  8541. return 0;
  8542. Spawn* player = lua_interface->GetSpawn(state);
  8543. int32 amount = lua_interface->GetInt32Value(state, 2);
  8544. if (!player) {
  8545. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8546. return 0;
  8547. }
  8548. if (!player->IsPlayer()) {
  8549. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8550. return 0;
  8551. }
  8552. if (amount == 0) {
  8553. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8554. return 0;
  8555. }
  8556. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8557. return 1;
  8558. }
  8559. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8560. if (!lua_interface)
  8561. return 0;
  8562. ZoneServer* zone = lua_interface->GetZone(state);
  8563. if (!zone) {
  8564. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8565. return 0;
  8566. }
  8567. vector<Entity*> players = zone->GetPlayers();
  8568. if (players.size() == 0)
  8569. return 0;
  8570. lua_createtable(state, players.size(), 0);
  8571. int newTable = lua_gettop(state);
  8572. for (int32 i = 0; i < players.size(); i++) {
  8573. lua_interface->SetSpawnValue(state, players.at(i));
  8574. lua_rawseti(state, newTable, i + 1);
  8575. }
  8576. return 1;
  8577. }
  8578. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8579. if (!lua_interface)
  8580. return 0;
  8581. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8582. if (!zone) {
  8583. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8584. return 0;
  8585. }
  8586. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8587. //Map of <placement_id, location_id>
  8588. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8589. map<int32, int32>::iterator itr;
  8590. vector<Spawn*> group;
  8591. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8592. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8593. if (!location) {
  8594. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8595. return 0;
  8596. }
  8597. Spawn* spawn = 0;
  8598. if (location->entities[0]) {
  8599. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8600. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8601. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8602. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8603. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8604. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8605. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8606. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8607. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8608. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8609. if (spawn) {
  8610. const char* script = 0;
  8611. for (int x = 0; x < 3; x++) {
  8612. switch (x) {
  8613. case 0:
  8614. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8615. break;
  8616. case 1:
  8617. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8618. break;
  8619. case 2:
  8620. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8621. break;
  8622. }
  8623. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8624. spawn->SetSpawnScript(string(script));
  8625. break;
  8626. }
  8627. }
  8628. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8629. lua_interface->SetSpawnValue(state, spawn);
  8630. group.push_back(spawn);
  8631. }
  8632. else {
  8633. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8634. safe_delete(spawn);
  8635. }
  8636. }
  8637. }
  8638. if (!group.empty()) {
  8639. lua_createtable(state, group.size(), 0);
  8640. int newTable = lua_gettop(state);
  8641. for (int32 i = 0; i < group.size(); i++) {
  8642. lua_interface->SetSpawnValue(state, group[i]);
  8643. lua_rawseti(state, newTable, i + 1);
  8644. }
  8645. }
  8646. else
  8647. lua_pushnil(state);
  8648. return 1;
  8649. }
  8650. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8651. if (!lua_interface)
  8652. return 0;
  8653. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8654. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8655. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8656. if (!spawn) {
  8657. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8658. return 0;
  8659. }
  8660. if (anim_id == 0) {
  8661. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8662. return 0;
  8663. }
  8664. if (leeway == 0)
  8665. leeway = 5000;
  8666. spawn->SetSpawnAnim(anim_id);
  8667. spawn->SetSpawnAnimLeeway(leeway);
  8668. return 0;
  8669. }
  8670. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8671. if (!lua_interface)
  8672. return 0;
  8673. Spawn* player = lua_interface->GetSpawn(state);
  8674. if (!player) {
  8675. return 0;
  8676. }
  8677. Client* client = player->GetZone()->GetClientBySpawn(player);
  8678. if (!client) {
  8679. return 0;
  8680. }
  8681. lua_interface->SetInt32Value(state, client->GetVersion());
  8682. return 1;
  8683. }
  8684. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8685. if (!lua_interface)
  8686. return 0;
  8687. Item* item = lua_interface->GetItem(state);
  8688. if (!item) {
  8689. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8690. return 0;
  8691. }
  8692. lua_interface->SetInt32Value(state, item->details.item_id);
  8693. return 1;
  8694. }
  8695. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8696. if (!lua_interface)
  8697. return 0;
  8698. Spawn* spawn = lua_interface->GetSpawn(state);
  8699. if (!spawn) {
  8700. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8701. return 0;
  8702. }
  8703. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8704. return 1;
  8705. }
  8706. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8707. if (!lua_interface)
  8708. return 0;
  8709. Spawn* spawn = lua_interface->GetSpawn(state);
  8710. if (!spawn) {
  8711. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8712. return 0;
  8713. }
  8714. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8715. return 1;
  8716. }
  8717. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8718. if (!lua_interface)
  8719. return 0;
  8720. Spawn* spawn = lua_interface->GetSpawn(state);
  8721. if (!spawn) {
  8722. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8723. return 0;
  8724. }
  8725. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8726. return 1;
  8727. }
  8728. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8729. if (!lua_interface)
  8730. return 0;
  8731. Spawn* spawn = lua_interface->GetSpawn(state);
  8732. if (!spawn) {
  8733. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8734. return 0;
  8735. }
  8736. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8737. return 1;
  8738. }
  8739. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8740. if (!lua_interface)
  8741. return 0;
  8742. Spawn* spawn = lua_interface->GetSpawn(state);
  8743. float pct = lua_interface->GetFloatValue(state, 2);
  8744. if (!spawn) {
  8745. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8746. return 0;
  8747. }
  8748. if (pct == 0) {
  8749. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8750. return 0;
  8751. }
  8752. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8753. lua_interface->SetInt32Value(state, amount);
  8754. return 1;
  8755. }
  8756. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8757. if (!lua_interface)
  8758. return 0;
  8759. Spawn* spawn = lua_interface->GetSpawn(state);
  8760. float pct = lua_interface->GetFloatValue(state, 2);
  8761. if (!spawn) {
  8762. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8763. return 0;
  8764. }
  8765. if (pct == 0) {
  8766. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8767. return 0;
  8768. }
  8769. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8770. lua_interface->SetInt32Value(state, amount);
  8771. return 1;
  8772. }
  8773. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8774. if (!lua_interface)
  8775. return 0;
  8776. Spawn* spawn = lua_interface->GetSpawn(state);
  8777. if (!spawn) {
  8778. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8779. return 0;
  8780. }
  8781. if (!spawn->IsPlayer()) {
  8782. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8783. return 0;
  8784. }
  8785. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8786. return 1;
  8787. }
  8788. int EQ2Emu_lua_Evac(lua_State* state) {
  8789. if (!lua_interface)
  8790. return 0;
  8791. Spawn* target = lua_interface->GetSpawn(state);
  8792. if (target) {
  8793. float x = target->GetZone()->GetSafeX();
  8794. float y = target->GetZone()->GetSafeY();
  8795. float z = target->GetZone()->GetSafeZ();
  8796. float h = target->GetZone()->GetSafeHeading();
  8797. target->SetX(x);
  8798. target->SetY(y);
  8799. target->SetZ(z);
  8800. target->SetHeading(h);
  8801. target->SetSpawnOrigX(target->GetX());
  8802. target->SetSpawnOrigY(target->GetY());
  8803. target->SetSpawnOrigZ(target->GetZ());
  8804. target->SetSpawnOrigHeading(target->GetHeading());
  8805. if (target->IsPlayer()) {
  8806. Client* client = target->GetZone()->GetClientBySpawn(target);
  8807. if (client) {
  8808. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8809. if (packet)
  8810. {
  8811. packet->setDataByName("x", x);
  8812. packet->setDataByName("y", y);
  8813. packet->setDataByName("z", z);
  8814. client->QueuePacket(packet->serialize());
  8815. safe_delete(packet);
  8816. }
  8817. }
  8818. }
  8819. }
  8820. else {
  8821. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8822. ZoneServer* zone = spell->caster->GetZone();
  8823. float x = spell->caster->GetZone()->GetSafeX();
  8824. float y = spell->caster->GetZone()->GetSafeY();
  8825. float z = spell->caster->GetZone()->GetSafeZ();
  8826. float h = spell->caster->GetZone()->GetSafeHeading();
  8827. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8828. for (int32 i = 0; i < spell->targets.size(); i++) {
  8829. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8830. if (!target2)
  8831. continue;
  8832. target2->SetX(x);
  8833. target2->SetY(y);
  8834. target2->SetZ(z);
  8835. target2->SetHeading(h);
  8836. target2->SetSpawnOrigX(target2->GetX());
  8837. target2->SetSpawnOrigY(target2->GetY());
  8838. target2->SetSpawnOrigZ(target2->GetZ());
  8839. target2->SetSpawnOrigHeading(target2->GetHeading());
  8840. if (target2->IsPlayer()) {
  8841. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8842. if (client) {
  8843. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8844. if (packet)
  8845. {
  8846. client->SetReloadingZone(true);
  8847. packet->setDataByName("x", x);
  8848. packet->setDataByName("y", y);
  8849. packet->setDataByName("z", z);
  8850. client->QueuePacket(packet->serialize());
  8851. safe_delete(packet);
  8852. }
  8853. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8854. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8855. }
  8856. }
  8857. }
  8858. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8859. }
  8860. return 0;
  8861. }
  8862. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8863. if (!lua_interface)
  8864. return 0;
  8865. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8866. if (!luaspell) {
  8867. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8868. return 0;
  8869. }
  8870. int8 tier = luaspell->spell->GetSpellTier();
  8871. lua_interface->SetInt32Value(state, tier);
  8872. return 1;
  8873. }
  8874. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8875. if (!lua_interface)
  8876. return 0;
  8877. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8878. if (!luaspell) {
  8879. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8880. return 0;
  8881. }
  8882. int32 spell_id = luaspell->spell->GetSpellID();
  8883. lua_interface->SetInt32Value(state, spell_id);
  8884. return 1;
  8885. }
  8886. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8887. if (!lua_interface)
  8888. return 0;
  8889. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8890. if (!spawn) {
  8891. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8892. return 0;
  8893. }
  8894. if (!spawn->IsPlayer()) {
  8895. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8896. return 0;
  8897. }
  8898. ZoneServer* zone = spawn->GetZone();
  8899. if (!zone) {
  8900. return 0;
  8901. }
  8902. Client* client = zone->GetClientBySpawn(spawn);
  8903. if (!client) {
  8904. return 0;
  8905. }
  8906. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8907. return 0;
  8908. }
  8909. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8910. if (!lua_interface)
  8911. return 0;
  8912. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8913. if (!spawn) {
  8914. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8915. return 0;
  8916. }
  8917. if (!spawn->IsPlayer()) {
  8918. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8919. return 0;
  8920. }
  8921. ZoneServer* zone = spawn->GetZone();
  8922. if (!zone) {
  8923. return 0;
  8924. }
  8925. Client* client = zone->GetClientBySpawn(spawn);
  8926. if (!client) {
  8927. return 0;
  8928. }
  8929. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8930. return 0;
  8931. }
  8932. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8933. if (!lua_interface)
  8934. return 0;
  8935. Spawn* caster = lua_interface->GetSpawn(state);
  8936. Spawn* target = lua_interface->GetSpawn(state, 2);
  8937. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8938. string spell_name = lua_interface->GetStringValue(state, 4);
  8939. if (!caster) {
  8940. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8941. return 0;
  8942. }
  8943. if (!caster->IsEntity()) {
  8944. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8945. return 0;
  8946. }
  8947. if (!target) {
  8948. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8949. return 0;
  8950. }
  8951. if (!target->IsEntity()) {
  8952. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8953. return 0;
  8954. }
  8955. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8956. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8957. return 0;
  8958. }
  8959. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8960. if (!lua_interface)
  8961. return 0;
  8962. Spawn* player = lua_interface->GetSpawn(state);
  8963. int32 amount = lua_interface->GetInt32Value(state, 2);
  8964. if (player && player->IsPlayer() && amount > 0) {
  8965. ((Player*)player)->AddXP(amount);
  8966. ((Player*)player)->SetCharSheetChanged(true);
  8967. Client* client = player->GetZone()->GetClientBySpawn(player);
  8968. if (client) {
  8969. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8970. }
  8971. }
  8972. return 0;
  8973. }
  8974. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8975. if (!lua_interface)
  8976. return 0;
  8977. Spawn* player = lua_interface->GetSpawn(state);
  8978. int8 type = lua_interface->GetInt8Value(state, 2);
  8979. string text = lua_interface->GetStringValue(state, 3);
  8980. Client* client = 0;
  8981. if (player && player->IsPlayer())
  8982. client = player->GetZone()->GetClientBySpawn(player);
  8983. if (!client || text.length() == 0) {
  8984. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8985. return 0;
  8986. }
  8987. client->SimpleMessage(type, text.c_str());
  8988. return 0;
  8989. }
  8990. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8991. if (!lua_interface)
  8992. return 0;
  8993. Spawn* player = lua_interface->GetSpawn(state);
  8994. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8995. Client* client = 0;
  8996. if (player && player->IsPlayer())
  8997. client = player->GetZone()->GetClientBySpawn(player);
  8998. if (!client || !spawn) {
  8999. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9000. return 0;
  9001. }
  9002. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9003. if (!items) {
  9004. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9005. return 0;
  9006. }
  9007. client->Loot(spawn->GetLootCoins(), items, spawn);
  9008. return 0;
  9009. }
  9010. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9011. if (!lua_interface)
  9012. return 0;
  9013. Spawn* spawnref = lua_interface->GetSpawn(state);
  9014. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9015. if (spawn_id > 0 && spawnref) {
  9016. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9017. if (spawns.size() == 0) {
  9018. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9019. return 0;
  9020. }
  9021. Spawn* spawn = 0;
  9022. int16 index = MakeRandomInt(0, spawns.size());
  9023. if (index >= spawns.size() || index < 0)
  9024. index = 0;
  9025. spawn = spawns[index];
  9026. lua_interface->SetSpawnValue(state, spawn);
  9027. return 1;
  9028. }
  9029. else {
  9030. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9031. }
  9032. return 0;
  9033. }
  9034. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9035. Spawn* player = lua_interface->GetSpawn(state);
  9036. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9037. string name = lua_interface->GetStringValue(state, 3);
  9038. float distance = lua_interface->GetFloatValue(state, 4);
  9039. string command = lua_interface->GetStringValue(state, 5);
  9040. string error_text = lua_interface->GetStringValue(state, 6);
  9041. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9042. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9043. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9044. if (distance == 0)
  9045. distance = 10.0f;
  9046. if (command.length() == 0)
  9047. command = name;
  9048. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9049. if (spawns.size() == 0) {
  9050. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9051. return 0;
  9052. }
  9053. Spawn* spawn = 0;
  9054. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9055. spawn = *itr;
  9056. if (spawn) {
  9057. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9058. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9059. }
  9060. }
  9061. }
  9062. return 0;
  9063. }
  9064. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9065. if (!lua_interface)
  9066. return 0;
  9067. Client* client = 0;
  9068. Spawn* player = lua_interface->GetSpawn(state);
  9069. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9070. if (player && player->IsPlayer() && player->GetZone())
  9071. client = player->GetZone()->GetClientBySpawn(player);
  9072. else{
  9073. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9074. return 0;
  9075. }
  9076. if (client) {
  9077. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9078. if (packet) {
  9079. packet->setDataByName("goal_num", goal_num);
  9080. client->QueuePacket(packet->serialize());
  9081. safe_delete(packet);
  9082. }
  9083. }
  9084. return 0;
  9085. }
  9086. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9087. if (!lua_interface)
  9088. return 0;
  9089. Client* client = 0;
  9090. Spawn* player = lua_interface->GetSpawn(state);
  9091. if (player && player->IsPlayer() && player->GetZone())
  9092. client = player->GetZone()->GetClientBySpawn(player);
  9093. else {
  9094. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9095. return 0;
  9096. }
  9097. if (client) {
  9098. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9099. }
  9100. return 0;
  9101. }
  9102. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9103. if (!lua_interface)
  9104. return 0;
  9105. Client* client = 0;
  9106. Spawn* player = lua_interface->GetSpawn(state);
  9107. float duration = lua_interface->GetFloatValue(state, 2);
  9108. string text = lua_interface->GetStringValue(state, 3);
  9109. string voice = lua_interface->GetStringValue(state, 4);
  9110. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9111. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9112. string signal = lua_interface->GetStringValue(state, 7);
  9113. string goal1 = lua_interface->GetStringValue(state, 8);
  9114. string task1 = lua_interface->GetStringValue(state, 9);
  9115. string goal2 = lua_interface->GetStringValue(state, 10);
  9116. string task2 = lua_interface->GetStringValue(state, 11);
  9117. string goal3 = lua_interface->GetStringValue(state, 12);
  9118. string task3 = lua_interface->GetStringValue(state, 13);
  9119. string goal4 = lua_interface->GetStringValue(state, 14);
  9120. string task4 = lua_interface->GetStringValue(state, 15);
  9121. if (!player) {
  9122. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9123. return 0;
  9124. }
  9125. if (!player->IsPlayer()) {
  9126. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9127. return 0;
  9128. }
  9129. else
  9130. client = ((Player*)player)->GetClient();
  9131. if (!client) {
  9132. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9133. return 0;
  9134. }
  9135. if (text.length() == 0) {
  9136. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9137. return 0;
  9138. }
  9139. if (duration >= 0 && duration < 2)
  9140. duration = 2;
  9141. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9142. if (packet) {
  9143. packet->setDataByName("open_seconds_max", duration);
  9144. packet->setDataByName("text", text.c_str());
  9145. packet->setDataByName("voice", voice.c_str());
  9146. int8 num_goals = 1;
  9147. if (task2.length() > 0)
  9148. num_goals++;
  9149. if (task3.length() > 0)
  9150. num_goals++;
  9151. if (task4.length() > 0)
  9152. num_goals++;
  9153. packet->setArrayLengthByName("num_goals", num_goals);
  9154. for (int8 i = 0; i < num_goals; i++) {
  9155. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9156. }
  9157. if (goal1.length() > 0)
  9158. packet->setArrayDataByName("goal_text", goal1.c_str());
  9159. if (goal2.length() > 0)
  9160. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9161. if (goal3.length() > 0)
  9162. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9163. if (goal4.length() > 0)
  9164. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9165. packet->setSubArrayDataByName("task_text", task1.c_str());
  9166. if (task2.length() > 0)
  9167. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9168. if (task3.length() > 0)
  9169. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9170. if (task4.length() > 0)
  9171. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9172. packet->setDataByName("complete_sound", "click");
  9173. packet->setDataByName("signal", signal.c_str());
  9174. packet->setDataByName("voice_key1", voice_key1);
  9175. packet->setDataByName("voice_key2", voice_key2);
  9176. client->QueuePacket(packet->serialize());
  9177. safe_delete(packet);
  9178. }
  9179. return 0;
  9180. }
  9181. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9182. if (!lua_interface)
  9183. return 0;
  9184. Client* client = 0;
  9185. Spawn* player = lua_interface->GetSpawn(state);
  9186. string window = lua_interface->GetStringValue(state, 2);
  9187. int8 show = lua_interface->GetInt8Value(state, 3);
  9188. if (!player) {
  9189. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9190. return 0;
  9191. }
  9192. if (!player->IsPlayer()) {
  9193. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9194. return 0;
  9195. }
  9196. else
  9197. client = ((Player*)player)->GetClient();
  9198. if (!client) {
  9199. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9200. return 0;
  9201. }
  9202. if (window.length() == 0) {
  9203. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9204. return 0;
  9205. }
  9206. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9207. if (packet) {
  9208. packet->setDataByName("window", window.c_str());
  9209. packet->setDataByName("show", show);
  9210. client->QueuePacket(packet->serialize());
  9211. safe_delete(packet);
  9212. }
  9213. return 0;
  9214. }
  9215. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9216. //See GameEvents.txt for options that can be used for this function
  9217. if (!lua_interface)
  9218. return 0;
  9219. Client* client = 0;
  9220. Spawn* player = lua_interface->GetSpawn(state);
  9221. string event_name = lua_interface->GetStringValue(state, 2);
  9222. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9223. if (!player || !player->IsPlayer()) {
  9224. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9225. return 0;
  9226. }
  9227. if (player->GetZone())
  9228. client = player->GetZone()->GetClientBySpawn(player);
  9229. if (!client) {
  9230. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9231. return 0;
  9232. }
  9233. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9234. if (packet) {
  9235. packet->setDataByName("event_name", event_name.c_str());
  9236. packet->setDataByName("enabled", enabled);
  9237. client->QueuePacket(packet->serialize());
  9238. safe_delete(packet);
  9239. }
  9240. return 0;
  9241. }
  9242. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9243. if (!lua_interface)
  9244. return 0;
  9245. Spawn* player = lua_interface->GetSpawn(state);
  9246. if (player && player->IsPlayer()) {
  9247. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9248. return 1;
  9249. }
  9250. return 0;
  9251. }
  9252. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9253. if (!lua_interface)
  9254. return 0;
  9255. Spawn* player = lua_interface->GetSpawn(state);
  9256. int8 step = lua_interface->GetInt8Value(state, 2);
  9257. if (player && player->IsPlayer() && step > 0) {
  9258. ((Player*)player)->SetTutorialStep(step);
  9259. }
  9260. return 0;
  9261. }
  9262. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9263. if (!lua_interface)
  9264. return 0;
  9265. Client* client = 0;
  9266. Spawn* player = lua_interface->GetSpawn(state);
  9267. string window = lua_interface->GetStringValue(state, 2);
  9268. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9269. if (!player) {
  9270. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9271. return 0;
  9272. }
  9273. if (!player->IsPlayer()) {
  9274. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9275. return 0;
  9276. }
  9277. else
  9278. client = ((Player*)player)->GetClient();
  9279. if (!client) {
  9280. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9281. return 0;
  9282. }
  9283. if (window.length() == 0) {
  9284. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9285. return 0;
  9286. }
  9287. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9288. if (packet) {
  9289. packet->setDataByName("window", window.c_str());
  9290. packet->setDataByName("flash_seconds", flash_seconds);
  9291. client->QueuePacket(packet->serialize());
  9292. safe_delete(packet);
  9293. }
  9294. return 0;
  9295. }
  9296. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9297. if (!lua_interface)
  9298. return 0;
  9299. Spawn* spawn = lua_interface->GetSpawn(state);
  9300. Spawn* target = lua_interface->GetSpawn(state, 2);
  9301. if (spawn && target)
  9302. return spawn->CheckLoS(target);
  9303. return 0;
  9304. }
  9305. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9306. if (!lua_interface)
  9307. return 0;
  9308. Spawn* spawn = lua_interface->GetSpawn(state);
  9309. float x = lua_interface->GetFloatValue(state, 2);
  9310. float y = lua_interface->GetFloatValue(state, 3);
  9311. float z = lua_interface->GetFloatValue(state, 4);
  9312. if (spawn)
  9313. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9314. return 0;
  9315. }
  9316. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9317. if (!lua_interface)
  9318. return 0;
  9319. ZoneServer* zone = lua_interface->GetZone(state);
  9320. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9321. if (zone)
  9322. zone->SetExpansionFlag(xpackFlag);
  9323. return 0;
  9324. }
  9325. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9326. if (!lua_interface)
  9327. return 0;
  9328. ZoneServer* zone = lua_interface->GetZone(state);
  9329. if (zone) {
  9330. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9331. return 1;
  9332. }
  9333. return 0;
  9334. }
  9335. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9336. if (!lua_interface)
  9337. return 0;
  9338. ZoneServer* zone = lua_interface->GetZone(state);
  9339. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9340. if (zone)
  9341. zone->SetHolidayFlag(holidayFlag);
  9342. return 0;
  9343. }
  9344. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9345. if (!lua_interface)
  9346. return 0;
  9347. ZoneServer* zone = lua_interface->GetZone(state);
  9348. if (zone) {
  9349. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9350. return 1;
  9351. }
  9352. return 0;
  9353. }
  9354. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9355. if (!lua_interface)
  9356. return 0;
  9357. Spawn* spawn = lua_interface->GetSpawn(state);
  9358. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9359. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9360. float distance = lua_interface->GetFloatValue(state, 4);
  9361. string in_range_function = lua_interface->GetStringValue(state, 5);
  9362. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9363. if (spawn && distance > 0 && in_range_function.length() > 0)
  9364. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9365. return 0;
  9366. }
  9367. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9368. if (!lua_interface)
  9369. return 0;
  9370. Spawn* spawn = lua_interface->GetSpawn(state);
  9371. Spawn* target = lua_interface->GetSpawn(state, 2);
  9372. if (spawn && target)
  9373. {
  9374. if (spawn->IsPlayer() && target->IsEntity())
  9375. {
  9376. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9377. return 1;
  9378. }
  9379. else if (spawn->IsEntity() && target->IsEntity())
  9380. {
  9381. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9382. return 1;
  9383. }
  9384. }
  9385. return 0;
  9386. }
  9387. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9388. if (!lua_interface)
  9389. return 0;
  9390. Spawn* spawn = lua_interface->GetSpawn(state);
  9391. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9392. if (spawn && spawn->IsEntity())
  9393. {
  9394. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9395. if (spawn->IsPlayer())
  9396. {
  9397. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9398. if (client)
  9399. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9400. }
  9401. }
  9402. return 0;
  9403. }
  9404. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9405. if (!lua_interface)
  9406. return 0;
  9407. Spawn* spawn = lua_interface->GetSpawn(state);
  9408. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9409. if (spawn && spawn->IsEntity())
  9410. {
  9411. ((Entity*)spawn)->SetSeeHideSpell(val);
  9412. if (spawn->IsPlayer())
  9413. {
  9414. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9415. if (client)
  9416. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9417. }
  9418. }
  9419. return 0;
  9420. }
  9421. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9422. {
  9423. if (!lua_interface)
  9424. return 0;
  9425. Spawn* player = lua_interface->GetSpawn(state);
  9426. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9427. string command = lua_interface->GetStringValue(state, 3);
  9428. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9429. lua_interface->ResetFunctionStack(state);
  9430. if (spawn && player && player->IsPlayer())
  9431. {
  9432. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9433. bool res = false;
  9434. if (cmd)
  9435. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9436. lua_interface->SetBooleanValue(state, res);
  9437. return 1;
  9438. }
  9439. return 0;
  9440. }
  9441. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9442. {
  9443. if (!lua_interface)
  9444. return 0;
  9445. Spawn* spawn = lua_interface->GetSpawn(state);
  9446. int32 charID = lua_interface->GetInt32Value(state, 2);
  9447. string command = lua_interface->GetStringValue(state, 3);
  9448. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9449. lua_interface->ResetFunctionStack(state);
  9450. if (spawn && charID)
  9451. {
  9452. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9453. bool res = false;
  9454. if (cmd)
  9455. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9456. lua_interface->SetBooleanValue(state, res);
  9457. return 1;
  9458. }
  9459. return 0;
  9460. }
  9461. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9462. {
  9463. if (!lua_interface)
  9464. return 0;
  9465. Spawn* spawn = lua_interface->GetSpawn(state);
  9466. string command = lua_interface->GetStringValue(state, 2);
  9467. lua_interface->ResetFunctionStack(state);
  9468. if (spawn && command.length() > 0)
  9469. spawn->RemovePrimaryEntityCommand(command.c_str());
  9470. return 0;
  9471. }
  9472. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9473. if (!lua_interface)
  9474. return 0;
  9475. Spawn* spawn = lua_interface->GetSpawn(state);
  9476. float distance = lua_interface->GetFloatValue(state, 2);
  9477. string command = lua_interface->GetStringValue(state, 3);
  9478. Spawn* player = lua_interface->GetSpawn(state, 4);
  9479. lua_interface->ResetFunctionStack(state);
  9480. if (spawn) {
  9481. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9482. }
  9483. return 0;
  9484. }
  9485. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9486. if (!lua_interface)
  9487. return 0;
  9488. Spawn* spawn = lua_interface->GetSpawn(state);
  9489. Spawn* player = lua_interface->GetSpawn(state, 2);
  9490. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9491. lua_interface->ResetFunctionStack(state);
  9492. if (spawn && player && transport_id && player->IsPlayer()) {
  9493. Client* client = 0;
  9494. if (player && player->IsPlayer())
  9495. client = player->GetZone()->GetClientBySpawn(player);
  9496. if (!client)
  9497. return 0;
  9498. vector<TransportDestination*> destinations;
  9499. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9500. if (destinations.size())
  9501. {
  9502. client->SetTemporaryTransportID(transport_id);
  9503. client->ProcessTeleport(spawn, &destinations, transport_id);
  9504. }
  9505. else
  9506. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9507. }
  9508. return 0;
  9509. }
  9510. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9511. if (!lua_interface)
  9512. return 0;
  9513. Spawn* player = lua_interface->GetSpawn(state);
  9514. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9515. lua_interface->ResetFunctionStack(state);
  9516. if (player && player->IsPlayer()) {
  9517. Client* client = 0;
  9518. if (player && player->IsPlayer())
  9519. client = player->GetZone()->GetClientBySpawn(player);
  9520. if (!client)
  9521. return 0;
  9522. client->SetTemporaryTransportID(transport_id);
  9523. }
  9524. return 0;
  9525. }
  9526. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9527. if (!lua_interface)
  9528. return 0;
  9529. Spawn* player = lua_interface->GetSpawn(state);
  9530. lua_interface->ResetFunctionStack(state);
  9531. if (player && player->IsPlayer()) {
  9532. Client* client = 0;
  9533. if (player && player->IsPlayer())
  9534. client = player->GetZone()->GetClientBySpawn(player);
  9535. if (!client)
  9536. return 0;
  9537. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9538. return 1;
  9539. }
  9540. return 0;
  9541. }
  9542. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9543. if (!lua_interface)
  9544. return 0;
  9545. Spawn* spawn = lua_interface->GetSpawn(state);
  9546. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9547. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9548. if (!spawn) {
  9549. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9550. return 0;
  9551. }
  9552. if (!spawn->IsEntity()) {
  9553. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9554. return 0;
  9555. }
  9556. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9557. {
  9558. 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);
  9559. return 0;
  9560. }
  9561. lua_interface->ResetFunctionStack(state);
  9562. if (spell && spell->targets.size() > 0) {
  9563. ZoneServer* zone = spell->caster->GetZone();
  9564. for (int8 i = 0; i < spell->targets.size(); i++) {
  9565. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9566. if (target && target->IsEntity()) {
  9567. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9568. if (target->IsPlayer())
  9569. ((Player*)target)->SetCharSheetChanged(true);
  9570. }
  9571. }
  9572. }
  9573. else {
  9574. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9575. if (spawn->IsPlayer())
  9576. ((Player*)spawn)->SetCharSheetChanged(true);
  9577. }
  9578. return 0;
  9579. }
  9580. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9581. if (!lua_interface)
  9582. return 0;
  9583. Spawn* spawn = lua_interface->GetSpawn(state);
  9584. lua_interface->ResetFunctionStack(state);
  9585. if (!spawn) {
  9586. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9587. return 0;
  9588. }
  9589. if (!spawn->IsEntity()) {
  9590. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9591. return 0;
  9592. }
  9593. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9594. return 1;
  9595. }
  9596. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9597. if (!lua_interface)
  9598. return 0;
  9599. int32 spell_id = lua_interface->GetInt32Value(state);
  9600. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9601. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9602. if (spell_id > 0) {
  9603. if (spell_tier == 0)
  9604. spell_tier = 1;
  9605. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9606. LuaSpell* lua_spell = 0;
  9607. if(custom_lua_script.size() > 0)
  9608. {
  9609. // attempt to load the custom script since it isn't already loaded
  9610. // we will re-obtain the lua_spell further below
  9611. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9612. {
  9613. 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());
  9614. lua_interface->LoadLuaSpell(custom_lua_script);
  9615. }
  9616. }
  9617. else
  9618. custom_lua_script = spell->GetSpellData()->lua_script;
  9619. if (!lua_spell && lua_interface)
  9620. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9621. if (!lua_spell)
  9622. {
  9623. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9624. return 0;
  9625. }
  9626. lua_spell->spell = new Spell(spell);
  9627. lua_interface->AddCustomSpell(lua_spell);
  9628. lua_interface->SetSpellValue(state, lua_spell);
  9629. return 1;
  9630. }
  9631. return 0;
  9632. }
  9633. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9634. if (!lua_interface)
  9635. return 0;
  9636. LuaSpell* spell = lua_interface->GetSpell(state);
  9637. string field = lua_interface->GetStringValue(state, 2);
  9638. if (!spell) {
  9639. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9640. return 0;
  9641. }
  9642. if (!spell->spell || !spell->spell->GetSpellData()) {
  9643. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9644. return 0;
  9645. }
  9646. boost::to_lower(field);
  9647. return spell->spell->GetSpellData(state, field);
  9648. }
  9649. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9650. if (!lua_interface)
  9651. return 0;
  9652. LuaSpell* spell = lua_interface->GetSpell(state);
  9653. string field = lua_interface->GetStringValue(state, 2);
  9654. int8 fieldArg = 3; // field value after the initial set
  9655. if (!spell) {
  9656. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9657. return 0;
  9658. }
  9659. if (!spell->spell || !spell->spell->GetSpellData()) {
  9660. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9661. return 0;
  9662. }
  9663. boost::to_lower(field);
  9664. bool valSet = false;
  9665. spell->spell->SetSpellData(state, field, fieldArg);
  9666. return valSet;
  9667. }
  9668. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9669. if (!lua_interface)
  9670. return 0;
  9671. LuaSpell* spell = lua_interface->GetSpell(state);
  9672. int8 idx = lua_interface->GetInt32Value(state, 2);
  9673. if (!spell) {
  9674. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9675. return 0;
  9676. }
  9677. if (!spell->spell || !spell->spell->GetSpellData()) {
  9678. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9679. return 0;
  9680. }
  9681. if (spell->spell->lua_data.size() <= idx)
  9682. {
  9683. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9684. return 0;
  9685. }
  9686. bool setVal = true;
  9687. LUAData* data = spell->spell->lua_data[idx];
  9688. switch (data->type)
  9689. {
  9690. case 0:
  9691. {
  9692. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9693. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9694. data->int_value = value;
  9695. data->int_value2 = value2;
  9696. break;
  9697. }
  9698. case 1:
  9699. {
  9700. float value = lua_interface->GetFloatValue(state, 3);
  9701. float value2 = lua_interface->GetFloatValue(state, 4);
  9702. data->float_value = value;
  9703. data->float_value2 = value2;
  9704. break;
  9705. }
  9706. case 2:
  9707. {
  9708. bool value = lua_interface->GetBooleanValue(state, 3);
  9709. data->bool_value = value;
  9710. break;
  9711. }
  9712. case 3:
  9713. {
  9714. string value = lua_interface->GetStringValue(state, 3);
  9715. string value2 = lua_interface->GetStringValue(state, 4);
  9716. data->string_value = value;
  9717. data->string_value2 = value2;
  9718. break;
  9719. }
  9720. default:
  9721. setVal = false;
  9722. }
  9723. return setVal;
  9724. }
  9725. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9726. if (!lua_interface)
  9727. return 0;
  9728. LuaSpell* spell = lua_interface->GetSpell(state);
  9729. int8 idx = lua_interface->GetInt32Value(state, 2);
  9730. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9731. if (!spell) {
  9732. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9733. return 0;
  9734. }
  9735. if (!spell->spell || !spell->spell->GetSpellData()) {
  9736. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9737. return 0;
  9738. }
  9739. if (spell->spell->lua_data.size() <= idx)
  9740. {
  9741. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9742. return 0;
  9743. }
  9744. bool setVal = true;
  9745. LUAData* data = spell->spell->lua_data[idx];
  9746. switch (data->type)
  9747. {
  9748. case 0:
  9749. {
  9750. if(!secondfield)
  9751. lua_interface->SetSInt32Value(state, data->int_value);
  9752. else
  9753. lua_interface->SetSInt32Value(state, data->int_value2);
  9754. break;
  9755. }
  9756. case 1:
  9757. {
  9758. if (!secondfield)
  9759. lua_interface->SetFloatValue(state, data->float_value);
  9760. else
  9761. lua_interface->SetFloatValue(state, data->float_value2);
  9762. break;
  9763. }
  9764. case 2:
  9765. {
  9766. lua_interface->SetBooleanValue(state, data->bool_value);
  9767. break;
  9768. }
  9769. case 3:
  9770. {
  9771. if (!secondfield)
  9772. lua_interface->SetStringValue(state, data->string_value.c_str());
  9773. else
  9774. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9775. break;
  9776. }
  9777. default:
  9778. setVal = false;
  9779. }
  9780. return setVal;
  9781. }
  9782. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9783. if (!lua_interface)
  9784. return 0;
  9785. LuaSpell* spell = lua_interface->GetSpell(state);
  9786. int8 idx = lua_interface->GetInt32Value(state, 2);
  9787. string field = lua_interface->GetStringValue(state, 3);
  9788. boost::to_lower(field);
  9789. if (!spell) {
  9790. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9791. return 0;
  9792. }
  9793. if (!spell->spell || !spell->spell->GetSpellData()) {
  9794. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9795. return 0;
  9796. }
  9797. if (spell->spell->effects.size() <= idx)
  9798. {
  9799. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9800. return 0;
  9801. }
  9802. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9803. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9804. if (field == "description")
  9805. effect->description = string(lua_interface->GetStringValue(state, 4));
  9806. else if (field == "bullet")
  9807. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9808. else if (field == "percentage")
  9809. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9810. else // no match
  9811. return 0;
  9812. return 1;
  9813. }
  9814. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9815. if (!lua_interface)
  9816. return 0;
  9817. LuaSpell* spell = lua_interface->GetSpell(state);
  9818. int8 idx = lua_interface->GetInt32Value(state, 2);
  9819. string field = lua_interface->GetStringValue(state, 3);
  9820. boost::to_lower(field);
  9821. if (!spell) {
  9822. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9823. return 0;
  9824. }
  9825. if (!spell->spell || !spell->spell->GetSpellData()) {
  9826. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9827. return 0;
  9828. }
  9829. if (spell->spell->effects.size() <= idx)
  9830. {
  9831. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9832. return 0;
  9833. }
  9834. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9835. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9836. if (field == "description")
  9837. lua_interface->SetStringValue(state, effect->description.c_str());
  9838. else if (field == "bullet")
  9839. lua_interface->SetInt32Value(state, effect->subbullet);
  9840. else if (field == "percentage")
  9841. lua_interface->SetInt32Value(state, effect->percentage);
  9842. else // no match
  9843. return 0;
  9844. return 1;
  9845. }
  9846. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9847. if (!lua_interface)
  9848. return 0;
  9849. LuaSpell* spell = lua_interface->GetSpell(state);
  9850. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9851. Spawn* target = lua_interface->GetSpawn(state, 3);
  9852. if (!target) {
  9853. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9854. return 0;
  9855. }
  9856. if (!target->IsEntity()) {
  9857. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9858. return 0;
  9859. }
  9860. if (!spell) {
  9861. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9862. return 0;
  9863. }
  9864. if (caster && !caster->IsEntity()) {
  9865. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9866. return 0;
  9867. }
  9868. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9869. return 0;
  9870. }
  9871. int EQ2Emu_lua_InWater(lua_State* state) {
  9872. if (!lua_interface)
  9873. return 0;
  9874. Spawn* spawn = lua_interface->GetSpawn(state);
  9875. lua_interface->ResetFunctionStack(state);
  9876. if (spawn) {
  9877. lua_interface->SetBooleanValue(state, spawn->InWater());
  9878. return 1;
  9879. }
  9880. return 0;
  9881. }
  9882. int EQ2Emu_lua_InLava(lua_State* state) {
  9883. if (!lua_interface)
  9884. return 0;
  9885. Spawn* spawn = lua_interface->GetSpawn(state);
  9886. lua_interface->ResetFunctionStack(state);
  9887. if (spawn) {
  9888. lua_interface->SetBooleanValue(state, spawn->InLava());
  9889. return 1;
  9890. }
  9891. return 0;
  9892. }
  9893. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9894. if (!lua_interface)
  9895. return 0;
  9896. Spawn* attacker = lua_interface->GetSpawn(state);
  9897. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9898. int8 type = lua_interface->GetInt8Value(state, 3);
  9899. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9900. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9901. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9902. string spell_name = lua_interface->GetStringValue(state, 7);
  9903. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9904. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9905. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9906. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9907. lua_interface->ResetFunctionStack(state);
  9908. if (!attacker) {
  9909. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9910. return 0;
  9911. }
  9912. if (!attacker->IsEntity()) {
  9913. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9914. return 0;
  9915. }
  9916. if (!victim) {
  9917. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9918. return 0;
  9919. }
  9920. if (!victim->IsEntity()) {
  9921. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9922. return 0;
  9923. }
  9924. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9925. return 0;
  9926. }
  9927. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9928. if (!lua_interface)
  9929. return 0;
  9930. Spawn* spawn = lua_interface->GetSpawn(state);
  9931. lua_interface->ResetFunctionStack(state);
  9932. if (spawn) {
  9933. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9934. return 1;
  9935. }
  9936. return 0;
  9937. }
  9938. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9939. if (!lua_interface)
  9940. return 0;
  9941. Spawn* spawn = lua_interface->GetSpawn(state);
  9942. bool invul = lua_interface->GetBooleanValue(state, 2);
  9943. lua_interface->ResetFunctionStack(state);
  9944. if (spawn) {
  9945. spawn->SetInvulnerable(invul);
  9946. }
  9947. return 0;
  9948. }
  9949. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  9950. if (!lua_interface)
  9951. return 0;
  9952. string category = lua_interface->GetStringValue(state);
  9953. string name = lua_interface->GetStringValue(state, 2);
  9954. lua_interface->ResetFunctionStack(state);
  9955. Rule *ret = 0;
  9956. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9957. lua_interface->SetBooleanValue(state, ret->GetBool());
  9958. return 1;
  9959. }
  9960. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9961. return 0;
  9962. }
  9963. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9964. if (!lua_interface)
  9965. return 0;
  9966. string category = lua_interface->GetStringValue(state);
  9967. string name = lua_interface->GetStringValue(state, 2);
  9968. lua_interface->ResetFunctionStack(state);
  9969. Rule *ret = 0;
  9970. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9971. lua_interface->SetInt32Value(state, ret->GetInt32());
  9972. return 1;
  9973. }
  9974. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9975. return 0;
  9976. }
  9977. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  9978. if (!lua_interface)
  9979. return 0;
  9980. string category = lua_interface->GetStringValue(state);
  9981. string name = lua_interface->GetStringValue(state, 2);
  9982. lua_interface->ResetFunctionStack(state);
  9983. Rule *ret = 0;
  9984. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9985. lua_interface->SetFloatValue(state, ret->GetFloat());
  9986. return 1;
  9987. }
  9988. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9989. return 0;
  9990. }
  9991. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  9992. if (!lua_interface)
  9993. return 0;
  9994. Spawn* spawn = lua_interface->GetSpawn(state);
  9995. string type = lua_interface->GetStringValue(state, 2);
  9996. lua_interface->ResetFunctionStack(state);
  9997. if (spawn) {
  9998. int res = 1;
  9999. boost::to_lower(type);
  10000. if(type == "assigned_aa")
  10001. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10002. else if ( type == "unassigned_aa")
  10003. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10004. else if ( type == "assigned_tradeskill_aa")
  10005. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10006. else if ( type == "unassigned_tradeskill_aa")
  10007. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10008. else if ( type == "assigned_prestige_aa")
  10009. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10010. else if ( type == "unassigned_prestige_aa")
  10011. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10012. else if ( type == "assigned_tradeskill_prestige_aa")
  10013. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10014. else if ( type == "unassigned_tradeskill_prestige_aa")
  10015. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10016. else
  10017. res = 0;
  10018. return res;
  10019. }
  10020. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10021. return 0;
  10022. }
  10023. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10024. if (!lua_interface)
  10025. return 0;
  10026. Spawn* spawn = lua_interface->GetSpawn(state);
  10027. string type = lua_interface->GetStringValue(state, 2);
  10028. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10029. lua_interface->ResetFunctionStack(state);
  10030. if (spawn) {
  10031. boost::to_lower(type);
  10032. if(type == "assigned_aa")
  10033. spawn->SetAssignedAA((sint16)value);
  10034. else if ( type == "unassigned_aa")
  10035. spawn->SetUnassignedAA((sint16)value);
  10036. else if ( type == "assigned_tradeskill_aa")
  10037. spawn->SetTradeskillAA((sint16)value);
  10038. else if ( type == "unassigned_tradeskill_aa")
  10039. spawn->SetUnassignedTradeskillAA((sint16)value);
  10040. else if ( type == "assigned_prestige_aa")
  10041. spawn->SetPrestigeAA((sint16)value);
  10042. else if ( type == "unassigned_prestige_aa")
  10043. spawn->SetUnassignedPrestigeAA((sint16)value);
  10044. else if ( type == "assigned_tradeskill_prestige_aa")
  10045. spawn->SetTradeskillPrestigeAA((sint16)value);
  10046. else if ( type == "unassigned_tradeskill_prestige_aa")
  10047. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10048. if(spawn->IsPlayer())
  10049. ((Player*)spawn)->SetCharSheetChanged(true);
  10050. }
  10051. return 0;
  10052. }
  10053. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10054. if (!lua_interface)
  10055. return 0;
  10056. string titleName = lua_interface->GetStringValue(state);
  10057. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10058. lua_interface->ResetFunctionStack(state);
  10059. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10060. lua_interface->SetSInt32Value(state, index);
  10061. return 1;
  10062. }
  10063. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10064. if (!lua_interface)
  10065. return 0;
  10066. Spawn* spawn = lua_interface->GetSpawn(state);
  10067. string titleName = lua_interface->GetStringValue(state, 2);
  10068. lua_interface->ResetFunctionStack(state);
  10069. if(!spawn->IsPlayer())
  10070. {
  10071. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10072. lua_interface->SetSInt32Value(state, -1);
  10073. return 1;
  10074. }
  10075. Player* player = (Player*)spawn;
  10076. // check if player already has the title, don't need to add twice
  10077. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10078. if ( playerHasTitle)
  10079. {
  10080. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10081. return 1;
  10082. }
  10083. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10084. if(!title)
  10085. {
  10086. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10087. lua_interface->SetSInt32Value(state, -1);
  10088. return 1;
  10089. }
  10090. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10091. if(returnIdx < 0)
  10092. {
  10093. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10094. }
  10095. lua_interface->SetSInt32Value(state, returnIdx);
  10096. player->GetClient()->SendTitleUpdate();
  10097. return 1;
  10098. }
  10099. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10100. if (!lua_interface)
  10101. return 0;
  10102. Spawn* spawn = lua_interface->GetSpawn(state);
  10103. string titleName = lua_interface->GetStringValue(state, 2);
  10104. lua_interface->ResetFunctionStack(state);
  10105. if(!spawn->IsPlayer())
  10106. {
  10107. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10108. return 0;
  10109. }
  10110. Player* player = (Player*)spawn;
  10111. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10112. if(!title)
  10113. {
  10114. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10115. return 0;
  10116. }
  10117. if(title->GetPrefix())
  10118. {
  10119. 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());
  10120. return 0;
  10121. }
  10122. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10123. player->GetClient()->SendTitleUpdate();
  10124. return 1;
  10125. }
  10126. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10127. if (!lua_interface)
  10128. return 0;
  10129. Spawn* spawn = lua_interface->GetSpawn(state);
  10130. string titleName = lua_interface->GetStringValue(state, 2);
  10131. lua_interface->ResetFunctionStack(state);
  10132. if(!spawn->IsPlayer())
  10133. {
  10134. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10135. return 0;
  10136. }
  10137. Player* player = (Player*)spawn;
  10138. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10139. if(!title)
  10140. {
  10141. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10142. return 0;
  10143. }
  10144. if(!title->GetPrefix())
  10145. {
  10146. 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());
  10147. return 0;
  10148. }
  10149. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10150. player->GetClient()->SendTitleUpdate();
  10151. return 1;
  10152. }
  10153. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10154. if (!lua_interface)
  10155. return 0;
  10156. Spawn* spawn = lua_interface->GetSpawn(state);
  10157. lua_interface->ResetFunctionStack(state);
  10158. if(!spawn->IsPlayer())
  10159. {
  10160. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10161. return 0;
  10162. }
  10163. Player* player = (Player*)spawn;
  10164. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10165. player->GetClient()->SendTitleUpdate();
  10166. return 1;
  10167. }
  10168. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10169. if (!lua_interface)
  10170. return 0;
  10171. Spawn* spawn = lua_interface->GetSpawn(state);
  10172. lua_interface->ResetFunctionStack(state);
  10173. if(!spawn->IsPlayer())
  10174. {
  10175. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10176. return 0;
  10177. }
  10178. Player* player = (Player*)spawn;
  10179. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10180. player->GetClient()->SendTitleUpdate();
  10181. return 1;
  10182. }
  10183. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10184. if (!lua_interface)
  10185. return 0;
  10186. Spawn* spawn = lua_interface->GetSpawn(state);
  10187. string field = lua_interface->GetStringValue(state, 2);
  10188. lua_interface->ResetFunctionStack(state);
  10189. if(!spawn || !spawn->IsEntity())
  10190. {
  10191. 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));
  10192. return 0;
  10193. }
  10194. Entity* ent = (Entity*)spawn;
  10195. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10196. return 1;
  10197. }
  10198. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10199. if (!lua_interface)
  10200. return 0;
  10201. Spawn* spawn = lua_interface->GetSpawn(state);
  10202. string field = lua_interface->GetStringValue(state, 2);
  10203. lua_interface->ResetFunctionStack(state);
  10204. if(!spawn || !spawn->IsEntity())
  10205. {
  10206. 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));
  10207. return 0;
  10208. }
  10209. Entity* ent = (Entity*)spawn;
  10210. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10211. return 1;
  10212. }
  10213. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10214. if (!lua_interface)
  10215. return 0;
  10216. Spawn* spawn = lua_interface->GetSpawn(state);
  10217. string field = lua_interface->GetStringValue(state, 2);
  10218. lua_interface->ResetFunctionStack(state);
  10219. if(!spawn || !spawn->IsEntity())
  10220. {
  10221. 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));
  10222. return 0;
  10223. }
  10224. Entity* ent = (Entity*)spawn;
  10225. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10226. return 1;
  10227. }
  10228. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10229. if (!lua_interface)
  10230. return 0;
  10231. Spawn* spawn = lua_interface->GetSpawn(state);
  10232. string field = lua_interface->GetStringValue(state, 2);
  10233. lua_interface->ResetFunctionStack(state);
  10234. if(!spawn || !spawn->IsEntity())
  10235. {
  10236. 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));
  10237. return 0;
  10238. }
  10239. Entity* ent = (Entity*)spawn;
  10240. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10241. return 1;
  10242. }
  10243. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10244. if (!lua_interface)
  10245. return 0;
  10246. Spawn* spawn = lua_interface->GetSpawn(state);
  10247. string field = lua_interface->GetStringValue(state, 2);
  10248. string value = lua_interface->GetStringValue(state, 3);
  10249. lua_interface->ResetFunctionStack(state);
  10250. if(!spawn || !spawn->IsEntity())
  10251. {
  10252. 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));
  10253. return 0;
  10254. }
  10255. Entity* ent = (Entity*)spawn;
  10256. bool set_ = ent->SetInfoStructString(field, value);
  10257. lua_interface->SetBooleanValue(state, set_);
  10258. return 1;
  10259. }
  10260. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10261. if (!lua_interface)
  10262. return 0;
  10263. Spawn* spawn = lua_interface->GetSpawn(state);
  10264. string field = lua_interface->GetStringValue(state, 2);
  10265. int64 value = lua_interface->GetInt64Value(state, 3);
  10266. lua_interface->ResetFunctionStack(state);
  10267. if(!spawn || !spawn->IsEntity())
  10268. {
  10269. 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));
  10270. return 0;
  10271. }
  10272. Entity* ent = (Entity*)spawn;
  10273. bool set_ = ent->SetInfoStructUInt(field, value);
  10274. lua_interface->SetBooleanValue(state, set_);
  10275. return 1;
  10276. }
  10277. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10278. if (!lua_interface)
  10279. return 0;
  10280. Spawn* spawn = lua_interface->GetSpawn(state);
  10281. string field = lua_interface->GetStringValue(state, 2);
  10282. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10283. lua_interface->ResetFunctionStack(state);
  10284. if(!spawn || !spawn->IsEntity())
  10285. {
  10286. 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));
  10287. return 0;
  10288. }
  10289. Entity* ent = (Entity*)spawn;
  10290. bool set_ = ent->SetInfoStructSInt(field, value);
  10291. lua_interface->SetBooleanValue(state, set_);
  10292. return 1;
  10293. }
  10294. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10295. if (!lua_interface)
  10296. return 0;
  10297. Spawn* spawn = lua_interface->GetSpawn(state);
  10298. string field = lua_interface->GetStringValue(state, 2);
  10299. float value = lua_interface->GetFloatValue(state, 3);
  10300. lua_interface->ResetFunctionStack(state);
  10301. if(!spawn || !spawn->IsEntity())
  10302. {
  10303. 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));
  10304. return 0;
  10305. }
  10306. Entity* ent = (Entity*)spawn;
  10307. bool set_ = ent->SetInfoStructFloat(field, value);
  10308. lua_interface->SetBooleanValue(state, set_);
  10309. return 1;
  10310. }
  10311. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10312. if (!lua_interface)
  10313. return 0;
  10314. Spawn* spawn = lua_interface->GetSpawn(state);
  10315. bool value = lua_interface->GetBooleanValue(state, 2);
  10316. lua_interface->ResetFunctionStack(state);
  10317. if(!spawn || !spawn->IsPlayer())
  10318. {
  10319. 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));
  10320. return 0;
  10321. }
  10322. ((Player*)spawn)->SetCharSheetChanged(value);
  10323. return 0;
  10324. }
  10325. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10326. if (!lua_interface)
  10327. return 0;
  10328. Spawn* spawn = lua_interface->GetSpawn(state);
  10329. std::string fromName = lua_interface->GetStringValue(state, 2);
  10330. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10331. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10332. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10333. int32 copper = lua_interface->GetInt32Value(state, 6);
  10334. int32 silver = lua_interface->GetInt32Value(state, 7);
  10335. int32 gold = lua_interface->GetInt32Value(state, 8);
  10336. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10337. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10338. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10339. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10340. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10341. lua_interface->ResetFunctionStack(state);
  10342. if(!spawn || !spawn->IsPlayer())
  10343. {
  10344. 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));
  10345. lua_interface->SetBooleanValue(state, false);
  10346. return 1;
  10347. }
  10348. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10349. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10350. lua_interface->SetBooleanValue(state, true);
  10351. return 1;
  10352. }
  10353. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10354. if (!lua_interface)
  10355. return 0;
  10356. int32 char_id = lua_interface->GetInt32Value(state);
  10357. std::string fromName = lua_interface->GetStringValue(state, 2);
  10358. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10359. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10360. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10361. int32 copper = lua_interface->GetInt32Value(state, 6);
  10362. int32 silver = lua_interface->GetInt32Value(state, 7);
  10363. int32 gold = lua_interface->GetInt32Value(state, 8);
  10364. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10365. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10366. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10367. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10368. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10369. lua_interface->ResetFunctionStack(state);
  10370. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10371. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10372. lua_interface->SetBooleanValue(state, true);
  10373. return 1;
  10374. }
  10375. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10376. Spawn* widget;
  10377. if (lua_interface) {
  10378. widget = lua_interface->GetSpawn(state);
  10379. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10380. lua_interface->ResetFunctionStack(state);
  10381. if (widget && widget->IsWidget())
  10382. {
  10383. ((Widget*)widget)->OpenDoor();
  10384. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10385. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10386. }
  10387. else
  10388. 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));
  10389. }
  10390. return 0;
  10391. }
  10392. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10393. Spawn* widget;
  10394. if (lua_interface) {
  10395. widget = lua_interface->GetSpawn(state);
  10396. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10397. lua_interface->ResetFunctionStack(state);
  10398. if (widget && widget->IsWidget())
  10399. {
  10400. ((Widget*)widget)->CloseDoor();
  10401. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10402. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10403. }
  10404. else
  10405. 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));
  10406. }
  10407. return 0;
  10408. }
  10409. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10410. if (!lua_interface)
  10411. return 0;
  10412. Spawn* widget = lua_interface->GetSpawn(state);
  10413. lua_interface->ResetFunctionStack(state);
  10414. if (widget && widget->IsWidget())
  10415. {
  10416. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10417. return 1;
  10418. }
  10419. return 0;
  10420. }
  10421. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10422. if (!lua_interface)
  10423. return 0;
  10424. sint32 min = lua_interface->GetSInt32Value(state);
  10425. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10426. lua_interface->ResetFunctionStack(state);
  10427. sint32 result = MakeRandomInt(min, max);
  10428. lua_interface->SetSInt32Value(state, result);
  10429. return 1;
  10430. }
  10431. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10432. if (!lua_interface)
  10433. return 0;
  10434. float min = lua_interface->GetFloatValue(state);
  10435. float max = lua_interface->GetFloatValue(state, 2);
  10436. lua_interface->ResetFunctionStack(state);
  10437. float result = MakeRandomFloat(min, max);
  10438. lua_interface->SetFloatValue(state, result);
  10439. return 1;
  10440. }
  10441. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10442. if (!lua_interface)
  10443. return 0;
  10444. Spawn* spawn = lua_interface->GetSpawn(state);
  10445. int32 value = lua_interface->GetInt32Value(state, 2);
  10446. lua_interface->ResetFunctionStack(state);
  10447. if(!spawn)
  10448. {
  10449. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10450. lua_interface->SetBooleanValue(state, false);
  10451. return 1;
  10452. }
  10453. spawn->AddIconValue(value);
  10454. lua_interface->SetBooleanValue(state, true);
  10455. return 1;
  10456. }
  10457. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10458. if (!lua_interface)
  10459. return 0;
  10460. Spawn* spawn = lua_interface->GetSpawn(state);
  10461. int32 value = lua_interface->GetInt32Value(state, 2);
  10462. lua_interface->ResetFunctionStack(state);
  10463. if(!spawn)
  10464. {
  10465. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10466. lua_interface->SetBooleanValue(state, false);
  10467. return 1;
  10468. }
  10469. spawn->RemoveIconValue(value);
  10470. lua_interface->SetBooleanValue(state, true);
  10471. return 1;
  10472. }
  10473. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10474. Spawn* npc = lua_interface->GetSpawn(state);
  10475. lua_interface->ResetFunctionStack(state);
  10476. if (npc && npc->IsNPC()) {
  10477. NPC* shard = (NPC*)npc;
  10478. int32 shardid = shard->GetShardID();
  10479. lua_interface->SetInt32Value(state, shardid);
  10480. return 1;
  10481. }
  10482. lua_interface->SetInt32Value(state, 0);
  10483. return 1;
  10484. }
  10485. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10486. Spawn* npc = lua_interface->GetSpawn(state);
  10487. lua_interface->ResetFunctionStack(state);
  10488. if (npc && npc->IsNPC()) {
  10489. NPC* shard = (NPC*)npc;
  10490. int32 charid = shard->GetShardCharID();
  10491. lua_interface->SetInt32Value(state, charid);
  10492. return 1;
  10493. }
  10494. lua_interface->SetInt32Value(state, 0);
  10495. return 1;
  10496. }
  10497. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10498. Spawn* npc = lua_interface->GetSpawn(state);
  10499. lua_interface->ResetFunctionStack(state);
  10500. if (npc && npc->IsNPC()) {
  10501. NPC* shard = (NPC*)npc;
  10502. int64 timestamp = shard->GetShardCreatedTimestamp();
  10503. lua_interface->SetSInt64Value(state, timestamp);
  10504. return 1;
  10505. }
  10506. lua_interface->SetSInt64Value(state, 0);
  10507. return 1;
  10508. }
  10509. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10510. if (!lua_interface)
  10511. return 0;
  10512. int32 shardid = lua_interface->GetInt32Value(state);
  10513. lua_interface->ResetFunctionStack(state);
  10514. if(shardid < 1)
  10515. lua_interface->SetBooleanValue(state, false);
  10516. else
  10517. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10518. return 1;
  10519. }
  10520. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10521. if (!lua_interface)
  10522. return 0;
  10523. Spawn* spawn = lua_interface->GetSpawn(state);
  10524. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10525. if (spawn) {
  10526. spawn->PauseMovement(delay_in_ms);
  10527. }
  10528. lua_interface->ResetFunctionStack(state);
  10529. return 0;
  10530. }
  10531. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10532. Player* player = (Player*)lua_interface->GetSpawn(state);
  10533. int8 level = lua_interface->GetInt8Value(state, 2);
  10534. lua_interface->ResetFunctionStack(state);
  10535. if (player && player->IsPlayer() && level > 0) {
  10536. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10537. return 1;
  10538. }
  10539. return 0;
  10540. }
  10541. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10542. Player* player = (Player*)lua_interface->GetSpawn(state);
  10543. int8 level = lua_interface->GetInt8Value(state, 2);
  10544. lua_interface->ResetFunctionStack(state);
  10545. if (player && player->IsPlayer() && level > 0) {
  10546. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10547. return 1;
  10548. }
  10549. return 0;
  10550. }