LuaFunctions.cpp 412 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 546 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //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
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //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
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. 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());
  399. }
  400. else
  401. 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());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. 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.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. 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
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  453. int32 position = lua_interface->GetInt32Value(state, 2);
  454. lua_interface->ResetFunctionStack(state);
  455. if (spawnList) {
  456. if (spawnList->size() > position) {
  457. lua_interface->SetSpawnValue(state, spawnList->at(position));
  458. return 1;
  459. }
  460. else {
  461. return 0;
  462. }
  463. return spawnList->size();
  464. }
  465. return 0;
  466. }
  467. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  468. if (!lua_interface)
  469. return 0;
  470. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  471. lua_interface->ResetFunctionStack(state);
  472. if (spawnList) {
  473. return spawnList->size();
  474. }
  475. return 0;
  476. }
  477. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  478. if (!lua_interface)
  479. return 0;
  480. vector<Spawn*>* spawnList = new vector<Spawn*>();
  481. lua_interface->SetSpawnListValue(state, spawnList);
  482. return 1;
  483. }
  484. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  485. if (!lua_interface)
  486. return 0;
  487. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  488. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  489. lua_interface->ResetFunctionStack(state);
  490. if (spawnList) {
  491. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  492. if (it == spawnList->end())
  493. spawnList->push_back(spawn);
  494. }
  495. return 0;
  496. }
  497. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  498. if (!lua_interface)
  499. return 0;
  500. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  501. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  502. lua_interface->ResetFunctionStack(state);
  503. if (spawnList) {
  504. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  505. if(it != spawnList->end())
  506. spawnList->erase(it);
  507. }
  508. return 0;
  509. }
  510. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  511. if (!lua_interface)
  512. return 0;
  513. Spawn* spawn = lua_interface->GetSpawn(state);
  514. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  515. lua_interface->ResetFunctionStack(state);
  516. if (spawn) {
  517. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  518. if (spawns.size() > 0) {
  519. vector<Spawn*>* spawnList = new vector<Spawn*>();
  520. vector<Spawn*>::iterator itr;
  521. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  522. spawnList->push_back(*itr);
  523. }
  524. lua_interface->SetSpawnListValue(state, spawnList);
  525. return 1;
  526. }
  527. }
  528. return 0;
  529. }
  530. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  531. if (!lua_interface)
  532. return 0;
  533. Spawn* spawn = lua_interface->GetSpawn(state);
  534. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  535. lua_interface->ResetFunctionStack(state);
  536. if (spawn) {
  537. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  538. if (spawns.size() > 0) {
  539. vector<Spawn*>* spawnList = new vector<Spawn*>();
  540. vector<Spawn*>::iterator itr;
  541. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  542. spawnList->push_back(*itr);
  543. }
  544. lua_interface->SetSpawnListValue(state, spawnList);
  545. return 1;
  546. }
  547. }
  548. return 0;
  549. }
  550. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  551. if (!lua_interface)
  552. return 0;
  553. Spawn* spawn = lua_interface->GetSpawn(state);
  554. lua_interface->ResetFunctionStack(state);
  555. if (spawn) {
  556. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  557. if (spawns.size() > 0) {
  558. lua_createtable(state, spawns.size(), 0);
  559. int newTable = lua_gettop(state);
  560. for (int32 i = 0; i < spawns.size(); i++) {
  561. lua_interface->SetSpawnValue(state, spawns.at(i));
  562. lua_rawseti(state, newTable, i + 1);
  563. }
  564. return 1;
  565. }
  566. }
  567. return 0;
  568. }
  569. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  570. if (!lua_interface)
  571. return 0;
  572. string variable_name = lua_interface->GetStringValue(state);
  573. lua_interface->ResetFunctionStack(state);
  574. Variable* var = variables.FindVariable(variable_name);
  575. if (var) {
  576. lua_interface->SetStringValue(state, var->GetValue());
  577. return 1;
  578. }
  579. return 0;
  580. }
  581. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  582. if (!lua_interface)
  583. return 0;
  584. int32 total_coins = lua_interface->GetInt32Value(state);
  585. lua_interface->ResetFunctionStack(state);
  586. if (total_coins == 0) {
  587. lua_interface->SetStringValue(state, "0 copper");
  588. return 1;
  589. }
  590. char tmp[64] = { 0 };
  591. string message = "";
  592. int32 val = 0;
  593. if (total_coins >= 1000000) {
  594. val = total_coins / 1000000;
  595. total_coins -= 1000000 * val;
  596. sprintf(tmp, " %u Platinum", val);
  597. message.append(tmp);
  598. memset(tmp, 0, 64);
  599. }
  600. if (total_coins >= 10000) {
  601. val = total_coins / 10000;
  602. total_coins -= 10000 * val;
  603. sprintf(tmp, " %u Gold", val);
  604. message.append(tmp);
  605. memset(tmp, 0, 64);
  606. }
  607. if (total_coins >= 100) {
  608. val = total_coins / 100;
  609. total_coins -= 100 * val;
  610. sprintf(tmp, " %u Silver", val);
  611. message.append(tmp);
  612. memset(tmp, 0, 64);
  613. }
  614. if (total_coins > 0) {
  615. sprintf(tmp, " %u Copper", (int32)total_coins);
  616. message.append(tmp);
  617. }
  618. lua_interface->SetStringValue(state, message.c_str());
  619. return 1;
  620. }
  621. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  622. ZoneServer* zone = lua_interface->GetZone(state);
  623. int32 group_id = lua_interface->GetInt32Value(state, 2);
  624. lua_interface->ResetFunctionStack(state);
  625. if (zone) {
  626. Spawn* spawn = zone->GetSpawnGroup(group_id);
  627. if (spawn) {
  628. lua_interface->SetSpawnValue(state, spawn);
  629. return 1;
  630. }
  631. }
  632. return 0;
  633. }
  634. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  635. ZoneServer* zone = lua_interface->GetZone(state);
  636. int32 location_id = lua_interface->GetInt32Value(state, 2);
  637. lua_interface->ResetFunctionStack(state);
  638. if (zone) {
  639. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  640. if (spawn) {
  641. lua_interface->SetSpawnValue(state, spawn);
  642. return 1;
  643. }
  644. }
  645. return 0;
  646. }
  647. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  648. Spawn* spawn = lua_interface->GetSpawn(state);
  649. lua_interface->ResetFunctionStack(state);
  650. if (spawn) {
  651. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  652. return 1;
  653. }
  654. return 0;
  655. }
  656. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. lua_interface->ResetFunctionStack(state);
  659. if (spawn) {
  660. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  661. return 1;
  662. }
  663. return 0;
  664. }
  665. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  666. if (!lua_interface)
  667. return 0;
  668. Spawn* spawn = lua_interface->GetSpawn(state);
  669. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. spawn->SetSpawnGroupID(new_group_id);
  673. lua_interface->SetBooleanValue(state, true);
  674. return 1;
  675. }
  676. lua_interface->SetBooleanValue(state, false);
  677. return 1;
  678. }
  679. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  680. if (!lua_interface)
  681. return 0;
  682. Spawn* spawn = lua_interface->GetSpawn(state);
  683. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  684. lua_interface->ResetFunctionStack(state);
  685. if (spawn) {
  686. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  687. lua_interface->SetBooleanValue(state, true);
  688. return 1;
  689. }
  690. lua_interface->SetBooleanValue(state, false);
  691. return 1;
  692. }
  693. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  694. Spawn* spawn = lua_interface->GetSpawn(state);
  695. lua_interface->ResetFunctionStack(state);
  696. if (spawn) {
  697. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  698. return 1;
  699. }
  700. return 0;
  701. }
  702. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  703. Spawn* spawn = lua_interface->GetSpawn(state);
  704. lua_interface->ResetFunctionStack(state);
  705. if (spawn) {
  706. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  707. return 1;
  708. }
  709. return 0;
  710. }
  711. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  712. Player* player = (Player*)lua_interface->GetSpawn(state);
  713. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  714. lua_interface->ResetFunctionStack(state);
  715. if (player && player->IsPlayer() && faction_id > 0) {
  716. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  717. return 1;
  718. }
  719. return 0;
  720. }
  721. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  722. if (!lua_interface)
  723. return 0;
  724. Spawn* spawn = lua_interface->GetSpawn(state);
  725. int32 value = lua_interface->GetInt32Value(state, 2);
  726. lua_interface->ResetFunctionStack(state);
  727. if (spawn) {
  728. spawn->SetFactionID(value);
  729. }
  730. return 0;
  731. }
  732. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  733. Spawn* spawn = lua_interface->GetSpawn(state);
  734. lua_interface->ResetFunctionStack(state);
  735. if (spawn) {
  736. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  737. return 1;
  738. }
  739. return 0;
  740. }
  741. int EQ2Emu_lua_GetGender(lua_State* state) {
  742. Spawn* spawn = lua_interface->GetSpawn(state);
  743. lua_interface->ResetFunctionStack(state);
  744. if (spawn) {
  745. lua_interface->SetInt32Value(state, spawn->GetGender());
  746. return 1;
  747. }
  748. return 0;
  749. }
  750. int EQ2Emu_lua_GetTarget(lua_State* state) {
  751. Spawn* spawn = lua_interface->GetSpawn(state);
  752. lua_interface->ResetFunctionStack(state);
  753. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  754. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  755. return 1;
  756. }
  757. return 0;
  758. }
  759. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  760. if (!lua_interface)
  761. return 0;
  762. Spawn* spawn = lua_interface->GetSpawn(state);
  763. string mp3_string = lua_interface->GetStringValue(state, 2);
  764. int32 key1 = lua_interface->GetInt32Value(state, 3);
  765. int32 key2 = lua_interface->GetInt32Value(state, 4);
  766. Spawn* player = lua_interface->GetSpawn(state, 5);
  767. lua_interface->ResetFunctionStack(state);
  768. if (spawn && mp3_string.length() > 0) {
  769. Client* client = 0;
  770. if (player && player->IsPlayer())
  771. client = ((Player*)player)->GetClient();
  772. if (client) {
  773. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  774. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  775. }
  776. else
  777. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  778. }
  779. return 0;
  780. }
  781. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  782. if (!lua_interface)
  783. return 0;
  784. Spawn* spawn = lua_interface->GetSpawn(state);
  785. lua_interface->ResetFunctionStack(state);
  786. if (spawn) {
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  788. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  789. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  790. return 3;
  791. }
  792. return 0;
  793. }
  794. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  795. if (!lua_interface)
  796. return 0;
  797. Spawn* spawn = lua_interface->GetSpawn(state);
  798. if (spawn) {
  799. int32 item_id = lua_interface->GetInt32Value(state, 2);
  800. lua_interface->ResetFunctionStack(state);
  801. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  802. return 1;
  803. }
  804. lua_interface->ResetFunctionStack(state);
  805. return 0;
  806. }
  807. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  808. if (!lua_interface)
  809. return 0;
  810. Spawn* spawn = lua_interface->GetSpawn(state);
  811. if (spawn && spawn->IsEntity()) {
  812. int32 item_id = lua_interface->GetInt32Value(state, 2);
  813. int16 charges = lua_interface->GetInt16Value(state, 3);
  814. if (charges == 0)
  815. charges = 1;
  816. ((Entity*)spawn)->AddLootItem(item_id, charges);
  817. }
  818. lua_interface->ResetFunctionStack(state);
  819. return 0;
  820. }
  821. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  822. if (!lua_interface)
  823. return 0;
  824. Spawn* spawn = lua_interface->GetSpawn(state);
  825. if (spawn && spawn->IsEntity()) {
  826. int32 item_id = lua_interface->GetInt32Value(state, 2);
  827. Item* item = spawn->LootItem(item_id);
  828. lua_interface->SetLuaUserDataStale(item);
  829. safe_delete(item);
  830. }
  831. lua_interface->ResetFunctionStack(state);
  832. return 0;
  833. }
  834. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  835. if (!lua_interface)
  836. return 0;
  837. Spawn* spawn = lua_interface->GetSpawn(state);
  838. if (spawn) {
  839. int32 val = lua_interface->GetInt32Value(state, 2);
  840. spawn->AddLootCoins(val);
  841. }
  842. lua_interface->ResetFunctionStack(state);
  843. return 0;
  844. }
  845. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  846. if (!lua_interface)
  847. return 0;
  848. Spawn* entity = lua_interface->GetSpawn(state);
  849. Spawn* player = lua_interface->GetSpawn(state, 2);
  850. if (entity && player && player->IsPlayer()) {
  851. int32 coins = lua_interface->GetInt32Value(state, 3);
  852. vector<Item*>* items = 0;
  853. int i = 0;
  854. int32 item_id = 0;
  855. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  856. if (items == 0)
  857. items = new vector<Item*>;
  858. if (master_item_list.GetItem(item_id))
  859. items->push_back(master_item_list.GetItem(item_id));
  860. i++;
  861. }
  862. Client* client = 0;
  863. client = ((Player*)player)->GetClient();
  864. if (client)
  865. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  866. if(coins > 0)
  867. entity->AddLootCoins(coins);
  868. safe_delete(items);
  869. }
  870. lua_interface->ResetFunctionStack(state);
  871. return 0;
  872. }
  873. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  874. if (!lua_interface)
  875. return 0;
  876. Spawn* entity = lua_interface->GetSpawn(state);
  877. Spawn* player = lua_interface->GetSpawn(state, 2);
  878. int32 item_id = lua_interface->GetInt32Value(state, 3);
  879. lua_interface->ResetFunctionStack(state);
  880. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  881. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  882. return 1;
  883. }
  884. return 0;
  885. }
  886. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  887. if (!lua_interface)
  888. return 0;
  889. Spawn* entity = lua_interface->GetSpawn(state);
  890. Spawn* player = lua_interface->GetSpawn(state, 2);
  891. lua_interface->ResetFunctionStack(state);
  892. if (entity && player && player->IsPlayer()) {
  893. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  894. return 1;
  895. }
  896. return 0;
  897. }
  898. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  899. if (!lua_interface)
  900. return 0;
  901. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  902. lua_interface->SetLuaUserDataStale(conversation);
  903. safe_delete(conversation);
  904. lua_interface->ResetFunctionStack(state);
  905. conversation = new vector<ConversationOption>();
  906. lua_interface->SetConversationValue(state, conversation);
  907. return 1;
  908. }
  909. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  910. if (!lua_interface)
  911. return 0;
  912. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  913. if (conversation) {
  914. ConversationOption conv_option;
  915. conv_option.option = lua_interface->GetStringValue(state, 2);
  916. conv_option.function = lua_interface->GetStringValue(state, 3);
  917. if (conv_option.option.length() > 0)
  918. conversation->push_back(conv_option);
  919. }
  920. lua_interface->ResetFunctionStack(state);
  921. return 0;
  922. }
  923. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  924. if (!lua_interface)
  925. return 0;
  926. Spawn* npc = lua_interface->GetSpawn(state);
  927. Spawn* player = lua_interface->GetSpawn(state, 2);
  928. lua_interface->ResetFunctionStack(state);
  929. if (npc && player && player->IsPlayer() && player->GetZone()) {
  930. Client* client = ((Player*)player)->GetClient();
  931. if (client) {
  932. int32 conversation_id = client->GetConversationID(npc, 0);
  933. client->CloseDialog(conversation_id);
  934. }
  935. }
  936. return 0;
  937. }
  938. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  939. if (!lua_interface)
  940. return 0;
  941. Item* item = lua_interface->GetItem(state);
  942. Spawn* player = lua_interface->GetSpawn(state, 2);
  943. lua_interface->ResetFunctionStack(state);
  944. if (item && player && player->IsPlayer() && player->GetZone()) {
  945. Client* client = ((Player*)player)->GetClient();
  946. if (client) {
  947. int32 conversation_id = client->GetConversationID(0, item);
  948. client->CloseDialog(conversation_id);
  949. }
  950. }
  951. return 0;
  952. }
  953. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  954. if (!lua_interface)
  955. return 0;
  956. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  957. Spawn* spawn = 0;
  958. Item* item = 0;
  959. int8 type = lua_interface->GetInt8Value(state, 2);
  960. if (type == 1 || type == 3)
  961. spawn = lua_interface->GetSpawn(state, 3);
  962. else if (type == 2 || type == 4)
  963. item = lua_interface->GetItem(state, 3);
  964. Spawn* player = lua_interface->GetSpawn(state, 4);
  965. string text = lua_interface->GetStringValue(state, 5);
  966. string mp3 = lua_interface->GetStringValue(state, 6);
  967. int32 key1 = lua_interface->GetInt32Value(state, 7);
  968. int32 key2 = lua_interface->GetInt32Value(state, 8);
  969. int8 language = lua_interface->GetInt8Value(state, 9);
  970. int numargs = lua_interface->GetNumberOfArgs(state);
  971. int8 can_close = 1;
  972. if(numargs > 9)
  973. can_close = lua_interface->GetInt32Value(state, 10);
  974. lua_interface->ResetFunctionStack(state);
  975. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  976. Client* client = ((Player*)player)->GetClient();
  977. if (client) {
  978. if (spawn) {
  979. // Need to do this so the function works the same as it did before
  980. if (type == 1)
  981. type++;
  982. if (mp3.length() > 0)
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  984. else
  985. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  986. }
  987. else {
  988. if (mp3.length() > 0)
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  990. else
  991. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  992. }
  993. }
  994. }
  995. lua_interface->SetLuaUserDataStale(conversation);
  996. safe_delete(conversation);
  997. return 0;
  998. }
  999. int EQ2Emu_lua_StartConversation(lua_State* state) {
  1000. if (!lua_interface)
  1001. return 0;
  1002. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1003. Spawn* source = lua_interface->GetSpawn(state, 2);
  1004. Spawn* player = lua_interface->GetSpawn(state, 3);
  1005. string text = lua_interface->GetStringValue(state, 4);
  1006. string mp3 = lua_interface->GetStringValue(state, 5);
  1007. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1008. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1009. int8 language = lua_interface->GetInt32Value(state, 8);
  1010. int numargs = lua_interface->GetNumberOfArgs(state);
  1011. int8 can_close = 1;
  1012. if(numargs > 8)
  1013. can_close = lua_interface->GetInt32Value(state, 9);
  1014. lua_interface->ResetFunctionStack(state);
  1015. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1016. Client* client = ((Player*)player)->GetClient();
  1017. if (mp3.length() > 0)
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1019. else
  1020. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1021. lua_interface->SetLuaUserDataStale(conversation);
  1022. safe_delete(conversation);
  1023. }
  1024. else
  1025. 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);
  1026. return 0;
  1027. }
  1028. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1029. if (!lua_interface)
  1030. return 0;
  1031. Spawn* spawn = lua_interface->GetSpawn(state);
  1032. float distance = lua_interface->GetFloatValue(state, 2);
  1033. string in_range_function = lua_interface->GetStringValue(state, 3);
  1034. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1035. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1036. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1037. return 0;
  1038. }
  1039. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1040. ZoneServer* zone = lua_interface->GetZone(state);
  1041. float x = lua_interface->GetFloatValue(state, 2);
  1042. float y = lua_interface->GetFloatValue(state, 3);
  1043. float z = lua_interface->GetFloatValue(state, 4);
  1044. float max_variation = lua_interface->GetFloatValue(state, 5);
  1045. string in_range_function = lua_interface->GetStringValue(state, 6);
  1046. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1047. lua_interface->ResetFunctionStack(state);
  1048. if (zone && in_range_function.length() > 0)
  1049. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1050. return 0;
  1051. }
  1052. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1053. if (!lua_interface)
  1054. return 0;
  1055. Spawn* spawn = lua_interface->GetSpawn(state);
  1056. if (spawn && spawn->IsEntity()) {
  1057. int32 val = lua_interface->GetInt32Value(state, 2);
  1058. ((Entity*)spawn)->SetLootCoins(val);
  1059. }
  1060. lua_interface->ResetFunctionStack(state);
  1061. return 0;
  1062. }
  1063. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1064. if (!lua_interface)
  1065. return 0;
  1066. Spawn* spawn = lua_interface->GetSpawn(state);
  1067. lua_interface->ResetFunctionStack(state);
  1068. if (spawn && spawn->IsEntity()) {
  1069. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1070. return 1;
  1071. }
  1072. return 0;
  1073. }
  1074. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1075. if (!lua_interface)
  1076. return 0;
  1077. Spawn* spawn = lua_interface->GetSpawn(state);
  1078. float x = lua_interface->GetFloatValue(state, 2);
  1079. float y = lua_interface->GetFloatValue(state, 3);
  1080. float z = lua_interface->GetFloatValue(state, 4);
  1081. float speed = lua_interface->GetFloatValue(state, 5);
  1082. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1083. string function = lua_interface->GetStringValue(state, 7);
  1084. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1085. float heading = lua_interface->GetFloatValue(state, 8);
  1086. if (spawn) {
  1087. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1088. spawn->GetZone()->AddMovementNPC(spawn);
  1089. }
  1090. lua_interface->ResetFunctionStack(state);
  1091. return 0;
  1092. }
  1093. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1094. if (!lua_interface)
  1095. return 0;
  1096. Spawn* spawn = lua_interface->GetSpawn(state);
  1097. lua_interface->ResetFunctionStack(state);
  1098. if (spawn) {
  1099. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1100. return 1;
  1101. }
  1102. return 0;
  1103. }
  1104. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1105. if (!lua_interface)
  1106. return 0;
  1107. Spawn* spawn = lua_interface->GetSpawn(state);
  1108. lua_interface->ResetFunctionStack(state);
  1109. if (spawn && spawn->IsPlayer()) {
  1110. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1111. return 1;
  1112. }
  1113. lua_interface->SetInt32Value(state, 0);
  1114. return 1;
  1115. }
  1116. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1117. if (!lua_interface)
  1118. return 0;
  1119. Spawn* spawn = lua_interface->GetSpawn(state);
  1120. Spawn* target = lua_interface->GetSpawn(state, 2);
  1121. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1122. bool reset_action_state = true;
  1123. if(num_args > 2)
  1124. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1125. if (spawn && target) {
  1126. if (spawn->IsEntity())
  1127. // ((Entity*)spawn)->FaceTarget(target);
  1128. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1129. }
  1130. lua_interface->ResetFunctionStack(state);
  1131. return 0;
  1132. }
  1133. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1134. if (!lua_interface)
  1135. return 0;
  1136. Spawn* spawn = lua_interface->GetSpawn(state);
  1137. float x = lua_interface->GetFloatValue(state, 2);
  1138. float y = lua_interface->GetFloatValue(state, 3);
  1139. float z = lua_interface->GetFloatValue(state, 4);
  1140. float speed = lua_interface->GetFloatValue(state, 5);
  1141. string lua_function = lua_interface->GetStringValue(state, 6);
  1142. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1143. if (spawn) {
  1144. if (speed == 0)
  1145. speed = spawn->GetSpeed();
  1146. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1147. }
  1148. lua_interface->ResetFunctionStack(state);
  1149. return 0;
  1150. }
  1151. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1152. if (!lua_interface)
  1153. return 0;
  1154. Spawn* spawn = lua_interface->GetSpawn(state);
  1155. lua_interface->ResetFunctionStack(state);
  1156. if (spawn) {
  1157. spawn->ClearRunningLocations();
  1158. }
  1159. return 0;
  1160. }
  1161. int EQ2Emu_lua_Say(lua_State* state) {
  1162. if (!lua_interface)
  1163. return 0;
  1164. Spawn* spawn = lua_interface->GetSpawn(state);
  1165. string message = lua_interface->GetStringValue(state, 2);
  1166. Spawn* player = lua_interface->GetSpawn(state, 3);
  1167. float dist = lua_interface->GetFloatValue(state, 4);
  1168. int32 language = lua_interface->GetInt32Value(state, 5);
  1169. if (spawn && message.length() > 0) {
  1170. Client* client = 0;
  1171. if (player && player->IsPlayer())
  1172. client = ((Player*)player)->GetClient();
  1173. if (client)
  1174. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. else
  1176. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1177. }
  1178. lua_interface->ResetFunctionStack(state);
  1179. return 0;
  1180. }
  1181. int EQ2Emu_lua_Shout(lua_State* state) {
  1182. if (!lua_interface)
  1183. return 0;
  1184. Spawn* spawn = lua_interface->GetSpawn(state);
  1185. string message = lua_interface->GetStringValue(state, 2);
  1186. Spawn* player = lua_interface->GetSpawn(state, 3);
  1187. float dist = lua_interface->GetFloatValue(state, 4);
  1188. int32 language = lua_interface->GetInt32Value(state, 5);
  1189. if (spawn && message.length() > 0) {
  1190. Client* client = 0;
  1191. if (player && player->IsPlayer())
  1192. client = ((Player*)player)->GetClient();
  1193. if (client)
  1194. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. else
  1196. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1197. }
  1198. lua_interface->ResetFunctionStack(state);
  1199. return 0;
  1200. }
  1201. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1202. if (!lua_interface)
  1203. return 0;
  1204. Spawn* spawn = lua_interface->GetSpawn(state);
  1205. string message = lua_interface->GetStringValue(state, 2);
  1206. Spawn* player = lua_interface->GetSpawn(state, 3);
  1207. float dist = lua_interface->GetFloatValue(state, 4);
  1208. int32 language = lua_interface->GetInt32Value(state, 5);
  1209. if (spawn && message.length() > 0) {
  1210. Client* client = 0;
  1211. if (player && player->IsPlayer())
  1212. client = ((Player*)player)->GetClient();
  1213. if (client)
  1214. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. else
  1216. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1217. }
  1218. lua_interface->ResetFunctionStack(state);
  1219. return 0;
  1220. }
  1221. int EQ2Emu_lua_Emote(lua_State* state) {
  1222. if (!lua_interface)
  1223. return 0;
  1224. Spawn* spawn = lua_interface->GetSpawn(state);
  1225. string message = lua_interface->GetStringValue(state, 2);
  1226. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1227. Spawn* player = lua_interface->GetSpawn(state, 4);
  1228. char* to = 0;
  1229. if (spawn2)
  1230. to = spawn2->GetName();
  1231. if (spawn && message.length() > 0) {
  1232. Client* client = 0;
  1233. if (player && player->IsPlayer())
  1234. client = ((Player*)player)->GetClient();
  1235. if (client)
  1236. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. else
  1238. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1239. }
  1240. lua_interface->ResetFunctionStack(state);
  1241. return 0;
  1242. }
  1243. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1244. if (!lua_interface)
  1245. return 0;
  1246. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1247. if(!luaspell || luaspell->resisted) {
  1248. return 0;
  1249. }
  1250. Spawn* caster = luaspell->caster;
  1251. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1252. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1253. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1254. Spawn* target = lua_interface->GetSpawn(state, 4);
  1255. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1256. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1257. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1258. lua_interface->ResetFunctionStack(state);
  1259. boost::to_lower(heal_type);
  1260. if (caster && caster->IsEntity()) {
  1261. bool success = false;
  1262. luaspell->resisted = false;
  1263. if (target) {
  1264. float distance = caster->GetDistance(target, true);
  1265. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1266. success = true;
  1267. }
  1268. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1269. Spawn* target = 0;
  1270. ZoneServer* zone = luaspell->caster->GetZone();
  1271. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1272. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1273. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1274. float distance = caster->GetDistance(target, true);
  1275. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1276. }
  1277. }
  1278. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1279. success = true;
  1280. }
  1281. if (success) {
  1282. if (caster->GetZone())
  1283. caster->GetZone()->TriggerCharSheetTimer();
  1284. }
  1285. }
  1286. return 0;
  1287. }
  1288. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1289. if (!lua_interface)
  1290. return 0;
  1291. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1292. if(!luaspell || luaspell->resisted) {
  1293. return 0;
  1294. }
  1295. Spawn* caster = luaspell->caster;
  1296. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1297. float percentage = lua_interface->GetFloatValue(state, 2);
  1298. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1299. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1300. Spawn* target = lua_interface->GetSpawn(state, 5);
  1301. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1302. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1303. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1304. lua_interface->ResetFunctionStack(state);
  1305. boost::to_lower(heal_type);
  1306. int32 min_heal = 0, max_heal = 0;
  1307. if (caster && caster->IsEntity() && target) {
  1308. if(percentage <= 0.0f)
  1309. {
  1310. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1311. return 0;
  1312. }
  1313. if(heal_type == "power")
  1314. {
  1315. if(current_value)
  1316. {
  1317. if(caster_value)
  1318. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1319. else
  1320. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1321. }
  1322. else
  1323. {
  1324. if(caster_value)
  1325. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1326. else
  1327. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(current_value)
  1333. {
  1334. if(caster_value)
  1335. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1336. else
  1337. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1338. }
  1339. else
  1340. {
  1341. if(caster_value)
  1342. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1343. else
  1344. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1345. }
  1346. }
  1347. bool success = false;
  1348. luaspell->resisted = false;
  1349. if (target) {
  1350. float distance = caster->GetDistance(target, true);
  1351. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1352. success = true;
  1353. }
  1354. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1355. Spawn* target = 0;
  1356. ZoneServer* zone = luaspell->caster->GetZone();
  1357. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1358. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1359. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1360. float distance = caster->GetDistance(target, true);
  1361. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1362. }
  1363. }
  1364. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1365. success = true;
  1366. }
  1367. if (success) {
  1368. if (caster->GetZone())
  1369. caster->GetZone()->TriggerCharSheetTimer();
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. int EQ2Emu_lua_AddItem(lua_State* state) {
  1375. if (!lua_interface)
  1376. return 0;
  1377. Spawn* spawn = lua_interface->GetSpawn(state);
  1378. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1379. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1380. lua_interface->ResetFunctionStack(state);
  1381. // default of 1 quantity to add
  1382. if (quantity == 0)
  1383. quantity = 1;
  1384. if (spawn && spawn->IsPlayer()) {
  1385. Client* client = ((Player*)spawn)->GetClient();
  1386. if (client && item_id > 0) {
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1388. return 1;
  1389. }
  1390. }
  1391. lua_interface->SetBooleanValue(state, false);
  1392. return 1;
  1393. }
  1394. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. Spawn* spawn = lua_interface->GetSpawn(state);
  1398. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1399. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1400. string location = lua_interface->GetStringValue(state, 4);
  1401. int16 item_count = lua_interface->GetInt16Value(state,5);
  1402. //devn00b: if we dont have a count, assume 1 item.
  1403. if(!item_count) {
  1404. item_count = 1;
  1405. }
  1406. lua_interface->ResetFunctionStack(state);
  1407. if (spawn && spawn->IsPlayer()) {
  1408. Client* client = ((Player*)spawn)->GetClient();
  1409. if (client && item_id > 0) {
  1410. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1411. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1412. else
  1413. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1414. if (send_messages) {
  1415. Item* item = master_item_list.GetItem(item_id);
  1416. if (item) {
  1417. if(item_count > 1) {
  1418. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1419. string popup_text1 = "You receive "+ item_count;
  1420. string popup_text2 = " " + item->name;
  1421. string popup_text = popup_text1 + popup_text2;
  1422. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1423. // return 1;
  1424. } else {
  1425. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1426. string popup_text = "You receive " + item->name;
  1427. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1428. }
  1429. }
  1430. }
  1431. return 1;
  1432. }
  1433. }
  1434. lua_interface->SetBooleanValue(state, false);
  1435. return 1;
  1436. }
  1437. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1440. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1441. lua_interface->ResetFunctionStack(state);
  1442. // default of 1 to remove
  1443. if (quantity == 0)
  1444. quantity = 1;
  1445. Client* client;
  1446. Item* item;
  1447. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1448. if ((client = ((Player*)spawn)->GetClient())) {
  1449. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1450. if (client->RemoveItem(item, quantity)) {
  1451. lua_interface->SetBooleanValue(state, true);
  1452. return 1;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. lua_interface->SetBooleanValue(state, false);
  1458. return 1;
  1459. }
  1460. int EQ2Emu_lua_HasItem(lua_State* state) {
  1461. Spawn* player = lua_interface->GetSpawn(state);
  1462. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1463. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1464. lua_interface->ResetFunctionStack(state);
  1465. if (player && player->IsPlayer()) {
  1466. bool hasItem = false;
  1467. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1468. if (!hasItem)
  1469. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1470. lua_interface->SetBooleanValue(state, hasItem);
  1471. return 1;
  1472. }
  1473. lua_interface->SetBooleanValue(state, false);
  1474. return 1;
  1475. }
  1476. int EQ2Emu_lua_Spawn(lua_State* state) {
  1477. if (!lua_interface)
  1478. return 0;
  1479. ZoneServer* zone = lua_interface->GetZone(state);
  1480. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1481. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1482. float x = lua_interface->GetFloatValue(state, 4);
  1483. float y = lua_interface->GetFloatValue(state, 5);
  1484. float z = lua_interface->GetFloatValue(state, 6);
  1485. float heading = lua_interface->GetFloatValue(state, 7);
  1486. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1487. Spawn* spawn = zone->GetSpawn(spawn_id);
  1488. if (!spawn)
  1489. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1490. else {
  1491. spawn->SetX(x);
  1492. spawn->SetZ(z);
  1493. spawn->SetY(y,true,true);
  1494. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1495. spawn->SetHeading(heading);
  1496. if (restricted_npc)
  1497. spawn->AddAllowAccessSpawn(spawn);
  1498. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1499. bool scriptActive = false;
  1500. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1501. scriptActive = true;
  1502. spawn->SetSpawnScript(string(spawn_script));
  1503. }
  1504. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1505. zone->AddSpawn(spawn);
  1506. if (scriptActive) {
  1507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1508. }
  1509. lua_interface->ResetFunctionStack(state);
  1510. lua_interface->SetSpawnValue(state, spawn);
  1511. return 1;
  1512. }
  1513. }
  1514. else {
  1515. string output = "Invalid paramaters to LUA Spawn command: \n";
  1516. if (!zone)
  1517. output = output.append("\t").append("Missing zone reference. \n");
  1518. if (spawn_id == 0)
  1519. output = output.append("\t").append("Missing spawn_id.");
  1520. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1521. }
  1522. lua_interface->ResetFunctionStack(state);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. ZoneServer* zone = lua_interface->GetZone(state);
  1529. lua_interface->ResetFunctionStack(state);
  1530. if (zone) {
  1531. lua_interface->SetStringValue(state, zone->GetZoneName());
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. ZoneServer* zone = lua_interface->GetZone(state);
  1540. lua_interface->ResetFunctionStack(state);
  1541. if (zone) {
  1542. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1543. return 1;
  1544. }
  1545. return 0;
  1546. }
  1547. int EQ2Emu_lua_GetZone(lua_State* state) {
  1548. if (!lua_interface)
  1549. return 0;
  1550. int32 zone_id = lua_interface->GetInt32Value(state);
  1551. ZoneServer* zone = 0;
  1552. if (zone_id > 0)
  1553. zone = zone_list.Get(zone_id);
  1554. else {
  1555. string zone_name = lua_interface->GetStringValue(state);
  1556. if (zone_name.length() > 0) {
  1557. zone = zone_list.Get(zone_name.c_str());
  1558. }
  1559. else {
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. if (spawn)
  1562. zone = spawn->GetZone();
  1563. }
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (zone) {
  1567. lua_interface->SetZoneValue(state, zone);
  1568. return 1;
  1569. }
  1570. return 0;
  1571. }
  1572. int EQ2Emu_lua_AddHate(lua_State* state) {
  1573. Spawn* entity = lua_interface->GetSpawn(state);
  1574. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1575. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1576. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if(!luaspell || luaspell->resisted) {
  1579. return 0;
  1580. }
  1581. if (entity && entity->IsEntity() && amount != 0) {
  1582. if (luaspell) {
  1583. ZoneServer* zone = luaspell->caster->GetZone();
  1584. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1585. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1586. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1587. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1588. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1589. if (send_packet)
  1590. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1591. }
  1592. }
  1593. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1594. }
  1595. else if (npc && npc->IsNPC() && npc->GetZone())
  1596. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1597. }
  1598. lua_interface->ResetFunctionStack(state);
  1599. return 0;
  1600. }
  1601. int EQ2Emu_lua_Zone(lua_State* state) {
  1602. if (!lua_interface)
  1603. return 0;
  1604. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1605. ZoneServer* zone = lua_interface->GetZone(state);
  1606. Spawn* player = lua_interface->GetSpawn(state, 2);
  1607. Client* client = 0;
  1608. if (player && player->IsPlayer())
  1609. client = ((Player*)player)->GetClient();
  1610. float x = lua_interface->GetFloatValue(state, 3);
  1611. float y = lua_interface->GetFloatValue(state, 4);
  1612. float z = lua_interface->GetFloatValue(state, 5);
  1613. float heading = lua_interface->GetFloatValue(state, 6);
  1614. if (zone && client) {
  1615. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1616. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1617. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1618. {
  1619. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1620. return 0;
  1621. }
  1622. if (x != 0 || y != 0 || z != 0) {
  1623. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1624. player->SetX(x);
  1625. player->SetY(y);
  1626. player->SetZ(z);
  1627. player->SetHeading(heading);
  1628. client->Zone(zone->GetZoneName(), false);
  1629. }
  1630. else
  1631. client->Zone(zone->GetZoneName());
  1632. }
  1633. else
  1634. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1635. lua_interface->ResetFunctionStack(state);
  1636. return 0;
  1637. }
  1638. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1639. if (!lua_interface)
  1640. return 0;
  1641. Spawn* spawn = lua_interface->GetSpawn(state);
  1642. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1643. if (spawn && spawn2)
  1644. spawn->AddAllowAccessSpawn(spawn2);
  1645. lua_interface->ResetFunctionStack(state);
  1646. return 0;
  1647. }
  1648. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1649. if (!lua_interface)
  1650. return 0;
  1651. Spawn* target = lua_interface->GetSpawn(state);
  1652. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1653. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1654. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1655. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1656. lua_interface->ResetFunctionStack(state);
  1657. if (!target) {
  1658. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1659. return 0;
  1660. }
  1661. if (!target->IsEntity()) {
  1662. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1663. return 0;
  1664. }
  1665. if (spell_id <= 0) {
  1666. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1667. return 0;
  1668. }
  1669. if (caster && !caster->IsEntity()) {
  1670. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1671. return 0;
  1672. }
  1673. if (spell_tier == 0)
  1674. spell_tier = 1;
  1675. if (!caster)
  1676. caster = target;
  1677. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1678. return 0;
  1679. }
  1680. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1681. if (!lua_interface)
  1682. return 0;
  1683. Spawn* target = lua_interface->GetSpawn(state);
  1684. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1685. if(!luaspell || luaspell->resisted) {
  1686. return 0;
  1687. }
  1688. Spawn* caster = luaspell->caster;
  1689. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1690. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1691. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1692. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1693. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1694. //lua_interface->ResetFunctionStack(state);
  1695. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1696. vector<int16> faction_req;
  1697. vector<int16> race_req;
  1698. int32 class_req = 0;
  1699. int32 i = 0;
  1700. int8 f = 0;
  1701. int8 r = 0;
  1702. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1703. if (class_id < 100) {
  1704. class_req += pow(2.0, double(class_id - 1));
  1705. }
  1706. else if (class_id > 100 && class_id < 1000) {
  1707. race_req.push_back(class_id);
  1708. r++;
  1709. }
  1710. else {
  1711. faction_req.push_back(class_id);
  1712. f++;
  1713. }
  1714. i++;
  1715. }
  1716. lua_interface->ResetFunctionStack(state);
  1717. if (caster && caster->IsEntity()) {
  1718. bool race_match = false;
  1719. bool success = false;
  1720. luaspell->resisted = false;
  1721. if (luaspell->targets.size() > 0) {
  1722. ZoneServer* zone = luaspell->caster->GetZone();
  1723. Spawn* target = 0;
  1724. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1725. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1726. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1727. if (race_req.size() > 0) {
  1728. for (int8 i = 0; i < race_req.size(); i++) {
  1729. if(race_req[i] == target->GetRace() ||
  1730. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1731. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1732. race_match = true;
  1733. }
  1734. }
  1735. }
  1736. else
  1737. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1738. if (race_match == true) {
  1739. float distance = caster->GetDistance(target, true);
  1740. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1741. }
  1742. }
  1743. }
  1744. success = true;
  1745. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1746. }
  1747. else if (target) {
  1748. //check class and race/faction here
  1749. if (race_req.size() > 0) {
  1750. for (int8 i = 0; i < race_req.size(); i++) {
  1751. if(race_req[i] == target->GetRace() ||
  1752. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1753. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1754. race_match = true;
  1755. }
  1756. }
  1757. }
  1758. else
  1759. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1760. if (race_match == true) {
  1761. float distance = caster->GetDistance(target, true);
  1762. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1763. success = true;
  1764. }
  1765. }
  1766. if (success) {
  1767. Spell* spell = luaspell->spell;
  1768. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1769. ((Player*)caster)->InCombat(true);
  1770. if (caster->GetZone())
  1771. caster->GetZone()->TriggerCharSheetTimer();
  1772. }
  1773. }
  1774. }
  1775. return 0;
  1776. }
  1777. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1778. if (!lua_interface)
  1779. return 0;
  1780. Spawn* spawn = lua_interface->GetSpawn(state);
  1781. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1782. lua_interface->ResetFunctionStack(state);
  1783. if (spawn && value != 0) {
  1784. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1785. spawn->SetPower(spawn->GetTotalPower());
  1786. else
  1787. spawn->SetPower(spawn->GetPower() + value);
  1788. }
  1789. return 0;
  1790. }
  1791. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1792. if (!lua_interface)
  1793. return 0;
  1794. Spawn* spawn = lua_interface->GetSpawn(state);
  1795. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1796. lua_interface->ResetFunctionStack(state);
  1797. if (spawn && value != 0) {
  1798. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1799. spawn->SetHP(spawn->GetTotalHP());
  1800. else
  1801. spawn->SetHP(spawn->GetHP() + value);
  1802. }
  1803. return 0;
  1804. }
  1805. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1806. if (!lua_interface)
  1807. return 0;
  1808. Spawn* spawn = lua_interface->GetSpawn(state);
  1809. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1810. lua_interface->ResetFunctionStack(state);
  1811. if (spawn && value != 0) {
  1812. spawn->SetPower(spawn->GetPower() + value);
  1813. if (value > spawn->GetTotalHPBase())
  1814. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1815. }
  1816. return 0;
  1817. }
  1818. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1819. if (!lua_interface)
  1820. return 0;
  1821. Spawn* spawn = lua_interface->GetSpawn(state);
  1822. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1823. lua_interface->ResetFunctionStack(state);
  1824. if (spawn && value != 0) {
  1825. spawn->SetHP(spawn->GetHP() + value);
  1826. if (value > spawn->GetTotalHPBase())
  1827. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1828. }
  1829. return 0;
  1830. }
  1831. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1832. if (!lua_interface)
  1833. return 0;
  1834. Spawn* spawn = lua_interface->GetSpawn(state);
  1835. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1836. lua_interface->ResetFunctionStack(state);
  1837. if (spawn) {
  1838. spawn->SetHP(value);
  1839. if (value > spawn->GetTotalHPBase())
  1840. spawn->SetTotalHP(value);
  1841. }
  1842. return 0;
  1843. }
  1844. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1845. if (!lua_interface)
  1846. return 0;
  1847. Spawn* spawn = lua_interface->GetSpawn(state);
  1848. float value = lua_interface->GetFloatValue(state, 2);
  1849. lua_interface->ResetFunctionStack(state);
  1850. if (spawn && spawn->IsEntity() && value > 0)
  1851. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1852. if (spawn->IsPlayer())
  1853. ((Player*)spawn)->SetCharSheetChanged(true);
  1854. return 0;
  1855. }
  1856. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1857. if (!lua_interface)
  1858. return 0;
  1859. Spawn* spawn = lua_interface->GetSpawn(state);
  1860. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1861. lua_interface->ResetFunctionStack(state);
  1862. if (spawn && spawn->IsEntity() && value > 0)
  1863. ((Entity*)spawn)->SetTotalHPBase(value);
  1864. return 0;
  1865. }
  1866. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1867. if (!lua_interface)
  1868. return 0;
  1869. Spawn* spawn = lua_interface->GetSpawn(state);
  1870. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1871. lua_interface->ResetFunctionStack(state);
  1872. if (spawn && value > 0) {
  1873. spawn->SetPower(value);
  1874. if (value > spawn->GetTotalPowerBase())
  1875. spawn->SetTotalPower(value);
  1876. }
  1877. return 0;
  1878. }
  1879. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1880. if (!lua_interface)
  1881. return 0;
  1882. Spawn* spawn = lua_interface->GetSpawn(state);
  1883. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1884. lua_interface->ResetFunctionStack(state);
  1885. if (spawn && spawn->IsEntity() && value > 0)
  1886. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1887. return 0;
  1888. }
  1889. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1890. if (!lua_interface)
  1891. return 0;
  1892. Spawn* spawn = lua_interface->GetSpawn(state);
  1893. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1894. lua_interface->ResetFunctionStack(state);
  1895. if (spawn && spawn->IsEntity() && value > 0)
  1896. ((Entity*)spawn)->SetTotalPowerBase(value);
  1897. return 0;
  1898. }
  1899. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1900. if (!lua_interface)
  1901. return 0;
  1902. Spawn* spawn = lua_interface->GetSpawn(state);
  1903. float x = lua_interface->GetFloatValue(state, 2);
  1904. float y = lua_interface->GetFloatValue(state, 3);
  1905. float z = lua_interface->GetFloatValue(state, 4);
  1906. float heading = lua_interface->GetFloatValue(state, 5);
  1907. lua_interface->ResetFunctionStack(state);
  1908. if (spawn) {
  1909. spawn->SetX(x);
  1910. spawn->SetY(y);
  1911. spawn->SetZ(z);
  1912. if (heading != 0)
  1913. spawn->SetHeading(heading);
  1914. spawn->SetSpawnOrigX(spawn->GetX());
  1915. spawn->SetSpawnOrigY(spawn->GetY());
  1916. spawn->SetSpawnOrigZ(spawn->GetZ());
  1917. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1918. if (spawn->IsPlayer()) {
  1919. Client* client = ((Player*)spawn)->GetClient();
  1920. if (client) {
  1921. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1922. client->QueuePacket(packet);
  1923. }
  1924. }
  1925. }
  1926. return 0;
  1927. }
  1928. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1929. if (!lua_interface)
  1930. return 0;
  1931. Spawn* spawn = lua_interface->GetSpawn(state);
  1932. float value = lua_interface->GetFloatValue(state, 2);
  1933. lua_interface->ResetFunctionStack(state);
  1934. if (spawn) {
  1935. spawn->SetHeading(value);
  1936. if (spawn->IsPlayer()) {
  1937. Client* client = ((Player*)spawn)->GetClient();
  1938. if (client) {
  1939. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1940. client->QueuePacket(packet);
  1941. }
  1942. }
  1943. }
  1944. return 0;
  1945. }
  1946. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1947. if (!lua_interface)
  1948. return 0;
  1949. Spawn* spawn = lua_interface->GetSpawn(state);
  1950. int16 value = lua_interface->GetInt16Value(state, 2);
  1951. lua_interface->ResetFunctionStack(state);
  1952. if (spawn)
  1953. spawn->SetModelType(value);
  1954. return 0;
  1955. }
  1956. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1957. if (!lua_interface)
  1958. return 0;
  1959. Spawn* spawn = lua_interface->GetSpawn(state);
  1960. int8 value = lua_interface->GetInt8Value(state, 2);
  1961. lua_interface->ResetFunctionStack(state);
  1962. if (spawn) {
  1963. if (spawn->IsPlayer())
  1964. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1965. else
  1966. spawn->SetAdventureClass(value);
  1967. }
  1968. return 0;
  1969. }
  1970. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1971. if (!lua_interface)
  1972. return 0;
  1973. Spawn* spawn = lua_interface->GetSpawn(state);
  1974. int8 value = lua_interface->GetInt8Value(state, 2);
  1975. lua_interface->ResetFunctionStack(state);
  1976. if (spawn) {
  1977. spawn->SetTradeskillClass(value);
  1978. if (spawn->IsEntity()) {
  1979. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1980. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1981. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1982. }
  1983. if (spawn->IsPlayer())
  1984. ((Player*)spawn)->SetCharSheetChanged(true);
  1985. }
  1986. return 0;
  1987. }
  1988. int EQ2Emu_lua_SetMount(lua_State* state) {
  1989. if (!lua_interface)
  1990. return 0;
  1991. Spawn* spawn = lua_interface->GetSpawn(state);
  1992. int16 value = lua_interface->GetInt16Value(state, 2);
  1993. if (spawn && spawn->IsEntity()) {
  1994. ((Entity*)spawn)->SetMount(value);
  1995. EQ2_Color color;
  1996. color.red = 255;
  1997. color.green = 255;
  1998. color.blue = 255;
  1999. ((Entity*)spawn)->SetMountColor(&color);
  2000. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2001. }
  2002. return 0;
  2003. }
  2004. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2005. if (!lua_interface)
  2006. return 0;
  2007. Spawn* spawn = lua_interface->GetSpawn(state);
  2008. EQ2_Color mount_color;
  2009. EQ2_Color saddle_color;
  2010. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2011. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2012. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2013. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2014. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2015. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2016. if (spawn && spawn->IsEntity()) {
  2017. ((Entity*)spawn)->SetMountColor(&mount_color);
  2018. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2019. }
  2020. return 0;
  2021. }
  2022. int EQ2Emu_lua_GetMount(lua_State* state) {
  2023. if (!lua_interface)
  2024. return 0;
  2025. Spawn* spawn = lua_interface->GetSpawn(state);
  2026. if (spawn && spawn->IsEntity()) {
  2027. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2028. return 1;
  2029. }
  2030. return 0;
  2031. }
  2032. int EQ2Emu_lua_GetRace(lua_State* state) {
  2033. if (!lua_interface)
  2034. return 0;
  2035. Spawn* spawn = lua_interface->GetSpawn(state);
  2036. if (spawn)
  2037. {
  2038. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2039. lua_interface->SetInt32Value(state, spawn->GetRace());
  2040. return 1;
  2041. }
  2042. return 0;
  2043. }
  2044. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2045. if (!lua_interface)
  2046. return 0;
  2047. Spawn* spawn = lua_interface->GetSpawn(state);
  2048. if (spawn) {
  2049. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2050. return 1;
  2051. }
  2052. return 0;
  2053. }
  2054. int EQ2Emu_lua_GetClass(lua_State* state) {
  2055. Spawn* spawn = lua_interface->GetSpawn(state);
  2056. if (spawn) {
  2057. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2058. return 1;
  2059. }
  2060. return 0;
  2061. }
  2062. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2063. Spawn* spawn = lua_interface->GetSpawn(state);
  2064. if (spawn) {
  2065. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2066. return 1;
  2067. }
  2068. return 0;
  2069. }
  2070. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2071. if (!lua_interface)
  2072. return 0;
  2073. Spawn* spawn = lua_interface->GetSpawn(state);
  2074. float value = lua_interface->GetFloatValue(state, 2);
  2075. lua_interface->ResetFunctionStack(state);
  2076. if (spawn) {
  2077. spawn->SetSpeed(value);
  2078. if(spawn->IsEntity())
  2079. ((Entity*)spawn)->SetSpeed(value);
  2080. if (spawn->IsPlayer()) {
  2081. Client* client = ((Player*)spawn)->GetClient();
  2082. if (client) {
  2083. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2084. if (packet) {
  2085. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2086. packet->setDataByName("speed", value);
  2087. packet->setDataByName("size", 0.51);
  2088. EQ2Packet* app = packet->serialize();
  2089. client->QueuePacket(app);
  2090. safe_delete(packet);
  2091. }
  2092. }
  2093. }
  2094. }
  2095. return 0;
  2096. }
  2097. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2098. if (!lua_interface)
  2099. return 0;
  2100. Spawn* spawn = lua_interface->GetSpawn(state);
  2101. const int16 type = lua_interface->GetInt16Value(state, 2);
  2102. const float value = lua_interface->GetFloatValue(state, 3);
  2103. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2104. if(!luaspell || luaspell->resisted) {
  2105. return 0;
  2106. }
  2107. int64 class_req = 0;
  2108. int32 class_id = 0;
  2109. vector<int16> faction_req;
  2110. vector<int16> race_req;
  2111. int32 i = 0;
  2112. int8 f = 0;
  2113. int8 r = 0;
  2114. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2115. if (class_id < 100) {
  2116. class_req += pow(2.0, double(class_id - 1));
  2117. }
  2118. else if (class_id > 100 && class_id < 1000) {
  2119. race_req.push_back(class_id);
  2120. r++;
  2121. }
  2122. else {
  2123. faction_req.push_back(class_id);
  2124. f++;
  2125. }
  2126. i++;
  2127. }
  2128. if (value != 0 && type >= 0) {
  2129. if (luaspell && luaspell->spell && luaspell->caster) {
  2130. ZoneServer* zone = luaspell->caster->GetZone();
  2131. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2132. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2133. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2134. if (target) {
  2135. if (target->IsPlayer()) {
  2136. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2137. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2138. if (((Player*)target)->GetGroupMemberInfo())
  2139. ((Player*)target)->UpdateGroupMemberInfo();
  2140. ((Player*)target)->SetCharSheetChanged(true);
  2141. }
  2142. else if (target->IsNPC())
  2143. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2144. else
  2145. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2146. }
  2147. }
  2148. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2149. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2150. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2151. }
  2152. else if (spawn && spawn->IsEntity()) {
  2153. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2154. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2155. if (spawn->IsPlayer())
  2156. ((Player*)spawn)->SetCharSheetChanged(true);
  2157. }
  2158. else
  2159. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2160. }
  2161. else
  2162. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2163. return 0;
  2164. }
  2165. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2166. if (!lua_interface)
  2167. return 0;
  2168. Spawn* spawn = lua_interface->GetSpawn(state);
  2169. int16 type = lua_interface->GetInt16Value(state, 2);
  2170. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2171. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2172. if (!spawn) {
  2173. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2174. return 0;
  2175. }
  2176. if (!spawn->IsEntity()) {
  2177. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2178. return 0;
  2179. }
  2180. if (value == 0) {
  2181. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2182. return 0;
  2183. }
  2184. if (!luaspell || !luaspell->spell) {
  2185. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2186. return 0;
  2187. }
  2188. if(luaspell->resisted) {
  2189. return 0;
  2190. }
  2191. int32 class_req = 0;
  2192. vector<int16> faction_req;
  2193. vector<int16> race_req;
  2194. int32 class_id = 0;
  2195. int32 i = 0;
  2196. int8 f = 0;
  2197. int8 r = 0;
  2198. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2199. if (class_id < 100) {
  2200. class_req += pow(2.0, double(class_id - 1));
  2201. }
  2202. else if (class_id > 100 && class_id < 1000) {
  2203. race_req.push_back(class_id);
  2204. r++;
  2205. }
  2206. else {
  2207. faction_req.push_back(class_id);
  2208. f++;
  2209. }
  2210. i++;
  2211. }
  2212. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2213. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2214. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2215. if (spawn->IsPlayer())
  2216. ((Player*)spawn)->SetCharSheetChanged(true);
  2217. return 0;
  2218. }
  2219. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2220. if (!lua_interface)
  2221. return 0;
  2222. Spawn* spawn = lua_interface->GetSpawn(state);
  2223. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2224. if (!spawn) {
  2225. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2226. return 0;
  2227. }
  2228. if (!spawn->IsEntity()) {
  2229. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2230. return 0;
  2231. }
  2232. if (!luaspell || !luaspell->spell) {
  2233. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2234. return 0;
  2235. }
  2236. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2237. if (spawn->IsPlayer())
  2238. ((Player*)spawn)->SetCharSheetChanged(true);
  2239. return 0;
  2240. }
  2241. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2242. if (!lua_interface)
  2243. return 0;
  2244. Spawn* spawn = lua_interface->GetSpawn(state);
  2245. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2246. if (luaspell && luaspell->spell) {
  2247. ZoneServer* zone = luaspell->caster->GetZone();
  2248. Spawn* target = 0;
  2249. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2250. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2251. target = zone->GetSpawnByID(luaspell->targets[i]);
  2252. if (target && target->IsEntity()) {
  2253. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2254. if (target->IsPlayer())
  2255. ((Player*)target)->SetCharSheetChanged(true);
  2256. }
  2257. }
  2258. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2259. }
  2260. else if (spawn && spawn->IsEntity()) {
  2261. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2262. if (spawn->IsPlayer())
  2263. ((Player*)spawn)->SetCharSheetChanged(true);
  2264. }
  2265. return 0;
  2266. }
  2267. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2268. if (!lua_interface)
  2269. return 0;
  2270. Spawn* spawn = lua_interface->GetSpawn(state);
  2271. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2272. float value = lua_interface->GetFloatValue(state, 3);
  2273. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2274. if (value != 0) {
  2275. int32 spell_id = 0;
  2276. if (luaspell && luaspell->spell && luaspell->caster) {
  2277. if(luaspell->resisted) {
  2278. return 0;
  2279. }
  2280. spell_id = luaspell->spell->GetSpellID();
  2281. ZoneServer* zone = luaspell->caster->GetZone();
  2282. Spawn* target = 0;
  2283. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2284. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2285. target = zone->GetSpawnByID(luaspell->targets[i]);
  2286. if (target && target->Alive()) {
  2287. if (target->IsPlayer()) {
  2288. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2289. Client* client = ((Player*)target)->GetClient();
  2290. if (client) {
  2291. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2292. if (packet)
  2293. client->QueuePacket(packet);
  2294. }
  2295. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2296. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2297. }
  2298. else if (target->IsNPC()) {
  2299. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2300. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2301. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2302. }
  2303. else
  2304. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2305. }
  2306. }
  2307. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2308. }
  2309. else if (spawn) {
  2310. if (spawn->IsPlayer()) {
  2311. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2312. Client* client = ((Player*)spawn)->GetClient();
  2313. if (client) {
  2314. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2315. if (packet)
  2316. client->QueuePacket(packet);
  2317. }
  2318. }
  2319. else if (spawn->IsNPC())
  2320. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2321. else
  2322. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2323. }
  2324. }
  2325. else
  2326. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2327. return 0;
  2328. }
  2329. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2330. if (!lua_interface)
  2331. return 0;
  2332. Spawn* spawn = lua_interface->GetSpawn(state);
  2333. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2334. if (spawn && spawn->IsPlayer()) {
  2335. int32 spell_id = 0;
  2336. if (luaspell && luaspell->spell) {
  2337. if(luaspell->resisted) {
  2338. return 0;
  2339. }
  2340. spell_id = luaspell->spell->GetSpellID();
  2341. ZoneServer* zone = luaspell->caster->GetZone();
  2342. Spawn* target = 0;
  2343. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2344. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2345. target = zone->GetSpawnByID(luaspell->targets[i]);
  2346. if (target) {
  2347. if (target->IsPlayer()) {
  2348. ((Player*)target)->RemoveSkillBonus(spell_id);
  2349. Client* client = ((Player*)target)->GetClient();
  2350. if (client) {
  2351. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2352. if (packet)
  2353. client->QueuePacket(packet);
  2354. }
  2355. }
  2356. else if (target->IsNPC())
  2357. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2358. else
  2359. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2360. }
  2361. }
  2362. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2363. }
  2364. else if (spawn) {
  2365. if (spawn->IsPlayer()) {
  2366. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2367. Client* client = ((Player*)spawn)->GetClient();
  2368. if (client) {
  2369. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2370. if (packet)
  2371. client->QueuePacket(packet);
  2372. }
  2373. }
  2374. else if (spawn->IsNPC())
  2375. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2376. else
  2377. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2378. }
  2379. }
  2380. return 0;
  2381. }
  2382. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2383. if (!lua_interface)
  2384. return 0;
  2385. Spawn* spawn = lua_interface->GetSpawn(state);
  2386. int8 type = lua_interface->GetInt32Value(state, 2);
  2387. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2388. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2389. if(luaspell && luaspell->resisted) {
  2390. return 0;
  2391. }
  2392. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2393. ZoneServer* zone = luaspell->caster->GetZone();
  2394. Spawn* target = 0;
  2395. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2396. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2397. target = zone->GetSpawnByID(luaspell->targets[i]);
  2398. if (target && target->IsEntity()) {
  2399. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2400. ((Entity*)target)->AddMezSpell(luaspell);
  2401. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2402. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2403. if (target->IsNPC())
  2404. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2405. }
  2406. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2407. ((Entity*)target)->AddStifleSpell(luaspell);
  2408. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2409. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2410. if (target->IsNPC())
  2411. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2412. }
  2413. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2414. ((Entity*)target)->AddDazeSpell(luaspell);
  2415. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2416. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2417. if (target->IsNPC())
  2418. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2419. }
  2420. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2421. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2422. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2423. ((Entity*)target)->AddStunSpell(luaspell);
  2424. if (target->IsNPC())
  2425. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2426. }
  2427. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2428. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2429. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2430. ((Entity*)target)->AddRootSpell(luaspell);
  2431. if (target->IsNPC())
  2432. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2433. }
  2434. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2435. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2436. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2437. ((Entity*)target)->AddFearSpell(luaspell);
  2438. if (target->IsNPC())
  2439. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2440. }
  2441. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2442. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2443. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2444. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2445. }
  2446. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2447. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2448. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2449. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2450. }
  2451. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2452. ((Entity*)target)->AddSnareSpell(luaspell);
  2453. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2454. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2455. if (target->IsNPC())
  2456. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2457. }
  2458. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2459. ((Entity*)target)->AddFlightSpell(luaspell);
  2460. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2461. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2462. }
  2463. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2464. ((Entity*)target)->AddGlideSpell(luaspell);
  2465. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2466. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2467. }
  2468. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2469. ((Entity*)target)->AddSafefallSpell(luaspell);
  2470. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2471. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2472. }
  2473. else
  2474. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2475. }
  2476. else
  2477. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2478. }
  2479. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2480. }
  2481. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2482. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2483. ((Entity*)spawn)->AddMezSpell(luaspell);
  2484. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2485. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2486. }
  2487. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2488. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2489. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2490. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2491. }
  2492. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2493. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2494. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2495. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2496. }
  2497. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2498. ((Entity*)spawn)->AddStunSpell(luaspell);
  2499. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2500. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2501. }
  2502. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2503. ((Entity*)spawn)->AddRootSpell(luaspell);
  2504. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2505. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2506. }
  2507. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2508. ((Entity*)spawn)->AddFearSpell(luaspell);
  2509. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2510. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2511. }
  2512. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2513. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2514. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2515. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2516. }
  2517. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2518. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2519. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2520. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2521. }
  2522. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2523. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2524. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2525. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2526. }
  2527. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2528. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2529. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2530. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2531. }
  2532. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2533. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2534. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2535. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2536. }
  2537. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2538. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2539. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2540. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2541. }
  2542. else
  2543. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2544. }
  2545. else
  2546. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2547. return 0;
  2548. }
  2549. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2550. if (!lua_interface)
  2551. return 0;
  2552. Spawn* spawn = lua_interface->GetSpawn(state);
  2553. int8 type = lua_interface->GetInt8Value(state, 2);
  2554. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2555. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2556. if (spawn && spawn->IsEntity()) {
  2557. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2558. ZoneServer* zone = luaspell->caster->GetZone();
  2559. Spawn* target = 0;
  2560. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2561. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2562. target = zone->GetSpawnByID(luaspell->targets[i]);
  2563. if (target) {
  2564. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2565. ((Entity*)target)->RemoveMezSpell(luaspell);
  2566. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2567. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2568. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2569. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2570. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2571. ((Entity*)target)->RemoveStunSpell(luaspell);
  2572. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2573. ((Entity*)target)->RemoveRootSpell(luaspell);
  2574. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2575. ((Entity*)target)->RemoveFearSpell(luaspell);
  2576. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2577. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2579. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2581. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2583. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2585. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2587. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2588. else
  2589. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2590. }
  2591. }
  2592. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2593. }
  2594. else if (only_remove_spawn) {
  2595. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2596. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2597. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2598. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2599. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2600. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2601. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2602. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2603. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2604. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2605. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2606. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2607. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2608. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2609. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2610. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2611. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2612. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2613. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2614. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2615. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2616. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2617. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2618. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2619. else
  2620. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2621. }
  2622. }
  2623. return 0;
  2624. }
  2625. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2626. if (!lua_interface)
  2627. return 0;
  2628. Spawn* spawn = lua_interface->GetSpawn(state);
  2629. int8 type = lua_interface->GetInt8Value(state, 2);
  2630. bool hasEffect = false;
  2631. if (!spawn)
  2632. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2633. else if (!spawn->IsEntity())
  2634. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2635. else if (type < CONTROL_MAX_EFFECTS)
  2636. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2637. else
  2638. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2639. lua_interface->SetBooleanValue(state, hasEffect);
  2640. return 1;
  2641. }
  2642. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2643. if (!lua_interface)
  2644. return 0;
  2645. Spawn* spawn = lua_interface->GetSpawn(state);
  2646. float distance = 0.0f;
  2647. if (!spawn)
  2648. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2649. else if (!spawn->IsNPC())
  2650. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2651. else
  2652. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2653. lua_interface->SetFloatValue(state, distance);
  2654. return 1;
  2655. }
  2656. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2657. if (!lua_interface)
  2658. return 0;
  2659. Spawn* spawn = lua_interface->GetSpawn(state);
  2660. float distance = 0.0f;
  2661. if (!spawn)
  2662. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2663. else if (!spawn->IsNPC())
  2664. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2665. else
  2666. distance = ((NPC*)spawn)->GetAggroRadius();
  2667. lua_interface->SetFloatValue(state, distance);
  2668. return 1;
  2669. }
  2670. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2671. if (!lua_interface)
  2672. return 0;
  2673. Spawn* spawn = lua_interface->GetSpawn(state);
  2674. float distance = lua_interface->GetFloatValue(state, 2);
  2675. bool override = lua_interface->GetBooleanValue(state, 3);
  2676. bool result = false;
  2677. lua_interface->ResetFunctionStack(state);
  2678. if (!spawn)
  2679. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2680. else if (!spawn->IsNPC())
  2681. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2682. else
  2683. {
  2684. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2685. result = true;
  2686. }
  2687. lua_interface->SetBooleanValue(state, result);
  2688. return 1;
  2689. }
  2690. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2691. if (!lua_interface)
  2692. return 0;
  2693. Spawn* spawn = lua_interface->GetSpawn(state);
  2694. int16 value = lua_interface->GetInt16Value(state, 2);
  2695. if (spawn && spawn->IsEntity()) {
  2696. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2697. if (spawn->IsPlayer())
  2698. ((Player*)spawn)->SetCharSheetChanged(true);
  2699. }
  2700. return 0;
  2701. }
  2702. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2703. if (!lua_interface)
  2704. return 0;
  2705. Spawn* spawn = lua_interface->GetSpawn(state);
  2706. int16 value = lua_interface->GetInt16Value(state, 2);
  2707. if (spawn && spawn->IsEntity()) {
  2708. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2709. if (spawn->IsPlayer())
  2710. ((Player*)spawn)->SetCharSheetChanged(true);
  2711. }
  2712. return 0;
  2713. }
  2714. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2715. if (!lua_interface)
  2716. return 0;
  2717. Spawn* spawn = lua_interface->GetSpawn(state);
  2718. int16 value = lua_interface->GetInt16Value(state, 2);
  2719. if (spawn && spawn->IsEntity()) {
  2720. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2721. if (spawn->IsPlayer())
  2722. ((Player*)spawn)->SetCharSheetChanged(true);
  2723. }
  2724. return 0;
  2725. }
  2726. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2727. if (!lua_interface)
  2728. return 0;
  2729. Spawn* spawn = lua_interface->GetSpawn(state);
  2730. int16 value = lua_interface->GetInt16Value(state, 2);
  2731. if (spawn && spawn->IsEntity()) {
  2732. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2733. if (spawn->IsPlayer())
  2734. ((Player*)spawn)->SetCharSheetChanged(true);
  2735. }
  2736. return 0;
  2737. }
  2738. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2739. if (!lua_interface)
  2740. return 0;
  2741. Spawn* spawn = lua_interface->GetSpawn(state);
  2742. int16 value = lua_interface->GetInt16Value(state, 2);
  2743. if (spawn && spawn->IsEntity()) {
  2744. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2745. if (spawn->IsPlayer())
  2746. ((Player*)spawn)->SetCharSheetChanged(true);
  2747. }
  2748. return 0;
  2749. }
  2750. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2751. if (!lua_interface)
  2752. return 0;
  2753. Spawn* spawn = lua_interface->GetSpawn(state);
  2754. int8 value = lua_interface->GetInt8Value(state, 2);
  2755. if (spawn && spawn->IsEntity()) {
  2756. ((Entity*)spawn)->SetDeity(value);
  2757. if (spawn->IsPlayer())
  2758. ((Player*)spawn)->SetCharSheetChanged(true);
  2759. }
  2760. lua_interface->ResetFunctionStack(state);
  2761. return 0;
  2762. }
  2763. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2764. if (!lua_interface)
  2765. return 0;
  2766. Spawn* spawn = lua_interface->GetSpawn(state);
  2767. if (spawn && spawn->IsEntity()) {
  2768. int8 deity = ((Entity*)spawn)->GetDeity();
  2769. lua_interface->SetInt32Value(state, deity);
  2770. return 1;
  2771. }
  2772. return 0;
  2773. }
  2774. int EQ2Emu_lua_SetInt(lua_State* state) {
  2775. if (!lua_interface)
  2776. return 0;
  2777. Spawn* spawn = lua_interface->GetSpawn(state);
  2778. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2779. if (spawn && spawn->IsEntity()) {
  2780. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2781. if (spawn->IsPlayer())
  2782. ((Player*)spawn)->SetCharSheetChanged(true);
  2783. }
  2784. return 0;
  2785. }
  2786. int EQ2Emu_lua_SetWis(lua_State* state) {
  2787. if (!lua_interface)
  2788. return 0;
  2789. Spawn* spawn = lua_interface->GetSpawn(state);
  2790. float value = lua_interface->GetFloatValue(state, 2);
  2791. if (spawn && spawn->IsEntity()) {
  2792. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2793. if (spawn->IsPlayer())
  2794. ((Player*)spawn)->SetCharSheetChanged(true);
  2795. }
  2796. return 0;
  2797. }
  2798. int EQ2Emu_lua_SetSta(lua_State* state) {
  2799. if (!lua_interface)
  2800. return 0;
  2801. Spawn* spawn = lua_interface->GetSpawn(state);
  2802. float value = lua_interface->GetFloatValue(state, 2);
  2803. if (spawn && spawn->IsEntity()) {
  2804. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2805. if (spawn->IsPlayer())
  2806. ((Player*)spawn)->SetCharSheetChanged(true);
  2807. }
  2808. return 0;
  2809. }
  2810. int EQ2Emu_lua_SetStr(lua_State* state) {
  2811. if (!lua_interface)
  2812. return 0;
  2813. Spawn* spawn = lua_interface->GetSpawn(state);
  2814. float value = lua_interface->GetFloatValue(state, 2);
  2815. if (spawn && spawn->IsEntity()) {
  2816. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2817. if (spawn->IsPlayer())
  2818. ((Player*)spawn)->SetCharSheetChanged(true);
  2819. }
  2820. return 0;
  2821. }
  2822. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2823. if (!lua_interface)
  2824. return 0;
  2825. Spawn* spawn = lua_interface->GetSpawn(state);
  2826. float value = lua_interface->GetFloatValue(state, 2);
  2827. if (spawn && spawn->IsEntity()) {
  2828. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2829. if (spawn->IsPlayer())
  2830. ((Player*)spawn)->SetCharSheetChanged(true);
  2831. }
  2832. return 0;
  2833. }
  2834. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2835. if (!lua_interface)
  2836. return 0;
  2837. Spawn* spawn = lua_interface->GetSpawn(state);
  2838. if (spawn) {
  2839. lua_interface->SetInt32Value(state, spawn->GetHP());
  2840. return 1;
  2841. }
  2842. return 0;
  2843. }
  2844. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2845. if (!lua_interface)
  2846. return 0;
  2847. Spawn* spawn = lua_interface->GetSpawn(state);
  2848. if (spawn) {
  2849. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2850. return 1;
  2851. }
  2852. return 0;
  2853. }
  2854. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2855. if (!lua_interface)
  2856. return 0;
  2857. Spawn* spawn = lua_interface->GetSpawn(state);
  2858. if (spawn) {
  2859. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2860. return 1;
  2861. }
  2862. return 0;
  2863. }
  2864. int EQ2Emu_lua_GetName(lua_State* state) {
  2865. if (!lua_interface)
  2866. return 0;
  2867. Spawn* spawn = lua_interface->GetSpawn(state);
  2868. if (spawn) {
  2869. lua_interface->SetStringValue(state, spawn->GetName());
  2870. return 1;
  2871. }
  2872. return 0;
  2873. }
  2874. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2875. Spawn* spawn = lua_interface->GetSpawn(state);
  2876. if (spawn) {
  2877. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2878. return 1;
  2879. }
  2880. return 0;
  2881. }
  2882. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2883. if (!lua_interface)
  2884. return 0;
  2885. Spawn* spawn = lua_interface->GetSpawn(state);
  2886. if (spawn) {
  2887. lua_interface->SetInt32Value(state, spawn->GetPower());
  2888. return 1;
  2889. }
  2890. return 0;
  2891. }
  2892. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2893. if (!lua_interface)
  2894. return 0;
  2895. Spawn* spawn = lua_interface->GetSpawn(state);
  2896. if (spawn) {
  2897. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2898. return 1;
  2899. }
  2900. return 0;
  2901. }
  2902. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2903. if (!lua_interface)
  2904. return 0;
  2905. Spawn* spawn = lua_interface->GetSpawn(state);
  2906. if (spawn) {
  2907. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2908. return 1;
  2909. }
  2910. return 0;
  2911. }
  2912. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2913. if (!lua_interface)
  2914. return 0;
  2915. Spawn* spawn = lua_interface->GetSpawn(state);
  2916. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2917. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2918. if (spawn && spawn2) {
  2919. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2920. lua_interface->SetFloatValue(state, distance);
  2921. return 1;
  2922. }
  2923. return 0;
  2924. }
  2925. int EQ2Emu_lua_GetX(lua_State* state) {
  2926. if (!lua_interface)
  2927. return 0;
  2928. Spawn* spawn = lua_interface->GetSpawn(state);
  2929. if (spawn) {
  2930. lua_interface->SetFloatValue(state, spawn->GetX());
  2931. return 1;
  2932. }
  2933. return 0;
  2934. }
  2935. int EQ2Emu_lua_GetY(lua_State* state) {
  2936. if (!lua_interface)
  2937. return 0;
  2938. Spawn* spawn = lua_interface->GetSpawn(state);
  2939. if (spawn) {
  2940. lua_interface->SetFloatValue(state, spawn->GetY());
  2941. return 1;
  2942. }
  2943. return 0;
  2944. }
  2945. int EQ2Emu_lua_GetZ(lua_State* state) {
  2946. if (!lua_interface)
  2947. return 0;
  2948. Spawn* spawn = lua_interface->GetSpawn(state);
  2949. if (spawn) {
  2950. lua_interface->SetFloatValue(state, spawn->GetZ());
  2951. return 1;
  2952. }
  2953. return 0;
  2954. }
  2955. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2956. if (!lua_interface)
  2957. return 0;
  2958. Spawn* spawn = lua_interface->GetSpawn(state);
  2959. if (spawn) {
  2960. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2961. return 1;
  2962. }
  2963. return 0;
  2964. }
  2965. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2966. if (!lua_interface)
  2967. return 0;
  2968. Spawn* spawn = lua_interface->GetSpawn(state);
  2969. if (spawn) {
  2970. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2971. return 1;
  2972. }
  2973. return 0;
  2974. }
  2975. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2976. if (!lua_interface)
  2977. return 0;
  2978. Spawn* spawn = lua_interface->GetSpawn(state);
  2979. if (spawn) {
  2980. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2981. return 1;
  2982. }
  2983. return 0;
  2984. }
  2985. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2986. if (!lua_interface)
  2987. return 0;
  2988. Spawn* spawn = lua_interface->GetSpawn(state);
  2989. if (spawn && spawn->IsEntity()) {
  2990. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2991. return 1;
  2992. }
  2993. return 0;
  2994. }
  2995. int EQ2Emu_lua_GetInt(lua_State* state) {
  2996. if (!lua_interface)
  2997. return 0;
  2998. Spawn* spawn = lua_interface->GetSpawn(state);
  2999. if (spawn && spawn->IsEntity()) {
  3000. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3001. return 1;
  3002. }
  3003. return 0;
  3004. }
  3005. int EQ2Emu_lua_GetWis(lua_State* state) {
  3006. if (!lua_interface)
  3007. return 0;
  3008. Spawn* spawn = lua_interface->GetSpawn(state);
  3009. if (spawn && spawn->IsEntity()) {
  3010. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3011. return 1;
  3012. }
  3013. return 0;
  3014. }
  3015. int EQ2Emu_lua_GetSta(lua_State* state) {
  3016. if (!lua_interface)
  3017. return 0;
  3018. Spawn* spawn = lua_interface->GetSpawn(state);
  3019. if (spawn && spawn->IsEntity()) {
  3020. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3021. return 1;
  3022. }
  3023. return 0;
  3024. }
  3025. int EQ2Emu_lua_GetStr(lua_State* state) {
  3026. if (!lua_interface)
  3027. return 0;
  3028. Spawn* spawn = lua_interface->GetSpawn(state);
  3029. if (spawn && spawn->IsEntity()) {
  3030. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3031. return 1;
  3032. }
  3033. return 0;
  3034. }
  3035. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3036. if (!lua_interface)
  3037. return 0;
  3038. Spawn* spawn = lua_interface->GetSpawn(state);
  3039. if (spawn && spawn->IsEntity()) {
  3040. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3041. return 1;
  3042. }
  3043. return 0;
  3044. }
  3045. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3046. if (!lua_interface)
  3047. return 0;
  3048. Spawn* spawn = lua_interface->GetSpawn(state);
  3049. if (spawn && spawn->IsEntity()) {
  3050. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3051. return 1;
  3052. }
  3053. return 0;
  3054. }
  3055. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3056. if (!lua_interface)
  3057. return 0;
  3058. Spawn* spawn = lua_interface->GetSpawn(state);
  3059. if (spawn && spawn->IsEntity()) {
  3060. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3061. return 1;
  3062. }
  3063. return 0;
  3064. }
  3065. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3066. if (!lua_interface)
  3067. return 0;
  3068. Spawn* spawn = lua_interface->GetSpawn(state);
  3069. if (spawn && spawn->IsEntity()) {
  3070. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3071. return 1;
  3072. }
  3073. return 0;
  3074. }
  3075. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3076. if (!lua_interface)
  3077. return 0;
  3078. Spawn* spawn = lua_interface->GetSpawn(state);
  3079. if (spawn && spawn->IsEntity()) {
  3080. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3081. return 1;
  3082. }
  3083. return 0;
  3084. }
  3085. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3086. if (!lua_interface)
  3087. return 0;
  3088. Spawn* spawn = lua_interface->GetSpawn(state);
  3089. if (spawn && spawn->IsEntity()) {
  3090. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3091. return 1;
  3092. }
  3093. return 0;
  3094. }
  3095. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3096. if (!lua_interface)
  3097. return 0;
  3098. Spawn* player = lua_interface->GetSpawn(state);
  3099. if (!player || !player->IsPlayer()) {
  3100. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3101. return 0;
  3102. }
  3103. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3104. if (quest_id <= 0) {
  3105. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3106. return 0;
  3107. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3108. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3109. return 0;
  3110. }
  3111. int32 step = lua_interface->GetInt32Value(state, 3);
  3112. if (step > 0) {
  3113. Client* client = ((Player*)player)->GetClient();
  3114. if (client)
  3115. client->AddPendingQuestUpdate(quest_id, step);
  3116. } else {
  3117. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3118. }
  3119. return 0;
  3120. }
  3121. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3122. Spawn* player = lua_interface->GetSpawn(state);
  3123. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3124. int32 step = lua_interface->GetInt32Value(state, 3);
  3125. int32 progress = lua_interface->GetInt32Value(state, 4);
  3126. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3127. Client* client = ((Player*)player)->GetClient();
  3128. if (client)
  3129. client->AddPendingQuestUpdate(quest_id, step, progress);
  3130. }
  3131. return 0;
  3132. }
  3133. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3134. if (!lua_interface)
  3135. return 0;
  3136. Spawn* player = lua_interface->GetSpawn(state);
  3137. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3138. if (player && player->IsPlayer() && quest_id > 0) {
  3139. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3140. return 1;
  3141. }
  3142. return 0;
  3143. }
  3144. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3145. if (!lua_interface)
  3146. return 0;
  3147. Spawn* player = lua_interface->GetSpawn(state);
  3148. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3149. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3150. if (player && player->IsPlayer() && quest_id > 0) {
  3151. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3152. return 1;
  3153. }
  3154. return 0;
  3155. }
  3156. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3157. if (!lua_interface)
  3158. return 0;
  3159. Spawn* player = lua_interface->GetSpawn(state);
  3160. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3161. if (player && player->IsPlayer() && quest_id > 0) {
  3162. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3163. return 1;
  3164. }
  3165. return 0;
  3166. }
  3167. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3168. if (!lua_interface)
  3169. return 0;
  3170. Quest* quest = lua_interface->GetQuest(state);
  3171. string name = lua_interface->GetStringValue(state, 2);
  3172. string type = lua_interface->GetStringValue(state, 3);
  3173. string zone = lua_interface->GetStringValue(state, 4);
  3174. int16 level = lua_interface->GetInt16Value(state, 5);
  3175. string description = lua_interface->GetStringValue(state, 6);
  3176. bool load = true;
  3177. if (!quest) {
  3178. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3179. load = false;
  3180. }
  3181. if (load && name.length() == 0) {
  3182. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3183. load = false;
  3184. }
  3185. if (load && type.length() == 0) {
  3186. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3187. load = false;
  3188. }
  3189. if (load && zone.length() == 0) {
  3190. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3191. load = false;
  3192. }
  3193. if (load && description.length() == 0) {
  3194. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3195. load = false;
  3196. }
  3197. if (load && level == 0) {
  3198. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3199. load = false;
  3200. }
  3201. if (load)
  3202. quest->RegisterQuest(name, type, zone, level, description);
  3203. return 0;
  3204. }
  3205. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3206. if (!lua_interface)
  3207. return 0;
  3208. Quest* quest = lua_interface->GetQuest(state);
  3209. if (quest) {
  3210. int8 level = lua_interface->GetInt16Value(state, 2);
  3211. quest->SetPrereqLevel(level);
  3212. }
  3213. return 0;
  3214. }
  3215. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3216. if (!lua_interface)
  3217. return 0;
  3218. Quest* quest = lua_interface->GetQuest(state);
  3219. if (quest) {
  3220. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3221. quest->AddPrereqQuest(quest_id);
  3222. }
  3223. return 0;
  3224. }
  3225. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3226. if (!lua_interface)
  3227. return 0;
  3228. Quest* quest = lua_interface->GetQuest(state);
  3229. if (quest) {
  3230. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3231. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3232. if (quantity == 0)
  3233. quantity = 1;
  3234. Item* master_item = master_item_list.GetItem(item_id);
  3235. if (master_item) {
  3236. Item* item = new Item(master_item);
  3237. item->details.count = quantity;
  3238. quest->AddPrereqItem(item);
  3239. }
  3240. }
  3241. return 0;
  3242. }
  3243. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3244. if (!lua_interface)
  3245. return 0;
  3246. Spawn* player = lua_interface->GetSpawn(state);
  3247. if(!player || !player->IsPlayer()) {
  3248. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3249. return 0;
  3250. }
  3251. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3252. if (quest_id > 0) {
  3253. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3254. return 1;
  3255. } else {
  3256. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3257. }
  3258. return 0;
  3259. }
  3260. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3261. if (!lua_interface)
  3262. return 0;
  3263. Quest* quest = lua_interface->GetQuest(state);
  3264. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3265. lua_interface->ResetFunctionStack(state);
  3266. if (quest && spawn_id > 0)
  3267. quest->SetQuestReturnNPC(spawn_id);
  3268. return 0;
  3269. }
  3270. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3271. if (!lua_interface)
  3272. return 0;
  3273. Spawn* spawn = lua_interface->GetSpawn(state);
  3274. int32 time = lua_interface->GetInt32Value(state, 2);
  3275. string function = lua_interface->GetStringValue(state, 3);
  3276. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3277. Spawn* player = lua_interface->GetSpawn(state, 5);
  3278. lua_interface->ResetFunctionStack(state);
  3279. if (!spawn) {
  3280. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3281. return 0;
  3282. }
  3283. if (time <= 0) {
  3284. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3285. return 0;
  3286. }
  3287. if (function.length() == 0) {
  3288. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3289. return 0;
  3290. }
  3291. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3292. if ( time < 10)
  3293. time = 10;
  3294. timer->timer = Timer::GetCurrentTime2() + time;
  3295. timer->function = function;
  3296. timer->spawn = spawn->GetID();
  3297. timer->player = player ? player->GetID() : 0;
  3298. if (max_count == 0)
  3299. max_count = 1;
  3300. timer->max_count = max_count;
  3301. timer->current_count = 0;
  3302. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3303. return 0;
  3304. }
  3305. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3306. if (!lua_interface)
  3307. return 0;
  3308. Spawn* spawn = lua_interface->GetSpawn(state);
  3309. string function = lua_interface->GetStringValue(state, 2);
  3310. lua_interface->ResetFunctionStack(state);
  3311. if (!spawn) {
  3312. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3313. return 0;
  3314. }
  3315. if(!spawn->GetZone()) {
  3316. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3317. return 0;
  3318. }
  3319. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3320. return 0;
  3321. }
  3322. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3323. if (!lua_interface)
  3324. return 0;
  3325. Spawn* player = lua_interface->GetSpawn(state);
  3326. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3327. lua_interface->ResetFunctionStack(state);
  3328. if (player && player->IsPlayer() && quest_id > 0) {
  3329. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3330. return 1;
  3331. }
  3332. return 0;
  3333. }
  3334. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3335. if (!lua_interface)
  3336. return 0;
  3337. Spawn* player = lua_interface->GetSpawn(state);
  3338. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3339. lua_interface->ResetFunctionStack(state);
  3340. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3341. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3342. if (quest)
  3343. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3344. return 1;
  3345. }
  3346. return 0;
  3347. }
  3348. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3349. if (!lua_interface)
  3350. return 0;
  3351. Spawn* player = lua_interface->GetSpawn(state);
  3352. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3353. lua_interface->ResetFunctionStack(state);
  3354. if (player && player->IsPlayer() && quest_id > 0) {
  3355. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3356. return 1;
  3357. }
  3358. return 0;
  3359. }
  3360. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3361. if (!lua_interface)
  3362. return 0;
  3363. Spawn* npc = lua_interface->GetSpawn(state);
  3364. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3365. lua_interface->ResetFunctionStack(state);
  3366. if (npc && !npc->IsPlayer() && quest_id > 0)
  3367. npc->AddProvidedQuest(quest_id);
  3368. return 0;
  3369. }
  3370. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3371. if (!lua_interface)
  3372. return 0;
  3373. Spawn* npc = lua_interface->GetSpawn(state);
  3374. Spawn* player = lua_interface->GetSpawn(state, 2);
  3375. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3376. bool forced = lua_interface->GetBooleanValue(state, 4);
  3377. lua_interface->ResetFunctionStack(state);
  3378. /* NPC is allowed to be null */
  3379. if (player && player->IsPlayer() && quest_id > 0) {
  3380. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3381. if (master_quest) {
  3382. Client* client = ((Player*)player)->GetClient();
  3383. if (!client) {
  3384. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3385. }
  3386. Quest* quest = new Quest(master_quest);
  3387. if (!quest) {
  3388. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3389. }
  3390. if (client && quest) {
  3391. if (npc)
  3392. quest->SetQuestGiver(npc->GetDatabaseID());
  3393. else
  3394. quest->SetQuestGiver(0);
  3395. client->AddPendingQuest(quest, forced);
  3396. }
  3397. }
  3398. else {
  3399. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3400. }
  3401. }
  3402. else {
  3403. 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);
  3404. }
  3405. return 0;
  3406. }
  3407. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3408. if (!lua_interface)
  3409. return 0;
  3410. Quest* quest = lua_interface->GetQuest(state);
  3411. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3412. lua_interface->ResetFunctionStack(state);
  3413. if (quest) {
  3414. quest->AddPrereqClass(class_id);
  3415. }
  3416. return 0;
  3417. }
  3418. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3419. if (!lua_interface)
  3420. return 0;
  3421. Quest* quest = lua_interface->GetQuest(state);
  3422. int8 race = lua_interface->GetInt8Value(state, 2);
  3423. lua_interface->ResetFunctionStack(state);
  3424. if (quest) {
  3425. quest->AddPrereqRace(race);
  3426. }
  3427. return 0;
  3428. }
  3429. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3430. if (!lua_interface)
  3431. return 0;
  3432. Quest* quest = lua_interface->GetQuest(state);
  3433. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3434. lua_interface->ResetFunctionStack(state);
  3435. if (quest) {
  3436. quest->AddPrereqModelType(model_type);
  3437. }
  3438. return 0;
  3439. }
  3440. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3441. if (!lua_interface)
  3442. return 0;
  3443. Quest* quest = lua_interface->GetQuest(state);
  3444. int8 level = lua_interface->GetInt8Value(state, 2);
  3445. lua_interface->ResetFunctionStack(state);
  3446. if (!quest) {
  3447. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3448. return 0;
  3449. }
  3450. quest->SetPrereqTSLevel(level);
  3451. return 0;
  3452. }
  3453. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3454. if (!lua_interface)
  3455. return 0;
  3456. Quest* quest = lua_interface->GetQuest(state);
  3457. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3458. lua_interface->ResetFunctionStack(state);
  3459. if (!quest) {
  3460. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3461. return 0;
  3462. }
  3463. quest->AddPrereqTradeskillClass(class_id);
  3464. return 0;
  3465. }
  3466. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3467. if (!lua_interface)
  3468. return 0;
  3469. Quest* quest = lua_interface->GetQuest(state);
  3470. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3471. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3472. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3473. lua_interface->ResetFunctionStack(state);
  3474. if (quest) {
  3475. quest->AddPrereqFaction(faction_id, min, max);
  3476. }
  3477. return 0;
  3478. }
  3479. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3480. if (!lua_interface)
  3481. return 0;
  3482. Quest* quest = lua_interface->GetQuest(state);
  3483. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3484. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3485. lua_interface->ResetFunctionStack(state);
  3486. if (quest) {
  3487. if (quantity == 0)
  3488. quantity = 1;
  3489. Item* master_item = master_item_list.GetItem(item_id);
  3490. if (master_item) {
  3491. Item* item = new Item(master_item);
  3492. item->details.count = quantity;
  3493. quest->AddSelectableRewardItem(item);
  3494. }
  3495. }
  3496. return 0;
  3497. }
  3498. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3499. if (!lua_interface)
  3500. return 0;
  3501. Quest* quest = lua_interface->GetQuest(state);
  3502. if (quest) {
  3503. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3504. vector<Item*>* items = quest->GetRewardItems();
  3505. if (items) {
  3506. vector<Item*>::iterator itr;
  3507. for (itr = items->begin(); itr != items->end(); itr++) {
  3508. if (*itr && (*itr)->details.item_id == item_id) {
  3509. lua_interface->SetBooleanValue(state, true);
  3510. return 1;
  3511. }
  3512. }
  3513. }
  3514. }
  3515. lua_interface->SetBooleanValue(state, false);
  3516. return 1;
  3517. }
  3518. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3519. if (!lua_interface)
  3520. return 0;
  3521. Quest* quest = lua_interface->GetQuest(state);
  3522. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3523. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3524. lua_interface->ResetFunctionStack(state);
  3525. if (quest) {
  3526. if (quantity == 0)
  3527. quantity = 1;
  3528. Item* master_item = master_item_list.GetItem(item_id);
  3529. if (master_item) {
  3530. Item* item = new Item(master_item);
  3531. item->details.count = quantity;
  3532. quest->AddRewardItem(item);
  3533. }
  3534. }
  3535. return 0;
  3536. }
  3537. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3538. if (!lua_interface)
  3539. return 0;
  3540. Quest* quest = lua_interface->GetQuest(state);
  3541. int32 copper = lua_interface->GetInt32Value(state, 2);
  3542. int32 silver = lua_interface->GetInt32Value(state, 3);
  3543. int32 gold = lua_interface->GetInt32Value(state, 4);
  3544. int32 plat = lua_interface->GetInt32Value(state, 5);
  3545. lua_interface->ResetFunctionStack(state);
  3546. if (quest) {
  3547. quest->AddRewardCoins(copper, silver, gold, plat);
  3548. }
  3549. return 0;
  3550. }
  3551. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3552. if (!lua_interface)
  3553. return 0;
  3554. Quest* quest = lua_interface->GetQuest(state);
  3555. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3556. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3557. lua_interface->ResetFunctionStack(state);
  3558. if (quest && faction_id > 0 && amount != 0)
  3559. quest->AddRewardFaction(faction_id, amount);
  3560. return 0;
  3561. }
  3562. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3563. if (!lua_interface)
  3564. return 0;
  3565. Quest* quest = lua_interface->GetQuest(state);
  3566. int32 status = lua_interface->GetInt32Value(state, 2);
  3567. lua_interface->ResetFunctionStack(state);
  3568. if (quest) {
  3569. quest->SetRewardStatus(status);
  3570. }
  3571. return 0;
  3572. }
  3573. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3574. if (!lua_interface)
  3575. return 0;
  3576. Quest* quest = lua_interface->GetQuest(state);
  3577. int32 status = lua_interface->GetInt32Value(state, 2);
  3578. lua_interface->ResetFunctionStack(state);
  3579. if (quest) {
  3580. quest->SetStatusTmpReward(status);
  3581. }
  3582. return 0;
  3583. }
  3584. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3585. if (!lua_interface)
  3586. return 0;
  3587. Quest* quest = lua_interface->GetQuest(state);
  3588. int64 coins = lua_interface->GetInt64Value(state, 2);
  3589. lua_interface->ResetFunctionStack(state);
  3590. if (quest) {
  3591. quest->SetCoinTmpReward(coins);
  3592. }
  3593. return 0;
  3594. }
  3595. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3596. if (!lua_interface)
  3597. return 0;
  3598. Quest* quest = lua_interface->GetQuest(state);
  3599. string comment = lua_interface->GetStringValue(state, 2);
  3600. lua_interface->ResetFunctionStack(state);
  3601. if (quest) {
  3602. quest->SetRewardComment(comment);
  3603. }
  3604. return 0;
  3605. }
  3606. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3607. if (!lua_interface)
  3608. return 0;
  3609. Quest* quest = lua_interface->GetQuest(state);
  3610. int32 exp = lua_interface->GetInt32Value(state, 2);
  3611. lua_interface->ResetFunctionStack(state);
  3612. if (quest) {
  3613. quest->SetRewardXP(exp);
  3614. }
  3615. return 0;
  3616. }
  3617. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3618. Quest* quest = lua_interface->GetQuest(state);
  3619. int32 step = lua_interface->GetInt32Value(state, 2);
  3620. string description = lua_interface->GetStringValue(state, 3);
  3621. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3622. float percentage = lua_interface->GetFloatValue(state, 5);
  3623. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3624. int16 icon = lua_interface->GetInt16Value(state, 7);
  3625. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3626. if (quest) {
  3627. const char* taskgroup = 0;
  3628. if (str_taskgroup.length() > 0)
  3629. taskgroup = str_taskgroup.c_str();
  3630. int32 id = 0;
  3631. vector<int32>* ids = 0;
  3632. int i = 0;
  3633. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3634. if (ids == 0)
  3635. ids = new vector<int32>;
  3636. ids->push_back(id);
  3637. i++;
  3638. }
  3639. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3640. if (quest_step && icon && quantity > 0)
  3641. quest_step->SetIcon(icon);
  3642. if (quest->GetPlayer()) {
  3643. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3644. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3645. }
  3646. }
  3647. lua_interface->ResetFunctionStack(state);
  3648. return 0;
  3649. }
  3650. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3651. {
  3652. if (!lua_interface)
  3653. return 0;
  3654. Quest* quest = lua_interface->GetQuest(state);
  3655. int32 step = lua_interface->GetInt32Value(state, 2);
  3656. string description = lua_interface->GetStringValue(state, 3);
  3657. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3658. float percentage = lua_interface->GetFloatValue(state, 5);
  3659. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3660. int16 icon = lua_interface->GetInt16Value(state, 7);
  3661. if (quest) {
  3662. const char* taskgroup = 0;
  3663. if (str_taskgroup.length() > 0)
  3664. taskgroup = str_taskgroup.c_str();
  3665. int32 id = 0;
  3666. vector<int32>* ids = 0;
  3667. int i = 0;
  3668. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3669. if (ids == 0)
  3670. ids = new vector<int32>;
  3671. ids->push_back(id);
  3672. i++;
  3673. }
  3674. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3675. if (quest_step && icon > 0 && quantity > 0)
  3676. quest_step->SetIcon(icon);
  3677. if (quest->GetPlayer()) {
  3678. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3679. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3680. }
  3681. safe_delete(ids);
  3682. }
  3683. lua_interface->ResetFunctionStack(state);
  3684. return 0;
  3685. }
  3686. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3687. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3688. }
  3689. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3690. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3691. }
  3692. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3693. if (!lua_interface)
  3694. return 0;
  3695. Quest* quest = lua_interface->GetQuest(state);
  3696. int32 step = lua_interface->GetInt32Value(state, 2);
  3697. string description = lua_interface->GetStringValue(state, 3);
  3698. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3699. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3700. int16 icon = lua_interface->GetInt16Value(state, 6);
  3701. if (quest) {
  3702. const char* taskgroup = 0;
  3703. if (str_taskgroup.length() > 0)
  3704. taskgroup = str_taskgroup.c_str();
  3705. int32 npc_id = 0;
  3706. vector<int32>* ids = 0;
  3707. int i = 0;
  3708. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3709. if (ids == 0)
  3710. ids = new vector<int32>;
  3711. ids->push_back(npc_id);
  3712. i++;
  3713. }
  3714. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3715. if (quest_step && icon > 0)
  3716. quest_step->SetIcon(icon);
  3717. if (quest->GetPlayer()) {
  3718. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3719. if(client)
  3720. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3721. }
  3722. safe_delete(ids);
  3723. }
  3724. lua_interface->ResetFunctionStack(state);
  3725. return 0;
  3726. }
  3727. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3728. if (!lua_interface)
  3729. return 0;
  3730. Quest* quest = lua_interface->GetQuest(state);
  3731. int32 step = lua_interface->GetInt32Value(state, 2);
  3732. string description = lua_interface->GetStringValue(state, 3);
  3733. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3734. float percentage = lua_interface->GetFloatValue(state, 5);
  3735. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3736. int16 icon = lua_interface->GetInt16Value(state, 7);
  3737. if (quest) {
  3738. const char* taskgroup = 0;
  3739. if (str_taskgroup.length() > 0)
  3740. taskgroup = str_taskgroup.c_str();
  3741. int32 item_id = 0;
  3742. vector<int32>* ids = 0;
  3743. int i = 0;
  3744. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3745. if (ids == 0)
  3746. ids = new vector<int32>;
  3747. ids->push_back(item_id);
  3748. i++;
  3749. }
  3750. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3751. if (quest_step && icon > 0 && quantity > 0)
  3752. quest_step->SetIcon(icon);
  3753. if (quest->GetPlayer()) {
  3754. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3755. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3756. }
  3757. safe_delete(ids);
  3758. }
  3759. lua_interface->ResetFunctionStack(state);
  3760. return 0;
  3761. }
  3762. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3763. if (!lua_interface)
  3764. return 0;
  3765. Quest* quest = lua_interface->GetQuest(state);
  3766. int32 step = lua_interface->GetInt32Value(state, 2);
  3767. string description = lua_interface->GetStringValue(state, 3);
  3768. float max_variation = lua_interface->GetFloatValue(state, 4);
  3769. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3770. int16 icon = lua_interface->GetInt16Value(state, 6);
  3771. if (quest) {
  3772. const char* taskgroup = 0;
  3773. if (str_taskgroup.length() > 0)
  3774. taskgroup = str_taskgroup.c_str();
  3775. vector<Location>* locations = 0;
  3776. int8 i = 7;
  3777. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3778. while (true) {
  3779. Location loc;
  3780. loc.x = lua_interface->GetFloatValue(state, i);
  3781. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3782. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3783. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3784. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3785. break;
  3786. if (locations == 0)
  3787. locations = new vector<Location>;
  3788. locations->push_back(loc);
  3789. i += 4;
  3790. }
  3791. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3792. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3793. if (quest_step && icon > 0)
  3794. quest_step->SetIcon(icon);
  3795. if (quest->GetPlayer()) {
  3796. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3797. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3798. }
  3799. }
  3800. lua_interface->ResetFunctionStack(state);
  3801. return 0;
  3802. }
  3803. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3804. if (!lua_interface)
  3805. return 0;
  3806. Quest* quest = lua_interface->GetQuest(state);
  3807. int32 step = lua_interface->GetInt32Value(state, 2);
  3808. string description = lua_interface->GetStringValue(state, 3);
  3809. float max_variation = lua_interface->GetFloatValue(state, 4);
  3810. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3811. int16 icon = lua_interface->GetInt16Value(state, 6);
  3812. if (quest) {
  3813. const char* taskgroup = 0;
  3814. if (str_taskgroup.length() > 0)
  3815. taskgroup = str_taskgroup.c_str();
  3816. vector<Location>* locations = 0;
  3817. int8 i = 7;
  3818. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3819. while (true) {
  3820. Location loc;
  3821. loc.x = lua_interface->GetFloatValue(state, i);
  3822. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3823. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3824. loc.zone_id = 0;
  3825. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3826. break;
  3827. if (locations == 0)
  3828. locations = new vector<Location>;
  3829. locations->push_back(loc);
  3830. i += 3;
  3831. }
  3832. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3833. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3834. if (quest_step && icon > 0)
  3835. quest_step->SetIcon(icon);
  3836. if (quest->GetPlayer()) {
  3837. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3838. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3839. }
  3840. }
  3841. lua_interface->ResetFunctionStack(state);
  3842. return 0;
  3843. }
  3844. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3845. if (!lua_interface)
  3846. return 0;
  3847. Quest* quest = lua_interface->GetQuest(state);
  3848. int32 step = lua_interface->GetInt32Value(state, 2);
  3849. string description = lua_interface->GetStringValue(state, 3);
  3850. float max_variation = lua_interface->GetFloatValue(state, 4);
  3851. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3852. int16 icon = lua_interface->GetInt16Value(state, 6);
  3853. if (quest) {
  3854. const char* taskgroup = 0;
  3855. if (str_taskgroup.length() > 0)
  3856. taskgroup = str_taskgroup.c_str();
  3857. vector<Location>* locations = 0;
  3858. int i = 7;
  3859. while (true) {
  3860. Location loc;
  3861. loc.x = lua_interface->GetFloatValue(state, i);
  3862. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3863. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3864. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3865. break;
  3866. if (locations == 0)
  3867. locations = new vector<Location>;
  3868. locations->push_back(loc);
  3869. i += 3;
  3870. }
  3871. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3872. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3873. if (quest_step && icon > 0)
  3874. quest_step->SetIcon(icon);
  3875. if (quest->GetPlayer()) {
  3876. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3877. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3878. }
  3879. }
  3880. lua_interface->ResetFunctionStack(state);
  3881. return 0;
  3882. }
  3883. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3884. Quest* quest = lua_interface->GetQuest(state);
  3885. int32 step = lua_interface->GetInt32Value(state, 2);
  3886. string description = lua_interface->GetStringValue(state, 3);
  3887. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3888. float percentage = lua_interface->GetFloatValue(state, 5);
  3889. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3890. int16 icon = lua_interface->GetInt16Value(state, 7);
  3891. if (quest) {
  3892. const char* taskgroup = 0;
  3893. if (str_taskgroup.length() > 0)
  3894. taskgroup = str_taskgroup.c_str();
  3895. int32 spell_id = 0;
  3896. vector<int32>* ids = 0;
  3897. int i = 0;
  3898. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3899. if (ids == 0)
  3900. ids = new vector<int32>;
  3901. ids->push_back(spell_id);
  3902. i++;
  3903. }
  3904. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3905. if (quest_step && icon > 0 && quantity > 0)
  3906. quest_step->SetIcon(icon);
  3907. if (quest->GetPlayer()) {
  3908. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3909. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3910. }
  3911. safe_delete(ids);
  3912. }
  3913. lua_interface->ResetFunctionStack(state);
  3914. return 0;
  3915. }
  3916. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3917. if (!lua_interface)
  3918. return 0;
  3919. Quest* quest = lua_interface->GetQuest(state);
  3920. int32 step = lua_interface->GetInt32Value(state, 2);
  3921. string description = lua_interface->GetStringValue(state, 3);
  3922. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3923. float percentage = lua_interface->GetFloatValue(state, 5);
  3924. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3925. int16 icon = lua_interface->GetInt16Value(state, 7);
  3926. if (quest) {
  3927. const char* taskgroup = 0;
  3928. if (str_taskgroup.length() > 0)
  3929. taskgroup = str_taskgroup.c_str();
  3930. int32 item_id = 0;
  3931. vector<int32>* ids = 0;
  3932. int i = 0;
  3933. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3934. if (ids == 0)
  3935. ids = new vector<int32>;
  3936. ids->push_back(item_id);
  3937. i++;
  3938. }
  3939. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3940. if (quest_step && icon > 0 && quantity > 0)
  3941. quest_step->SetIcon(icon);
  3942. if (quest->GetPlayer()) {
  3943. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3944. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3945. }
  3946. safe_delete(ids);
  3947. }
  3948. lua_interface->ResetFunctionStack(state);
  3949. return 0;
  3950. }
  3951. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3952. if (!lua_interface)
  3953. return 0;
  3954. Quest* quest = lua_interface->GetQuest(state);
  3955. int32 step = lua_interface->GetInt32Value(state, 2);
  3956. string description = lua_interface->GetStringValue(state, 3);
  3957. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3958. float percentage = lua_interface->GetFloatValue(state, 5);
  3959. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3960. int16 icon = lua_interface->GetInt16Value(state, 7);
  3961. if (quest) {
  3962. const char* taskgroup = 0;
  3963. if (str_taskgroup.length() > 0)
  3964. taskgroup = str_taskgroup.c_str();
  3965. int32 item_id = 0;
  3966. vector<int32>* ids = 0;
  3967. int i = 0;
  3968. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3969. if (ids == 0)
  3970. ids = new vector<int32>;
  3971. ids->push_back(item_id);
  3972. i++;
  3973. }
  3974. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3975. if (quest_step && icon > 0 && quantity > 0)
  3976. quest_step->SetIcon(icon);
  3977. if (quest->GetPlayer()) {
  3978. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3979. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3980. }
  3981. safe_delete(ids);
  3982. }
  3983. lua_interface->ResetFunctionStack(state);
  3984. return 0;
  3985. }
  3986. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3987. if (!lua_interface)
  3988. return 0;
  3989. Quest* quest = lua_interface->GetQuest(state);
  3990. string action = lua_interface->GetStringValue(state, 2);
  3991. lua_interface->ResetFunctionStack(state);
  3992. if (quest) {
  3993. if (action.length() > 0)
  3994. quest->SetCompleteAction(action);
  3995. }
  3996. return 0;
  3997. }
  3998. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3999. if (!lua_interface)
  4000. return 0;
  4001. Quest* quest = lua_interface->GetQuest(state);
  4002. int32 step = lua_interface->GetInt32Value(state, 2);
  4003. string action = lua_interface->GetStringValue(state, 3);
  4004. lua_interface->ResetFunctionStack(state);
  4005. if (quest) {
  4006. if (step > 0 && action.length() > 0)
  4007. quest->AddCompleteAction(step, action);
  4008. }
  4009. return 0;
  4010. }
  4011. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4012. if (!lua_interface)
  4013. return 0;
  4014. Quest* quest = lua_interface->GetQuest(state);
  4015. int32 step = lua_interface->GetInt32Value(state, 2);
  4016. string action = lua_interface->GetStringValue(state, 3);
  4017. lua_interface->ResetFunctionStack(state);
  4018. if (quest) {
  4019. if (step > 0 && action.length() > 0)
  4020. quest->AddProgressAction(step, action);
  4021. }
  4022. return 0;
  4023. }
  4024. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4025. if (!lua_interface)
  4026. return 0;
  4027. Quest* quest = lua_interface->GetQuest(state);
  4028. string description = lua_interface->GetStringValue(state, 2);
  4029. lua_interface->ResetFunctionStack(state);
  4030. if (quest && description.length() > 0)
  4031. quest->SetDescription(description);
  4032. return 0;
  4033. }
  4034. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4035. if (!lua_interface)
  4036. return 0;
  4037. Quest* quest = lua_interface->GetQuest(state);
  4038. string description = lua_interface->GetStringValue(state, 2);
  4039. lua_interface->ResetFunctionStack(state);
  4040. if (quest && description.length() > 0)
  4041. quest->SetCompletedDescription(description);
  4042. return 0;
  4043. }
  4044. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4045. if (!lua_interface)
  4046. return 0;
  4047. Quest* quest = lua_interface->GetQuest(state);
  4048. int32 step = lua_interface->GetInt32Value(state, 2);
  4049. string description = lua_interface->GetStringValue(state, 3);
  4050. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4051. lua_interface->ResetFunctionStack(state);
  4052. if (quest && step > 0 && description.length() > 0) {
  4053. quest->SetTaskGroupDescription(step, description, display_bullets);
  4054. /* if (quest->GetPlayer()) {
  4055. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4056. if (client)
  4057. client->SendQuestUpdateStep(quest, step, false);
  4058. }*/
  4059. }
  4060. return 0;
  4061. }
  4062. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4063. if (!lua_interface)
  4064. return 0;
  4065. Quest* quest = lua_interface->GetQuest(state);
  4066. int32 step = lua_interface->GetInt32Value(state, 2);
  4067. string description = lua_interface->GetStringValue(state, 3);
  4068. lua_interface->ResetFunctionStack(state);
  4069. if (quest && step > 0 && description.length() > 0) {
  4070. quest->SetStepDescription(step, description);
  4071. /*if (quest->GetPlayer()) {
  4072. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4073. if (client)
  4074. client->SendQuestUpdateStepImmediately(quest, step);
  4075. }*/
  4076. }
  4077. return 0;
  4078. }
  4079. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4080. Quest* quest = lua_interface->GetQuest(state);
  4081. string zone = lua_interface->GetStringValue(state, 2);
  4082. lua_interface->ResetFunctionStack(state);
  4083. if (quest && zone.length() > 0)
  4084. quest->SetZone(zone);
  4085. return 0;
  4086. }
  4087. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4088. if (!lua_interface)
  4089. return 0;
  4090. Quest* quest = lua_interface->GetQuest(state);
  4091. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4092. lua_interface->ResetFunctionStack(state);
  4093. if (quest && spawn) {
  4094. if (spawn->IsPlayer()) {
  4095. Client* client = ((Player*)spawn)->GetClient();
  4096. if (client) {
  4097. client->AddPendingQuestReward(quest);
  4098. }
  4099. }
  4100. }
  4101. return 0;
  4102. }
  4103. int EQ2Emu_lua_Harvest(lua_State* state) {
  4104. if (!lua_interface)
  4105. return 0;
  4106. Spawn* player = lua_interface->GetSpawn(state);
  4107. Spawn* node = lua_interface->GetSpawn(state, 2);
  4108. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4109. Client* client = ((Player*)player)->GetClient();
  4110. if (client) {
  4111. ((GroundSpawn*)node)->ProcessHarvest(client);
  4112. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4113. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4114. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4115. }
  4116. }
  4117. }
  4118. else if (player && player->IsPlayer()) {
  4119. Client* client = ((Player*)player)->GetClient();
  4120. if (client)
  4121. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4122. }
  4123. lua_interface->ResetFunctionStack(state);
  4124. return 0;
  4125. }
  4126. int EQ2Emu_lua_Bind(lua_State* state) {
  4127. if (!lua_interface)
  4128. return 0;
  4129. Spawn* spawn = lua_interface->GetSpawn(state);
  4130. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4131. float x = lua_interface->GetFloatValue(state, 3);
  4132. float y = lua_interface->GetFloatValue(state, 4);
  4133. float z = lua_interface->GetFloatValue(state, 5);
  4134. float h = lua_interface->GetFloatValue(state, 6);
  4135. lua_interface->ResetFunctionStack(state);
  4136. if (!spawn) {
  4137. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4138. return 0;
  4139. }
  4140. if (!spawn->IsPlayer()) {
  4141. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4142. return 0;
  4143. }
  4144. if (zone_id == 0) {
  4145. Client* client = ((Player*)spawn)->GetClient();
  4146. if (!client) {
  4147. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4148. return 0;
  4149. }
  4150. if (!client->Bind())
  4151. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4152. }
  4153. else {
  4154. Player* player = (Player*)spawn;
  4155. player->GetPlayerInfo()->SetBindZone(zone_id);
  4156. player->GetPlayerInfo()->SetBindX(x);
  4157. player->GetPlayerInfo()->SetBindY(y);
  4158. player->GetPlayerInfo()->SetBindZ(z);
  4159. player->GetPlayerInfo()->SetBindHeading(h);
  4160. }
  4161. return 0;
  4162. }
  4163. int EQ2Emu_lua_Gate(lua_State* state) {
  4164. if (!lua_interface)
  4165. return 0;
  4166. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4167. Spawn* spawn = lua_interface->GetSpawn(state);
  4168. lua_interface->ResetFunctionStack(state);
  4169. if (spawn) {
  4170. if (spawn->IsPlayer()) {
  4171. Client* client = ((Player*)spawn)->GetClient();
  4172. if (client) {
  4173. if (!client->Gate((spell != nullptr) ? true : false))
  4174. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4175. }
  4176. }
  4177. }
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4181. if (!lua_interface)
  4182. return 0;
  4183. bool ret = false;
  4184. Spawn* spawn = lua_interface->GetSpawn(state);
  4185. lua_interface->ResetFunctionStack(state);
  4186. if (spawn) {
  4187. if (spawn->IsPlayer()) {
  4188. Client* client = ((Player*)spawn)->GetClient();
  4189. if (client)
  4190. ret = client->BindAllowed();
  4191. }
  4192. }
  4193. lua_interface->SetBooleanValue(state, ret);
  4194. return 1;
  4195. }
  4196. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4197. if (!lua_interface)
  4198. return 0;
  4199. bool ret = false;
  4200. Spawn* spawn = lua_interface->GetSpawn(state);
  4201. lua_interface->ResetFunctionStack(state);
  4202. if (spawn) {
  4203. if (spawn->IsPlayer()) {
  4204. Client* client = ((Player*)spawn)->GetClient();
  4205. ZoneServer* zone = lua_interface->GetZone(state);
  4206. if (client && zone){
  4207. ret = zone->GetCanGate();
  4208. }
  4209. }
  4210. }
  4211. lua_interface->SetBooleanValue(state, ret);
  4212. return 1;
  4213. }
  4214. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4215. Spawn* spawn = lua_interface->GetSpawn(state);
  4216. lua_interface->ResetFunctionStack(state);
  4217. if (spawn) {
  4218. lua_interface->SetBooleanValue(state, spawn->Alive());
  4219. return 1;
  4220. }
  4221. return 0;
  4222. }
  4223. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4224. if (!lua_interface)
  4225. return 0;
  4226. Spawn* spawn = lua_interface->GetSpawn(state);
  4227. lua_interface->ResetFunctionStack(state);
  4228. if (spawn && spawn->IsEntity()) {
  4229. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4230. return 1;
  4231. }
  4232. return 0;
  4233. }
  4234. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4235. Spawn* spawn = lua_interface->GetSpawn(state);
  4236. string message = lua_interface->GetStringValue(state, 2);
  4237. string color_str = lua_interface->GetStringValue(state, 3);
  4238. lua_interface->ResetFunctionStack(state);
  4239. int8 color = CHANNEL_NARRATIVE;
  4240. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4241. Client* client = ((Player*)spawn)->GetClient();
  4242. if (client) {
  4243. if (color_str.length() > 0) {
  4244. // leave for backwards compat, but all future should just use the number
  4245. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4246. color = CHANNEL_COLOR_RED;
  4247. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4248. color = CHANNEL_COLOR_YELLOW;
  4249. else
  4250. {
  4251. // use a number to specify the channel as per Commands/Commands.h defines
  4252. color = (int8)atoul(color_str.c_str());
  4253. }
  4254. }
  4255. client->SimpleMessage(color, message.c_str());
  4256. }
  4257. }
  4258. return 0;
  4259. }
  4260. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4261. Spawn* spawn = lua_interface->GetSpawn(state);
  4262. string message = lua_interface->GetStringValue(state, 2);
  4263. int8 red = lua_interface->GetInt8Value(state, 3);
  4264. int8 green = lua_interface->GetInt8Value(state, 4);
  4265. int8 blue = lua_interface->GetInt8Value(state, 5);
  4266. lua_interface->ResetFunctionStack(state);
  4267. if (!spawn) {
  4268. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4269. return 0;
  4270. }
  4271. if (!spawn->IsPlayer()) {
  4272. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4273. return 0;
  4274. }
  4275. int32 words = ::CountWordsInString(message.c_str());
  4276. if (words < 5)
  4277. words = 5;
  4278. Client* client = ((Player*)spawn)->GetClient();
  4279. if (client)
  4280. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4281. return 0;
  4282. }
  4283. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4284. Spawn* spawn = lua_interface->GetSpawn(state);
  4285. int8 param = lua_interface->GetInt8Value(state, 2);
  4286. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4287. int8 value = lua_interface->GetInt8Value(state, 4);
  4288. lua_interface->ResetFunctionStack(state);
  4289. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4290. Client* client = ((Player*)spawn)->GetClient();
  4291. if (client) {
  4292. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4293. switch (param) {
  4294. case 1: {
  4295. packet->setDataByName("parameter1", param_value);
  4296. break;
  4297. }
  4298. case 2: {
  4299. packet->setDataByName("parameter2", param_value);
  4300. break;
  4301. }
  4302. case 3: {
  4303. packet->setDataByName("parameter3", param_value);
  4304. break;
  4305. }
  4306. case 4: {
  4307. packet->setDataByName("parameter4", param_value);
  4308. break;
  4309. }
  4310. case 5: {
  4311. packet->setDataByName("parameter5", param_value);
  4312. break;
  4313. }
  4314. }
  4315. packet->setDataByName("value", value);
  4316. client->QueuePacket(packet->serialize());
  4317. safe_delete(packet);
  4318. }
  4319. }
  4320. return 0;
  4321. }
  4322. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4323. Spawn* spawn = lua_interface->GetSpawn(state);
  4324. lua_interface->ResetFunctionStack(state);
  4325. if (spawn && spawn->IsPlayer()) {
  4326. if (((Player*)spawn)->GetIsTracking())
  4327. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4328. else
  4329. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4330. }
  4331. return 0;
  4332. }
  4333. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4334. Spawn* player = lua_interface->GetSpawn(state);
  4335. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4336. string name = lua_interface->GetStringValue(state, 3);
  4337. float distance = lua_interface->GetFloatValue(state, 4);
  4338. string command = lua_interface->GetStringValue(state, 5);
  4339. string error_text = lua_interface->GetStringValue(state, 6);
  4340. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4341. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4342. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4343. lua_interface->ResetFunctionStack(state);
  4344. if (spawn) {
  4345. if (distance == 0)
  4346. distance = 10.0f;
  4347. if (command.length() == 0)
  4348. command = name;
  4349. if (command.length() < 1 && name.length() < 1)
  4350. {
  4351. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4352. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4353. spawn->RemovePrimaryCommands();
  4354. }
  4355. else
  4356. {
  4357. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4358. }
  4359. }
  4360. return 0;
  4361. }
  4362. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4363. if (!lua_interface)
  4364. return 0;
  4365. Spawn* player = lua_interface->GetSpawn(state);
  4366. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4367. int16 tier = lua_interface->GetInt16Value(state, 3);
  4368. lua_interface->ResetFunctionStack(state);
  4369. if (player && player->IsPlayer()) {
  4370. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4371. return 1;
  4372. }
  4373. return 0;
  4374. }
  4375. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4376. if (!lua_interface)
  4377. return 0;
  4378. Spawn* player = lua_interface->GetSpawn(state);
  4379. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4380. int16 tier = lua_interface->GetInt16Value(state, 3);
  4381. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4382. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4383. bool add_to_hotbar = true;
  4384. if (num_args > 4) {
  4385. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4386. }
  4387. lua_interface->ResetFunctionStack(state);
  4388. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4389. if (player && spell && player->IsPlayer()) {
  4390. Client* client = player->GetClient();
  4391. if (client) {
  4392. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4393. {
  4394. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4395. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4396. client->GetPlayer()->UnlockSpell(spell);
  4397. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4398. }
  4399. else
  4400. {
  4401. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4402. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4403. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4404. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4405. client->GetPlayer()->UnlockSpell(spell);
  4406. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4407. }
  4408. //if (client ) {
  4409. // ((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);
  4410. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4411. if (outapp)
  4412. client->QueuePacket(outapp);
  4413. }
  4414. }
  4415. return 0;
  4416. }
  4417. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4418. if (!lua_interface)
  4419. return 0;
  4420. Spawn* player = lua_interface->GetSpawn(state);
  4421. lua_interface->ResetFunctionStack(state);
  4422. if (player && player->IsPlayer()) {
  4423. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4424. return 1;
  4425. }
  4426. return 0;
  4427. }
  4428. int EQ2Emu_lua_Attack(lua_State* state) {
  4429. if (lua_interface) {
  4430. Spawn* npc = lua_interface->GetSpawn(state);
  4431. Spawn* player = lua_interface->GetSpawn(state, 2);
  4432. lua_interface->ResetFunctionStack(state);
  4433. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4434. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4435. }
  4436. return 0;
  4437. }
  4438. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4439. if (lua_interface) {
  4440. Spawn* target = lua_interface->GetSpawn(state);
  4441. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4442. lua_interface->ResetFunctionStack(state);
  4443. if (target && target->GetZone())
  4444. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4445. }
  4446. return 0;
  4447. }
  4448. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4449. Spawn* player;
  4450. if (lua_interface) {
  4451. player = lua_interface->GetSpawn(state);
  4452. lua_interface->ResetFunctionStack(state);
  4453. if (player && player->IsPlayer()) {
  4454. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4455. return 1;
  4456. }
  4457. }
  4458. return 0;
  4459. }
  4460. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4461. Spawn* player;
  4462. Client* client;
  4463. if (lua_interface) {
  4464. player = lua_interface->GetSpawn(state);
  4465. lua_interface->ResetFunctionStack(state);
  4466. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4467. if ((client = ((Player*)player)->GetClient()))
  4468. client->HandInCollections();
  4469. }
  4470. return 0;
  4471. }
  4472. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4473. Spawn* widget;
  4474. if (lua_interface) {
  4475. widget = lua_interface->GetSpawn(state);
  4476. lua_interface->ResetFunctionStack(state);
  4477. if (widget && widget->IsWidget())
  4478. ((Widget*)widget)->HandleUse(nullptr, "");
  4479. }
  4480. return 0;
  4481. }
  4482. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4483. Spawn* spawn = 0;
  4484. int32 primary_list = 0;
  4485. int32 secondary_list = 0;
  4486. if (lua_interface) {
  4487. spawn = lua_interface->GetSpawn(state);
  4488. primary_list = lua_interface->GetInt32Value(state, 2);
  4489. secondary_list = lua_interface->GetInt32Value(state, 3);
  4490. lua_interface->ResetFunctionStack(state);
  4491. if (!spawn->IsNPC()) {
  4492. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4493. return 0;
  4494. }
  4495. NPC* npc = (NPC*)spawn;
  4496. npc->SetPrimarySpellList(primary_list);
  4497. npc->SetSecondarySpellList(secondary_list);
  4498. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4499. }
  4500. return 0;
  4501. }
  4502. int EQ2Emu_lua_GetPet(lua_State* state) {
  4503. if (!lua_interface)
  4504. return 0;
  4505. Spawn* spawn = lua_interface->GetSpawn(state);
  4506. lua_interface->ResetFunctionStack(state);
  4507. if (spawn) {
  4508. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4509. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4510. return 1;
  4511. }
  4512. }
  4513. return 0;
  4514. }
  4515. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4516. if (!lua_interface)
  4517. return 0;
  4518. Spawn* spawn = lua_interface->GetSpawn(state);
  4519. lua_interface->ResetFunctionStack(state);
  4520. if (spawn) {
  4521. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4522. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4523. return 1;
  4524. }
  4525. }
  4526. return 0;
  4527. }
  4528. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4529. if (!lua_interface)
  4530. return 0;
  4531. Spawn* spawn = lua_interface->GetSpawn(state);
  4532. lua_interface->ResetFunctionStack(state);
  4533. if (spawn) {
  4534. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4535. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4536. return 1;
  4537. }
  4538. }
  4539. return 0;
  4540. }
  4541. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4542. if (!lua_interface)
  4543. return 0;
  4544. Spawn* spawn = lua_interface->GetSpawn(state);
  4545. lua_interface->ResetFunctionStack(state);
  4546. if (spawn) {
  4547. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4548. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4549. return 1;
  4550. }
  4551. }
  4552. return 0;
  4553. }
  4554. int EQ2Emu_lua_Charm(lua_State* state) {
  4555. if (!lua_interface)
  4556. return 0;
  4557. Spawn* owner = lua_interface->GetSpawn(state);
  4558. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4559. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4560. lua_interface->ResetFunctionStack(state);
  4561. if (!luaspell) {
  4562. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4563. return 0;
  4564. }
  4565. if(luaspell->resisted) {
  4566. return 0;
  4567. }
  4568. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4569. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4570. pet->SetPet(true);
  4571. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4572. ((NPC*)pet)->SetOwner((Entity*)owner);
  4573. // If owner is player and player does not have a summoned pet set the players charsheet
  4574. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4575. Player* player = (Player*)owner;
  4576. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4577. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4578. player->GetInfoStruct()->set_pet_movement(2);
  4579. player->GetInfoStruct()->set_pet_behavior(3);
  4580. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4581. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4582. // Make sure the values get sent to the client
  4583. player->SetCharSheetChanged(true);
  4584. }
  4585. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4586. pet->SetSpawnScript("");
  4587. // Set faction to the same as the owner
  4588. pet->SetFactionID(owner->GetFactionID());
  4589. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4590. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4591. // Clear hate list
  4592. ((NPC*)pet)->Brain()->ClearHate();
  4593. // Set the brain to a pet brain
  4594. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4595. }
  4596. return 0;
  4597. }
  4598. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4599. if (!lua_interface)
  4600. return 0;
  4601. Spawn* spawn = lua_interface->GetSpawn(state);
  4602. lua_interface->ResetFunctionStack(state);
  4603. if (!spawn) {
  4604. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4605. return 0;
  4606. }
  4607. vector<Spawn*> groupMembers;
  4608. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4609. groupMembers = *spawn->GetSpawnGroup();
  4610. }
  4611. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4612. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4613. deque<GroupMemberInfo*>::iterator itr;
  4614. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4615. if (group)
  4616. {
  4617. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4618. deque<GroupMemberInfo*>* members = group->GetMembers();
  4619. GroupMemberInfo* info = 0;
  4620. for (itr = members->begin(); itr != members->end(); itr++) {
  4621. info = *itr;
  4622. if (info->client)
  4623. groupMembers.push_back(info->client->GetPlayer());
  4624. }
  4625. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4626. }
  4627. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4628. }
  4629. else
  4630. return 0;
  4631. lua_createtable(state, groupMembers.size(), 0);
  4632. int newTable = lua_gettop(state);
  4633. for (int32 i = 0; i < groupMembers.size(); i++) {
  4634. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4635. lua_rawseti(state, newTable, i + 1);
  4636. }
  4637. return 1;
  4638. }
  4639. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4640. if (!lua_interface)
  4641. return 0;
  4642. lua_interface->ResetFunctionStack(state);
  4643. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4644. lua_interface->SetOptionWindowValue(state, option_window);
  4645. return 1;
  4646. }
  4647. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4648. if (!lua_interface)
  4649. return 0;
  4650. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4651. if (option_window) {
  4652. OptionWindowOption option_window_option;
  4653. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4654. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4655. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4656. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4657. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4658. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4659. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4660. option_window->push_back(option_window_option);
  4661. }
  4662. lua_interface->ResetFunctionStack(state);
  4663. return 0;
  4664. }
  4665. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4666. if (!lua_interface)
  4667. return 0;
  4668. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4669. Spawn* player = lua_interface->GetSpawn(state, 2);
  4670. string window_title = lua_interface->GetStringValue(state, 3);
  4671. string cancel_command = lua_interface->GetStringValue(state, 4);
  4672. lua_interface->ResetFunctionStack(state);
  4673. if (!player->IsPlayer()) {
  4674. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4675. return 0;
  4676. }
  4677. Client* client = ((Player*)player)->GetClient();
  4678. if (option_window && window_title.length() > 0 && client) {
  4679. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4680. if (!packet)
  4681. return 0;
  4682. packet->setDataByName("title_text", window_title.c_str());
  4683. if (cancel_command.length() > 0)
  4684. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4685. packet->setArrayLengthByName("num_selections", option_window->size());
  4686. vector<OptionWindowOption>::iterator itr;
  4687. int8 i = 0;
  4688. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4689. OptionWindowOption opt = *itr;
  4690. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4691. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4692. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4693. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4694. if (opt.optionCommand.length() > 0)
  4695. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4696. if (opt.optionConfirmTitle.length() > 0)
  4697. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4698. i++;
  4699. }
  4700. client->QueuePacket(packet->serialize());
  4701. lua_interface->SetLuaUserDataStale(option_window);
  4702. safe_delete(option_window);
  4703. safe_delete(packet);
  4704. }
  4705. return 0;
  4706. }
  4707. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4708. if (!lua_interface)
  4709. return 0;
  4710. Spawn* spawn = lua_interface->GetSpawn(state);
  4711. lua_interface->ResetFunctionStack(state);
  4712. if (spawn) {
  4713. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4714. return 1;
  4715. }
  4716. else
  4717. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4718. return 0;
  4719. }
  4720. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4721. if (!lua_interface)
  4722. return 0;
  4723. Spawn* spawn = lua_interface->GetSpawn(state);
  4724. lua_interface->ResetFunctionStack(state);
  4725. if (spawn) {
  4726. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4727. return 1;
  4728. }
  4729. else
  4730. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4731. return 0;
  4732. }
  4733. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4734. if (!lua_interface)
  4735. return 0;
  4736. Spawn* spawn = lua_interface->GetSpawn(state);
  4737. lua_interface->ResetFunctionStack(state);
  4738. if (spawn) {
  4739. int8 class_id = spawn->GetTradeskillClass();
  4740. // Need to add 42 for the offset in the array
  4741. class_id += 44;
  4742. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4743. return 1;
  4744. }
  4745. else
  4746. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4747. return 0;
  4748. }
  4749. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4750. if (!lua_interface)
  4751. return 0;
  4752. Spawn* spawn = lua_interface->GetSpawn(state);
  4753. int16 level = lua_interface->GetInt8Value(state, 2);
  4754. lua_interface->ResetFunctionStack(state);
  4755. if (spawn) {
  4756. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4757. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4758. else
  4759. spawn->SetTSLevel(level);
  4760. }
  4761. else
  4762. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4763. return 0;
  4764. }
  4765. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4766. if (!lua_interface)
  4767. return 0;
  4768. Spawn* spawn = lua_interface->GetSpawn(state);
  4769. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4770. lua_interface->ResetFunctionStack(state);
  4771. if (spawn) {
  4772. spawn->SetAttackable(attackable);
  4773. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4774. }
  4775. return 0;
  4776. }
  4777. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4778. // Check to see if we have a valid lua_interface
  4779. if (!lua_interface)
  4780. return 0;
  4781. // Get the spawn that is getting the pet
  4782. Spawn* spawn = lua_interface->GetSpawn(state);
  4783. // Get the DB ID of the pet
  4784. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4785. // The max level the pet can gain
  4786. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4787. // Get the spell that this command was called from
  4788. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4789. lua_interface->ResetFunctionStack(state);
  4790. // Check to make sure the spawn pointer is valid
  4791. if (!spawn) {
  4792. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4793. return 0;
  4794. }
  4795. // Check to make sure the spawn is an entity
  4796. if (!spawn->IsEntity()) {
  4797. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4798. return 0;
  4799. }
  4800. // Check to make sure the spawn doesn't already have a pet of this type
  4801. if (((Entity*)spawn)->GetPet()) {
  4802. if (spawn->IsPlayer()) {
  4803. Client* client = ((Player*)spawn)->GetClient();
  4804. if (client)
  4805. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4806. }
  4807. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4808. return 0;
  4809. }
  4810. // Check to see if the DB ID for the pet is set
  4811. if (pet_id == 0) {
  4812. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4813. return 0;
  4814. }
  4815. // Check to see if the pointer to the spell is valid
  4816. if (!luaspell) {
  4817. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4818. return 0;
  4819. }
  4820. if(luaspell->resisted) {
  4821. return 0;
  4822. }
  4823. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4824. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4825. if (!pet) {
  4826. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4827. return 0;
  4828. }
  4829. // Check to make sure the pet is an npc
  4830. if (!pet->IsNPC()) {
  4831. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4832. return 0;
  4833. }
  4834. // Spawn the pet at the same location as the owner
  4835. pet->SetX(spawn->GetX());
  4836. pet->SetY(spawn->GetY());
  4837. pet->SetZ(spawn->GetZ());
  4838. pet->SetLocation(spawn->GetLocation());
  4839. pet->SetHeading(spawn->GetHeading());
  4840. spawn->GetZone()->AddSpawn(pet);
  4841. /*
  4842. const char* spawn_script = world.GetSpawnScript(pet_id);
  4843. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4844. spawn->SetSpawnScript(string(spawn_script));
  4845. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4846. }*/
  4847. // Get a random pet name
  4848. string random_pet_name;
  4849. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4850. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4851. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4852. // If player set various values for the char sheet (pet window)
  4853. if (spawn->IsPlayer()) {
  4854. Player* player = (Player*)spawn;
  4855. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4856. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4857. player->GetInfoStruct()->set_pet_movement(2);
  4858. player->GetInfoStruct()->set_pet_behavior(3);
  4859. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4860. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4861. // Make sure the values get sent to the client
  4862. player->SetCharSheetChanged(true);
  4863. }
  4864. // Set the pets name
  4865. pet->SetName(random_pet_name.c_str());
  4866. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4867. if (max_level > 0)
  4868. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4869. else
  4870. pet->SetLevel(spawn->GetLevel());
  4871. // Set the max level this pet can reach
  4872. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4873. // Set the faction of the pet to the same faction as the owner
  4874. pet->SetFactionID(spawn->GetFactionID());
  4875. // Set the spawn as a pet
  4876. pet->SetPet(true);
  4877. // Give a pointer of the owner to the pet
  4878. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4879. // Give a pointer of the pet to the owner
  4880. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4881. // Set the pet type
  4882. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4883. // Set the spell id used to create this pet
  4884. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4885. // Set the spell tier used to create this pet
  4886. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4887. // Set the pets spawn type to 6
  4888. pet->SetSpawnType(6);
  4889. // Set the pets brain
  4890. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4891. // Check to see if the pet has a subtitle
  4892. if (strlen(pet->GetSubTitle()) > 0) {
  4893. // Add the players name to the front of the sub title
  4894. string pet_subtitle;
  4895. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4896. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4897. // Set the pets subtitle to the new one
  4898. pet->SetSubTitle(pet_subtitle.c_str());
  4899. }
  4900. // Add the "Pet Options" entity command to the pet
  4901. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4902. // Set the pet as the return value for this function
  4903. lua_interface->SetSpawnValue(state, pet);
  4904. return 1;
  4905. }
  4906. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4907. if (!lua_interface)
  4908. return 0;
  4909. Spawn* spawn = lua_interface->GetSpawn(state);
  4910. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4911. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4912. lua_interface->ResetFunctionStack(state);
  4913. if (!spawn) {
  4914. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4915. return 0;
  4916. }
  4917. if (!spawn->IsEntity()) {
  4918. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4919. return 0;
  4920. }
  4921. if (((Entity*)spawn)->GetDeityPet()) {
  4922. if (spawn->IsPlayer()) {
  4923. Client* client = ((Player*)spawn)->GetClient();
  4924. if (client)
  4925. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4926. }
  4927. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4928. return 0;
  4929. }
  4930. if (pet_id == 0) {
  4931. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4932. return 0;
  4933. }
  4934. if (!luaspell) {
  4935. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4936. return 0;
  4937. }
  4938. if(luaspell->resisted) {
  4939. return 0;
  4940. }
  4941. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4942. if (!pet) {
  4943. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4944. return 0;
  4945. }
  4946. if (!pet->IsNPC()) {
  4947. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4948. return 0;
  4949. }
  4950. pet->SetX(spawn->GetX());
  4951. pet->SetY(spawn->GetY());
  4952. pet->SetZ(spawn->GetZ());
  4953. pet->SetLocation(spawn->GetLocation());
  4954. pet->SetHeading(spawn->GetHeading());
  4955. spawn->GetZone()->AddSpawn(pet);
  4956. string random_pet_name;
  4957. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4958. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4959. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4960. pet->SetName(random_pet_name.c_str());
  4961. pet->SetLevel(spawn->GetLevel());
  4962. pet->SetFactionID(spawn->GetFactionID());
  4963. pet->SetPet(true);
  4964. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4965. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4966. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4967. pet->SetSpawnType(6);
  4968. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4969. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4970. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4971. if (strlen(pet->GetSubTitle()) > 0) {
  4972. string pet_subtitle;
  4973. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4974. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4975. pet->SetSubTitle(pet_subtitle.c_str());
  4976. }
  4977. // deity and cosmetic pets are not attackable
  4978. pet->SetAttackable(false);
  4979. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4980. lua_interface->SetSpawnValue(state, pet);
  4981. return 1;
  4982. }
  4983. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4984. if (!lua_interface)
  4985. return 0;
  4986. Spawn* spawn = lua_interface->GetSpawn(state);
  4987. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4988. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4989. lua_interface->ResetFunctionStack(state);
  4990. if (!spawn) {
  4991. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4992. return 0;
  4993. }
  4994. if (!spawn->IsEntity()) {
  4995. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4996. return 0;
  4997. }
  4998. if (((Entity*)spawn)->GetCosmeticPet()) {
  4999. if (spawn->IsPlayer()) {
  5000. Client* client = ((Player*)spawn)->GetClient();
  5001. if (client)
  5002. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5003. }
  5004. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5005. return 0;
  5006. }
  5007. if (pet_id == 0) {
  5008. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5009. return 0;
  5010. }
  5011. if (!luaspell) {
  5012. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5013. return 0;
  5014. }
  5015. if(luaspell->resisted) {
  5016. return 0;
  5017. }
  5018. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5019. if (!pet) {
  5020. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5021. return 0;
  5022. }
  5023. if (!pet->IsNPC()) {
  5024. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5025. return 0;
  5026. }
  5027. pet->SetX(spawn->GetX());
  5028. pet->SetY(spawn->GetY());
  5029. pet->SetZ(spawn->GetZ());
  5030. pet->SetLocation(spawn->GetLocation());
  5031. pet->SetHeading(spawn->GetHeading());
  5032. spawn->GetZone()->AddSpawn(pet);
  5033. string random_pet_name;
  5034. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5035. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5036. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5037. pet->SetName(random_pet_name.c_str());
  5038. pet->SetLevel(spawn->GetLevel());
  5039. pet->SetFactionID(spawn->GetFactionID());
  5040. pet->SetPet(true);
  5041. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5042. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5043. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5044. pet->SetSpawnType(6);
  5045. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5046. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5047. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5048. if (strlen(pet->GetSubTitle()) > 0) {
  5049. string pet_subtitle;
  5050. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5051. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5052. pet->SetSubTitle(pet_subtitle.c_str());
  5053. }
  5054. pet->SetAttackable(false);
  5055. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5056. lua_interface->SetSpawnValue(state, pet);
  5057. return 1;
  5058. }
  5059. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5060. if (!lua_interface)
  5061. return 0;
  5062. Spawn* spawn = lua_interface->GetSpawn(state);
  5063. lua_interface->ResetFunctionStack(state);
  5064. if (!spawn) {
  5065. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5066. return 0;
  5067. }
  5068. if (!spawn->IsPet()) {
  5069. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5070. return 0;
  5071. }
  5072. if (!((NPC*)spawn)->IsDismissing())
  5073. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5074. return 0;
  5075. }
  5076. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5077. if (!lua_interface)
  5078. return 0;
  5079. Quest* quest = lua_interface->GetQuest(state);
  5080. if (!quest) {
  5081. 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));
  5082. lua_interface->ResetFunctionStack(state);
  5083. return 0;
  5084. }
  5085. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5086. lua_interface->ResetFunctionStack(state);
  5087. if (feather_color > 0)
  5088. quest->SetFeatherColor(feather_color);
  5089. return 0;
  5090. }
  5091. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5092. if (!lua_interface)
  5093. return 0;
  5094. Spawn* spawn = lua_interface->GetSpawn(state);
  5095. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5096. lua_interface->ResetFunctionStack(state);
  5097. if (!spawn) {
  5098. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5099. return 0;
  5100. }
  5101. if (!spawn2) {
  5102. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5103. return 0;
  5104. }
  5105. spawn->RemoveSpawnAccess(spawn2);
  5106. return 0;
  5107. }
  5108. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5109. if (!lua_interface)
  5110. return 0;
  5111. ZoneServer* zone = lua_interface->GetZone(state);
  5112. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5113. lua_interface->ResetFunctionStack(state);
  5114. if (!zone) {
  5115. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5116. return 0;
  5117. }
  5118. if (location_id == 0) {
  5119. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5120. return 0;
  5121. }
  5122. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5123. if (!location) {
  5124. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5125. return 0;
  5126. }
  5127. Spawn* spawn = 0;
  5128. if (location->entities[0]) {
  5129. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5130. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5131. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5132. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5133. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5134. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5135. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5136. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5137. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5138. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5139. if(spawn && spawn->IsOmittedByDBFlag())
  5140. {
  5141. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5142. safe_delete(spawn);
  5143. spawn = 0;
  5144. return 0;
  5145. }
  5146. if (spawn) {
  5147. const char* script = 0;
  5148. for (int x = 0; x < 3; x++) {
  5149. switch (x) {
  5150. case 0:
  5151. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5152. break;
  5153. case 1:
  5154. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5155. break;
  5156. case 2:
  5157. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5158. break;
  5159. }
  5160. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5161. spawn->SetSpawnScript(string(script));
  5162. break;
  5163. }
  5164. }
  5165. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5166. lua_interface->SetSpawnValue(state, spawn);
  5167. return 1;
  5168. }
  5169. else {
  5170. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5171. safe_delete(spawn);
  5172. }
  5173. }
  5174. return 0;
  5175. }
  5176. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5177. if (!lua_interface)
  5178. return 0;
  5179. Spawn* caster = lua_interface->GetSpawn(state);
  5180. Spawn* target = lua_interface->GetSpawn(state, 2);
  5181. int32 id = lua_interface->GetInt32Value(state, 3);
  5182. string command = lua_interface->GetStringValue(state, 4);
  5183. lua_interface->ResetFunctionStack(state);
  5184. if (!caster) {
  5185. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5186. return 0;
  5187. }
  5188. if (!target) {
  5189. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5190. return 0;
  5191. }
  5192. if (!caster->IsPlayer()) {
  5193. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5194. return 0;
  5195. }
  5196. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5197. if (!entity_command) {
  5198. 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());
  5199. return 0;
  5200. }
  5201. Client* client = ((Player*)caster)->GetClient();
  5202. if (!client) {
  5203. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5204. return 0;
  5205. }
  5206. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5207. return 0;
  5208. }
  5209. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5210. if (!lua_interface)
  5211. return 0;
  5212. Spawn* spawn = lua_interface->GetSpawn(state);
  5213. lua_interface->ResetFunctionStack(state);
  5214. if (!spawn) {
  5215. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5216. return 0;
  5217. }
  5218. if (!spawn->IsNPC()) {
  5219. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5220. return 0;
  5221. }
  5222. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5223. return 0;
  5224. }
  5225. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5226. if (!lua_interface)
  5227. return 0;
  5228. Spawn* spawn = lua_interface->GetSpawn(state);
  5229. int16 tick = lua_interface->GetInt16Value(state, 2);
  5230. lua_interface->ResetFunctionStack(state);
  5231. if (!spawn) {
  5232. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5233. return 0;
  5234. }
  5235. if (!spawn->IsNPC()) {
  5236. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5237. return 0;
  5238. }
  5239. if (tick < 20) {
  5240. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5241. return 0;
  5242. }
  5243. ((NPC*)spawn)->Brain()->SetTick(tick);
  5244. return 0;
  5245. }
  5246. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5247. if (!lua_interface)
  5248. return 0;
  5249. Spawn* spawn = lua_interface->GetSpawn(state);
  5250. Spawn* target = lua_interface->GetSpawn(state, 2);
  5251. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5252. lua_interface->ResetFunctionStack(state);
  5253. if (!spawn) {
  5254. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5255. return 0;
  5256. }
  5257. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5258. spawn->SetFollowTarget(target, follow_distance);
  5259. return 0;
  5260. }
  5261. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5262. if (!lua_interface)
  5263. return 0;
  5264. Spawn* spawn = lua_interface->GetSpawn(state);
  5265. lua_interface->ResetFunctionStack(state);
  5266. if (!spawn) {
  5267. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5268. return 0;
  5269. }
  5270. Spawn* target = spawn->GetFollowTarget();
  5271. if (target) {
  5272. lua_interface->SetSpawnValue(state, target);
  5273. return 1;
  5274. }
  5275. return 0;
  5276. }
  5277. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5278. if (!lua_interface)
  5279. return 0;
  5280. Spawn* spawn = lua_interface->GetSpawn(state);
  5281. lua_interface->ResetFunctionStack(state);
  5282. if (!spawn) {
  5283. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5284. return 0;
  5285. }
  5286. if (spawn->following)
  5287. spawn->following = false;
  5288. else
  5289. spawn->following = true;
  5290. return 0;
  5291. }
  5292. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5293. if (!lua_interface)
  5294. return 0;
  5295. Spawn* spawn = lua_interface->GetSpawn(state);
  5296. lua_interface->ResetFunctionStack(state);
  5297. if (!spawn) {
  5298. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5299. return 0;
  5300. }
  5301. lua_interface->SetBooleanValue(state, spawn->following);
  5302. return 1;
  5303. }
  5304. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5305. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5306. // I will attempt to explain how this function works for future refrence
  5307. // Fist lets make sure lua_interface is valid, if not return out
  5308. if (!lua_interface)
  5309. return 0;
  5310. // Next we grab the first 2 params same as we usually would
  5311. Spawn* spawn = lua_interface->GetSpawn(state);
  5312. string var = lua_interface->GetStringValue(state, 2);
  5313. // 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
  5314. // 1 = Spawn
  5315. // 2 = Zone
  5316. // 3 = Item
  5317. // 4 = Quest
  5318. // 5 = String
  5319. // 6 = nil (null)
  5320. int8 dataType = 0;
  5321. // Define pointers for each potential type
  5322. Spawn* spawnVal = 0;
  5323. ZoneServer* zone = 0;
  5324. Item* item = 0;
  5325. Quest* quest = 0;
  5326. string val;
  5327. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5328. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5329. // options window are also light user data be we do not handle those.
  5330. // We check with lua_islightuserdata(lua_State*, index)
  5331. if (lua_islightuserdata(state, 3)) {
  5332. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5333. // and convert it to LUAUserData*
  5334. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5335. // Check to make sure the data we got is valid, if not give an error
  5336. if (!data || !data->IsCorrectlyInitialized()) {
  5337. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5338. }
  5339. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5340. else if (data->IsSpawn()) {
  5341. spawnVal = data->spawn;
  5342. dataType = 1;
  5343. }
  5344. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5345. else if (data->IsZone()) {
  5346. zone = data->zone;
  5347. dataType = 2;
  5348. }
  5349. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5350. else if (data->IsItem()) {
  5351. item = data->item;
  5352. dataType = 3;
  5353. }
  5354. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5355. else if (data->IsQuest()) {
  5356. quest = data->quest;
  5357. dataType = 4;
  5358. }
  5359. }
  5360. // Wasn't light user data, check if it is nil(null)
  5361. else if (lua_isnil(state, 3)) {
  5362. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5363. dataType = 6;
  5364. }
  5365. // Wasn't light user data or nil (null), must be a string
  5366. else {
  5367. // Set the string and dataType variable
  5368. val = lua_interface->GetStringValue(state, 3);
  5369. dataType = 5;
  5370. }
  5371. lua_interface->ResetFunctionStack(state);
  5372. // We now have all the params, lets check to make sure they are valid
  5373. if (!spawn) {
  5374. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5375. return 0;
  5376. }
  5377. if (var.length() == 0) {
  5378. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5379. return 0;
  5380. }
  5381. if (dataType == 0) {
  5382. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5383. return 0;
  5384. }
  5385. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5386. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5387. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5388. switch (dataType) {
  5389. case 1:
  5390. // 1 = Spawn
  5391. spawn->AddTempVariable(var, spawnVal);
  5392. break;
  5393. case 2:
  5394. // 2 = Zone
  5395. spawn->AddTempVariable(var, zone);
  5396. break;
  5397. case 3:
  5398. // 3 = Item
  5399. spawn->AddTempVariable(var, item);
  5400. break;
  5401. case 4:
  5402. // 4 = Quest
  5403. spawn->AddTempVariable(var, quest);
  5404. break;
  5405. case 5:
  5406. // 5 = String
  5407. spawn->AddTempVariable(var, val);
  5408. break;
  5409. case 6:
  5410. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5411. spawn->DeleteTempVariable(var);
  5412. break;
  5413. }
  5414. // And we are done so return out
  5415. return 0;
  5416. }
  5417. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5418. if (!lua_interface)
  5419. return 0;
  5420. Spawn* spawn = lua_interface->GetSpawn(state);
  5421. string var = lua_interface->GetStringValue(state, 2);
  5422. lua_interface->ResetFunctionStack(state);
  5423. if (!spawn) {
  5424. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5425. return 0;
  5426. }
  5427. if (var.length() == 0) {
  5428. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5429. return 0;
  5430. }
  5431. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5432. int8 type = spawn->GetTempVariableType(var);
  5433. Spawn* spawn2 = 0;
  5434. ZoneServer* zone = 0;
  5435. Item* item = 0;
  5436. Quest* quest = 0;
  5437. // Set the lua function return value based on the type of data the variable contains
  5438. switch (type) {
  5439. case 1:
  5440. spawn2 = spawn->GetTempVariableSpawn(var);
  5441. if (!spawn2)
  5442. return 0;
  5443. lua_interface->SetSpawnValue(state, spawn2);
  5444. break;
  5445. case 2:
  5446. zone = spawn->GetTempVariableZone(var);
  5447. if (!zone)
  5448. return 0;
  5449. lua_interface->SetZoneValue(state, zone);
  5450. break;
  5451. case 3:
  5452. item = spawn->GetTempVariableItem(var);
  5453. if (!item)
  5454. return 0;
  5455. lua_interface->SetItemValue(state, item);
  5456. break;
  5457. case 4:
  5458. quest = spawn->GetTempVariableQuest(var);
  5459. if (!quest)
  5460. return 0;
  5461. lua_interface->SetQuestValue(state, quest);
  5462. break;
  5463. case 5:
  5464. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5465. break;
  5466. default:
  5467. // Not a valid type then the variable was not set so return out
  5468. return 0;
  5469. }
  5470. // Return value was set so return out
  5471. return 1;
  5472. }
  5473. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5474. {
  5475. if (!lua_interface)
  5476. return 0;
  5477. Quest* quest = lua_interface->GetQuest(state);
  5478. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5479. string description = lua_interface->GetStringValue(state, 3);
  5480. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5481. if (!quest) {
  5482. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5483. lua_interface->ResetFunctionStack(state);
  5484. lua_interface->SetBooleanValue(state, false);
  5485. return 1;
  5486. }
  5487. if (!spawn) {
  5488. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5489. lua_interface->ResetFunctionStack(state);
  5490. lua_interface->SetBooleanValue(state, false);
  5491. return 1;
  5492. }
  5493. if (!spawn->IsPlayer()) {
  5494. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5495. lua_interface->ResetFunctionStack(state);
  5496. lua_interface->SetBooleanValue(state, false);
  5497. return 1;
  5498. }
  5499. if (item_id == 0) {
  5500. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5501. lua_interface->ResetFunctionStack(state);
  5502. lua_interface->SetBooleanValue(state, false);
  5503. return 1;
  5504. }
  5505. Client* client = ((Player*)spawn)->GetClient();
  5506. if (!client) {
  5507. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5508. lua_interface->ResetFunctionStack(state);
  5509. lua_interface->SetBooleanValue(state, false);
  5510. return 1;
  5511. }
  5512. Item* item = master_item_list.GetItem(item_id);
  5513. if (!item) {
  5514. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5515. lua_interface->ResetFunctionStack(state);
  5516. lua_interface->SetBooleanValue(state, false);
  5517. return 1;
  5518. }
  5519. Item* firstItem = new Item(item);
  5520. quest->AddTmpRewardItem(firstItem);
  5521. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5522. bool itemsAddedSuccessfully = true;
  5523. if(num_args > 4)
  5524. {
  5525. for(int8 n=5;n<num_args+1;n++)
  5526. {
  5527. int32 new_item = lua_interface->GetInt32Value(state, n);
  5528. Item* tmpItem = master_item_list.GetItem(new_item);
  5529. if(tmpItem)
  5530. {
  5531. Item* newTmpItem = new Item(tmpItem);
  5532. quest->AddTmpRewardItem(newTmpItem);
  5533. }
  5534. else
  5535. itemsAddedSuccessfully = false;
  5536. }
  5537. }
  5538. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5539. lua_interface->ResetFunctionStack(state);
  5540. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5541. return 1;
  5542. }
  5543. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5544. if (!lua_interface)
  5545. return 0;
  5546. Quest* quest = lua_interface->GetQuest(state);
  5547. lua_interface->ResetFunctionStack(state);
  5548. if (!quest) {
  5549. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5550. return 0;
  5551. }
  5552. quest->SetRepeatable(true);
  5553. return 0;
  5554. }
  5555. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5556. if (!lua_interface)
  5557. return 0;
  5558. Spawn* spawn = lua_interface->GetSpawn(state);
  5559. lua_interface->ResetFunctionStack(state);
  5560. if (!spawn) {
  5561. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5562. return 0;
  5563. }
  5564. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5565. string ret = classes.GetClassNameCase(base_class);
  5566. if (ret.length() > 0) {
  5567. lua_interface->SetStringValue(state, ret.c_str());
  5568. return 1;
  5569. }
  5570. return 0;
  5571. }
  5572. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5573. if (!lua_interface)
  5574. return 0;
  5575. Spawn* player = lua_interface->GetSpawn(state);
  5576. lua_interface->ResetFunctionStack(state);
  5577. if (player && player->IsPlayer()) {
  5578. Client* client = player->GetClient();
  5579. if (client)
  5580. client->SendWaypoints();
  5581. }
  5582. return 0;
  5583. }
  5584. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5585. if (!lua_interface)
  5586. return 0;
  5587. Spawn* player = lua_interface->GetSpawn(state);
  5588. string name = lua_interface->GetStringValue(state, 2);
  5589. int32 type = lua_interface->GetInt32Value(state, 3);
  5590. lua_interface->ResetFunctionStack(state);
  5591. if (type == 0)
  5592. type = 2;
  5593. if (name.length() > 0) {
  5594. if (player && player->IsPlayer()) {
  5595. Client* client = player->GetClient();
  5596. if (client)
  5597. client->AddWaypoint(name, type);
  5598. }
  5599. }
  5600. return 0;
  5601. }
  5602. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5603. if (!lua_interface)
  5604. return 0;
  5605. Spawn* player = lua_interface->GetSpawn(state);
  5606. string name = lua_interface->GetStringValue(state, 2);
  5607. lua_interface->ResetFunctionStack(state);
  5608. if (name.length() > 0) {
  5609. if (player && player->IsPlayer()) {
  5610. Client* client = player->GetClient();
  5611. if (client)
  5612. client->RemoveWaypoint(name);
  5613. }
  5614. }
  5615. return 0;
  5616. }
  5617. int EQ2Emu_lua_AddWard(lua_State* state) {
  5618. if (!lua_interface)
  5619. return 0;
  5620. int32 damage = lua_interface->GetInt32Value(state);
  5621. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5622. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5623. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5624. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5625. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5626. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5627. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5628. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5629. lua_interface->ResetFunctionStack(state);
  5630. if(!spell || spell->resisted) {
  5631. return 0;
  5632. }
  5633. bool ward_was_added = false;
  5634. ZoneServer* zone = spell->caster->GetZone();
  5635. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5636. for (int32 i = 0; i < spell->targets.size(); i++) {
  5637. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5638. if (!target)
  5639. continue;
  5640. if (target->IsEntity()) {
  5641. // If the ward is already active remove it
  5642. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5643. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5644. // Create new ward info
  5645. WardInfo* ward = new WardInfo;
  5646. ward->Spell = spell;
  5647. ward->BaseDamage = damage;
  5648. ward->DamageLeft = damage;
  5649. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5650. ward->keepWard = keepWard;
  5651. ward->WardType = wardType;
  5652. if (damageAbsorptionPercent > 100)
  5653. damageAbsorptionPercent = 100;
  5654. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5655. if (damageAbsorptionMaxHealthPercent > 100)
  5656. damageAbsorptionMaxHealthPercent = 100;
  5657. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5658. ward->RedirectDamagePercent = redirectDamagePercent;
  5659. ward->LastRedirectDamage = 0;
  5660. ward->LastAbsorbedDamage = 0;
  5661. ward->HitCount = 0;
  5662. spell->num_triggers = maxHitCount;
  5663. spell->had_triggers = true;
  5664. spell->cancel_after_all_triggers = false;
  5665. ward->MaxHitCount = maxHitCount;
  5666. if (wardType == WARD_TYPE_MAGICAL)
  5667. ward->DamageType = damageTypes;
  5668. // Add the ward to the entity
  5669. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5670. ward_was_added = true;
  5671. }
  5672. }
  5673. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5674. if (ward_was_added && spell->caster->IsPlayer()) {
  5675. spell->had_dmg_remaining = true;
  5676. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5677. }
  5678. return 0;
  5679. }
  5680. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5681. if (!lua_interface)
  5682. return 0;
  5683. int32 amount = lua_interface->GetInt32Value(state);
  5684. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5685. lua_interface->ResetFunctionStack(state);
  5686. WardInfo* ward = 0;
  5687. if(!spell || spell->resisted) {
  5688. return 0;
  5689. }
  5690. ZoneServer* zone = spell->caster->GetZone();
  5691. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5692. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5693. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5694. ward = target->GetWard(spell->spell->GetSpellID());
  5695. if (target && ward) {
  5696. ward->DamageLeft += amount;
  5697. if (ward->DamageLeft > ward->BaseDamage)
  5698. ward->DamageLeft = ward->BaseDamage;
  5699. for (int32 i = 0; i < spell->targets.size(); i++) {
  5700. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5701. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5702. }
  5703. }
  5704. }
  5705. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5706. if (ward && spell->caster->IsPlayer())
  5707. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5708. return 0;
  5709. }
  5710. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5711. if (!lua_interface)
  5712. return 0;
  5713. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5714. lua_interface->ResetFunctionStack(state);
  5715. if (!spell) {
  5716. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5717. return 0;
  5718. }
  5719. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5720. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5721. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5722. if (ward) {
  5723. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5724. return 1;
  5725. }
  5726. }
  5727. return 0;
  5728. }
  5729. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5730. if (!lua_interface)
  5731. return 0;
  5732. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5733. if (!spell) {
  5734. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5735. lua_interface->ResetFunctionStack(state);
  5736. return 0;
  5737. }
  5738. string type = lua_interface->GetStringValue(state, 2);
  5739. lua_interface->ResetFunctionStack(state);
  5740. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5741. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5742. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5743. if (ward) {
  5744. if (boost::iequals(type, "damageleft"))
  5745. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5746. else if (boost::iequals(type, "basedamage"))
  5747. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5748. else if (boost::iequals(type, "keepward"))
  5749. lua_interface->SetBooleanValue(state, ward->keepWard);
  5750. else if (boost::iequals(type, "wardtype"))
  5751. lua_interface->SetInt32Value(state, ward->WardType);
  5752. else if (boost::iequals(type, "dmgabsorptionpct"))
  5753. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5754. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5755. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5756. else if (boost::iequals(type, "redirectdamagepercent"))
  5757. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5758. else if (boost::iequals(type, "lastredirectdamage"))
  5759. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5760. else if (boost::iequals(type, "lastabsorbeddamage"))
  5761. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5762. else if (boost::iequals(type, "hitcount"))
  5763. lua_interface->SetInt32Value(state, ward->HitCount);
  5764. else if (boost::iequals(type, "maxhitcount"))
  5765. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5766. else
  5767. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5768. return 1;
  5769. }
  5770. }
  5771. return 0;
  5772. }
  5773. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5774. if (!lua_interface)
  5775. return 0;
  5776. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5777. lua_interface->ResetFunctionStack(state);
  5778. if(!spell) {
  5779. return 0;
  5780. }
  5781. ZoneServer* zone = spell->caster->GetZone();
  5782. Spawn* target = 0;
  5783. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5784. for (int32 i = 0; i < spell->targets.size(); i++) {
  5785. target = zone->GetSpawnByID(spell->targets.at(i));
  5786. if (target && target->IsEntity()) {
  5787. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5788. }
  5789. }
  5790. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5791. return 0;
  5792. }
  5793. int EQ2Emu_lua_Interrupt(lua_State* state)
  5794. {
  5795. if (!lua_interface)
  5796. return 0;
  5797. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5798. Spawn* target = lua_interface->GetSpawn(state, 2);
  5799. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5800. lua_interface->ResetFunctionStack(state);
  5801. if (!caster)
  5802. {
  5803. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5804. return 0;
  5805. }
  5806. if (!target)
  5807. {
  5808. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5809. return 0;
  5810. }
  5811. if (!spell) {
  5812. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5813. return 0;
  5814. }
  5815. if (!target->IsEntity() && !spell)
  5816. {
  5817. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. if (!target && spell) {
  5821. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5822. for (int8 i = 0; i < spell->targets.size(); i++) {
  5823. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5824. if (!target || !target->IsEntity())
  5825. continue;
  5826. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5827. }
  5828. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5829. }
  5830. else
  5831. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5832. return 0;
  5833. }
  5834. int EQ2Emu_lua_Stealth(lua_State* state) {
  5835. if (!lua_interface)
  5836. return 0;
  5837. int8 type = lua_interface->GetInt8Value(state);
  5838. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5839. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5840. lua_interface->ResetFunctionStack(state);
  5841. if (!spell) {
  5842. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5843. return 0;
  5844. }
  5845. ZoneServer* zone = spell->caster->GetZone();
  5846. if (spawn) {
  5847. if (spawn->IsEntity()) {
  5848. if (type == 1) {
  5849. ((Entity*)spawn)->AddStealthSpell(spell);
  5850. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5851. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5852. }
  5853. else if (type == 2) {
  5854. ((Entity*)spawn)->AddInvisSpell(spell);
  5855. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5856. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5857. }
  5858. return 0;
  5859. }
  5860. else {
  5861. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5862. return 0;
  5863. }
  5864. }
  5865. else {
  5866. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5867. for (int32 i = 0; i < spell->targets.size(); i++) {
  5868. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5869. if (!spawn || !spawn->IsEntity())
  5870. continue;
  5871. if (type == 1) {
  5872. ((Entity*)spawn)->AddStealthSpell(spell);
  5873. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5874. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5875. }
  5876. else if (type == 2) {
  5877. ((Entity*)spawn)->AddInvisSpell(spell);
  5878. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5879. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5880. }
  5881. else {
  5882. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5883. break;
  5884. }
  5885. }
  5886. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5887. }
  5888. return 0;
  5889. }
  5890. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5891. if (!lua_interface)
  5892. return 0;
  5893. Spawn* spawn = lua_interface->GetSpawn(state);
  5894. lua_interface->ResetFunctionStack(state);
  5895. if (!spawn) {
  5896. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5897. return 0;
  5898. }
  5899. if (spawn->IsEntity()) {
  5900. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5901. return 1;
  5902. }
  5903. else
  5904. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5905. return 0;
  5906. }
  5907. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5908. if (!lua_interface)
  5909. return 0;
  5910. Spawn* spawn = lua_interface->GetSpawn(state);
  5911. lua_interface->ResetFunctionStack(state);
  5912. if (!spawn) {
  5913. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5914. return 0;
  5915. }
  5916. if (spawn->IsEntity()) {
  5917. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5918. return 1;
  5919. }
  5920. else
  5921. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5922. return 0;
  5923. }
  5924. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5925. if (!lua_interface)
  5926. return 0;
  5927. Spawn* player = lua_interface->GetSpawn(state);
  5928. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5929. lua_interface->ResetFunctionStack(state);
  5930. if (!player->IsPlayer()) {
  5931. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5932. return 0;
  5933. }
  5934. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5935. return 1;
  5936. }
  5937. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5938. if (!lua_interface)
  5939. return 0;
  5940. Spawn* player = lua_interface->GetSpawn(state);
  5941. int8 slot = lua_interface->GetInt8Value(state, 2);
  5942. lua_interface->ResetFunctionStack(state);
  5943. if (!player) {
  5944. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5945. return 0;
  5946. }
  5947. if (!player->IsPlayer()) {
  5948. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5952. if (!item) {
  5953. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5954. return 0;
  5955. }
  5956. lua_interface->SetItemValue(state, item);
  5957. return 1;
  5958. }
  5959. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5960. if (!lua_interface)
  5961. return 0;
  5962. Spawn* player = lua_interface->GetSpawn(state);
  5963. int32 id = lua_interface->GetInt32Value(state, 2);
  5964. lua_interface->ResetFunctionStack(state);
  5965. if (!player) {
  5966. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5967. return 0;
  5968. }
  5969. if (!player->IsPlayer()) {
  5970. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5971. return 0;
  5972. }
  5973. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5974. if (!item) {
  5975. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5976. return 0;
  5977. }
  5978. lua_interface->SetItemValue(state, item);
  5979. return 1;
  5980. }
  5981. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5982. if (!lua_interface)
  5983. return 0;
  5984. Spawn* spawn = lua_interface->GetSpawn(state);
  5985. int8 slot = lua_interface->GetInt8Value(state, 2);
  5986. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5987. lua_interface->ResetFunctionStack(state);
  5988. if (!spawn) {
  5989. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5990. return 0;
  5991. }
  5992. if (!spawn->IsEntity()) {
  5993. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5994. return 0;
  5995. }
  5996. Item* item = master_item_list.GetItem(item_id);
  5997. if (!item) {
  5998. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. Item* copy = new Item(item);
  6002. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6003. if(result)
  6004. {
  6005. ((Entity*)spawn)->SetEquipment(copy, slot);
  6006. spawn->vis_changed = true;
  6007. if(spawn->IsPlayer())
  6008. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6009. }
  6010. else
  6011. {
  6012. safe_delete(copy);
  6013. }
  6014. lua_interface->SetBooleanValue(state, result);
  6015. return 1;
  6016. }
  6017. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6018. if (!lua_interface)
  6019. return 0;
  6020. Spawn* spawn = lua_interface->GetSpawn(state);
  6021. int8 slot = lua_interface->GetInt8Value(state, 2);
  6022. Item* item = lua_interface->GetItem(state, 3);
  6023. lua_interface->ResetFunctionStack(state);
  6024. if (!spawn) {
  6025. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6026. return 0;
  6027. }
  6028. if (!spawn->IsEntity()) {
  6029. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6030. return 0;
  6031. }
  6032. if (!item) {
  6033. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6034. return 0;
  6035. }
  6036. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6037. if(result)
  6038. {
  6039. ((Entity*)spawn)->SetEquipment(item, slot);
  6040. spawn->vis_changed = true;
  6041. if(spawn->IsPlayer())
  6042. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6043. }
  6044. lua_interface->SetBooleanValue(state, result);
  6045. return 1;
  6046. }
  6047. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6048. if (!lua_interface)
  6049. return 0;
  6050. Spawn* spawn = lua_interface->GetSpawn(state);
  6051. int8 slot = lua_interface->GetInt8Value(state, 2);
  6052. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6053. lua_interface->ResetFunctionStack(state);
  6054. if (!spawn) {
  6055. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6056. return 0;
  6057. }
  6058. if (!spawn->IsEntity()) {
  6059. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6060. return 0;
  6061. }
  6062. if(slot >= NUM_SLOTS) {
  6063. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6064. return 0;
  6065. }
  6066. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6067. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6068. if(item) {
  6069. item->save_needed = true;
  6070. if(no_delete_item) {
  6071. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6072. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6073. }
  6074. else{
  6075. Client* client = ((Player*)spawn)->GetClient();
  6076. client->UnequipItem(item->details.index);
  6077. }
  6078. }
  6079. }
  6080. else
  6081. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6082. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6083. spawn->vis_changed = true;
  6084. if(spawn->IsPlayer())
  6085. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6086. lua_interface->SetBooleanValue(state, true);
  6087. return 1;
  6088. }
  6089. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6090. if (!lua_interface)
  6091. return 0;
  6092. Spawn* spawn = lua_interface->GetSpawn(state);
  6093. int8 slot = lua_interface->GetInt8Value(state, 2);
  6094. int16 type = lua_interface->GetInt16Value(state, 3);
  6095. int8 r = lua_interface->GetInt8Value(state, 4);
  6096. int8 g = lua_interface->GetInt8Value(state, 5);
  6097. int8 b = lua_interface->GetInt8Value(state, 6);
  6098. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6099. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6100. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6101. lua_interface->ResetFunctionStack(state);
  6102. if (!spawn) {
  6103. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6104. return 0;
  6105. }
  6106. if (!spawn->IsEntity()) {
  6107. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6108. return 0;
  6109. }
  6110. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6111. spawn->vis_changed = true;
  6112. lua_interface->SetBooleanValue(state, true);
  6113. return 1;
  6114. }
  6115. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6116. if (!lua_interface)
  6117. return 0;
  6118. Spawn* player = lua_interface->GetSpawn(state);
  6119. int32 id = lua_interface->GetInt32Value(state, 2);
  6120. int8 count = lua_interface->GetInt8Value(state, 3);
  6121. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6122. lua_interface->ResetFunctionStack(state);
  6123. if (!player) {
  6124. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6125. return 0;
  6126. }
  6127. if (!player->IsPlayer()) {
  6128. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6129. return 0;
  6130. }
  6131. if (!count)
  6132. count = 1;
  6133. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6134. if (!item) {
  6135. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. lua_interface->SetItemValue(state, item);
  6139. return 1;
  6140. }
  6141. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6142. if (!lua_interface)
  6143. return 0;
  6144. Spawn* spawn = lua_interface->GetSpawn(state);
  6145. int32 anim = lua_interface->GetInt32Value(state, 2);
  6146. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6147. int8 type = lua_interface->GetInt8Value(state, 4);
  6148. lua_interface->ResetFunctionStack(state);
  6149. if (!spawn) {
  6150. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6151. return 0;
  6152. }
  6153. if (spawn2) {
  6154. if (spawn2->IsPlayer()) {
  6155. if (type != 1 && type != 2)
  6156. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6157. else
  6158. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6159. return 0;
  6160. }
  6161. else {
  6162. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6163. return 0;
  6164. }
  6165. }
  6166. else
  6167. spawn->GetZone()->PlayAnimation(spawn, anim);
  6168. return 0;
  6169. }
  6170. int EQ2Emu_lua_IsPet(lua_State* state) {
  6171. if (!lua_interface)
  6172. return 0;
  6173. Spawn* spawn = lua_interface->GetSpawn(state);
  6174. lua_interface->ResetFunctionStack(state);
  6175. if (!spawn) {
  6176. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6177. return 0;
  6178. }
  6179. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6180. return 1;
  6181. }
  6182. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6183. if (!lua_interface)
  6184. return 0;
  6185. Spawn* spawn = lua_interface->GetSpawn(state);
  6186. lua_interface->ResetFunctionStack(state);
  6187. if (!spawn) {
  6188. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6189. return 0;
  6190. }
  6191. if (!spawn->IsNPC()) {
  6192. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6193. return 0;
  6194. }
  6195. if (((NPC*)spawn)->GetOwner()) {
  6196. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6197. return 1;
  6198. }
  6199. return 0;
  6200. }
  6201. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6202. if (!lua_interface)
  6203. return 0;
  6204. Spawn* spawn = lua_interface->GetSpawn(state);
  6205. Spawn* target = lua_interface->GetSpawn(state, 2);
  6206. lua_interface->ResetFunctionStack(state);
  6207. if (!spawn) {
  6208. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6209. return 0;
  6210. }
  6211. if (!spawn) {
  6212. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6213. return 0;
  6214. }
  6215. spawn->SetTarget(target);
  6216. return 0;
  6217. }
  6218. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6219. if (!lua_interface)
  6220. return 0;
  6221. Spawn* spawn = lua_interface->GetSpawn(state);
  6222. bool val = lua_interface->GetBooleanValue(state, 2);
  6223. lua_interface->ResetFunctionStack(state);
  6224. if (!spawn) {
  6225. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. if (!spawn->IsEntity()) {
  6229. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6230. return 0;
  6231. }
  6232. ((Entity*)spawn)->InCombat(val);
  6233. if (val) {
  6234. spawn->ClearRunningLocations();
  6235. spawn->CalculateRunningLocation(true);
  6236. }
  6237. return 0;
  6238. }
  6239. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6240. if (!lua_interface)
  6241. return 0;
  6242. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6243. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6244. lua_interface->ResetFunctionStack(state);
  6245. if (!spawn1) {
  6246. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6247. return 0;
  6248. }
  6249. if (!spawn2) {
  6250. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6251. return 0;
  6252. }
  6253. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6254. return 1;
  6255. }
  6256. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6257. if (!lua_interface)
  6258. return 0;
  6259. Spawn* spawn = lua_interface->GetSpawn(state);
  6260. lua_interface->ResetFunctionStack(state);
  6261. if (!spawn) {
  6262. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6263. return 0;
  6264. }
  6265. if (!spawn->IsNPC()) {
  6266. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6267. return 0;
  6268. }
  6269. ((NPC*)spawn)->ClearRunback();
  6270. return 0;
  6271. }
  6272. int EQ2Emu_lua_Runback(lua_State* state) {
  6273. if (!lua_interface)
  6274. return 0;
  6275. Spawn* spawn = lua_interface->GetSpawn(state);
  6276. lua_interface->ResetFunctionStack(state);
  6277. if (!spawn) {
  6278. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6279. return 0;
  6280. }
  6281. if (!spawn->IsNPC()) {
  6282. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6283. return 0;
  6284. }
  6285. ((NPC*)spawn)->Runback();
  6286. return 0;
  6287. }
  6288. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6289. if (!lua_interface)
  6290. return 0;
  6291. Spawn* spawn = lua_interface->GetSpawn(state);
  6292. lua_interface->ResetFunctionStack(state);
  6293. if (!spawn) {
  6294. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6295. return 0;
  6296. }
  6297. if (!spawn->IsNPC()) {
  6298. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6299. return 0;
  6300. }
  6301. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6302. return 1;
  6303. }
  6304. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6305. if (!lua_interface)
  6306. return 0;
  6307. Spawn* spawn = lua_interface->GetSpawn(state);
  6308. lua_interface->ResetFunctionStack(state);
  6309. if (!spawn) {
  6310. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6311. return 0;
  6312. }
  6313. if (!spawn->IsEntity()) {
  6314. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6315. return 0;
  6316. }
  6317. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6318. return 1;
  6319. }
  6320. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6321. if (!lua_interface)
  6322. return 0;
  6323. Spawn* spawn = lua_interface->GetSpawn(state);
  6324. lua_interface->ResetFunctionStack(state);
  6325. if (!spawn) {
  6326. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6327. return 0;
  6328. }
  6329. if (!spawn->IsEntity()) {
  6330. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6331. return 0;
  6332. }
  6333. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6334. return 1;
  6335. }
  6336. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6337. if (!lua_interface)
  6338. return 0;
  6339. Spawn* spawn = lua_interface->GetSpawn(state);
  6340. lua_interface->ResetFunctionStack(state);
  6341. if (!spawn) {
  6342. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6343. return 0;
  6344. }
  6345. if (!spawn->IsEntity()) {
  6346. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6347. return 0;
  6348. }
  6349. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6350. return 1;
  6351. }
  6352. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6353. if (!lua_interface)
  6354. return 0;
  6355. Spawn* spawn = lua_interface->GetSpawn(state);
  6356. lua_interface->ResetFunctionStack(state);
  6357. if (!spawn) {
  6358. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6359. return 0;
  6360. }
  6361. if (!spawn->IsEntity()) {
  6362. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6363. return 0;
  6364. }
  6365. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6366. return 1;
  6367. }
  6368. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6369. if (!lua_interface)
  6370. return 0;
  6371. Spawn* spawn = lua_interface->GetSpawn(state);
  6372. Spawn* target = lua_interface->GetSpawn(state, 2);
  6373. float distance = lua_interface->GetFloatValue(state, 3);
  6374. lua_interface->ResetFunctionStack(state);
  6375. if (!spawn) {
  6376. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6377. return 0;
  6378. }
  6379. if (!target) {
  6380. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6381. return 0;
  6382. }
  6383. if (!spawn->IsNPC()) {
  6384. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6385. return 0;
  6386. }
  6387. if (!target->IsEntity()) {
  6388. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6392. return 1;
  6393. }
  6394. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6395. if (!lua_interface)
  6396. return 0;
  6397. Spawn* spawn = lua_interface->GetSpawn(state);
  6398. Spawn* target = lua_interface->GetSpawn(state, 2);
  6399. float distance = lua_interface->GetFloatValue(state, 3);
  6400. lua_interface->ResetFunctionStack(state);
  6401. if (!spawn) {
  6402. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6403. return 0;
  6404. }
  6405. if (!target) {
  6406. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6407. return 0;
  6408. }
  6409. if (!spawn->IsNPC()) {
  6410. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6411. return 0;
  6412. }
  6413. if (!target->IsEntity()) {
  6414. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6415. return 0;
  6416. }
  6417. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6418. return 0;
  6419. }
  6420. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6421. if (!lua_interface)
  6422. return 0;
  6423. Spawn* spawn = lua_interface->GetSpawn(state);
  6424. lua_interface->ResetFunctionStack(state);
  6425. if (!spawn) {
  6426. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6427. return 0;
  6428. }
  6429. if (!spawn->IsNPC()) {
  6430. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6431. return 0;
  6432. }
  6433. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6434. return 1;
  6435. }
  6436. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6437. if (!lua_interface)
  6438. return 0;
  6439. Spawn* spawn = lua_interface->GetSpawn(state);
  6440. lua_interface->ResetFunctionStack(state);
  6441. if (!spawn) {
  6442. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6443. return 0;
  6444. }
  6445. if (!spawn->IsNPC()) {
  6446. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6447. return 0;
  6448. }
  6449. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6450. return 1;
  6451. }
  6452. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6453. if (!lua_interface)
  6454. return 0;
  6455. Spawn* spawn = lua_interface->GetSpawn(state);
  6456. lua_interface->ResetFunctionStack(state);
  6457. if (!spawn) {
  6458. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6459. return 0;
  6460. }
  6461. if (!spawn->IsNPC()) {
  6462. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6463. return 0;
  6464. }
  6465. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6466. if (hated) {
  6467. lua_interface->SetSpawnValue(state, hated);
  6468. return 1;
  6469. }
  6470. return 0;
  6471. }
  6472. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6473. if (!lua_interface)
  6474. return 0;
  6475. Spawn* spawn = lua_interface->GetSpawn(state);
  6476. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6477. lua_interface->ResetFunctionStack(state);
  6478. if (!spawn) {
  6479. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6480. return 0;
  6481. }
  6482. if (!spawn->IsNPC()) {
  6483. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6484. return 0;
  6485. }
  6486. if (!hated) {
  6487. ((NPC*)spawn)->Brain()->ClearHate();
  6488. return 0;
  6489. }
  6490. else
  6491. {
  6492. if (!hated->IsEntity()) {
  6493. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6494. return 0;
  6495. }
  6496. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6497. return 0;
  6498. }
  6499. return 0;
  6500. }
  6501. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6502. if (!lua_interface)
  6503. return 0;
  6504. Spawn* spawn = lua_interface->GetSpawn(state);
  6505. lua_interface->ResetFunctionStack(state);
  6506. if (!spawn) {
  6507. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6508. return 0;
  6509. }
  6510. if (!spawn->IsNPC()) {
  6511. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6512. return 0;
  6513. }
  6514. ((NPC*)spawn)->Brain()->ClearEncounter();
  6515. return 0;
  6516. }
  6517. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6518. if (!lua_interface)
  6519. return 0;
  6520. Spawn* spawn = lua_interface->GetSpawn(state);
  6521. lua_interface->ResetFunctionStack(state);
  6522. if (!spawn) {
  6523. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6524. return 0;
  6525. }
  6526. if (!spawn->IsNPC()) {
  6527. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6528. return 0;
  6529. }
  6530. // Temp list to store hate list
  6531. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6532. if (encounterList->size() == 0) {
  6533. safe_delete(encounterList);
  6534. return 0;
  6535. }
  6536. lua_createtable(state, encounterList->size(), 0);
  6537. int newTable = lua_gettop(state);
  6538. for (int32 i = 0; i < encounterList->size(); i++) {
  6539. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6540. if (temp)
  6541. lua_interface->SetSpawnValue(state, temp);
  6542. lua_rawseti(state, newTable, i + 1);
  6543. }
  6544. safe_delete(encounterList);
  6545. return 1;
  6546. }
  6547. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6548. if (!lua_interface)
  6549. return 0;
  6550. Spawn* spawn = lua_interface->GetSpawn(state);
  6551. lua_interface->ResetFunctionStack(state);
  6552. if (!spawn) {
  6553. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. if (!spawn->IsNPC()) {
  6557. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6558. return 0;
  6559. }
  6560. // Temp list to store hate list
  6561. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6562. if (hateList->size() == 0) {
  6563. safe_delete(hateList);
  6564. return 0;
  6565. }
  6566. lua_createtable(state, hateList->size(), 0);
  6567. int newTable = lua_gettop(state);
  6568. for (int32 i = 0; i < hateList->size(); i++) {
  6569. lua_interface->SetSpawnValue(state, hateList->at(i));
  6570. lua_rawseti(state, newTable, i + 1);
  6571. }
  6572. safe_delete(hateList);
  6573. return 1;
  6574. }
  6575. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6576. if (!lua_interface)
  6577. return 0;
  6578. Spawn* spawn = lua_interface->GetSpawn(state);
  6579. lua_interface->ResetFunctionStack(state);
  6580. if (!spawn) {
  6581. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6582. return 0;
  6583. }
  6584. if (spawn->IsPlayer()) {
  6585. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6586. lua_interface->SetBooleanValue(state, true);
  6587. else
  6588. lua_interface->SetBooleanValue(state, false);
  6589. return 1;
  6590. }
  6591. else {
  6592. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6593. return 1;
  6594. }
  6595. }
  6596. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6597. if (!lua_interface)
  6598. return 0;
  6599. Quest* quest = lua_interface->GetQuest(state);
  6600. lua_interface->ResetFunctionStack(state);
  6601. if (!quest) {
  6602. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6603. return 0;
  6604. }
  6605. quest->SetCompletedFlag(true);
  6606. return 0;
  6607. }
  6608. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6609. if (!lua_interface)
  6610. return 0;
  6611. Spawn* spawn = lua_interface->GetSpawn(state);
  6612. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6613. int8 tier = lua_interface->GetInt8Value(state, 3);
  6614. lua_interface->ResetFunctionStack(state);
  6615. if (!spawn) {
  6616. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6617. return 0;
  6618. }
  6619. if (!spawn->IsEntity()) {
  6620. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6621. return 0;
  6622. }
  6623. if (spellID == 0) {
  6624. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6625. return 0;
  6626. }
  6627. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6628. if (effect) {
  6629. if (tier > 0) {
  6630. // If a tier was passed chec to see if it is the same as the effect
  6631. if (tier == effect->tier)
  6632. lua_interface->SetBooleanValue(state, true);
  6633. else
  6634. lua_interface->SetBooleanValue(state, false);
  6635. return 1;
  6636. }
  6637. else {
  6638. // Have an effect but no tier was passed so return true
  6639. lua_interface->SetBooleanValue(state, true);
  6640. }
  6641. return 1;
  6642. }
  6643. // no effect so return false
  6644. lua_interface->SetBooleanValue(state, false);
  6645. return 1;
  6646. }
  6647. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6648. if (!lua_interface)
  6649. return 0;
  6650. Spawn* spawn = lua_interface->GetSpawn(state);
  6651. int32 id = lua_interface->GetInt32Value(state, 2);
  6652. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6653. lua_interface->ResetFunctionStack(state);
  6654. Spawn* spawn2 = 0;
  6655. vector<Spawn*> list;
  6656. if (!spawn) {
  6657. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6658. return 0;
  6659. }
  6660. //If zone not provided, use spawn's zone
  6661. if (!zone)
  6662. zone = spawn->GetZone();
  6663. list = zone->GetSpawnsByID(id);
  6664. if (list.size() == 0) {
  6665. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6666. return 0;
  6667. }
  6668. vector<Spawn*>::iterator itr = list.begin();
  6669. for (int8 i = 0; i < list.size(); i++) {
  6670. spawn2 = itr[i];
  6671. if (spawn2)
  6672. spawn2->AddAllowAccessSpawn(spawn);
  6673. }
  6674. return 0;
  6675. }
  6676. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6677. if (!lua_interface)
  6678. return 0;
  6679. Spawn* spawn = lua_interface->GetSpawn(state);
  6680. int32 id = lua_interface->GetInt32Value(state, 2);
  6681. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6682. lua_interface->ResetFunctionStack(state);
  6683. Spawn* spawn2 = 0;
  6684. if (!spawn) {
  6685. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6686. return 0;
  6687. }
  6688. //If zone not provided, use spawn's zone
  6689. if (!zone)
  6690. zone = spawn->GetZone();
  6691. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6692. vector<Spawn*>::iterator itr = list.begin();
  6693. if (list.size() == 0) {
  6694. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6695. return 0;
  6696. }
  6697. for (int8 i = 0; i < list.size(); i++) {
  6698. spawn2 = itr[i];
  6699. if (spawn2)
  6700. spawn2->RemoveSpawnAccess(spawn);
  6701. }
  6702. return 0;
  6703. }
  6704. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6705. if (!lua_interface)
  6706. return 0;
  6707. Quest* quest = lua_interface->GetQuest(state);
  6708. lua_interface->ResetFunctionStack(state);
  6709. if (!quest) {
  6710. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6711. return 0;
  6712. }
  6713. quest->SetYellowName(true);
  6714. return 0;
  6715. }
  6716. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6717. if (!lua_interface)
  6718. return 0;
  6719. Spawn* spawn = lua_interface->GetSpawn(state);
  6720. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6721. lua_interface->ResetFunctionStack(state);
  6722. if (!spawn) {
  6723. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6724. return 0;
  6725. }
  6726. if (!spawn->IsPlayer()) {
  6727. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6728. return 0;
  6729. }
  6730. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6731. return 1;
  6732. }
  6733. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6734. if (!lua_interface)
  6735. return 0;
  6736. Spawn* spawn = lua_interface->GetSpawn(state);
  6737. lua_interface->ResetFunctionStack(state);
  6738. if (!spawn) {
  6739. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6740. return 0;
  6741. }
  6742. if (!spawn->IsPlayer()) {
  6743. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6744. return 0;
  6745. }
  6746. ZoneServer* zone = spawn->GetZone();
  6747. if (!zone) {
  6748. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6749. return 0;
  6750. }
  6751. Instance_Type iType = zone->GetInstanceType();
  6752. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6753. iType == GROUP_LOCKOUT_INSTANCE ||
  6754. iType == RAID_LOCKOUT_INSTANCE ||
  6755. iType == SOLO_PERSIST_INSTANCE ||
  6756. iType == GROUP_PERSIST_INSTANCE ||
  6757. iType == RAID_PERSIST_INSTANCE) {
  6758. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6759. if (data) {
  6760. // Check to see if the timer has already been set, if it has return out.
  6761. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6762. return 0;
  6763. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6764. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6765. if(spawn->IsPlayer()) {
  6766. Client* client = ((Player*)spawn)->GetClient();
  6767. if (client) {
  6768. string time_msg = "";
  6769. int32 time = data->success_lockout_time;
  6770. int16 hour;
  6771. int8 min;
  6772. int8 sec;
  6773. hour = time / 3600;
  6774. time = time % 3600;
  6775. min = time / 60;
  6776. time = time % 60;
  6777. sec = time;
  6778. if (hour > 0) {
  6779. char temp[10];
  6780. sprintf(temp, " %i", hour);
  6781. time_msg.append(temp);
  6782. time_msg.append(" hour");
  6783. time_msg.append((hour > 1) ? "s" : "");
  6784. }
  6785. if (min > 0) {
  6786. char temp[5];
  6787. sprintf(temp, " %i", min);
  6788. time_msg.append(temp);
  6789. time_msg.append(" minute");
  6790. time_msg.append((min > 1) ? "s" : "");
  6791. }
  6792. // Only add seconds if minutes and hours are 0
  6793. if (hour == 0 && min == 0 && sec > 0) {
  6794. char temp[5];
  6795. sprintf(temp, " %i", sec);
  6796. time_msg.append(temp);
  6797. time_msg.append(" second");
  6798. time_msg.append((sec > 1) ? "s" : "");
  6799. }
  6800. 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());
  6801. }
  6802. else {
  6803. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6804. }
  6805. }
  6806. }
  6807. else
  6808. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6809. }
  6810. else
  6811. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6812. return 0;
  6813. }
  6814. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6815. if (!lua_interface)
  6816. return 0;
  6817. Spawn* spawn = lua_interface->GetSpawn(state);
  6818. lua_interface->ResetFunctionStack(state);
  6819. if (!spawn) {
  6820. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6821. return 0;
  6822. }
  6823. if (!spawn->IsPlayer()) {
  6824. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6825. return 0;
  6826. }
  6827. ZoneServer* zone = spawn->GetZone();
  6828. if (!zone) {
  6829. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6830. return 0;
  6831. }
  6832. Instance_Type iType = zone->GetInstanceType();
  6833. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6834. iType == GROUP_LOCKOUT_INSTANCE ||
  6835. iType == RAID_LOCKOUT_INSTANCE ||
  6836. iType == SOLO_PERSIST_INSTANCE ||
  6837. iType == GROUP_PERSIST_INSTANCE ||
  6838. iType == RAID_PERSIST_INSTANCE) {
  6839. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6840. if (data) {
  6841. // Check to see if the timer has already been set, if it has return out.
  6842. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6843. return 0;
  6844. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6845. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6846. if(spawn->IsPlayer()) {
  6847. Client* client = ((Player*)spawn)->GetClient();
  6848. if (client) {
  6849. string time_msg = "";
  6850. int32 time = data->failure_lockout_time;
  6851. int16 hour;
  6852. int8 min;
  6853. int8 sec;
  6854. hour = time / 3600;
  6855. time = time % 3600;
  6856. min = time / 60;
  6857. time = time % 60;
  6858. sec = time;
  6859. if (hour > 0) {
  6860. char temp[10];
  6861. sprintf(temp, " %i", hour);
  6862. time_msg.append(temp);
  6863. time_msg.append(" hour");
  6864. time_msg.append((hour > 1) ? "s" : "");
  6865. }
  6866. if (min > 0) {
  6867. char temp[5];
  6868. sprintf(temp, " %i", min);
  6869. time_msg.append(temp);
  6870. time_msg.append(" minute");
  6871. time_msg.append((min > 1) ? "s" : "");
  6872. }
  6873. // Only add seconds if minutes and hours are 0
  6874. if (hour == 0 && min == 0 && sec > 0) {
  6875. char temp[5];
  6876. sprintf(temp, " %i", sec);
  6877. time_msg.append(temp);
  6878. time_msg.append(" second");
  6879. time_msg.append((sec > 1) ? "s" : "");
  6880. }
  6881. 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());
  6882. }
  6883. }
  6884. else {
  6885. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6886. }
  6887. }
  6888. else
  6889. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6890. }
  6891. else
  6892. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6893. return 0;
  6894. }
  6895. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6896. if (!lua_interface)
  6897. return 0;
  6898. Spawn* spawn = lua_interface->GetSpawn(state);
  6899. lua_interface->ResetFunctionStack(state);
  6900. if (!spawn) {
  6901. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6902. return 0;
  6903. }
  6904. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6905. return 1;
  6906. }
  6907. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6908. if (!lua_interface)
  6909. return 0;
  6910. Spawn* player = lua_interface->GetSpawn(state);
  6911. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6912. if (!player) {
  6913. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6914. lua_interface->ResetFunctionStack(state);
  6915. return 0;
  6916. }
  6917. if (!player->IsPlayer()) {
  6918. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6919. lua_interface->ResetFunctionStack(state);
  6920. return 0;
  6921. }
  6922. if (!ground) {
  6923. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6924. lua_interface->ResetFunctionStack(state);
  6925. return 0;
  6926. }
  6927. if (!ground->IsGroundSpawn()) {
  6928. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6929. lua_interface->ResetFunctionStack(state);
  6930. return 0;
  6931. }
  6932. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6933. if (!groundspawn_entries) {
  6934. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6935. lua_interface->ResetFunctionStack(state);
  6936. return 0;
  6937. }
  6938. Skill* skill = 0;
  6939. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6940. if (collection_skill == "Collecting")
  6941. skill = ((Player*)player)->GetSkillByName("Gathering");
  6942. else
  6943. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6944. if (!skill) {
  6945. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6946. lua_interface->ResetFunctionStack(state);
  6947. return 0;
  6948. }
  6949. vector<GroundSpawnEntry*>::iterator itr;
  6950. GroundSpawnEntry* entry = 0;
  6951. bool can_harvest = false;
  6952. sint32 min_skill = -1;
  6953. int16 totalSkill = skill->current_val;
  6954. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6955. if(skillID != 0xFFFFFFFF)
  6956. {
  6957. ((Entity*)player)->MStats.lock();
  6958. totalSkill += ((Entity*)player)->stats[skillID];
  6959. ((Entity*)player)->MStats.unlock();
  6960. }
  6961. // first, iterate through groundspawn_entries, discard tables player cannot use
  6962. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6963. {
  6964. entry = *itr;
  6965. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6966. min_skill = entry->min_skill_level;
  6967. // if player lacks skill, skip table
  6968. if (entry->min_skill_level > totalSkill)
  6969. continue;
  6970. // if bonus, but player lacks level, skip table
  6971. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6972. continue;
  6973. can_harvest = true;
  6974. break;
  6975. }
  6976. lua_interface->SetBooleanValue(state, can_harvest);
  6977. // If false, send the message to the client
  6978. if (!can_harvest) {
  6979. Client* client = ((Player*)player)->GetClient();
  6980. if (client) {
  6981. string msg = "You do not have enough skill to ";
  6982. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6983. msg.append("gather");
  6984. else if (collection_skill == "Mining")
  6985. msg.append("mine");
  6986. else if (collection_skill == "Trapping")
  6987. msg.append("trap");
  6988. else if (collection_skill == "Foresting")
  6989. msg.append("forest");
  6990. else if (collection_skill == "Fishing")
  6991. msg.append("catch");
  6992. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6993. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6994. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6995. }
  6996. }
  6997. lua_interface->ResetFunctionStack(state);
  6998. return 1;
  6999. }
  7000. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7001. if (!lua_interface)
  7002. return 0;
  7003. Spawn* player = lua_interface->GetSpawn(state);
  7004. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7005. lua_interface->ResetFunctionStack(state);
  7006. if (!player) {
  7007. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7008. return 0;
  7009. }
  7010. if (!player->IsPlayer()) {
  7011. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7012. return 0;
  7013. }
  7014. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7015. lua_interface->SetBooleanValue(state, ret);
  7016. return 1;
  7017. }
  7018. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7019. // Check to see if we have a valid lua_interface
  7020. if (!lua_interface)
  7021. return 0;
  7022. // Get the spawn that is getting the pet
  7023. Spawn* spawn = lua_interface->GetSpawn(state);
  7024. Spawn* target = lua_interface->GetSpawn(state, 2);
  7025. // Get the DB ID of the pet
  7026. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7027. float x = lua_interface->GetFloatValue(state, 4);
  7028. float y = lua_interface->GetFloatValue(state, 5);
  7029. float z = lua_interface->GetFloatValue(state, 6);
  7030. // Get the spell that this command was called from
  7031. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7032. lua_interface->ResetFunctionStack(state);
  7033. // Check to make sure the spawn pointer is valid
  7034. if (!spawn) {
  7035. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7036. return 0;
  7037. }
  7038. // Check to make sure the spawn is an entity
  7039. if (!spawn->IsEntity()) {
  7040. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7041. return 0;
  7042. }
  7043. if (!target) {
  7044. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7045. return 0;
  7046. }
  7047. if (!target->IsEntity()) {
  7048. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7049. return 0;
  7050. }
  7051. // Check to see if the DB ID for the pet is set
  7052. if (pet_id == 0) {
  7053. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7054. return 0;
  7055. }
  7056. // Check to see if the pointer to the spell is valid
  7057. if (!luaspell) {
  7058. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7059. return 0;
  7060. }
  7061. if(luaspell->resisted) {
  7062. return 0;
  7063. }
  7064. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7065. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7066. if (!pet) {
  7067. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7068. return 0;
  7069. }
  7070. // Check to make sure the pet is an npc
  7071. if (!pet->IsNPC()) {
  7072. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7073. return 0;
  7074. }
  7075. if (x == 0)
  7076. x = spawn->GetX();
  7077. if (y == 0)
  7078. y = spawn->GetY();
  7079. if (z == 0)
  7080. z = spawn->GetZ();
  7081. // Spawn the pet at the same location as the owner
  7082. pet->SetX(x);
  7083. pet->SetY(y);
  7084. pet->SetZ(z);
  7085. pet->SetLocation(spawn->GetLocation());
  7086. pet->SetHeading(spawn->GetHeading());
  7087. spawn->GetZone()->AddSpawn(pet);
  7088. /*
  7089. const char* spawn_script = world.GetSpawnScript(pet_id);
  7090. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7091. spawn->SetSpawnScript(string(spawn_script));
  7092. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7093. }*/
  7094. // Get a random pet name
  7095. string random_pet_name;
  7096. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7097. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  7098. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  7099. // Set the pets name
  7100. pet->SetName(random_pet_name.c_str());
  7101. // Set the level of the pet to the owners level
  7102. pet->SetLevel(spawn->GetLevel());
  7103. // Set the faction of the pet to the same faction as the owner
  7104. pet->SetFactionID(spawn->GetFactionID());
  7105. // Set the spawn as a pet
  7106. pet->SetPet(true);
  7107. // Give a pointer of the owner to the pet
  7108. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7109. // Set the pet type
  7110. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7111. // Set the spell id used to create this pet
  7112. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7113. // Set the spell tier used to create this pet
  7114. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7115. // Set the pets spawn type to 6
  7116. pet->SetSpawnType(6);
  7117. // Set the pets brain
  7118. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7119. // Check to see if the pet has a subtitle
  7120. if (strlen(pet->GetSubTitle()) > 0) {
  7121. // Add the players name to the front of the sub title
  7122. string pet_subtitle;
  7123. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7124. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7125. // Set the pets subtitle to the new one
  7126. pet->SetSubTitle(pet_subtitle.c_str());
  7127. }
  7128. // Set the pet as the return value for this function
  7129. lua_interface->SetSpawnValue(state, pet);
  7130. return 1;
  7131. }
  7132. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7133. if (!lua_interface)
  7134. return 0;
  7135. Spawn* spawn = lua_interface->GetSpawn(state);
  7136. Spawn* player = lua_interface->GetSpawn(state, 2);
  7137. float max_distance = lua_interface->GetFloatValue(state, 3);
  7138. string type = lua_interface->GetStringValue(state, 4);
  7139. lua_interface->ResetFunctionStack(state);
  7140. if (!spawn || (spawn && spawn->IsPlayer())) {
  7141. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7142. return 0;
  7143. }
  7144. if (!player || !player->IsPlayer()) {
  7145. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7146. return 0;
  7147. }
  7148. Client* client = ((Player*)player)->GetClient();
  7149. if (!client) {
  7150. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7151. return 0;
  7152. }
  7153. //Set max_distance to default if not set or not proper value
  7154. if (max_distance <= 0)
  7155. max_distance = 500;
  7156. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7157. if (packet) {
  7158. float unknown2_3 = 0;
  7159. int8 placement_mode = 0;
  7160. if (type == "wall") {
  7161. placement_mode = 2;
  7162. unknown2_3 = 150;
  7163. }
  7164. else if (type == "ceiling")
  7165. placement_mode = 1;
  7166. packet->setDataByName("placement_mode", placement_mode);
  7167. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7168. packet->setDataByName("model_type", spawn->GetModelType());
  7169. packet->setDataByName("unknown", 1); //size
  7170. packet->setDataByName("unknown2", 1); //size 2
  7171. packet->setDataByName("unknown2", .5, 1); //size 3
  7172. packet->setDataByName("unknown2", 3, 2);
  7173. packet->setDataByName("unknown2", unknown2_3, 3);
  7174. packet->setDataByName("max_distance", max_distance);
  7175. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7176. client->QueuePacket(packet->serialize());
  7177. safe_delete(packet);
  7178. }
  7179. return 0;
  7180. }
  7181. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7182. if (!lua_interface)
  7183. return 0;
  7184. Item* item = lua_interface->GetItem(state);
  7185. lua_interface->ResetFunctionStack(state);
  7186. if (!item) {
  7187. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7188. return 0;
  7189. }
  7190. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7191. return 1;
  7192. }
  7193. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7194. if (!lua_interface)
  7195. return 0;
  7196. Item* item = lua_interface->GetItem(state);
  7197. lua_interface->ResetFunctionStack(state);
  7198. if (!item) {
  7199. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7200. return 0;
  7201. }
  7202. lua_interface->SetInt32Value(state, item->effect_type);
  7203. return 1;
  7204. }
  7205. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7206. if (!lua_interface)
  7207. return 0;
  7208. Spawn* spawn = lua_interface->GetSpawn(state);
  7209. lua_interface->ResetFunctionStack(state);
  7210. if (!spawn) {
  7211. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7212. return 0;
  7213. }
  7214. if (spawn->GetZone())
  7215. spawn->GetZone()->AddTransportSpawn(spawn);
  7216. return 0;
  7217. }
  7218. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7219. if (!lua_interface)
  7220. return 0;
  7221. Spawn* spawn = lua_interface->GetSpawn(state);
  7222. lua_interface->ResetFunctionStack(state);
  7223. if (!spawn) {
  7224. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7225. return 0;
  7226. }
  7227. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7228. return 1;
  7229. }
  7230. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7231. if (!lua_interface)
  7232. return 0;
  7233. Skill* skill = lua_interface->GetSkill(state);
  7234. lua_interface->ResetFunctionStack(state);
  7235. if (!skill) {
  7236. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7237. return 0;
  7238. }
  7239. lua_interface->SetInt32Value(state, skill->current_val);
  7240. return 1;
  7241. }
  7242. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7243. if (!lua_interface)
  7244. return 0;
  7245. Skill* skill = lua_interface->GetSkill(state);
  7246. lua_interface->ResetFunctionStack(state);
  7247. if (!skill) {
  7248. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. lua_interface->SetInt32Value(state, skill->max_val);
  7252. return 1;
  7253. }
  7254. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7255. if (!lua_interface)
  7256. return 0;
  7257. Skill* skill = lua_interface->GetSkill(state);
  7258. lua_interface->ResetFunctionStack(state);
  7259. if (!skill) {
  7260. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7261. return 0;
  7262. }
  7263. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7264. return 1;
  7265. }
  7266. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7267. if (!lua_interface)
  7268. return 0;
  7269. Skill* skill = lua_interface->GetSkill(state);
  7270. int16 value = lua_interface->GetInt16Value(state, 2);
  7271. lua_interface->ResetFunctionStack(state);
  7272. if (!skill) {
  7273. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7274. return 0;
  7275. }
  7276. skill->max_val = value;
  7277. if (skill->max_val < skill->current_val)
  7278. skill->current_val = skill->max_val;
  7279. return 0;
  7280. }
  7281. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7282. if (!lua_interface)
  7283. return 0;
  7284. Skill* skill = lua_interface->GetSkill(state);
  7285. int16 value = lua_interface->GetInt16Value(state, 2);
  7286. lua_interface->ResetFunctionStack(state);
  7287. if (!skill) {
  7288. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7289. return 0;
  7290. }
  7291. if (value > skill->max_val)
  7292. skill->current_val = skill->max_val;
  7293. else
  7294. skill->current_val = value;
  7295. return 0;
  7296. }
  7297. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7298. if (!lua_interface)
  7299. return 0;
  7300. Spawn* player = lua_interface->GetSpawn(state);
  7301. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7302. lua_interface->ResetFunctionStack(state);
  7303. if (skill_id > 0 && player && player->IsPlayer()) {
  7304. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7305. return 1;
  7306. }
  7307. return 0;
  7308. }
  7309. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7310. if (!lua_interface)
  7311. return 0;
  7312. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7313. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7314. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7315. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7316. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7317. lua_interface->ResetFunctionStack(state);
  7318. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7319. if (player_spawn && player_spawn->IsPlayer()) {
  7320. Player* player = (Player*)player_spawn;
  7321. bool added = false;
  7322. if (!player->skill_list.HasSkill(skill_id)) {
  7323. player->AddSkill(skill_id, current_val, max_val, true);
  7324. added = true;
  7325. }
  7326. 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
  7327. Client* client = player->GetClient();
  7328. if (client) {
  7329. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7330. if (packet)
  7331. client->QueuePacket(packet);
  7332. }
  7333. }
  7334. if (added) {
  7335. lua_interface->SetBooleanValue(state, true);
  7336. return 1;
  7337. }
  7338. }
  7339. else {
  7340. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7341. }
  7342. }
  7343. else {
  7344. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7345. }
  7346. lua_interface->SetBooleanValue(state, false);
  7347. return 1;
  7348. }
  7349. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7350. if (!lua_interface)
  7351. return 0;
  7352. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7353. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7354. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7355. lua_interface->ResetFunctionStack(state);
  7356. if (skill_id > 0) {
  7357. if (player_spawn && player_spawn->IsPlayer()) {
  7358. Player* player = (Player*)player_spawn;
  7359. if (player->skill_list.HasSkill(skill_id)) {
  7360. player->RemovePlayerSkill(skill_id);
  7361. if (!more_to_remove) {
  7362. Client* client = player->GetClient();
  7363. if (client) {
  7364. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7365. if (packet)
  7366. client->QueuePacket(packet);
  7367. }
  7368. }
  7369. }
  7370. }
  7371. else {
  7372. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7373. }
  7374. }
  7375. else {
  7376. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7377. }
  7378. return 0;
  7379. }
  7380. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7381. if (!lua_interface)
  7382. return 0;
  7383. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7384. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7385. int16 amount = lua_interface->GetInt8Value(state, 3);
  7386. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7387. lua_interface->ResetFunctionStack(state);
  7388. if (amount > 0 && skill_type < 100) {
  7389. if (player_spawn && player_spawn->IsPlayer()) {
  7390. Player* player = (Player*)player_spawn;
  7391. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7392. if (!more_to_increase) {
  7393. Client* client = player->GetClient();
  7394. if (client) {
  7395. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7396. if (packet)
  7397. client->QueuePacket(packet);
  7398. }
  7399. }
  7400. }
  7401. else {
  7402. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7403. }
  7404. }
  7405. else {
  7406. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7407. }
  7408. return 0;
  7409. }
  7410. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7411. if (!lua_interface)
  7412. return 0;
  7413. Spawn* spawn = lua_interface->GetSpawn(state);
  7414. string name = lua_interface->GetStringValue(state, 2);
  7415. lua_interface->ResetFunctionStack(state);
  7416. if (!spawn) {
  7417. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7418. return 0;
  7419. }
  7420. if (!spawn->IsEntity()) {
  7421. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7422. return 0;
  7423. }
  7424. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7425. if (skill) {
  7426. lua_interface->SetSkillValue(state, skill);
  7427. return 1;
  7428. }
  7429. return 0;
  7430. }
  7431. int EQ2Emu_lua_AddProc(lua_State* state) {
  7432. if (!lua_interface)
  7433. return 0;
  7434. Spawn* spawn = lua_interface->GetSpawn(state);
  7435. int8 type = lua_interface->GetInt8Value(state, 2);
  7436. float chance = lua_interface->GetFloatValue(state, 3);
  7437. Item* item = lua_interface->GetItem(state, 4);
  7438. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7439. LuaSpell* spell = 0;
  7440. if (!spawn && (!spell || !use_all_spelltargets)) {
  7441. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7442. return 0;
  7443. }
  7444. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7445. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7446. return 0;
  7447. }
  7448. if (!item)
  7449. spell = lua_interface->GetCurrentSpell(state);
  7450. if (!item && !spell) {
  7451. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7452. return 0;
  7453. }
  7454. if(spell && spell->resisted) {
  7455. return 0;
  7456. }
  7457. if (spell && use_all_spelltargets) {
  7458. Spawn* target;
  7459. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7460. for (int8 i = 0; i < spell->targets.size(); i++) {
  7461. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7462. if (!target || !target->IsEntity())
  7463. continue;
  7464. ((Entity*)target)->AddProc(type, chance, item, spell);
  7465. }
  7466. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7467. }
  7468. else
  7469. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7470. return 0;
  7471. }
  7472. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7473. if (!lua_interface)
  7474. return 0;
  7475. Spawn* spawn = lua_interface->GetSpawn(state);
  7476. Item* item = lua_interface->GetItem(state, 2);
  7477. LuaSpell* spell = 0;
  7478. if (!spawn) {
  7479. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7480. lua_interface->ResetFunctionStack(state);
  7481. return 0;
  7482. }
  7483. if (!spawn->IsEntity()) {
  7484. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7485. lua_interface->ResetFunctionStack(state);
  7486. return 0;
  7487. }
  7488. if (!item)
  7489. spell = lua_interface->GetCurrentSpell(state);
  7490. lua_interface->ResetFunctionStack(state);
  7491. if (!item && !spell) {
  7492. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7493. return 0;
  7494. }
  7495. if (spell) {
  7496. Spawn* target;
  7497. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7498. for (int8 i = 0; i < spell->targets.size(); i++) {
  7499. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7500. if (!target || !target->IsEntity())
  7501. continue;
  7502. ((Entity*)target)->RemoveProc(item, spell);
  7503. }
  7504. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7505. spell->caster->RemoveProc(item, spell);
  7506. }
  7507. else
  7508. ((Entity*)spawn)->RemoveProc(item, spell);
  7509. return 0;
  7510. }
  7511. int EQ2Emu_lua_Knockback(lua_State* state) {
  7512. if (!lua_interface)
  7513. return 0;
  7514. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7515. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7516. int32 duration = lua_interface->GetInt32Value(state, 3);
  7517. float vertical = lua_interface->GetFloatValue(state, 4);
  7518. float horizontal = lua_interface->GetFloatValue(state, 5);
  7519. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7520. lua_interface->ResetFunctionStack(state);
  7521. if (!target_spawn) {
  7522. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7523. return 0;
  7524. }
  7525. if (!spawn) {
  7526. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7527. return 0;
  7528. }
  7529. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7530. Client* client = ((Player*)spawn)->GetClient();
  7531. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7532. if (packet) {
  7533. packet->setDataByName("target_x", target_spawn->GetX());
  7534. packet->setDataByName("target_y", target_spawn->GetY());
  7535. packet->setDataByName("target_z", target_spawn->GetZ());
  7536. packet->setDataByName("vertical_movement", vertical);
  7537. packet->setDataByName("horizontal_movement", horizontal);
  7538. if (use_heading)
  7539. packet->setDataByName("use_player_heading", 1);
  7540. client->QueuePacket(packet->serialize());
  7541. }
  7542. safe_delete(packet);
  7543. }
  7544. return 0;
  7545. }
  7546. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7547. if (!lua_interface)
  7548. return 0;
  7549. Spawn* spawn = lua_interface->GetSpawn(state);
  7550. lua_interface->ResetFunctionStack(state);
  7551. if (!spawn) {
  7552. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7553. return 0;
  7554. }
  7555. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7556. return 1;
  7557. }
  7558. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7559. if (!lua_interface)
  7560. return 0;
  7561. Spawn* caster = lua_interface->GetSpawn(state);
  7562. Spawn* target = lua_interface->GetSpawn(state, 2);
  7563. string name = lua_interface->GetStringValue(state, 3);
  7564. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7565. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7566. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7567. string success_msg = lua_interface->GetStringValue(state, 7);
  7568. string effect_msg = lua_interface->GetStringValue(state, 8);
  7569. lua_interface->ResetFunctionStack(state);
  7570. if (!caster) {
  7571. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7572. return 0;
  7573. }
  7574. if (!caster->IsEntity()) {
  7575. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7576. return 0;
  7577. }
  7578. if (!target) {
  7579. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7580. return 0;
  7581. }
  7582. if (!target->IsEntity()) {
  7583. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7584. return 0;
  7585. }
  7586. if (name.length() == 0) {
  7587. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7588. return 0;
  7589. }
  7590. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7591. return 0;
  7592. }
  7593. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7594. if (!lua_interface)
  7595. return 0;
  7596. string name = lua_interface->GetStringValue(state);
  7597. lua_interface->ResetFunctionStack(state);
  7598. if (name.length() == 0) {
  7599. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7600. return 0;
  7601. }
  7602. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7603. if (!skill) {
  7604. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7605. return 0;
  7606. }
  7607. lua_interface->SetInt32Value(state, skill->skill_id);
  7608. return 1;
  7609. }
  7610. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7611. if (!lua_interface)
  7612. return 0;
  7613. Spawn* spawn = lua_interface->GetSpawn(state);
  7614. lua_interface->ResetFunctionStack(state);
  7615. if (!spawn) {
  7616. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7617. return 0;
  7618. }
  7619. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7620. return 1;
  7621. }
  7622. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7623. if (!lua_interface)
  7624. return 0;
  7625. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7626. lua_interface->ResetFunctionStack(state);
  7627. if (!luaspell) {
  7628. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7629. return 0;
  7630. }
  7631. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7632. return 1;
  7633. }
  7634. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7635. if (!lua_interface)
  7636. return 0;
  7637. Spawn* spawn = lua_interface->GetSpawn(state);
  7638. Spawn* target = lua_interface->GetSpawn(state, 2);
  7639. lua_interface->ResetFunctionStack(state);
  7640. if (!spawn) {
  7641. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7642. return 0;
  7643. }
  7644. if (!spawn->IsEntity()) {
  7645. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7646. return 0;
  7647. }
  7648. if (!target) {
  7649. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7650. return 0;
  7651. }
  7652. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7653. return 1;
  7654. }
  7655. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7656. if (!lua_interface)
  7657. return 0;
  7658. Spawn* spawn = lua_interface->GetSpawn(state);
  7659. Spawn* target = lua_interface->GetSpawn(state, 2);
  7660. lua_interface->ResetFunctionStack(state);
  7661. if (!spawn) {
  7662. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7663. return 0;
  7664. }
  7665. if (!spawn->IsEntity()) {
  7666. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7667. return 0;
  7668. }
  7669. if (!target) {
  7670. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7671. return 0;
  7672. }
  7673. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7674. return 1;
  7675. }
  7676. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7677. if (!lua_interface)
  7678. return 0;
  7679. Item* item = lua_interface->GetItem(state);
  7680. lua_interface->ResetFunctionStack(state);
  7681. if (!item) {
  7682. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7683. return 0;
  7684. }
  7685. lua_interface->SetInt32Value(state, item->details.count);
  7686. return 1;
  7687. }
  7688. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7689. if (!lua_interface)
  7690. return 0;
  7691. Item* item = lua_interface->GetItem(state);
  7692. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7693. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7694. lua_interface->ResetFunctionStack(state);
  7695. if (!item) {
  7696. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7697. return 0;
  7698. }
  7699. if (!owner) {
  7700. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7701. return 0;
  7702. }
  7703. if (!owner->IsPlayer()) {
  7704. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7705. return 0;
  7706. }
  7707. if (item->stack_count < new_count) {
  7708. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7709. return 0;
  7710. }
  7711. if (new_count > 0) {
  7712. item->details.count = new_count;
  7713. item->save_needed = true;
  7714. }
  7715. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7716. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7717. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7718. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7719. else
  7720. {
  7721. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7722. return 0;
  7723. }
  7724. Client* client = ((Player*)owner)->GetClient();
  7725. if (!client)
  7726. return 0;
  7727. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7728. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7729. if (app)
  7730. client->QueuePacket(app);
  7731. return 0;
  7732. }
  7733. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7734. if (!lua_interface)
  7735. return 0;
  7736. int32 time = lua_interface->GetInt32Value(state);
  7737. string function = lua_interface->GetStringValue(state, 2);
  7738. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7739. Spawn* target = lua_interface->GetSpawn(state, 4);
  7740. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7741. lua_interface->ResetFunctionStack(state);
  7742. if (time == 0) {
  7743. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7744. return 0;
  7745. }
  7746. if (function.length() == 0) {
  7747. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7748. return 0;
  7749. }
  7750. if (!spell) {
  7751. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7752. return 0;
  7753. }
  7754. SpellScriptTimer* timer = new SpellScriptTimer;
  7755. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7756. #ifdef WIN32
  7757. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7758. #else
  7759. bzero(timer, sizeof(SpellScriptTimer));
  7760. #endif*/
  7761. timer->caster = 0;
  7762. timer->deleteWhenDone = false;
  7763. timer->target = 0;
  7764. timer->time = Timer::GetCurrentTime2() + time;
  7765. timer->customFunction = function;
  7766. timer->spell = spell;
  7767. if (caster)
  7768. timer->caster = caster->GetID();
  7769. if (target)
  7770. timer->target = target->GetID();
  7771. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7772. return 0;
  7773. }
  7774. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7775. if (!lua_interface)
  7776. return 0;
  7777. float hp_perc = lua_interface->GetFloatValue(state);
  7778. float power_perc = lua_interface->GetFloatValue(state, 2);
  7779. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7780. Spawn* target = lua_interface->GetSpawn(state, 4);
  7781. string heal_name = lua_interface->GetStringValue(state, 5);
  7782. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7783. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7784. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7785. lua_interface->ResetFunctionStack(state);
  7786. if (!spell) {
  7787. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7788. return 0;
  7789. }
  7790. Entity* caster = spell->caster;
  7791. if (!caster) {
  7792. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7793. return 0;
  7794. }
  7795. Client* client = 0;
  7796. PendingResurrection* rez = 0;
  7797. ZoneServer* zone = spell->caster->GetZone();
  7798. if (!target) {
  7799. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7800. if (spell->targets.size() > 0) {
  7801. vector<int32> spell_targets = spell->targets;
  7802. for (int8 i = 0; i < spell_targets.size(); i++) {
  7803. target = zone->GetSpawnByID(spell_targets.at(i));
  7804. if (!target)
  7805. continue;
  7806. if (!target->IsPlayer())
  7807. continue;
  7808. client = ((Player*)target)->GetClient();
  7809. if (!client)
  7810. continue;
  7811. rez = client->GetCurrentRez();
  7812. if (rez->active)
  7813. continue;
  7814. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7815. rez->active = true;
  7816. rez->caster = caster;
  7817. rez->expire_timer = new Timer;
  7818. int32 duration = spell->spell->GetSpellDuration();
  7819. rez->expire_timer->Start(duration * 100);
  7820. rez->hp_perc = hp_perc;
  7821. rez->mp_perc = power_perc;
  7822. rez->range = spell->spell->GetSpellData()->range;
  7823. rez->spell_name = spell->spell->GetName();
  7824. if (heal_name.length() > 0)
  7825. rez->heal_name = heal_name;
  7826. else
  7827. rez->heal_name = rez->spell_name;
  7828. rez->no_calcs = no_calcs;
  7829. rez->crit_mod = crit_mod;
  7830. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7831. if (send_window)
  7832. client->SendResurrectionWindow();
  7833. else {
  7834. target->GetZone()->ResurrectSpawn(target, client);
  7835. rez->should_delete = true;
  7836. }
  7837. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7838. }
  7839. }
  7840. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7841. }
  7842. else {
  7843. if(!target->IsPlayer())
  7844. return 0;
  7845. client = ((Player*)target)->GetClient();
  7846. if (!client)
  7847. return 0;
  7848. rez = client->GetCurrentRez();
  7849. if (rez->active)
  7850. return 0;
  7851. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7852. rez->active = true;
  7853. rez->caster = caster;
  7854. rez->expire_timer = new Timer;
  7855. int32 duration = spell->spell->GetSpellDuration();
  7856. rez->expire_timer->Start(duration * 100);
  7857. rez->hp_perc = hp_perc;
  7858. rez->mp_perc = power_perc;
  7859. rez->range = spell->spell->GetSpellData()->range;
  7860. rez->spell_name = spell->spell->GetName();
  7861. if (heal_name.length() > 0)
  7862. rez->heal_name = heal_name;
  7863. else
  7864. rez->heal_name = rez->spell_name;
  7865. rez->no_calcs = no_calcs;
  7866. rez->crit_mod = crit_mod;
  7867. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7868. if (send_window)
  7869. client->SendResurrectionWindow();
  7870. else {
  7871. target->GetZone()->ResurrectSpawn(target, client);
  7872. rez->should_delete = true;
  7873. }
  7874. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7875. }
  7876. return 0;
  7877. }
  7878. int EQ2Emu_lua_SetVision(lua_State* state) {
  7879. if (!lua_interface)
  7880. return 0;
  7881. Spawn* spawn = lua_interface->GetSpawn(state);
  7882. int8 vision = lua_interface->GetInt8Value(state, 2);
  7883. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7884. lua_interface->ResetFunctionStack(state);
  7885. if (!spawn) {
  7886. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7887. return 0;
  7888. }
  7889. if (!spawn->IsEntity()) {
  7890. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7891. return 0;
  7892. }
  7893. if (spell && spell->targets.size() > 0) {
  7894. ZoneServer* zone = spell->caster->GetZone();
  7895. for (int8 i = 0; i < spell->targets.size(); i++) {
  7896. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7897. if (target && target->IsEntity()) {
  7898. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7899. if (target->IsPlayer())
  7900. ((Player*)target)->SetCharSheetChanged(true);
  7901. }
  7902. }
  7903. }
  7904. else {
  7905. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7906. if (spawn->IsPlayer())
  7907. ((Player*)spawn)->SetCharSheetChanged(true);
  7908. }
  7909. return 0;
  7910. }
  7911. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7912. if (!lua_interface)
  7913. return 0;
  7914. Spawn* spawn = lua_interface->GetSpawn(state);
  7915. float intensity = lua_interface->GetFloatValue(state, 2);
  7916. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7917. lua_interface->ResetFunctionStack(state);
  7918. if (!spawn) {
  7919. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7920. return 0;
  7921. }
  7922. if (!spawn->IsEntity()) {
  7923. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7924. return 0;
  7925. }
  7926. if (spell && spell->targets.size() > 0) {
  7927. ZoneServer* zone = spell->caster->GetZone();
  7928. for (int8 i = 0; i < spell->targets.size(); i++) {
  7929. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7930. if (target && target->IsEntity()) {
  7931. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7932. if (target->IsPlayer())
  7933. ((Player*)target)->SetCharSheetChanged(true);
  7934. }
  7935. }
  7936. }
  7937. else {
  7938. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7939. if (spawn->IsPlayer())
  7940. ((Player*)spawn)->SetCharSheetChanged(true);
  7941. }
  7942. return 0;
  7943. }
  7944. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7945. if (!lua_interface)
  7946. return 0;
  7947. Spawn* spawn = lua_interface->GetSpawn(state);
  7948. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7949. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7950. lua_interface->ResetFunctionStack(state);
  7951. if (!spawn) {
  7952. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7953. return 0;
  7954. }
  7955. if (!spawn->IsEntity()) {
  7956. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7957. return 0;
  7958. }
  7959. if (spell && spell->targets.size() > 0) {
  7960. ZoneServer* zone = spell->caster->GetZone();
  7961. for (int8 i = 0; i < spell->targets.size(); i++) {
  7962. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7963. if (target && target->IsEntity()) {
  7964. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7965. if (target->IsPlayer())
  7966. ((Player*)target)->SetCharSheetChanged(true);
  7967. }
  7968. }
  7969. }
  7970. else {
  7971. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7972. if (spawn->IsPlayer())
  7973. ((Player*)spawn)->SetCharSheetChanged(true);
  7974. }
  7975. return 0;
  7976. }
  7977. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7978. if (!lua_interface)
  7979. return 0;
  7980. Item* item = lua_interface->GetItem(state);
  7981. int8 type = lua_interface->GetInt32Value(state, 2);
  7982. lua_interface->ResetFunctionStack(state);
  7983. if (!item) {
  7984. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7985. return 0;
  7986. }
  7987. if (type == 1)
  7988. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7989. else if (type == 2)
  7990. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7991. return 1;
  7992. }
  7993. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7994. if (!lua_interface)
  7995. return 0;
  7996. Spawn* target = lua_interface->GetSpawn(state);
  7997. float val = lua_interface->GetFloatValue(state, 2);
  7998. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7999. lua_interface->ResetFunctionStack(state);
  8000. // Added from Gangrenous post
  8001. if (spell && spell->resisted)
  8002. return 0;
  8003. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8004. if (val > 1.0f)
  8005. val = 1.0f - (val / 100.0f);
  8006. if (spell && spell->spell && spell->targets.size() > 0) {
  8007. ZoneServer* zone = spell->caster->GetZone();
  8008. for (int32 i = 0; i != spell->targets.size(); i++) {
  8009. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8010. if (spawn && spawn->IsEntity()) {
  8011. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8012. if (spawn->IsPlayer())
  8013. ((Player*)spawn)->SetCharSheetChanged(true);
  8014. }
  8015. }
  8016. }
  8017. else {
  8018. if (target && target->IsEntity()) {
  8019. ((Entity*)target)->SetSpeedMultiplier(val);
  8020. if (target->IsPlayer())
  8021. ((Player*)target)->SetCharSheetChanged(true);
  8022. }
  8023. }
  8024. return 0;
  8025. }
  8026. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8027. if (!lua_interface)
  8028. return 0;
  8029. Spawn* spawn = lua_interface->GetSpawn(state);
  8030. int16 model = lua_interface->GetInt16Value(state, 2);
  8031. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8032. lua_interface->ResetFunctionStack(state);
  8033. if (spell && spell->spell && spell->targets.size() > 0) {
  8034. ZoneServer* zone = spell->caster->GetZone();
  8035. for (int32 i = 0; i < spell->targets.size(); i++) {
  8036. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8037. if (target)
  8038. target->SetIllusionModel(model);
  8039. }
  8040. }
  8041. else {
  8042. if (!spawn) {
  8043. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8044. return 0;
  8045. }
  8046. spawn->SetIllusionModel(model);
  8047. }
  8048. return 0;
  8049. }
  8050. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8051. if (!lua_interface)
  8052. return 0;
  8053. Spawn* spawn = lua_interface->GetSpawn(state);
  8054. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8055. lua_interface->ResetFunctionStack(state);
  8056. if (spell && spell->spell && spell->targets.size() > 0) {
  8057. ZoneServer* zone = spell->caster->GetZone();
  8058. for (int32 i = 0; i < spell->targets.size(); i++) {
  8059. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8060. if (target)
  8061. target->SetIllusionModel(0);
  8062. }
  8063. }
  8064. else {
  8065. if (!spawn) {
  8066. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8067. return 0;
  8068. }
  8069. spawn->SetIllusionModel(0);
  8070. }
  8071. return 0;
  8072. }
  8073. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8074. if (!lua_interface)
  8075. return 0;
  8076. Spawn* caster = lua_interface->GetSpawn(state);
  8077. Spawn* target = lua_interface->GetSpawn(state, 2);
  8078. float chance = lua_interface->GetFloatValue(state, 3);
  8079. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8080. lua_interface->ResetFunctionStack(state);
  8081. if (!caster) {
  8082. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8083. return 0;
  8084. }
  8085. if (!caster->IsEntity()) {
  8086. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8087. return 0;
  8088. }
  8089. if (!target) {
  8090. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8091. return 0;
  8092. }
  8093. if (!target->IsEntity()) {
  8094. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8095. return 0;
  8096. }
  8097. if (chance <= 0) {
  8098. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8099. return 0;
  8100. }
  8101. if (!spell) {
  8102. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8103. return 0;
  8104. }
  8105. if(spell->resisted) {
  8106. return 0;
  8107. }
  8108. if (((Entity*)caster)->GetThreatTransfer()) {
  8109. return 0;
  8110. }
  8111. ThreatTransfer* transfer = new ThreatTransfer;
  8112. transfer->Target = target->GetID();
  8113. transfer->Amount = chance;
  8114. transfer->Spell = spell;
  8115. ((Entity*)caster)->SetThreatTransfer(transfer);
  8116. return 0;
  8117. }
  8118. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8119. if (!lua_interface)
  8120. return 0;
  8121. Spawn* spawn = lua_interface->GetSpawn(state);
  8122. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8123. lua_interface->ResetFunctionStack(state);
  8124. if (!spawn) {
  8125. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8126. return 0;
  8127. }
  8128. if (!spell) {
  8129. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8130. return 0;
  8131. }
  8132. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8133. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8134. if(transfer && transfer->Spell != spell) {
  8135. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8136. return 0;
  8137. }
  8138. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8139. }
  8140. return 0;
  8141. }
  8142. int EQ2Emu_lua_CureByType(lua_State* state) {
  8143. if (!lua_interface)
  8144. return 0;
  8145. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8146. int8 cure_count = lua_interface->GetInt8Value(state);
  8147. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8148. string cure_name = lua_interface->GetStringValue(state, 3);
  8149. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8150. Spawn* target = lua_interface->GetSpawn(state, 5);
  8151. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8152. lua_interface->ResetFunctionStack(state);
  8153. if(spell && spell->resisted) {
  8154. return 0;
  8155. }
  8156. if (target) {
  8157. if (!target->IsEntity()) {
  8158. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8159. return 0;
  8160. }
  8161. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8162. std::string alternate_name = "item";
  8163. if(spell)
  8164. alternate_name = std::string(spell->spell->GetName());
  8165. if(!caster && spell)
  8166. caster = (Spawn*)spell->caster;
  8167. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8168. }
  8169. }
  8170. else {
  8171. ZoneServer* zone = spell->caster->GetZone();
  8172. vector<int32> targets = spell->targets;
  8173. vector<Entity*> targets_to_cure;
  8174. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8175. for (int8 i = 0; i < targets.size(); i++) {
  8176. target = zone->GetSpawnByID(targets.at(i));
  8177. if (!target || !target->IsEntity())
  8178. continue;
  8179. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8180. targets_to_cure.push_back((Entity*)target);
  8181. }
  8182. }
  8183. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8184. vector<Entity*>::iterator itr;
  8185. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8186. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8187. }
  8188. }
  8189. return 0;
  8190. }
  8191. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8192. if (!lua_interface)
  8193. return 0;
  8194. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8195. if (!spell) {
  8196. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8197. lua_interface->ResetFunctionStack(state);
  8198. return 0;
  8199. }
  8200. if(spell->resisted) {
  8201. lua_interface->ResetFunctionStack(state);
  8202. return 0;
  8203. }
  8204. int8 cure_count = lua_interface->GetInt8Value(state);
  8205. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8206. string cure_name = lua_interface->GetStringValue(state, 3);
  8207. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8208. Spawn* target = lua_interface->GetSpawn(state, 5);
  8209. lua_interface->ResetFunctionStack(state);
  8210. if (target) {
  8211. if (!target->IsEntity()) {
  8212. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8213. return 0;
  8214. }
  8215. if (((Entity*)target)->GetDetCount() > 0)
  8216. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8217. }
  8218. else {
  8219. ZoneServer* zone = spell->caster->GetZone();
  8220. vector<int32> targets = spell->targets;
  8221. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8222. for (int8 i = 0; i < targets.size(); i++) {
  8223. target = zone->GetSpawnByID(targets.at(i));
  8224. if (!target || !target->IsEntity())
  8225. continue;
  8226. if (((Entity*)target)->GetDetCount() > 0)
  8227. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8228. }
  8229. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8230. }
  8231. return 0;
  8232. }
  8233. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8234. if (!lua_interface)
  8235. return 0;
  8236. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8237. lua_interface->ResetFunctionStack(state);
  8238. if (!spell) {
  8239. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8240. return 0;
  8241. }
  8242. if (!spell->caster) {
  8243. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8244. return 0;
  8245. }
  8246. if (!spell->caster->GetZone()) {
  8247. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8248. return 0;
  8249. }
  8250. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8251. return 0;
  8252. }
  8253. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8254. if (!lua_interface)
  8255. return 0;
  8256. Spawn* spawn = lua_interface->GetSpawn(state);
  8257. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8258. lua_interface->ResetFunctionStack(state);
  8259. if (!spell) {
  8260. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8261. return 0;
  8262. }
  8263. if (spawn && spawn->IsEntity())
  8264. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8265. else {
  8266. ZoneServer* zone = spell->caster->GetZone();
  8267. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8268. for (int32 i = 0; i < spell->targets.size(); i++) {
  8269. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8270. if (!spawn || !spawn->IsEntity())
  8271. continue;
  8272. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8273. }
  8274. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8275. }
  8276. return 0;
  8277. }
  8278. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8279. if (!lua_interface)
  8280. return 0;
  8281. Spawn* spawn = lua_interface->GetSpawn(state);
  8282. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8283. lua_interface->ResetFunctionStack(state);
  8284. if (!spell) {
  8285. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8286. return 0;
  8287. }
  8288. if (spawn && spawn->IsEntity())
  8289. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8290. else {
  8291. ZoneServer* zone = spell->caster->GetZone();
  8292. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8293. for (int32 i = 0; i < spell->targets.size(); i++) {
  8294. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8295. if (!spawn || !spawn->IsEntity())
  8296. continue;
  8297. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8298. }
  8299. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8300. }
  8301. return 0;
  8302. }
  8303. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8304. if (!lua_interface)
  8305. return 0;
  8306. Spawn* caster = lua_interface->GetSpawn(state);
  8307. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8308. lua_interface->ResetFunctionStack(state);
  8309. if (!caster) {
  8310. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8311. return 0;
  8312. }
  8313. if (!caster->IsPlayer()) {
  8314. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8315. return 0;
  8316. }
  8317. Spawn* target = caster->GetTarget();
  8318. if (!target) {
  8319. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8320. return 0;
  8321. }
  8322. Client* client = ((Player*)caster)->GetClient();
  8323. if (!client) {
  8324. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8328. if (ho) {
  8329. ho->SetTarget(target->GetID());
  8330. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8331. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8332. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8333. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8334. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8335. deque<GroupMemberInfo*>::iterator itr;
  8336. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8337. if (group)
  8338. {
  8339. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8340. deque<GroupMemberInfo*>* members = group->GetMembers();
  8341. for (itr = members->begin(); itr != members->end(); itr++) {
  8342. if ((*itr)->client)
  8343. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8344. }
  8345. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8346. }
  8347. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8348. }
  8349. else
  8350. safe_delete(ho);
  8351. }
  8352. else {
  8353. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8354. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8355. }
  8356. else
  8357. safe_delete(ho);
  8358. }
  8359. }
  8360. return 0;
  8361. }
  8362. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8363. if (!lua_interface)
  8364. return 0;
  8365. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8366. if (!spell) {
  8367. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8368. return 0;
  8369. }
  8370. int16 triggerCount = lua_interface->GetInt16Value(state);
  8371. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8372. if (!triggerCount) {
  8373. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8374. return 0;
  8375. }
  8376. spell->num_triggers = triggerCount;
  8377. spell->had_triggers = true;
  8378. spell->cancel_after_all_triggers = cancel_after_triggers;
  8379. return 0;
  8380. }
  8381. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8382. if (!lua_interface)
  8383. return 0;
  8384. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8385. lua_interface->ResetFunctionStack(state);
  8386. if (!spell) {
  8387. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8388. return 0;
  8389. }
  8390. lua_interface->SetInt32Value(state, spell->num_triggers);
  8391. return 1;
  8392. }
  8393. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8394. if (!lua_interface)
  8395. return 0;
  8396. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8397. if (!spell) {
  8398. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8399. lua_interface->ResetFunctionStack(state);
  8400. return 0;
  8401. }
  8402. int16 remove_count = lua_interface->GetInt16Value(state);
  8403. lua_interface->ResetFunctionStack(state);
  8404. if (!remove_count)
  8405. remove_count = 1;
  8406. if (remove_count >= spell->num_triggers) {
  8407. spell->num_triggers = 0;
  8408. if (spell->cancel_after_all_triggers)
  8409. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8410. }
  8411. else {
  8412. spell->num_triggers -= remove_count;
  8413. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8414. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8415. }
  8416. return 0;
  8417. }
  8418. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8419. if (!lua_interface)
  8420. return 0;
  8421. Spawn* spawn = lua_interface->GetSpawn(state);
  8422. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8423. lua_interface->ResetFunctionStack(state);
  8424. if (!spawn) {
  8425. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8426. return 0;
  8427. }
  8428. if (!copy_spawn) {
  8429. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8430. return 0;
  8431. }
  8432. spawn->CopySpawnAppearance(copy_spawn);
  8433. return 0;
  8434. }
  8435. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8436. Spawn* spawn = lua_interface->GetSpawn(state);
  8437. int8 type = lua_interface->GetInt8Value(state, 2);
  8438. lua_interface->ResetFunctionStack(state);
  8439. if (!spawn) {
  8440. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8441. return 0;
  8442. }
  8443. else if (!spawn->IsEntity()) {
  8444. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8445. return 0;
  8446. }
  8447. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8448. return 1;
  8449. }
  8450. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8451. if (!lua_interface)
  8452. return 0;
  8453. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8454. int8 type = lua_interface->GetInt8Value(state);
  8455. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8456. lua_interface->ResetFunctionStack(state);
  8457. if (!spell) {
  8458. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8459. return 0;
  8460. }
  8461. if(spell->resisted) {
  8462. return 0;
  8463. }
  8464. if (spawn) {
  8465. if (!spawn->IsEntity()) {
  8466. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8467. return 0;
  8468. }
  8469. Entity* entity = ((Entity*)spawn);
  8470. entity->AddImmunity(spell, type);
  8471. }
  8472. else {
  8473. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8474. for (int8 i = 0; i < spell->targets.size(); i++) {
  8475. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8476. if (!spawn || !spawn->IsEntity())
  8477. continue;
  8478. Entity* entity = ((Entity*)spawn);
  8479. entity->AddImmunity(spell, type);
  8480. }
  8481. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8482. }
  8483. return 0;
  8484. }
  8485. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8486. if (!lua_interface)
  8487. return 0;
  8488. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8489. int8 type = lua_interface->GetInt8Value(state);
  8490. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8491. lua_interface->ResetFunctionStack(state);
  8492. if (!spell) {
  8493. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8494. return 0;
  8495. }
  8496. if (spawn) {
  8497. if (!spawn->IsEntity()) {
  8498. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8499. return 0;
  8500. }
  8501. Entity* entity = ((Entity*)spawn);
  8502. entity->RemoveImmunity(spell, type);
  8503. }
  8504. else {
  8505. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8506. for (int8 i = 0; i < spell->targets.size(); i++) {
  8507. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8508. if (!spawn || !spawn->IsEntity())
  8509. continue;
  8510. Entity* entity = ((Entity*)spawn);
  8511. entity->RemoveImmunity(spell, type);
  8512. }
  8513. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8514. }
  8515. return 0;
  8516. }
  8517. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8518. if (!lua_interface)
  8519. return 0;
  8520. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8521. if (!spell) {
  8522. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8523. lua_interface->ResetFunctionStack(state);
  8524. return 0;
  8525. }
  8526. if(spell->resisted) {
  8527. lua_interface->ResetFunctionStack(state);
  8528. return 0;
  8529. }
  8530. float snare = lua_interface->GetFloatValue(state);
  8531. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8532. lua_interface->ResetFunctionStack(state);
  8533. // convert the val to the speed multipler value (100 - val)
  8534. float val = 100.0 - snare;
  8535. val /= 100.0;
  8536. if (spawn) {
  8537. if (!spawn->IsEntity()) {
  8538. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8539. return 0;
  8540. }
  8541. ((Entity*)spawn)->SetSnareValue(spell, val);
  8542. }
  8543. else {
  8544. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8545. for (int8 i = 0; i < spell->targets.size(); i++) {
  8546. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8547. if (!spawn || !spawn->IsEntity())
  8548. continue;
  8549. ((Entity*)spawn)->SetSnareValue(spell, val);
  8550. }
  8551. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8552. }
  8553. return 0;
  8554. }
  8555. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8556. if (!lua_interface)
  8557. return 0;
  8558. Spawn* spawn = lua_interface->GetSpawn(state);
  8559. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8560. lua_interface->ResetFunctionStack(state);
  8561. if (!spawn) {
  8562. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8563. return 0;
  8564. }
  8565. if (race_id == 0) {
  8566. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8567. return 0;
  8568. }
  8569. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8570. return 1;
  8571. }
  8572. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8573. if (!lua_interface)
  8574. return 0;
  8575. Spawn* spawn = lua_interface->GetSpawn(state);
  8576. lua_interface->ResetFunctionStack(state);
  8577. if (!spawn) {
  8578. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8579. return 0;
  8580. }
  8581. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8582. return 1;
  8583. }
  8584. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8585. if (!lua_interface)
  8586. return 0;
  8587. Spawn* spawn = lua_interface->GetSpawn(state);
  8588. lua_interface->ResetFunctionStack(state);
  8589. if (!spawn) {
  8590. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8591. return 0;
  8592. }
  8593. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8594. return 1;
  8595. }
  8596. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8597. if (!lua_interface)
  8598. return 0;
  8599. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8600. lua_interface->ResetFunctionStack(state);
  8601. if (!spell) {
  8602. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8603. return 0;
  8604. }
  8605. lua_interface->SetStringValue(state, spell->spell->GetName());
  8606. return 1;
  8607. }
  8608. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8609. if (!lua_interface)
  8610. return 0;
  8611. Quest* quest = lua_interface->GetQuest(state);
  8612. lua_interface->ResetFunctionStack(state);
  8613. if (!quest) {
  8614. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8615. return 0;
  8616. }
  8617. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8618. return 1;
  8619. }
  8620. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8621. if (!lua_interface)
  8622. return 0;
  8623. Quest* quest = lua_interface->GetQuest(state);
  8624. int32 flags = lua_interface->GetInt32Value(state, 2);
  8625. lua_interface->ResetFunctionStack(state);
  8626. if (!quest) {
  8627. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8628. return 0;
  8629. }
  8630. quest->SetQuestFlags(flags);
  8631. return 0;
  8632. }
  8633. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8634. if (!lua_interface)
  8635. return 0;
  8636. Quest* quest = lua_interface->GetQuest(state);
  8637. Spawn* player = lua_interface->GetSpawn(state, 2);
  8638. int32 step = lua_interface->GetInt32Value(state, 3);
  8639. int32 duration = lua_interface->GetInt32Value(state, 4);
  8640. string action = lua_interface->GetStringValue(state, 5);
  8641. lua_interface->ResetFunctionStack(state);
  8642. if (!quest) {
  8643. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8644. return 0;
  8645. }
  8646. if (!player) {
  8647. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8648. return 0;
  8649. }
  8650. if (!player->IsPlayer()) {
  8651. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8652. return 0;
  8653. }
  8654. if (step == 0) {
  8655. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. if (duration == 0) {
  8659. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8660. return 0;
  8661. }
  8662. if (action.length() == 0) {
  8663. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8664. return 0;
  8665. }
  8666. Client* client = ((Player*)player)->GetClient();
  8667. if (!client) {
  8668. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8669. return 0;
  8670. }
  8671. quest->SetTimerStep(step);
  8672. quest->AddFailedAction(step, action);
  8673. quest->SetStepTimer(duration);
  8674. client->AddQuestTimer(quest->GetQuestID());
  8675. return 0;
  8676. }
  8677. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8678. if (!lua_interface)
  8679. return 0;
  8680. Quest* quest = lua_interface->GetQuest(state);
  8681. Spawn* player = lua_interface->GetSpawn(state, 2);
  8682. lua_interface->ResetFunctionStack(state);
  8683. if (!quest) {
  8684. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8685. return 0;
  8686. }
  8687. if (!player) {
  8688. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8689. return 0;
  8690. }
  8691. if (!player->IsPlayer()) {
  8692. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8693. return 0;
  8694. }
  8695. Client* client = ((Player*)player)->GetClient();
  8696. if (!client) {
  8697. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8698. return 0;
  8699. }
  8700. quest->SetTimerStep(0);
  8701. quest->SetStepTimer(0);
  8702. client->RemoveQuestTimer(quest->GetQuestID());
  8703. return 0;
  8704. }
  8705. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8706. if (!lua_interface)
  8707. return 0;
  8708. Spawn* player = lua_interface->GetSpawn(state);
  8709. Quest* quest = lua_interface->GetQuest(state, 2);
  8710. int32 step = lua_interface->GetInt32Value(state, 3);
  8711. lua_interface->ResetFunctionStack(state);
  8712. if (!player) {
  8713. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8714. return 0;
  8715. }
  8716. if (!player->IsPlayer()) {
  8717. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8718. return 0;
  8719. }
  8720. if (!quest) {
  8721. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8722. return 0;
  8723. }
  8724. if (step == 0) {
  8725. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8726. return 0;
  8727. }
  8728. Client* client = ((Player*)player)->GetClient();
  8729. if (!client) {
  8730. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8731. return 0;
  8732. }
  8733. if (quest->RemoveQuestStep(step, client)) {
  8734. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8735. client->GetCurrentZone()->SendQuestUpdates(client);
  8736. }
  8737. else
  8738. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8739. return 0;
  8740. }
  8741. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8742. if (!lua_interface)
  8743. return 0;
  8744. Quest* quest = lua_interface->GetQuest(state, 1);
  8745. int32 step = lua_interface->GetInt32Value(state, 2);
  8746. string desc = lua_interface->GetStringValue(state, 3);
  8747. string task_group = lua_interface->GetStringValue(state, 4);
  8748. lua_interface->ResetFunctionStack(state);
  8749. if (!quest) {
  8750. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8751. return 0;
  8752. }
  8753. if (step == 0) {
  8754. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8755. return 0;
  8756. }
  8757. QuestStep* quest_step = quest->GetQuestStep(step);
  8758. if (!quest_step) {
  8759. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8760. return 0;
  8761. }
  8762. quest_step->SetStepProgress(0);
  8763. quest_step->SetTaskGroup(task_group);
  8764. quest_step->SetDescription(desc);
  8765. return 0;
  8766. }
  8767. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8768. if (!lua_interface)
  8769. return 0;
  8770. Quest* quest = lua_interface->GetQuest(state);
  8771. int32 step = lua_interface->GetInt32Value(state, 2);
  8772. string action = lua_interface->GetStringValue(state, 3);
  8773. lua_interface->ResetFunctionStack(state);
  8774. if (!quest) {
  8775. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8776. return 0;
  8777. }
  8778. if (step == 0) {
  8779. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8780. return 0;
  8781. }
  8782. if (action.length() == 0) {
  8783. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8784. return 0;
  8785. }
  8786. quest->AddFailedAction(step, action);
  8787. return 0;
  8788. }
  8789. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8790. if (!lua_interface)
  8791. return 0;
  8792. Spawn* player = lua_interface->GetSpawn(state);
  8793. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8794. int32 step = lua_interface->GetInt32Value(state, 3);
  8795. lua_interface->ResetFunctionStack(state);
  8796. if (!player) {
  8797. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8798. return 0;
  8799. }
  8800. if (!player->IsPlayer()) {
  8801. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8802. return 0;
  8803. }
  8804. if (quest_id == 0) {
  8805. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8806. return 0;
  8807. }
  8808. if (step == 0) {
  8809. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8810. return 0;
  8811. }
  8812. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8813. if (!quest) {
  8814. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8815. return 0;
  8816. }
  8817. quest->StepFailed(step);
  8818. return 0;
  8819. }
  8820. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8821. if (!lua_interface)
  8822. return 0;
  8823. Spawn* player = lua_interface->GetSpawn(state);
  8824. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8825. lua_interface->ResetFunctionStack(state);
  8826. if (!player) {
  8827. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8828. return 0;
  8829. }
  8830. if (!player->IsPlayer()) {
  8831. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. if (quest_id == 0) {
  8835. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8836. return 0;
  8837. }
  8838. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8839. if (!quest) {
  8840. lua_interface->SetInt32Value(state, 0);
  8841. return 1;
  8842. }
  8843. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8844. return 1;
  8845. }
  8846. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8847. if (!lua_interface)
  8848. return 0;
  8849. string name = lua_interface->GetStringValue(state);
  8850. string value = lua_interface->GetStringValue(state, 2);
  8851. string comment = lua_interface->GetStringValue(state, 3);
  8852. lua_interface->ResetFunctionStack(state);
  8853. if (name.length() == 0) {
  8854. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8855. return 0;
  8856. }
  8857. if (value.length() == 0) {
  8858. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8859. return 0;
  8860. }
  8861. string varname = string("lua_").append(name);
  8862. Variable* var = variables.FindVariable(varname);
  8863. if (var)
  8864. var->SetValue(value.c_str());
  8865. else {
  8866. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8867. variables.AddVariable(var);
  8868. }
  8869. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8870. return 0;
  8871. }
  8872. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8873. if (!lua_interface)
  8874. return 0;
  8875. string name = lua_interface->GetStringValue(state);
  8876. lua_interface->ResetFunctionStack(state);
  8877. if (name.length() == 0) {
  8878. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8879. return 0;
  8880. }
  8881. string varname = string("lua_").append(name);
  8882. Variable* var = variables.FindVariable(varname);
  8883. if (var)
  8884. lua_interface->SetStringValue(state, var->GetValue());
  8885. else
  8886. lua_interface->SetStringValue(state, "NULL");
  8887. return 1;
  8888. }
  8889. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8890. if (!lua_interface)
  8891. return 0;
  8892. Spawn* player = lua_interface->GetSpawn(state);
  8893. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8894. lua_interface->ResetFunctionStack(state);
  8895. if (!player) {
  8896. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8897. return 0;
  8898. }
  8899. if (!player->IsPlayer()) {
  8900. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8901. return 0;
  8902. }
  8903. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8904. return 1;
  8905. }
  8906. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8907. if (!lua_interface)
  8908. return 0;
  8909. Spawn* player = lua_interface->GetSpawn(state);
  8910. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8911. lua_interface->ResetFunctionStack(state);
  8912. if (!player) {
  8913. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8914. return 0;
  8915. }
  8916. if (!player->IsPlayer()) {
  8917. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8918. return 0;
  8919. }
  8920. Language* language = master_languages_list.GetLanguage(language_id);
  8921. if (language)
  8922. {
  8923. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8924. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8925. }
  8926. return 0;
  8927. }
  8928. int EQ2Emu_lua_IsNight(lua_State* state) {
  8929. if (!lua_interface)
  8930. return 0;
  8931. ZoneServer* zone = lua_interface->GetZone(state);
  8932. lua_interface->ResetFunctionStack(state);
  8933. if (!zone) {
  8934. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8935. return 0;
  8936. }
  8937. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8938. return 1;
  8939. }
  8940. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8941. if (!lua_interface)
  8942. return 0;
  8943. Spawn* spawn = lua_interface->GetSpawn(state);
  8944. lua_interface->ResetFunctionStack(state);
  8945. if (!spawn) {
  8946. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8947. return 0;
  8948. }
  8949. if (!spawn->IsWidget()) {
  8950. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8951. return 0;
  8952. }
  8953. ((Widget*)spawn)->SetMultiFloorLift(true);
  8954. if (spawn->GetZone())
  8955. spawn->GetZone()->AddTransportSpawn(spawn);
  8956. return 0;
  8957. }
  8958. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8959. if (!lua_interface)
  8960. return 0;
  8961. Spawn* player = lua_interface->GetSpawn(state);
  8962. int32 path = lua_interface->GetInt32Value(state, 2);
  8963. lua_interface->ResetFunctionStack(state);
  8964. if (!player) {
  8965. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8966. return 0;
  8967. }
  8968. if (!player->IsPlayer()) {
  8969. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8970. return 0;
  8971. }
  8972. if (path == 0) {
  8973. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8974. return 0;
  8975. }
  8976. Client* client = ((Player*)player)->GetClient();
  8977. if (!client) {
  8978. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8979. return 0;
  8980. }
  8981. client->SendFlightAutoMount(path);
  8982. return 0;
  8983. }
  8984. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8985. if (!lua_interface)
  8986. return 0;
  8987. Spawn* player = lua_interface->GetSpawn(state);
  8988. if (!player) {
  8989. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8990. return 0;
  8991. }
  8992. if (!player->IsPlayer()) {
  8993. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8994. return 0;
  8995. }
  8996. Client* client = ((Player*)player)->GetClient();
  8997. if (!client) {
  8998. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8999. return 0;
  9000. }
  9001. client->EndAutoMount();
  9002. return 0;
  9003. }
  9004. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9005. if (!lua_interface)
  9006. return 0;
  9007. Spawn* player = lua_interface->GetSpawn(state);
  9008. lua_interface->ResetFunctionStack(state);
  9009. if (!player) {
  9010. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9011. return 0;
  9012. }
  9013. if (!player->IsPlayer()) {
  9014. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9015. return 0;
  9016. }
  9017. Client* client = ((Player*)player)->GetClient();
  9018. if (!client) {
  9019. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9020. return 0;
  9021. }
  9022. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9023. return 1;
  9024. }
  9025. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9026. if (!lua_interface)
  9027. return 0;
  9028. Spawn* player = lua_interface->GetSpawn(state);
  9029. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9030. int32 value = lua_interface->GetInt32Value(state, 3);
  9031. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9032. lua_interface->ResetFunctionStack(state);
  9033. if (!player) {
  9034. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9035. return 0;
  9036. }
  9037. if (!player->IsPlayer()) {
  9038. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9039. return 0;
  9040. }
  9041. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9042. return 0;
  9043. }
  9044. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9045. if (!lua_interface)
  9046. return 0;
  9047. Spawn* player = lua_interface->GetSpawn(state);
  9048. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9049. lua_interface->ResetFunctionStack(state);
  9050. if (!player) {
  9051. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9052. return 0;
  9053. }
  9054. if (!player->IsPlayer()) {
  9055. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9056. return 0;
  9057. }
  9058. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9059. if (!hd)
  9060. return 0;
  9061. lua_interface->SetInt32Value(state, hd->Value);
  9062. lua_interface->SetInt32Value(state, hd->Value2);
  9063. return 2;
  9064. }
  9065. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9066. if (!lua_interface)
  9067. return 0;
  9068. Spawn* spawn = lua_interface->GetSpawn(state);
  9069. int32 grid = lua_interface->GetInt32Value(state, 2);
  9070. lua_interface->ResetFunctionStack(state);
  9071. if (!spawn) {
  9072. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9073. return 0;
  9074. }
  9075. if (grid == 0) {
  9076. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9077. return 0;
  9078. }
  9079. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  9080. return 0;
  9081. }
  9082. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9083. if (!lua_interface)
  9084. return 0;
  9085. Spawn* spawn = lua_interface->GetSpawn(state);
  9086. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9087. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9088. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9089. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9090. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9091. lua_interface->ResetFunctionStack(state);
  9092. if (!spawn) {
  9093. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9094. return 0;
  9095. }
  9096. //Add this quest to the list of required quests for this spawn
  9097. spawn->SetRequiredHistory(event_id, value1, value2);
  9098. //If private spawn value set
  9099. if (private_spawn) {
  9100. //Set the spawn to be private when not granted access via history
  9101. spawn->AddAllowAccessSpawn(spawn);
  9102. spawn->SetPrivateQuestSpawn(true);
  9103. }
  9104. //This value will override vis_flags in the vis packet
  9105. if (flag_override > 0)
  9106. spawn->SetQuestsRequiredOverride(flag_override);
  9107. return 0;
  9108. }
  9109. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9110. if (!lua_interface)
  9111. return 0;
  9112. Spawn* player = lua_interface->GetSpawn(state);
  9113. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9114. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9115. lua_interface->ResetFunctionStack(state);
  9116. if (!player) {
  9117. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9118. return 0;
  9119. }
  9120. if (!player->IsPlayer()) {
  9121. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9122. return 0;
  9123. }
  9124. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9125. return 1;
  9126. }
  9127. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9128. if (!lua_interface)
  9129. return 0;
  9130. Spawn* player = lua_interface->GetSpawn(state);
  9131. int8 level = lua_interface->GetInt8Value(state, 2);
  9132. lua_interface->ResetFunctionStack(state);
  9133. if (!player) {
  9134. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9135. return 0;
  9136. }
  9137. if (!player->IsPlayer()) {
  9138. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9139. return 0;
  9140. }
  9141. if (level == 0) {
  9142. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9143. return 0;
  9144. }
  9145. Client* client = ((Player*)player)->GetClient();
  9146. if (!client) {
  9147. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9148. return 0;
  9149. }
  9150. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9151. return 0;
  9152. }
  9153. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9154. if (!lua_interface)
  9155. return 0;
  9156. Spawn* player = lua_interface->GetSpawn(state);
  9157. int32 amount = lua_interface->GetInt32Value(state, 2);
  9158. lua_interface->ResetFunctionStack(state);
  9159. if (!player) {
  9160. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9161. return 0;
  9162. }
  9163. if (!player->IsPlayer()) {
  9164. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9165. return 0;
  9166. }
  9167. if (amount == 0) {
  9168. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9169. return 0;
  9170. }
  9171. ((Player*)player)->AddCoins(amount);
  9172. return 0;
  9173. }
  9174. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9175. if (!lua_interface)
  9176. return 0;
  9177. Spawn* player = lua_interface->GetSpawn(state);
  9178. int32 amount = lua_interface->GetInt32Value(state, 2);
  9179. lua_interface->ResetFunctionStack(state);
  9180. if (!player) {
  9181. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9182. return 0;
  9183. }
  9184. if (!player->IsPlayer()) {
  9185. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9186. return 0;
  9187. }
  9188. if (amount == 0) {
  9189. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9190. return 0;
  9191. }
  9192. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9193. return 1;
  9194. }
  9195. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9196. if (!lua_interface)
  9197. return 0;
  9198. ZoneServer* zone = lua_interface->GetZone(state);
  9199. lua_interface->ResetFunctionStack(state);
  9200. if (!zone) {
  9201. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9202. return 0;
  9203. }
  9204. vector<Entity*> players = zone->GetPlayers();
  9205. if (players.size() == 0)
  9206. return 0;
  9207. lua_createtable(state, players.size(), 0);
  9208. int newTable = lua_gettop(state);
  9209. for (int32 i = 0; i < players.size(); i++) {
  9210. lua_interface->SetSpawnValue(state, players.at(i));
  9211. lua_rawseti(state, newTable, i + 1);
  9212. }
  9213. return 1;
  9214. }
  9215. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9216. if (!lua_interface)
  9217. return 0;
  9218. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9219. if (!zone) {
  9220. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9221. return 0;
  9222. }
  9223. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9224. lua_interface->ResetFunctionStack(state);
  9225. //Map of <placement_id, location_id>
  9226. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9227. map<int32, int32>::iterator itr;
  9228. vector<Spawn*> group;
  9229. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9230. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9231. if (!location) {
  9232. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9233. return 0;
  9234. }
  9235. Spawn* spawn = 0;
  9236. if (location->entities[0]) {
  9237. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9238. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9239. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9240. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9241. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9242. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9243. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9244. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9245. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9246. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9247. if(spawn && spawn->IsOmittedByDBFlag())
  9248. {
  9249. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  9250. safe_delete(spawn);
  9251. continue;
  9252. }
  9253. if (spawn) {
  9254. const char* script = 0;
  9255. for (int x = 0; x < 3; x++) {
  9256. switch (x) {
  9257. case 0:
  9258. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9259. break;
  9260. case 1:
  9261. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9262. break;
  9263. case 2:
  9264. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9265. break;
  9266. }
  9267. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9268. spawn->SetSpawnScript(string(script));
  9269. break;
  9270. }
  9271. }
  9272. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9273. lua_interface->SetSpawnValue(state, spawn);
  9274. group.push_back(spawn);
  9275. }
  9276. else {
  9277. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9278. safe_delete(spawn);
  9279. }
  9280. }
  9281. }
  9282. if (!group.empty()) {
  9283. lua_createtable(state, group.size(), 0);
  9284. int newTable = lua_gettop(state);
  9285. for (int32 i = 0; i < group.size(); i++) {
  9286. lua_interface->SetSpawnValue(state, group[i]);
  9287. lua_rawseti(state, newTable, i + 1);
  9288. }
  9289. }
  9290. else
  9291. lua_pushnil(state);
  9292. return 1;
  9293. }
  9294. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9295. if (!lua_interface)
  9296. return 0;
  9297. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9298. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9299. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9300. lua_interface->ResetFunctionStack(state);
  9301. if (!spawn) {
  9302. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9303. return 0;
  9304. }
  9305. if (anim_id == 0) {
  9306. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9307. return 0;
  9308. }
  9309. if (leeway == 0)
  9310. leeway = 5000;
  9311. spawn->SetSpawnAnim(anim_id);
  9312. spawn->SetSpawnAnimLeeway(leeway);
  9313. return 0;
  9314. }
  9315. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9316. if (!lua_interface)
  9317. return 0;
  9318. Spawn* player = lua_interface->GetSpawn(state);
  9319. lua_interface->ResetFunctionStack(state);
  9320. if (!player || !player->IsPlayer()) {
  9321. return 0;
  9322. }
  9323. Client* client = ((Player*)player)->GetClient();
  9324. if (!client) {
  9325. return 0;
  9326. }
  9327. lua_interface->SetInt32Value(state, client->GetVersion());
  9328. return 1;
  9329. }
  9330. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9331. if (!lua_interface)
  9332. return 0;
  9333. Item* item = lua_interface->GetItem(state);
  9334. lua_interface->ResetFunctionStack(state);
  9335. if (!item) {
  9336. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9337. return 0;
  9338. }
  9339. lua_interface->SetInt32Value(state, item->details.item_id);
  9340. return 1;
  9341. }
  9342. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9343. if (!lua_interface)
  9344. return 0;
  9345. Spawn* spawn = lua_interface->GetSpawn(state);
  9346. lua_interface->ResetFunctionStack(state);
  9347. if (!spawn) {
  9348. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9349. return 0;
  9350. }
  9351. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9352. return 1;
  9353. }
  9354. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9355. if (!lua_interface)
  9356. return 0;
  9357. Spawn* spawn = lua_interface->GetSpawn(state);
  9358. lua_interface->ResetFunctionStack(state);
  9359. if (!spawn) {
  9360. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9361. return 0;
  9362. }
  9363. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9364. return 1;
  9365. }
  9366. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9367. if (!lua_interface)
  9368. return 0;
  9369. Spawn* spawn = lua_interface->GetSpawn(state);
  9370. lua_interface->ResetFunctionStack(state);
  9371. if (!spawn) {
  9372. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9373. return 0;
  9374. }
  9375. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9376. return 1;
  9377. }
  9378. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9379. if (!lua_interface)
  9380. return 0;
  9381. Spawn* spawn = lua_interface->GetSpawn(state);
  9382. lua_interface->ResetFunctionStack(state);
  9383. if (!spawn) {
  9384. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9385. return 0;
  9386. }
  9387. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9388. return 1;
  9389. }
  9390. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9391. if (!lua_interface)
  9392. return 0;
  9393. Spawn* spawn = lua_interface->GetSpawn(state);
  9394. float pct = lua_interface->GetFloatValue(state, 2);
  9395. lua_interface->ResetFunctionStack(state);
  9396. if (!spawn) {
  9397. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9398. return 0;
  9399. }
  9400. if (pct == 0) {
  9401. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9402. return 0;
  9403. }
  9404. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9405. lua_interface->SetInt32Value(state, amount);
  9406. return 1;
  9407. }
  9408. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9409. if (!lua_interface)
  9410. return 0;
  9411. Spawn* spawn = lua_interface->GetSpawn(state);
  9412. float pct = lua_interface->GetFloatValue(state, 2);
  9413. lua_interface->ResetFunctionStack(state);
  9414. if (!spawn) {
  9415. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9416. return 0;
  9417. }
  9418. if (pct == 0) {
  9419. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9420. return 0;
  9421. }
  9422. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9423. lua_interface->SetInt32Value(state, amount);
  9424. return 1;
  9425. }
  9426. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9427. if (!lua_interface)
  9428. return 0;
  9429. Spawn* spawn = lua_interface->GetSpawn(state);
  9430. lua_interface->ResetFunctionStack(state);
  9431. if (!spawn) {
  9432. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9433. return 0;
  9434. }
  9435. if (!spawn->IsPlayer()) {
  9436. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9437. return 0;
  9438. }
  9439. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9440. return 1;
  9441. }
  9442. int EQ2Emu_lua_Evac(lua_State* state) {
  9443. if (!lua_interface)
  9444. return 0;
  9445. Spawn* target = lua_interface->GetSpawn(state);
  9446. if (target) {
  9447. float x = target->GetZone()->GetSafeX();
  9448. float y = target->GetZone()->GetSafeY();
  9449. float z = target->GetZone()->GetSafeZ();
  9450. float h = target->GetZone()->GetSafeHeading();
  9451. target->SetX(x);
  9452. target->SetY(y);
  9453. target->SetZ(z);
  9454. target->SetHeading(h);
  9455. target->SetSpawnOrigX(x);
  9456. target->SetSpawnOrigY(y);
  9457. target->SetSpawnOrigZ(z);
  9458. target->SetSpawnOrigHeading(h);
  9459. if (target->IsPlayer()) {
  9460. Client* client = ((Player*)target)->GetClient();
  9461. if (client) {
  9462. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9463. int numargs = lua_interface->GetNumberOfArgs(state);
  9464. if(numargs == 4) {
  9465. x = lua_interface->GetFloatValue(state,1);
  9466. y = lua_interface->GetFloatValue(state,2);
  9467. z = lua_interface->GetFloatValue(state,3);
  9468. h = lua_interface->GetFloatValue(state,4);
  9469. }
  9470. client->SetReloadingZone(true);
  9471. target->SetX(x);
  9472. target->SetY(y);
  9473. target->SetZ(z);
  9474. target->SetHeading(h);
  9475. target->SetSpawnOrigX(x);
  9476. target->SetSpawnOrigY(y);
  9477. target->SetSpawnOrigZ(z);
  9478. target->SetSpawnOrigHeading(h);
  9479. target->SetAppearancePosition(x,y,z);
  9480. client->SetZoningCoords(x,y,z,h);
  9481. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9482. if (packet)
  9483. {
  9484. packet->setDataByName("x", x);
  9485. packet->setDataByName("y", y);
  9486. packet->setDataByName("z", z);
  9487. client->QueuePacket(packet->serialize());
  9488. safe_delete(packet);
  9489. }
  9490. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9491. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9492. }
  9493. }
  9494. lua_interface->ResetFunctionStack(state);
  9495. }
  9496. else {
  9497. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9498. if(!spell) {
  9499. lua_interface->ResetFunctionStack(state);
  9500. return 0;
  9501. }
  9502. ZoneServer* zone = spell->caster->GetZone();
  9503. float x = spell->caster->GetZone()->GetSafeX();
  9504. float y = spell->caster->GetZone()->GetSafeY();
  9505. float z = spell->caster->GetZone()->GetSafeZ();
  9506. float h = spell->caster->GetZone()->GetSafeHeading();
  9507. int numargs = lua_interface->GetNumberOfArgs(state);
  9508. if(numargs == 4) {
  9509. x = lua_interface->GetFloatValue(state,1);
  9510. y = lua_interface->GetFloatValue(state,2);
  9511. z = lua_interface->GetFloatValue(state,3);
  9512. h = lua_interface->GetFloatValue(state,4);
  9513. }
  9514. lua_interface->ResetFunctionStack(state);
  9515. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9516. for (int32 i = 0; i < spell->targets.size(); i++) {
  9517. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9518. if (!target2)
  9519. continue;
  9520. if (target2->IsPlayer()) {
  9521. Client* client = ((Player*)target2)->GetClient();
  9522. if (client) {
  9523. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9524. client->SetReloadingZone(true);
  9525. target2->SetX(x);
  9526. target2->SetY(y);
  9527. target2->SetZ(z);
  9528. target2->SetHeading(h);
  9529. target2->SetSpawnOrigX(x);
  9530. target2->SetSpawnOrigY(y);
  9531. target2->SetSpawnOrigZ(z);
  9532. target2->SetSpawnOrigHeading(h);
  9533. target2->SetAppearancePosition(x,y,z);
  9534. client->SetZoningCoords(x,y,z,h);
  9535. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9536. if (packet)
  9537. {
  9538. packet->setDataByName("x", x);
  9539. packet->setDataByName("y", y);
  9540. packet->setDataByName("z", z);
  9541. client->QueuePacket(packet->serialize());
  9542. safe_delete(packet);
  9543. }
  9544. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9545. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9546. }
  9547. }
  9548. }
  9549. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9550. }
  9551. return 0;
  9552. }
  9553. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9554. if (!lua_interface)
  9555. return 0;
  9556. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9557. lua_interface->ResetFunctionStack(state);
  9558. if (!luaspell) {
  9559. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9560. return 0;
  9561. }
  9562. int8 tier = luaspell->spell->GetSpellTier();
  9563. lua_interface->SetInt32Value(state, tier);
  9564. return 1;
  9565. }
  9566. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9567. if (!lua_interface)
  9568. return 0;
  9569. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9570. lua_interface->ResetFunctionStack(state);
  9571. if (!luaspell) {
  9572. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9573. return 0;
  9574. }
  9575. int32 spell_id = luaspell->spell->GetSpellID();
  9576. lua_interface->SetInt32Value(state, spell_id);
  9577. return 1;
  9578. }
  9579. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9580. if (!lua_interface)
  9581. return 0;
  9582. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9583. lua_interface->ResetFunctionStack(state);
  9584. if (!spawn) {
  9585. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9586. return 0;
  9587. }
  9588. if (!spawn->IsPlayer()) {
  9589. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9590. return 0;
  9591. }
  9592. ZoneServer* zone = spawn->GetZone();
  9593. if (!zone) {
  9594. return 0;
  9595. }
  9596. Client* client = ((Player*)spawn)->GetClient();
  9597. if (!client) {
  9598. return 0;
  9599. }
  9600. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9601. return 0;
  9602. }
  9603. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9604. if (!lua_interface)
  9605. return 0;
  9606. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9607. lua_interface->ResetFunctionStack(state);
  9608. if (!spawn) {
  9609. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9610. return 0;
  9611. }
  9612. if (!spawn->IsPlayer()) {
  9613. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9614. return 0;
  9615. }
  9616. ZoneServer* zone = spawn->GetZone();
  9617. if (!zone) {
  9618. return 0;
  9619. }
  9620. Client* client = ((Player*)spawn)->GetClient();
  9621. if (!client) {
  9622. return 0;
  9623. }
  9624. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9625. return 0;
  9626. }
  9627. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9628. if (!lua_interface)
  9629. return 0;
  9630. Spawn* caster = lua_interface->GetSpawn(state);
  9631. Spawn* target = lua_interface->GetSpawn(state, 2);
  9632. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9633. string spell_name = lua_interface->GetStringValue(state, 4);
  9634. lua_interface->ResetFunctionStack(state);
  9635. if (!caster) {
  9636. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9637. return 0;
  9638. }
  9639. if (!caster->IsEntity()) {
  9640. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9641. return 0;
  9642. }
  9643. if (!target) {
  9644. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9645. return 0;
  9646. }
  9647. if (!target->IsEntity()) {
  9648. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9649. return 0;
  9650. }
  9651. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9652. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9653. return 0;
  9654. }
  9655. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9656. if (!lua_interface)
  9657. return 0;
  9658. Spawn* player = lua_interface->GetSpawn(state);
  9659. int32 amount = lua_interface->GetInt32Value(state, 2);
  9660. lua_interface->ResetFunctionStack(state);
  9661. if (player && player->IsPlayer() && amount > 0) {
  9662. ((Player*)player)->AddXP(amount);
  9663. }
  9664. return 0;
  9665. }
  9666. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9667. if (!lua_interface)
  9668. return 0;
  9669. Spawn* player = lua_interface->GetSpawn(state);
  9670. int8 type = lua_interface->GetInt8Value(state, 2);
  9671. string text = lua_interface->GetStringValue(state, 3);
  9672. lua_interface->ResetFunctionStack(state);
  9673. Client* client = 0;
  9674. if (player && player->IsPlayer())
  9675. client = ((Player*)player)->GetClient();
  9676. if (!client || text.length() == 0) {
  9677. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9678. return 0;
  9679. }
  9680. client->SimpleMessage(type, text.c_str());
  9681. return 0;
  9682. }
  9683. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9684. if (!lua_interface)
  9685. return 0;
  9686. Spawn* player = lua_interface->GetSpawn(state);
  9687. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9688. lua_interface->ResetFunctionStack(state);
  9689. Client* client = 0;
  9690. if (player && player->IsPlayer())
  9691. client = ((Player*)player)->GetClient();
  9692. if (!client || !spawn) {
  9693. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9694. return 0;
  9695. }
  9696. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9697. if (!items) {
  9698. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9699. return 0;
  9700. }
  9701. client->Loot(spawn->GetLootCoins(), items, spawn);
  9702. return 0;
  9703. }
  9704. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9705. if (!lua_interface)
  9706. return 0;
  9707. Spawn* spawnref = lua_interface->GetSpawn(state);
  9708. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9709. lua_interface->ResetFunctionStack(state);
  9710. if (spawn_id > 0 && spawnref) {
  9711. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9712. if (spawns.size() == 0) {
  9713. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9714. return 0;
  9715. }
  9716. Spawn* spawn = 0;
  9717. int16 index = MakeRandomInt(0, spawns.size());
  9718. if (index >= spawns.size() || index < 0)
  9719. index = 0;
  9720. spawn = spawns[index];
  9721. lua_interface->SetSpawnValue(state, spawn);
  9722. return 1;
  9723. }
  9724. else {
  9725. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9726. }
  9727. return 0;
  9728. }
  9729. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9730. Spawn* player = lua_interface->GetSpawn(state);
  9731. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9732. string name = lua_interface->GetStringValue(state, 3);
  9733. float distance = lua_interface->GetFloatValue(state, 4);
  9734. string command = lua_interface->GetStringValue(state, 5);
  9735. string error_text = lua_interface->GetStringValue(state, 6);
  9736. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9737. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9738. lua_interface->ResetFunctionStack(state);
  9739. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9740. if (distance == 0)
  9741. distance = 10.0f;
  9742. if (command.length() == 0)
  9743. command = name;
  9744. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9745. if (spawns.size() == 0) {
  9746. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9747. return 0;
  9748. }
  9749. Spawn* spawn = 0;
  9750. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9751. spawn = *itr;
  9752. if (spawn) {
  9753. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9754. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9755. }
  9756. }
  9757. }
  9758. return 0;
  9759. }
  9760. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9761. if (!lua_interface)
  9762. return 0;
  9763. Client* client = 0;
  9764. Spawn* player = lua_interface->GetSpawn(state);
  9765. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9766. lua_interface->ResetFunctionStack(state);
  9767. if (player && player->IsPlayer() && player->GetZone())
  9768. client = ((Player*)player)->GetClient();
  9769. else{
  9770. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9771. return 0;
  9772. }
  9773. if (client) {
  9774. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9775. if (packet) {
  9776. packet->setDataByName("goal_num", goal_num);
  9777. client->QueuePacket(packet->serialize());
  9778. safe_delete(packet);
  9779. }
  9780. }
  9781. return 0;
  9782. }
  9783. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9784. if (!lua_interface)
  9785. return 0;
  9786. Client* client = 0;
  9787. Spawn* player = lua_interface->GetSpawn(state);
  9788. lua_interface->ResetFunctionStack(state);
  9789. if (player && player->IsPlayer() && player->GetZone())
  9790. client = ((Player*)player)->GetClient();
  9791. else {
  9792. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9793. return 0;
  9794. }
  9795. if (client) {
  9796. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9797. }
  9798. return 0;
  9799. }
  9800. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9801. if (!lua_interface)
  9802. return 0;
  9803. Client* client = 0;
  9804. Spawn* player = lua_interface->GetSpawn(state);
  9805. float duration = lua_interface->GetFloatValue(state, 2);
  9806. string text = lua_interface->GetStringValue(state, 3);
  9807. string voice = lua_interface->GetStringValue(state, 4);
  9808. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9809. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9810. string signal = lua_interface->GetStringValue(state, 7);
  9811. string goal1 = lua_interface->GetStringValue(state, 8);
  9812. string task1 = lua_interface->GetStringValue(state, 9);
  9813. string goal2 = lua_interface->GetStringValue(state, 10);
  9814. string task2 = lua_interface->GetStringValue(state, 11);
  9815. string goal3 = lua_interface->GetStringValue(state, 12);
  9816. string task3 = lua_interface->GetStringValue(state, 13);
  9817. string goal4 = lua_interface->GetStringValue(state, 14);
  9818. string task4 = lua_interface->GetStringValue(state, 15);
  9819. lua_interface->ResetFunctionStack(state);
  9820. if (!player) {
  9821. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9822. return 0;
  9823. }
  9824. if (!player->IsPlayer()) {
  9825. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9826. return 0;
  9827. }
  9828. else
  9829. client = ((Player*)player)->GetClient();
  9830. if (!client) {
  9831. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9832. return 0;
  9833. }
  9834. if (text.length() == 0) {
  9835. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9836. return 0;
  9837. }
  9838. if (duration >= 0 && duration < 2)
  9839. duration = 2;
  9840. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9841. if (packet) {
  9842. packet->setDataByName("open_seconds_max", duration);
  9843. packet->setDataByName("text", text.c_str());
  9844. packet->setDataByName("voice", voice.c_str());
  9845. int8 num_goals = 1;
  9846. if (task2.length() > 0)
  9847. num_goals++;
  9848. if (task3.length() > 0)
  9849. num_goals++;
  9850. if (task4.length() > 0)
  9851. num_goals++;
  9852. packet->setArrayLengthByName("num_goals", num_goals);
  9853. for (int8 i = 0; i < num_goals; i++) {
  9854. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9855. }
  9856. if (goal1.length() > 0)
  9857. packet->setArrayDataByName("goal_text", goal1.c_str());
  9858. if (goal2.length() > 0)
  9859. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9860. if (goal3.length() > 0)
  9861. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9862. if (goal4.length() > 0)
  9863. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9864. packet->setSubArrayDataByName("task_text", task1.c_str());
  9865. if (task2.length() > 0)
  9866. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9867. if (task3.length() > 0)
  9868. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9869. if (task4.length() > 0)
  9870. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9871. packet->setDataByName("complete_sound", "click");
  9872. packet->setDataByName("signal", signal.c_str());
  9873. packet->setDataByName("voice_key1", voice_key1);
  9874. packet->setDataByName("voice_key2", voice_key2);
  9875. client->QueuePacket(packet->serialize());
  9876. safe_delete(packet);
  9877. }
  9878. return 0;
  9879. }
  9880. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9881. if (!lua_interface)
  9882. return 0;
  9883. Client* client = 0;
  9884. Spawn* player = lua_interface->GetSpawn(state);
  9885. string window = lua_interface->GetStringValue(state, 2);
  9886. int8 show = lua_interface->GetInt8Value(state, 3);
  9887. lua_interface->ResetFunctionStack(state);
  9888. if (!player) {
  9889. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9890. return 0;
  9891. }
  9892. if (!player->IsPlayer()) {
  9893. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9894. return 0;
  9895. }
  9896. else
  9897. client = ((Player*)player)->GetClient();
  9898. if (!client) {
  9899. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9900. return 0;
  9901. }
  9902. if (window.length() == 0) {
  9903. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9904. return 0;
  9905. }
  9906. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9907. if (packet) {
  9908. packet->setDataByName("window", window.c_str());
  9909. packet->setDataByName("show", show);
  9910. client->QueuePacket(packet->serialize());
  9911. safe_delete(packet);
  9912. }
  9913. return 0;
  9914. }
  9915. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9916. //See GameEvents.txt for options that can be used for this function
  9917. if (!lua_interface)
  9918. return 0;
  9919. Client* client = 0;
  9920. Spawn* player = lua_interface->GetSpawn(state);
  9921. string event_name = lua_interface->GetStringValue(state, 2);
  9922. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9923. lua_interface->ResetFunctionStack(state);
  9924. if (!player || !player->IsPlayer()) {
  9925. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9926. return 0;
  9927. }
  9928. client = ((Player*)player)->GetClient();
  9929. if (!client) {
  9930. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9931. return 0;
  9932. }
  9933. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9934. if (packet) {
  9935. packet->setDataByName("event_name", event_name.c_str());
  9936. packet->setDataByName("enabled", enabled);
  9937. client->QueuePacket(packet->serialize());
  9938. safe_delete(packet);
  9939. }
  9940. return 0;
  9941. }
  9942. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9943. if (!lua_interface)
  9944. return 0;
  9945. Spawn* player = lua_interface->GetSpawn(state);
  9946. lua_interface->ResetFunctionStack(state);
  9947. if (player && player->IsPlayer()) {
  9948. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9949. return 1;
  9950. }
  9951. return 0;
  9952. }
  9953. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9954. if (!lua_interface)
  9955. return 0;
  9956. Spawn* player = lua_interface->GetSpawn(state);
  9957. int8 step = lua_interface->GetInt8Value(state, 2);
  9958. lua_interface->ResetFunctionStack(state);
  9959. if (player && player->IsPlayer() && step > 0) {
  9960. ((Player*)player)->SetTutorialStep(step);
  9961. }
  9962. return 0;
  9963. }
  9964. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9965. if (!lua_interface)
  9966. return 0;
  9967. Client* client = 0;
  9968. Spawn* player = lua_interface->GetSpawn(state);
  9969. string window = lua_interface->GetStringValue(state, 2);
  9970. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9971. lua_interface->ResetFunctionStack(state);
  9972. if (!player) {
  9973. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9974. return 0;
  9975. }
  9976. if (!player->IsPlayer()) {
  9977. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9978. return 0;
  9979. }
  9980. else
  9981. client = ((Player*)player)->GetClient();
  9982. if (!client) {
  9983. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9984. return 0;
  9985. }
  9986. if (window.length() == 0) {
  9987. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9988. return 0;
  9989. }
  9990. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9991. if (packet) {
  9992. packet->setDataByName("window", window.c_str());
  9993. packet->setDataByName("flash_seconds", flash_seconds);
  9994. client->QueuePacket(packet->serialize());
  9995. safe_delete(packet);
  9996. }
  9997. return 0;
  9998. }
  9999. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10000. if (!lua_interface)
  10001. return 0;
  10002. Spawn* spawn = lua_interface->GetSpawn(state);
  10003. Spawn* target = lua_interface->GetSpawn(state, 2);
  10004. lua_interface->ResetFunctionStack(state);
  10005. if (spawn && target)
  10006. return spawn->CheckLoS(target);
  10007. return 0;
  10008. }
  10009. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10010. if (!lua_interface)
  10011. return 0;
  10012. Spawn* spawn = lua_interface->GetSpawn(state);
  10013. float x = lua_interface->GetFloatValue(state, 2);
  10014. float y = lua_interface->GetFloatValue(state, 3);
  10015. float z = lua_interface->GetFloatValue(state, 4);
  10016. lua_interface->ResetFunctionStack(state);
  10017. if (spawn)
  10018. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10019. return 0;
  10020. }
  10021. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10022. if (!lua_interface)
  10023. return 0;
  10024. ZoneServer* zone = lua_interface->GetZone(state);
  10025. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10026. lua_interface->ResetFunctionStack(state);
  10027. if (zone)
  10028. zone->SetExpansionFlag(xpackFlag);
  10029. return 0;
  10030. }
  10031. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10032. if (!lua_interface)
  10033. return 0;
  10034. ZoneServer* zone = lua_interface->GetZone(state);
  10035. lua_interface->ResetFunctionStack(state);
  10036. if (zone) {
  10037. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10038. return 1;
  10039. }
  10040. return 0;
  10041. }
  10042. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10043. if (!lua_interface)
  10044. return 0;
  10045. ZoneServer* zone = lua_interface->GetZone(state);
  10046. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10047. lua_interface->ResetFunctionStack(state);
  10048. if (zone)
  10049. zone->SetHolidayFlag(holidayFlag);
  10050. return 0;
  10051. }
  10052. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10053. if (!lua_interface)
  10054. return 0;
  10055. ZoneServer* zone = lua_interface->GetZone(state);
  10056. lua_interface->ResetFunctionStack(state);
  10057. if (zone) {
  10058. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10059. return 1;
  10060. }
  10061. return 0;
  10062. }
  10063. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10064. if (!lua_interface)
  10065. return 0;
  10066. Spawn* player = lua_interface->GetSpawn(state);
  10067. ZoneServer* zone = player->GetZone();
  10068. bool canbind = lua_interface->GetInt32Value(state, 2);
  10069. lua_interface->ResetFunctionStack(state);
  10070. if (zone)
  10071. zone->SetCanBind(canbind);
  10072. return 0;
  10073. }
  10074. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10075. if (!lua_interface)
  10076. return 0;
  10077. Spawn* player = lua_interface->GetSpawn(state);
  10078. ZoneServer* zone = player->GetZone();
  10079. lua_interface->ResetFunctionStack(state);
  10080. if (zone) {
  10081. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10082. return 1;
  10083. }
  10084. return 0;
  10085. }
  10086. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10087. if (!lua_interface)
  10088. return 0;
  10089. Spawn* player = lua_interface->GetSpawn(state);
  10090. ZoneServer* zone = player->GetZone();
  10091. bool cangate = lua_interface->GetInt32Value(state, 2);
  10092. lua_interface->ResetFunctionStack(state);
  10093. if (zone)
  10094. zone->SetCanGate(cangate);
  10095. return 0;
  10096. }
  10097. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10098. if (!lua_interface)
  10099. return 0;
  10100. Spawn* player = lua_interface->GetSpawn(state);
  10101. ZoneServer* zone = player->GetZone();
  10102. lua_interface->ResetFunctionStack(state);
  10103. if (zone) {
  10104. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10105. return 1;
  10106. }
  10107. return 0;
  10108. }
  10109. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10110. if (!lua_interface)
  10111. return 0;
  10112. Spawn* spawn = lua_interface->GetSpawn(state);
  10113. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10114. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10115. float distance = lua_interface->GetFloatValue(state, 4);
  10116. string in_range_function = lua_interface->GetStringValue(state, 5);
  10117. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10118. lua_interface->ResetFunctionStack(state);
  10119. if (spawn && distance > 0 && in_range_function.length() > 0)
  10120. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10121. return 0;
  10122. }
  10123. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10124. if (!lua_interface)
  10125. return 0;
  10126. Spawn* spawn = lua_interface->GetSpawn(state);
  10127. Spawn* target = lua_interface->GetSpawn(state, 2);
  10128. lua_interface->ResetFunctionStack(state);
  10129. if (spawn && target)
  10130. {
  10131. if (spawn->IsPlayer() && target->IsEntity())
  10132. {
  10133. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10134. return 1;
  10135. }
  10136. else if (spawn->IsEntity() && target->IsEntity())
  10137. {
  10138. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10139. return 1;
  10140. }
  10141. }
  10142. return 0;
  10143. }
  10144. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10145. if (!lua_interface)
  10146. return 0;
  10147. Spawn* spawn = lua_interface->GetSpawn(state);
  10148. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10149. lua_interface->ResetFunctionStack(state);
  10150. if (spawn && spawn->IsEntity())
  10151. {
  10152. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10153. if (spawn->IsPlayer())
  10154. {
  10155. Client* client = ((Player*)spawn)->GetClient();
  10156. if (client)
  10157. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10158. }
  10159. }
  10160. return 0;
  10161. }
  10162. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10163. if (!lua_interface)
  10164. return 0;
  10165. Spawn* spawn = lua_interface->GetSpawn(state);
  10166. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10167. lua_interface->ResetFunctionStack(state);
  10168. if (spawn && spawn->IsEntity())
  10169. {
  10170. ((Entity*)spawn)->SetSeeHideSpell(val);
  10171. if (spawn->IsPlayer())
  10172. {
  10173. Client* client = ((Player*)spawn)->GetClient();
  10174. if (client)
  10175. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10176. }
  10177. }
  10178. return 0;
  10179. }
  10180. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10181. {
  10182. if (!lua_interface)
  10183. return 0;
  10184. Spawn* player = lua_interface->GetSpawn(state);
  10185. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10186. string command = lua_interface->GetStringValue(state, 3);
  10187. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10188. lua_interface->ResetFunctionStack(state);
  10189. if (spawn && player && player->IsPlayer())
  10190. {
  10191. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10192. bool res = false;
  10193. if (cmd)
  10194. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10195. lua_interface->SetBooleanValue(state, res);
  10196. return 1;
  10197. }
  10198. return 0;
  10199. }
  10200. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10201. {
  10202. if (!lua_interface)
  10203. return 0;
  10204. Spawn* spawn = lua_interface->GetSpawn(state);
  10205. int32 charID = lua_interface->GetInt32Value(state, 2);
  10206. string command = lua_interface->GetStringValue(state, 3);
  10207. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10208. lua_interface->ResetFunctionStack(state);
  10209. if (spawn && charID)
  10210. {
  10211. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10212. bool res = false;
  10213. if (cmd)
  10214. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10215. lua_interface->SetBooleanValue(state, res);
  10216. return 1;
  10217. }
  10218. return 0;
  10219. }
  10220. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10221. {
  10222. if (!lua_interface)
  10223. return 0;
  10224. Spawn* spawn = lua_interface->GetSpawn(state);
  10225. string command = lua_interface->GetStringValue(state, 2);
  10226. lua_interface->ResetFunctionStack(state);
  10227. if (spawn && command.length() > 0)
  10228. spawn->RemovePrimaryEntityCommand(command.c_str());
  10229. return 0;
  10230. }
  10231. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10232. if (!lua_interface)
  10233. return 0;
  10234. Spawn* spawn = lua_interface->GetSpawn(state);
  10235. float distance = lua_interface->GetFloatValue(state, 2);
  10236. string command = lua_interface->GetStringValue(state, 3);
  10237. Spawn* player = lua_interface->GetSpawn(state, 4);
  10238. lua_interface->ResetFunctionStack(state);
  10239. if (spawn) {
  10240. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10241. }
  10242. return 0;
  10243. }
  10244. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10245. if (!lua_interface)
  10246. return 0;
  10247. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10248. Spawn* spawn = lua_interface->GetSpawn(state);
  10249. Spawn* player = lua_interface->GetSpawn(state, 2);
  10250. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10251. lua_interface->ResetFunctionStack(state);
  10252. if (spawn && player && transport_id && player->IsPlayer()) {
  10253. Client* client = 0;
  10254. if (player && player->IsPlayer())
  10255. client = ((Player*)player)->GetClient();
  10256. if (!client)
  10257. return 0;
  10258. vector<TransportDestination*> destinations;
  10259. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10260. if (destinations.size())
  10261. {
  10262. client->SetTemporaryTransportID(transport_id);
  10263. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10264. }
  10265. else
  10266. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10267. }
  10268. return 0;
  10269. }
  10270. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10271. if (!lua_interface)
  10272. return 0;
  10273. Spawn* player = lua_interface->GetSpawn(state);
  10274. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10275. lua_interface->ResetFunctionStack(state);
  10276. if (player && player->IsPlayer()) {
  10277. Client* client = 0;
  10278. if (player && player->IsPlayer())
  10279. client = ((Player*)player)->GetClient();
  10280. if (!client)
  10281. return 0;
  10282. client->SetTemporaryTransportID(transport_id);
  10283. }
  10284. return 0;
  10285. }
  10286. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10287. if (!lua_interface)
  10288. return 0;
  10289. Spawn* player = lua_interface->GetSpawn(state);
  10290. lua_interface->ResetFunctionStack(state);
  10291. if (player && player->IsPlayer()) {
  10292. Client* client = 0;
  10293. if (player && player->IsPlayer())
  10294. client = ((Player*)player)->GetClient();
  10295. if (!client)
  10296. return 0;
  10297. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10298. return 1;
  10299. }
  10300. return 0;
  10301. }
  10302. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10303. if (!lua_interface)
  10304. return 0;
  10305. Spawn* spawn = lua_interface->GetSpawn(state);
  10306. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10307. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10308. if (!spawn) {
  10309. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10310. return 0;
  10311. }
  10312. if (!spawn->IsEntity()) {
  10313. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10314. return 0;
  10315. }
  10316. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10317. {
  10318. 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);
  10319. return 0;
  10320. }
  10321. lua_interface->ResetFunctionStack(state);
  10322. if (spell && spell->targets.size() > 0) {
  10323. ZoneServer* zone = spell->caster->GetZone();
  10324. for (int8 i = 0; i < spell->targets.size(); i++) {
  10325. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10326. if (target && target->IsEntity()) {
  10327. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10328. if (target->IsPlayer())
  10329. ((Player*)target)->SetCharSheetChanged(true);
  10330. }
  10331. }
  10332. }
  10333. else {
  10334. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10335. if (spawn->IsPlayer())
  10336. ((Player*)spawn)->SetCharSheetChanged(true);
  10337. }
  10338. return 0;
  10339. }
  10340. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10341. if (!lua_interface)
  10342. return 0;
  10343. Spawn* spawn = lua_interface->GetSpawn(state);
  10344. lua_interface->ResetFunctionStack(state);
  10345. if (!spawn) {
  10346. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10347. return 0;
  10348. }
  10349. if (!spawn->IsEntity()) {
  10350. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10351. return 0;
  10352. }
  10353. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10354. return 1;
  10355. }
  10356. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10357. if (!lua_interface)
  10358. return 0;
  10359. int32 spell_id = lua_interface->GetInt32Value(state);
  10360. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10361. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10362. if (spell_id > 0) {
  10363. if (spell_tier == 0)
  10364. spell_tier = 1;
  10365. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10366. LuaSpell* lua_spell = 0;
  10367. if(custom_lua_script.size() > 0)
  10368. {
  10369. // attempt to load the custom script since it isn't already loaded
  10370. // we will re-obtain the lua_spell further below
  10371. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10372. {
  10373. 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());
  10374. lua_interface->LoadLuaSpell(custom_lua_script);
  10375. }
  10376. }
  10377. else
  10378. custom_lua_script = spell->GetSpellData()->lua_script;
  10379. if (!lua_spell && lua_interface)
  10380. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10381. if (!lua_spell)
  10382. {
  10383. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10384. return 0;
  10385. }
  10386. lua_spell->spell = new Spell(spell);
  10387. lua_interface->AddCustomSpell(lua_spell);
  10388. lua_interface->SetSpellValue(state, lua_spell);
  10389. return 1;
  10390. }
  10391. return 0;
  10392. }
  10393. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10394. if (!lua_interface)
  10395. return 0;
  10396. LuaSpell* spell = lua_interface->GetSpell(state);
  10397. string field = lua_interface->GetStringValue(state, 2);
  10398. if (!spell) {
  10399. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10400. return 0;
  10401. }
  10402. if (!spell->spell || !spell->spell->GetSpellData()) {
  10403. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10404. return 0;
  10405. }
  10406. boost::to_lower(field);
  10407. return spell->spell->GetSpellData(state, field);
  10408. }
  10409. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10410. if (!lua_interface)
  10411. return 0;
  10412. LuaSpell* spell = lua_interface->GetSpell(state);
  10413. string field = lua_interface->GetStringValue(state, 2);
  10414. int8 fieldArg = 3; // field value after the initial set
  10415. if (!spell) {
  10416. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10417. return 0;
  10418. }
  10419. if (!spell->spell || !spell->spell->GetSpellData()) {
  10420. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10421. return 0;
  10422. }
  10423. boost::to_lower(field);
  10424. bool valSet = false;
  10425. spell->spell->SetSpellData(state, field, fieldArg);
  10426. return valSet;
  10427. }
  10428. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10429. if (!lua_interface)
  10430. return 0;
  10431. LuaSpell* spell = lua_interface->GetSpell(state);
  10432. int8 idx = lua_interface->GetInt32Value(state, 2);
  10433. if (!spell) {
  10434. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10435. return 0;
  10436. }
  10437. if (!spell->spell || !spell->spell->GetSpellData()) {
  10438. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10439. return 0;
  10440. }
  10441. if (spell->spell->lua_data.size() <= idx)
  10442. {
  10443. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10444. return 0;
  10445. }
  10446. bool setVal = true;
  10447. LUAData* data = spell->spell->lua_data[idx];
  10448. switch (data->type)
  10449. {
  10450. case 0:
  10451. {
  10452. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10453. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10454. data->int_value = value;
  10455. data->int_value2 = value2;
  10456. break;
  10457. }
  10458. case 1:
  10459. {
  10460. float value = lua_interface->GetFloatValue(state, 3);
  10461. float value2 = lua_interface->GetFloatValue(state, 4);
  10462. data->float_value = value;
  10463. data->float_value2 = value2;
  10464. break;
  10465. }
  10466. case 2:
  10467. {
  10468. bool value = lua_interface->GetBooleanValue(state, 3);
  10469. data->bool_value = value;
  10470. break;
  10471. }
  10472. case 3:
  10473. {
  10474. string value = lua_interface->GetStringValue(state, 3);
  10475. string value2 = lua_interface->GetStringValue(state, 4);
  10476. data->string_value = value;
  10477. data->string_value2 = value2;
  10478. break;
  10479. }
  10480. default:
  10481. setVal = false;
  10482. }
  10483. return setVal;
  10484. }
  10485. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10486. if (!lua_interface)
  10487. return 0;
  10488. LuaSpell* spell = lua_interface->GetSpell(state);
  10489. int8 idx = lua_interface->GetInt32Value(state, 2);
  10490. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10491. if (!spell) {
  10492. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10493. return 0;
  10494. }
  10495. if (!spell->spell || !spell->spell->GetSpellData()) {
  10496. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10497. return 0;
  10498. }
  10499. if (spell->spell->lua_data.size() <= idx)
  10500. {
  10501. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10502. return 0;
  10503. }
  10504. bool setVal = true;
  10505. LUAData* data = spell->spell->lua_data[idx];
  10506. switch (data->type)
  10507. {
  10508. case 0:
  10509. {
  10510. if(!secondfield)
  10511. lua_interface->SetSInt32Value(state, data->int_value);
  10512. else
  10513. lua_interface->SetSInt32Value(state, data->int_value2);
  10514. break;
  10515. }
  10516. case 1:
  10517. {
  10518. if (!secondfield)
  10519. lua_interface->SetFloatValue(state, data->float_value);
  10520. else
  10521. lua_interface->SetFloatValue(state, data->float_value2);
  10522. break;
  10523. }
  10524. case 2:
  10525. {
  10526. lua_interface->SetBooleanValue(state, data->bool_value);
  10527. break;
  10528. }
  10529. case 3:
  10530. {
  10531. if (!secondfield)
  10532. lua_interface->SetStringValue(state, data->string_value.c_str());
  10533. else
  10534. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10535. break;
  10536. }
  10537. default:
  10538. setVal = false;
  10539. }
  10540. return setVal;
  10541. }
  10542. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10543. if (!lua_interface)
  10544. return 0;
  10545. LuaSpell* spell = lua_interface->GetSpell(state);
  10546. int8 idx = lua_interface->GetInt32Value(state, 2);
  10547. string field = lua_interface->GetStringValue(state, 3);
  10548. boost::to_lower(field);
  10549. if (!spell) {
  10550. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10551. return 0;
  10552. }
  10553. if (!spell->spell || !spell->spell->GetSpellData()) {
  10554. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10555. return 0;
  10556. }
  10557. if (spell->spell->effects.size() <= idx)
  10558. {
  10559. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10560. return 0;
  10561. }
  10562. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10563. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10564. if (field == "description")
  10565. effect->description = string(lua_interface->GetStringValue(state, 4));
  10566. else if (field == "bullet")
  10567. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10568. else if (field == "percentage")
  10569. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10570. else // no match
  10571. return 0;
  10572. return 1;
  10573. }
  10574. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10575. if (!lua_interface)
  10576. return 0;
  10577. LuaSpell* spell = lua_interface->GetSpell(state);
  10578. int8 idx = lua_interface->GetInt32Value(state, 2);
  10579. string field = lua_interface->GetStringValue(state, 3);
  10580. boost::to_lower(field);
  10581. if (!spell) {
  10582. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10583. return 0;
  10584. }
  10585. if (!spell->spell || !spell->spell->GetSpellData()) {
  10586. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10587. return 0;
  10588. }
  10589. if (spell->spell->effects.size() <= idx)
  10590. {
  10591. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10592. return 0;
  10593. }
  10594. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10595. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10596. if (field == "description")
  10597. lua_interface->SetStringValue(state, effect->description.c_str());
  10598. else if (field == "bullet")
  10599. lua_interface->SetInt32Value(state, effect->subbullet);
  10600. else if (field == "percentage")
  10601. lua_interface->SetInt32Value(state, effect->percentage);
  10602. else // no match
  10603. return 0;
  10604. return 1;
  10605. }
  10606. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10607. if (!lua_interface)
  10608. return 0;
  10609. LuaSpell* spell = lua_interface->GetSpell(state);
  10610. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10611. Spawn* target = lua_interface->GetSpawn(state, 3);
  10612. if (!target) {
  10613. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10614. return 0;
  10615. }
  10616. if (!target->IsEntity()) {
  10617. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10618. return 0;
  10619. }
  10620. if (!spell) {
  10621. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10622. return 0;
  10623. }
  10624. if (caster && !caster->IsEntity()) {
  10625. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10626. return 0;
  10627. }
  10628. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10629. return 0;
  10630. }
  10631. int EQ2Emu_lua_InWater(lua_State* state) {
  10632. if (!lua_interface)
  10633. return 0;
  10634. Spawn* spawn = lua_interface->GetSpawn(state);
  10635. lua_interface->ResetFunctionStack(state);
  10636. if (spawn) {
  10637. lua_interface->SetBooleanValue(state, spawn->InWater());
  10638. return 1;
  10639. }
  10640. return 0;
  10641. }
  10642. int EQ2Emu_lua_InLava(lua_State* state) {
  10643. if (!lua_interface)
  10644. return 0;
  10645. Spawn* spawn = lua_interface->GetSpawn(state);
  10646. lua_interface->ResetFunctionStack(state);
  10647. if (spawn) {
  10648. lua_interface->SetBooleanValue(state, spawn->InLava());
  10649. return 1;
  10650. }
  10651. return 0;
  10652. }
  10653. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10654. if (!lua_interface)
  10655. return 0;
  10656. Spawn* attacker = lua_interface->GetSpawn(state);
  10657. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10658. int8 type = lua_interface->GetInt8Value(state, 3);
  10659. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10660. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10661. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10662. string spell_name = lua_interface->GetStringValue(state, 7);
  10663. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10664. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10665. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10666. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10667. lua_interface->ResetFunctionStack(state);
  10668. if (!attacker) {
  10669. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10670. return 0;
  10671. }
  10672. if (!attacker->IsEntity()) {
  10673. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10674. return 0;
  10675. }
  10676. if (!victim) {
  10677. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10678. return 0;
  10679. }
  10680. if (!victim->IsEntity()) {
  10681. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10682. return 0;
  10683. }
  10684. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10685. return 0;
  10686. }
  10687. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10688. if (!lua_interface)
  10689. return 0;
  10690. Spawn* spawn = lua_interface->GetSpawn(state);
  10691. lua_interface->ResetFunctionStack(state);
  10692. if (spawn) {
  10693. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10694. return 1;
  10695. }
  10696. return 0;
  10697. }
  10698. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10699. if (!lua_interface)
  10700. return 0;
  10701. Spawn* spawn = lua_interface->GetSpawn(state);
  10702. bool invul = lua_interface->GetBooleanValue(state, 2);
  10703. lua_interface->ResetFunctionStack(state);
  10704. if (spawn) {
  10705. spawn->SetInvulnerable(invul);
  10706. }
  10707. return 0;
  10708. }
  10709. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10710. if (!lua_interface)
  10711. return 0;
  10712. string category = lua_interface->GetStringValue(state);
  10713. string name = lua_interface->GetStringValue(state, 2);
  10714. lua_interface->ResetFunctionStack(state);
  10715. Rule *ret = 0;
  10716. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10717. lua_interface->SetBooleanValue(state, ret->GetBool());
  10718. return 1;
  10719. }
  10720. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10721. return 0;
  10722. }
  10723. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10724. if (!lua_interface)
  10725. return 0;
  10726. string category = lua_interface->GetStringValue(state);
  10727. string name = lua_interface->GetStringValue(state, 2);
  10728. lua_interface->ResetFunctionStack(state);
  10729. Rule *ret = 0;
  10730. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10731. lua_interface->SetInt32Value(state, ret->GetInt32());
  10732. return 1;
  10733. }
  10734. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10735. return 0;
  10736. }
  10737. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10738. if (!lua_interface)
  10739. return 0;
  10740. string category = lua_interface->GetStringValue(state);
  10741. string name = lua_interface->GetStringValue(state, 2);
  10742. lua_interface->ResetFunctionStack(state);
  10743. Rule *ret = 0;
  10744. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10745. lua_interface->SetFloatValue(state, ret->GetFloat());
  10746. return 1;
  10747. }
  10748. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10749. return 0;
  10750. }
  10751. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10752. if (!lua_interface)
  10753. return 0;
  10754. Spawn* spawn = lua_interface->GetSpawn(state);
  10755. string type = lua_interface->GetStringValue(state, 2);
  10756. lua_interface->ResetFunctionStack(state);
  10757. if (spawn) {
  10758. int res = 1;
  10759. boost::to_lower(type);
  10760. if(type == "assigned_aa")
  10761. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10762. else if ( type == "unassigned_aa")
  10763. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10764. else if ( type == "assigned_tradeskill_aa")
  10765. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10766. else if ( type == "unassigned_tradeskill_aa")
  10767. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10768. else if ( type == "assigned_prestige_aa")
  10769. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10770. else if ( type == "unassigned_prestige_aa")
  10771. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10772. else if ( type == "assigned_tradeskill_prestige_aa")
  10773. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10774. else if ( type == "unassigned_tradeskill_prestige_aa")
  10775. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10776. else
  10777. res = 0;
  10778. return res;
  10779. }
  10780. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10781. return 0;
  10782. }
  10783. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10784. if (!lua_interface)
  10785. return 0;
  10786. Spawn* spawn = lua_interface->GetSpawn(state);
  10787. string type = lua_interface->GetStringValue(state, 2);
  10788. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10789. lua_interface->ResetFunctionStack(state);
  10790. if (spawn) {
  10791. boost::to_lower(type);
  10792. if(type == "assigned_aa")
  10793. spawn->SetAssignedAA((sint16)value);
  10794. else if ( type == "unassigned_aa")
  10795. spawn->SetUnassignedAA((sint16)value);
  10796. else if ( type == "assigned_tradeskill_aa")
  10797. spawn->SetTradeskillAA((sint16)value);
  10798. else if ( type == "unassigned_tradeskill_aa")
  10799. spawn->SetUnassignedTradeskillAA((sint16)value);
  10800. else if ( type == "assigned_prestige_aa")
  10801. spawn->SetPrestigeAA((sint16)value);
  10802. else if ( type == "unassigned_prestige_aa")
  10803. spawn->SetUnassignedPrestigeAA((sint16)value);
  10804. else if ( type == "assigned_tradeskill_prestige_aa")
  10805. spawn->SetTradeskillPrestigeAA((sint16)value);
  10806. else if ( type == "unassigned_tradeskill_prestige_aa")
  10807. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10808. if(spawn->IsPlayer())
  10809. ((Player*)spawn)->SetCharSheetChanged(true);
  10810. }
  10811. return 0;
  10812. }
  10813. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10814. if (!lua_interface)
  10815. return 0;
  10816. string titleName = lua_interface->GetStringValue(state);
  10817. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10818. lua_interface->ResetFunctionStack(state);
  10819. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10820. lua_interface->SetSInt32Value(state, index);
  10821. return 1;
  10822. }
  10823. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10824. if (!lua_interface)
  10825. return 0;
  10826. Spawn* spawn = lua_interface->GetSpawn(state);
  10827. string titleName = lua_interface->GetStringValue(state, 2);
  10828. lua_interface->ResetFunctionStack(state);
  10829. if(!spawn->IsPlayer())
  10830. {
  10831. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10832. lua_interface->SetSInt32Value(state, -1);
  10833. return 1;
  10834. }
  10835. Player* player = (Player*)spawn;
  10836. // check if player already has the title, don't need to add twice
  10837. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10838. if ( playerHasTitle)
  10839. {
  10840. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10841. return 1;
  10842. }
  10843. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10844. if(!title)
  10845. {
  10846. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10847. lua_interface->SetSInt32Value(state, -1);
  10848. return 1;
  10849. }
  10850. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10851. if(returnIdx < 0)
  10852. {
  10853. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10854. }
  10855. lua_interface->SetSInt32Value(state, returnIdx);
  10856. player->GetClient()->SendTitleUpdate();
  10857. return 1;
  10858. }
  10859. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10860. if (!lua_interface)
  10861. return 0;
  10862. Spawn* spawn = lua_interface->GetSpawn(state);
  10863. string titleName = lua_interface->GetStringValue(state, 2);
  10864. lua_interface->ResetFunctionStack(state);
  10865. if(!spawn->IsPlayer())
  10866. {
  10867. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10868. return 0;
  10869. }
  10870. Player* player = (Player*)spawn;
  10871. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10872. if(!title)
  10873. {
  10874. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10875. return 0;
  10876. }
  10877. if(title->GetPrefix())
  10878. {
  10879. 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());
  10880. return 0;
  10881. }
  10882. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10883. player->GetClient()->SendTitleUpdate();
  10884. return 1;
  10885. }
  10886. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10887. if (!lua_interface)
  10888. return 0;
  10889. Spawn* spawn = lua_interface->GetSpawn(state);
  10890. string titleName = lua_interface->GetStringValue(state, 2);
  10891. lua_interface->ResetFunctionStack(state);
  10892. if(!spawn->IsPlayer())
  10893. {
  10894. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10895. return 0;
  10896. }
  10897. Player* player = (Player*)spawn;
  10898. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10899. if(!title)
  10900. {
  10901. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10902. return 0;
  10903. }
  10904. if(!title->GetPrefix())
  10905. {
  10906. 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());
  10907. return 0;
  10908. }
  10909. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10910. player->GetClient()->SendTitleUpdate();
  10911. return 1;
  10912. }
  10913. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10914. if (!lua_interface)
  10915. return 0;
  10916. Spawn* spawn = lua_interface->GetSpawn(state);
  10917. lua_interface->ResetFunctionStack(state);
  10918. if(!spawn->IsPlayer())
  10919. {
  10920. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10921. return 0;
  10922. }
  10923. Player* player = (Player*)spawn;
  10924. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10925. player->GetClient()->SendTitleUpdate();
  10926. return 1;
  10927. }
  10928. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10929. if (!lua_interface)
  10930. return 0;
  10931. Spawn* spawn = lua_interface->GetSpawn(state);
  10932. lua_interface->ResetFunctionStack(state);
  10933. if(!spawn->IsPlayer())
  10934. {
  10935. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10936. return 0;
  10937. }
  10938. Player* player = (Player*)spawn;
  10939. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10940. player->GetClient()->SendTitleUpdate();
  10941. return 1;
  10942. }
  10943. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10944. if (!lua_interface)
  10945. return 0;
  10946. Spawn* spawn = lua_interface->GetSpawn(state);
  10947. string field = lua_interface->GetStringValue(state, 2);
  10948. lua_interface->ResetFunctionStack(state);
  10949. if(!spawn || !spawn->IsEntity())
  10950. {
  10951. 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));
  10952. return 0;
  10953. }
  10954. Entity* ent = (Entity*)spawn;
  10955. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10956. return 1;
  10957. }
  10958. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10959. if (!lua_interface)
  10960. return 0;
  10961. Spawn* spawn = lua_interface->GetSpawn(state);
  10962. string field = lua_interface->GetStringValue(state, 2);
  10963. lua_interface->ResetFunctionStack(state);
  10964. if(!spawn || !spawn->IsEntity())
  10965. {
  10966. 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));
  10967. return 0;
  10968. }
  10969. Entity* ent = (Entity*)spawn;
  10970. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10971. return 1;
  10972. }
  10973. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10974. if (!lua_interface)
  10975. return 0;
  10976. Spawn* spawn = lua_interface->GetSpawn(state);
  10977. string field = lua_interface->GetStringValue(state, 2);
  10978. lua_interface->ResetFunctionStack(state);
  10979. if(!spawn || !spawn->IsEntity())
  10980. {
  10981. 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));
  10982. return 0;
  10983. }
  10984. Entity* ent = (Entity*)spawn;
  10985. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10986. return 1;
  10987. }
  10988. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10989. if (!lua_interface)
  10990. return 0;
  10991. Spawn* spawn = lua_interface->GetSpawn(state);
  10992. string field = lua_interface->GetStringValue(state, 2);
  10993. lua_interface->ResetFunctionStack(state);
  10994. if(!spawn || !spawn->IsEntity())
  10995. {
  10996. 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));
  10997. return 0;
  10998. }
  10999. Entity* ent = (Entity*)spawn;
  11000. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11001. return 1;
  11002. }
  11003. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11004. if (!lua_interface)
  11005. return 0;
  11006. Spawn* spawn = lua_interface->GetSpawn(state);
  11007. string field = lua_interface->GetStringValue(state, 2);
  11008. string value = lua_interface->GetStringValue(state, 3);
  11009. lua_interface->ResetFunctionStack(state);
  11010. if(!spawn || !spawn->IsEntity())
  11011. {
  11012. 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));
  11013. return 0;
  11014. }
  11015. Entity* ent = (Entity*)spawn;
  11016. bool set_ = ent->SetInfoStructString(field, value);
  11017. lua_interface->SetBooleanValue(state, set_);
  11018. return 1;
  11019. }
  11020. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11021. if (!lua_interface)
  11022. return 0;
  11023. Spawn* spawn = lua_interface->GetSpawn(state);
  11024. string field = lua_interface->GetStringValue(state, 2);
  11025. int64 value = lua_interface->GetInt64Value(state, 3);
  11026. lua_interface->ResetFunctionStack(state);
  11027. if(!spawn || !spawn->IsEntity())
  11028. {
  11029. 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));
  11030. return 0;
  11031. }
  11032. Entity* ent = (Entity*)spawn;
  11033. bool set_ = ent->SetInfoStructUInt(field, value);
  11034. lua_interface->SetBooleanValue(state, set_);
  11035. return 1;
  11036. }
  11037. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11038. if (!lua_interface)
  11039. return 0;
  11040. Spawn* spawn = lua_interface->GetSpawn(state);
  11041. string field = lua_interface->GetStringValue(state, 2);
  11042. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11043. lua_interface->ResetFunctionStack(state);
  11044. if(!spawn || !spawn->IsEntity())
  11045. {
  11046. 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));
  11047. return 0;
  11048. }
  11049. Entity* ent = (Entity*)spawn;
  11050. bool set_ = ent->SetInfoStructSInt(field, value);
  11051. lua_interface->SetBooleanValue(state, set_);
  11052. return 1;
  11053. }
  11054. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11055. if (!lua_interface)
  11056. return 0;
  11057. Spawn* spawn = lua_interface->GetSpawn(state);
  11058. string field = lua_interface->GetStringValue(state, 2);
  11059. float value = lua_interface->GetFloatValue(state, 3);
  11060. lua_interface->ResetFunctionStack(state);
  11061. if(!spawn || !spawn->IsEntity())
  11062. {
  11063. 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));
  11064. return 0;
  11065. }
  11066. Entity* ent = (Entity*)spawn;
  11067. bool set_ = ent->SetInfoStructFloat(field, value);
  11068. lua_interface->SetBooleanValue(state, set_);
  11069. return 1;
  11070. }
  11071. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11072. if (!lua_interface)
  11073. return 0;
  11074. Spawn* spawn = lua_interface->GetSpawn(state);
  11075. bool value = lua_interface->GetBooleanValue(state, 2);
  11076. lua_interface->ResetFunctionStack(state);
  11077. if(!spawn || !spawn->IsPlayer())
  11078. {
  11079. 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));
  11080. return 0;
  11081. }
  11082. ((Player*)spawn)->SetCharSheetChanged(value);
  11083. return 0;
  11084. }
  11085. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11086. if (!lua_interface)
  11087. return 0;
  11088. Spawn* spawn = lua_interface->GetSpawn(state);
  11089. std::string fromName = lua_interface->GetStringValue(state, 2);
  11090. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11091. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11092. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11093. int32 copper = lua_interface->GetInt32Value(state, 6);
  11094. int32 silver = lua_interface->GetInt32Value(state, 7);
  11095. int32 gold = lua_interface->GetInt32Value(state, 8);
  11096. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11097. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11098. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11099. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11100. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11101. lua_interface->ResetFunctionStack(state);
  11102. if(!spawn || !spawn->IsPlayer())
  11103. {
  11104. 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));
  11105. lua_interface->SetBooleanValue(state, false);
  11106. return 1;
  11107. }
  11108. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11109. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11110. lua_interface->SetBooleanValue(state, true);
  11111. return 1;
  11112. }
  11113. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11114. if (!lua_interface)
  11115. return 0;
  11116. int32 char_id = lua_interface->GetInt32Value(state);
  11117. std::string fromName = lua_interface->GetStringValue(state, 2);
  11118. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11119. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11120. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11121. int32 copper = lua_interface->GetInt32Value(state, 6);
  11122. int32 silver = lua_interface->GetInt32Value(state, 7);
  11123. int32 gold = lua_interface->GetInt32Value(state, 8);
  11124. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11125. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11126. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11127. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11128. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11129. lua_interface->ResetFunctionStack(state);
  11130. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11131. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11132. lua_interface->SetBooleanValue(state, true);
  11133. return 1;
  11134. }
  11135. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11136. Spawn* widget;
  11137. if (lua_interface) {
  11138. widget = lua_interface->GetSpawn(state);
  11139. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11140. lua_interface->ResetFunctionStack(state);
  11141. if (widget && widget->IsWidget())
  11142. {
  11143. ((Widget*)widget)->OpenDoor();
  11144. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11145. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11146. }
  11147. else
  11148. 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));
  11149. }
  11150. return 0;
  11151. }
  11152. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11153. Spawn* widget;
  11154. if (lua_interface) {
  11155. widget = lua_interface->GetSpawn(state);
  11156. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11157. lua_interface->ResetFunctionStack(state);
  11158. if (widget && widget->IsWidget())
  11159. {
  11160. ((Widget*)widget)->CloseDoor();
  11161. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11162. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11163. }
  11164. else
  11165. 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));
  11166. }
  11167. return 0;
  11168. }
  11169. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11170. if (!lua_interface)
  11171. return 0;
  11172. Spawn* widget = lua_interface->GetSpawn(state);
  11173. lua_interface->ResetFunctionStack(state);
  11174. if (widget && widget->IsWidget())
  11175. {
  11176. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11177. return 1;
  11178. }
  11179. return 0;
  11180. }
  11181. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11182. if (!lua_interface)
  11183. return 0;
  11184. sint32 min = lua_interface->GetSInt32Value(state);
  11185. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11186. lua_interface->ResetFunctionStack(state);
  11187. sint32 result = MakeRandomInt(min, max);
  11188. lua_interface->SetSInt32Value(state, result);
  11189. return 1;
  11190. }
  11191. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11192. if (!lua_interface)
  11193. return 0;
  11194. float min = lua_interface->GetFloatValue(state);
  11195. float max = lua_interface->GetFloatValue(state, 2);
  11196. lua_interface->ResetFunctionStack(state);
  11197. float result = MakeRandomFloat(min, max);
  11198. lua_interface->SetFloatValue(state, result);
  11199. return 1;
  11200. }
  11201. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11202. if (!lua_interface)
  11203. return 0;
  11204. Spawn* spawn = lua_interface->GetSpawn(state);
  11205. int32 value = lua_interface->GetInt32Value(state, 2);
  11206. lua_interface->ResetFunctionStack(state);
  11207. if(!spawn)
  11208. {
  11209. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11210. lua_interface->SetBooleanValue(state, false);
  11211. return 1;
  11212. }
  11213. spawn->AddIconValue(value);
  11214. lua_interface->SetBooleanValue(state, true);
  11215. return 1;
  11216. }
  11217. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11218. if (!lua_interface)
  11219. return 0;
  11220. Spawn* spawn = lua_interface->GetSpawn(state);
  11221. int32 value = lua_interface->GetInt32Value(state, 2);
  11222. lua_interface->ResetFunctionStack(state);
  11223. if(!spawn)
  11224. {
  11225. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11226. lua_interface->SetBooleanValue(state, false);
  11227. return 1;
  11228. }
  11229. spawn->RemoveIconValue(value);
  11230. lua_interface->SetBooleanValue(state, true);
  11231. return 1;
  11232. }
  11233. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11234. Spawn* npc = lua_interface->GetSpawn(state);
  11235. lua_interface->ResetFunctionStack(state);
  11236. if (npc && npc->IsNPC()) {
  11237. NPC* shard = (NPC*)npc;
  11238. int32 shardid = shard->GetShardID();
  11239. lua_interface->SetInt32Value(state, shardid);
  11240. return 1;
  11241. }
  11242. lua_interface->SetInt32Value(state, 0);
  11243. return 1;
  11244. }
  11245. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11246. Spawn* npc = lua_interface->GetSpawn(state);
  11247. lua_interface->ResetFunctionStack(state);
  11248. if (npc && npc->IsNPC()) {
  11249. NPC* shard = (NPC*)npc;
  11250. int32 charid = shard->GetShardCharID();
  11251. lua_interface->SetInt32Value(state, charid);
  11252. return 1;
  11253. }
  11254. lua_interface->SetInt32Value(state, 0);
  11255. return 1;
  11256. }
  11257. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11258. Spawn* npc = lua_interface->GetSpawn(state);
  11259. lua_interface->ResetFunctionStack(state);
  11260. if (npc && npc->IsNPC()) {
  11261. NPC* shard = (NPC*)npc;
  11262. int64 timestamp = shard->GetShardCreatedTimestamp();
  11263. lua_interface->SetSInt64Value(state, timestamp);
  11264. return 1;
  11265. }
  11266. lua_interface->SetSInt64Value(state, 0);
  11267. return 1;
  11268. }
  11269. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11270. if (!lua_interface)
  11271. return 0;
  11272. int32 shardid = lua_interface->GetInt32Value(state);
  11273. lua_interface->ResetFunctionStack(state);
  11274. if(shardid < 1)
  11275. lua_interface->SetBooleanValue(state, false);
  11276. else
  11277. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11278. return 1;
  11279. }
  11280. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11281. if (!lua_interface)
  11282. return 0;
  11283. Spawn* spawn = lua_interface->GetSpawn(state);
  11284. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11285. if (spawn) {
  11286. spawn->PauseMovement(delay_in_ms);
  11287. }
  11288. lua_interface->ResetFunctionStack(state);
  11289. return 0;
  11290. }
  11291. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11292. if (!lua_interface)
  11293. return 0;
  11294. Spawn* spawn = lua_interface->GetSpawn(state);
  11295. if (spawn) {
  11296. spawn->StopMovement();
  11297. }
  11298. lua_interface->ResetFunctionStack(state);
  11299. return 0;
  11300. }
  11301. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11302. Player* player = (Player*)lua_interface->GetSpawn(state);
  11303. int8 level = lua_interface->GetInt8Value(state, 2);
  11304. lua_interface->ResetFunctionStack(state);
  11305. if (player && player->IsPlayer() && level > 0) {
  11306. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11307. return 1;
  11308. }
  11309. return 0;
  11310. }
  11311. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11312. Player* player = (Player*)lua_interface->GetSpawn(state);
  11313. int8 level = lua_interface->GetInt8Value(state, 2);
  11314. lua_interface->ResetFunctionStack(state);
  11315. if (player && player->IsPlayer() && level > 0) {
  11316. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11317. return 1;
  11318. }
  11319. return 0;
  11320. }
  11321. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11322. ZoneServer* zone = lua_interface->GetZone(state);
  11323. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11324. lua_interface->ResetFunctionStack(state);
  11325. if (zone) {
  11326. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11327. if (spawn) {
  11328. lua_interface->SetSpawnValue(state, spawn);
  11329. return 1;
  11330. }
  11331. }
  11332. return 0;
  11333. }
  11334. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11335. if (!lua_interface)
  11336. return 0;
  11337. Spawn* spawn = lua_interface->GetSpawn(state);
  11338. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11339. lua_interface->ResetFunctionStack(state);
  11340. bool res = false;
  11341. if(spawn && spawn->IsTransportSpawn())
  11342. {
  11343. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11344. spawn->SetRailID(rail_id);
  11345. res = true;
  11346. }
  11347. else if (!spawn) {
  11348. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11349. }
  11350. else if(!spawn->IsTransportSpawn()) {
  11351. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  11352. }
  11353. lua_interface->SetBooleanValue(state, res);
  11354. return 1;
  11355. }
  11356. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11357. if (!lua_interface)
  11358. return 0;
  11359. ZoneServer* zone = lua_interface->GetZone(state);
  11360. lua_interface->ResetFunctionStack(state);
  11361. if (zone) {
  11362. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11363. return 1;
  11364. }
  11365. return 0;
  11366. }
  11367. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11368. if (!lua_interface)
  11369. return 0;
  11370. Spawn* spawn = lua_interface->GetSpawn(state);
  11371. lua_interface->ResetFunctionStack(state);
  11372. if (spawn) {
  11373. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11374. return 1;
  11375. }
  11376. return 0;
  11377. }
  11378. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11379. if (!lua_interface)
  11380. return 0;
  11381. Spawn* player = lua_interface->GetSpawn(state);
  11382. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11383. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11384. lua_interface->ResetFunctionStack(state);
  11385. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11386. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11387. }
  11388. else if(!zoneID) {
  11389. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11390. }
  11391. else
  11392. {
  11393. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11394. return 1;
  11395. }
  11396. return 0;
  11397. }
  11398. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11399. if (!lua_interface)
  11400. return 0;
  11401. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11402. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11403. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11404. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11405. lua_interface->ResetFunctionStack(state);
  11406. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11407. world.GetWorldTimeStruct()->year = newYear;
  11408. world.GetWorldTimeStruct()->month = newMonth;
  11409. world.GetWorldTimeStruct()->hour = newHour;
  11410. world.GetWorldTimeStruct()->minute = newMinute;
  11411. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11412. return 0;
  11413. }
  11414. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11415. if (!lua_interface)
  11416. return 0;
  11417. lua_interface->ResetFunctionStack(state);
  11418. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11419. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11420. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11421. return 1;
  11422. }
  11423. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11424. if (!lua_interface)
  11425. return 0;
  11426. lua_interface->ResetFunctionStack(state);
  11427. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11428. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11429. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11430. return 1;
  11431. }
  11432. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11433. if (!lua_interface)
  11434. return 0;
  11435. lua_interface->ResetFunctionStack(state);
  11436. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11437. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11438. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11439. return 1;
  11440. }
  11441. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11442. if (!lua_interface)
  11443. return 0;
  11444. lua_interface->ResetFunctionStack(state);
  11445. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11446. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11447. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11448. return 1;
  11449. }
  11450. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11451. if (!lua_interface)
  11452. return 0;
  11453. lua_interface->ResetFunctionStack(state);
  11454. world.SendTimeUpdate();
  11455. return 0;
  11456. }
  11457. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11458. bool update_result = false;
  11459. Faction* faction = 0;
  11460. Spawn* spawn = lua_interface->GetSpawn(state);
  11461. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11462. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11463. lua_interface->ResetFunctionStack(state);
  11464. if(!spawn || !spawn->IsPlayer()) {
  11465. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11466. return 0;
  11467. }
  11468. Player* player = (Player*)spawn;
  11469. Client* client = player->GetClient();
  11470. if (faction_id > 0) {
  11471. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11472. if(hasfaction == 0) {
  11473. //they do not have the faction. Lets get the default value and feed it in.
  11474. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11475. //add the default faction for the player.
  11476. player->SetFactionValue(faction_id, defaultfaction);
  11477. }
  11478. if(increase >= 0) {
  11479. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11480. faction = master_faction_list.GetFaction(faction_id);
  11481. if(faction && update_result)
  11482. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11483. else if(faction)
  11484. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11485. lua_interface->SetBooleanValue(state, true);
  11486. return 1;
  11487. }
  11488. if(increase < 0){
  11489. //change the negative to a positive, since thats how decreasefaction() likes it.
  11490. increase *= -1;
  11491. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11492. faction = master_faction_list.GetFaction(faction_id);
  11493. if(faction && update_result)
  11494. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11495. else if(faction)
  11496. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11497. lua_interface->SetBooleanValue(state, true);
  11498. return 1;
  11499. }
  11500. }
  11501. lua_interface->SetBooleanValue(state, false);
  11502. return 1;
  11503. }
  11504. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11505. bool hascoin = 0;
  11506. Player* player = (Player*)lua_interface->GetSpawn(state);
  11507. int32 coins = lua_interface->GetInt32Value(state, 2);
  11508. lua_interface->ResetFunctionStack(state);
  11509. if (player && player->IsPlayer()) {
  11510. hascoin = player->HasCoins(coins);
  11511. if(hascoin == 0) {
  11512. lua_interface->SetBooleanValue(state, false);
  11513. return 1;
  11514. }
  11515. if(hascoin == 1) {
  11516. lua_interface->SetBooleanValue(state, true);
  11517. return 1;
  11518. }
  11519. }
  11520. return 0;
  11521. }
  11522. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11523. int32 loot_tier = 0;
  11524. Spawn* spawn = lua_interface->GetSpawn(state);
  11525. lua_interface->ResetFunctionStack(state);
  11526. if (spawn) {
  11527. loot_tier = spawn->GetLootTier();
  11528. lua_interface->SetInt32Value(state, loot_tier);
  11529. return 1;
  11530. }
  11531. return 0;
  11532. }
  11533. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11534. if (!lua_interface)
  11535. return 0;
  11536. Spawn* spawn = lua_interface->GetSpawn(state);
  11537. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11538. lua_interface->ResetFunctionStack(state);
  11539. if (spawn) {
  11540. spawn->SetLootTier(loot_tier);
  11541. lua_interface->SetBooleanValue(state, true);
  11542. return 1;
  11543. }
  11544. lua_interface->SetBooleanValue(state, false);
  11545. return 1;
  11546. }
  11547. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11548. int32 loot_drop_type = 0;
  11549. Spawn* spawn = lua_interface->GetSpawn(state);
  11550. lua_interface->ResetFunctionStack(state);
  11551. if (spawn) {
  11552. loot_drop_type = spawn->GetLootDropType();
  11553. lua_interface->SetInt32Value(state, loot_drop_type);
  11554. return 1;
  11555. }
  11556. return 0;
  11557. }
  11558. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11559. if (!lua_interface)
  11560. return 0;
  11561. Spawn* spawn = lua_interface->GetSpawn(state);
  11562. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11563. lua_interface->ResetFunctionStack(state);
  11564. if (spawn) {
  11565. spawn->SetLootDropType(loot_drop_type);
  11566. lua_interface->SetBooleanValue(state, true);
  11567. return 1;
  11568. }
  11569. lua_interface->SetBooleanValue(state, false);
  11570. return 1;
  11571. }
  11572. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11573. if (!lua_interface)
  11574. return 0;
  11575. Spawn* spawn = lua_interface->GetSpawn(state);
  11576. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11577. if(damage_amount > 100) {
  11578. damage_amount = 100;
  11579. }
  11580. if (!spawn) {
  11581. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11582. return 0;
  11583. }
  11584. if (spawn->IsPlayer()) {
  11585. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11586. lua_interface->SetBooleanValue(state, true);
  11587. else
  11588. lua_interface->SetBooleanValue(state, false);
  11589. }
  11590. else {
  11591. lua_interface->SetBooleanValue(state, false);
  11592. }
  11593. return 1;
  11594. }
  11595. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11596. ZoneServer* zone = lua_interface->GetZone(state);
  11597. int32 version = lua_interface->GetInt32Value(state, 2);
  11598. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11599. if(region_map == nullptr) {
  11600. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11601. return 0;
  11602. }
  11603. string region_name = lua_interface->GetStringValue(state, 3);
  11604. string env_name = lua_interface->GetStringValue(state, 4);
  11605. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11606. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11607. float dist = lua_interface->GetFloatValue(state, 7);
  11608. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11609. lua_interface->ResetFunctionStack(state);
  11610. lua_interface->SetBooleanValue(state, true);
  11611. return 1;
  11612. }
  11613. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11614. ZoneServer* zone = lua_interface->GetZone(state);
  11615. int32 version = lua_interface->GetInt32Value(state, 2);
  11616. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11617. if(region_map == nullptr) {
  11618. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11619. return 0;
  11620. }
  11621. string region_name = lua_interface->GetStringValue(state, 3);
  11622. region_map->RemoveRegionNode(region_name);
  11623. lua_interface->ResetFunctionStack(state);
  11624. lua_interface->SetBooleanValue(state, true);
  11625. return 1;
  11626. }
  11627. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11628. Client* client = nullptr;
  11629. Spawn* player = lua_interface->GetSpawn(state);
  11630. if (!player) {
  11631. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11632. lua_interface->SetBooleanValue(state, false);
  11633. return 1;
  11634. }
  11635. if (!player->IsPlayer()) {
  11636. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11637. lua_interface->SetBooleanValue(state, false);
  11638. return 1;
  11639. }
  11640. client = player->GetClient();
  11641. if (!client) {
  11642. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11643. lua_interface->SetBooleanValue(state, false);
  11644. return 1;
  11645. }
  11646. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11647. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11648. lua_interface->ResetFunctionStack(state);
  11649. lua_interface->SetBooleanValue(state, success_sight);
  11650. return 1;
  11651. }
  11652. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11653. if (!lua_interface)
  11654. return 0;
  11655. bool result = false;
  11656. Spawn* spawn = lua_interface->GetSpawn(state);
  11657. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11658. lua_interface->ResetFunctionStack(state);
  11659. if (!spawn)
  11660. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11661. else if (!spawn->IsNPC())
  11662. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11663. else
  11664. {
  11665. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11666. result = true;
  11667. }
  11668. lua_interface->SetBooleanValue(state, result);
  11669. return 1;
  11670. }
  11671. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11672. if (!lua_interface)
  11673. return 0;
  11674. bool result = false;
  11675. Spawn* spawn = lua_interface->GetSpawn(state);
  11676. lua_interface->ResetFunctionStack(state);
  11677. if (!spawn)
  11678. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11679. else if (!spawn->IsNPC())
  11680. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11681. else
  11682. {
  11683. if(((NPC*)spawn)->cast_on_aggro_completed)
  11684. result = true;
  11685. }
  11686. lua_interface->SetBooleanValue(state, result);
  11687. return 1;
  11688. }